Skip to content

Commit 4193589

Browse files
chore: integrate pre-commit (#1117)
* integrate pre-commit * run isort with profile black * run Trim Trailing Whitespace * run end-of-file-fixer * fix flake8 F401: import not used error * fix flake8 F841: local variable assigned to but never used error * fix flake8 F541: f-string is missing placeholders error * make isort black compatible * run black compatible isort * fix E712: comparison to True should be 'if cond:' error * fix E266: too many leading '#' error * fix F403: 'import *' used error * fix E402: module level import not at top of file error * remove ignored errors from .flake8 * document pre-commit and isort * ignore W503, E501 & C901 * Update README.md * Update README.md * don't remove migrate
1 parent 2b294ca commit 4193589

File tree

128 files changed

+435
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+435
-324
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[run]
2-
omit =
2+
omit =
33
# omit everything in the tests directory
44
tests/*

.flake8

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
ignore =
3+
# W503: line break before binary operator
4+
# ignored as it creates inconsistency with black
5+
W503,
6+
# E501: line too long (> 88 characters)
7+
# ignored till a final decision is made on what to do with long comments
8+
E501,
9+
# C901: variable or function name is too complex (> 18 characters)
10+
# ignored till someone simplifies the names
11+
C901
12+
max-line-length = 88
13+
max-complexity = 18

.github/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
* When developing a new feature, include at least one test when applicable.
88
* When submitting a PR, please follow [this template](PULL_REQUEST_TEMPLATE.md) (which will probably be already filled up once you create the PR).
99
* When submitting a PR with changes to user interface (e.g.: new screen, or an email template), please add screenshots to the PR description.
10-
* When you are finished with your work, please squash your commits otherwise we will squash them on your PR (this can help us maintain a clear commit history).
10+
* When you are finished with your work, please squash your commits otherwise we will squash them on your PR (this can help us maintain a clear commit history).
1111
* When writing in-code documentation as Docstrings, please follow [this guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings).
1212
* When creating an issue to report a bug in the project, please follow our [bug_report.md](https://github.com/anitab-org/.github/blob/main/.github/ISSUE_TEMPLATE/bug_report.md) template.
1313

1414
## General Guidelines
1515

1616
* If you’re just getting started work on an issue labeled “First Timers Only” in any project. Additional resources are available on our [website](http://www.systers.io).
17-
* In an active repository (not an archived one), choose an open issue from the issue list, claim it in the comments, and a maintainer will assign it to you.
17+
* In an active repository (not an archived one), choose an open issue from the issue list, claim it in the comments, and a maintainer will assign it to you.
1818
* After approval you must make continuous notes on your progress in the issue while working. If there is not at least one comment every 3 days, the maintainer can reassign the issue.
1919
* Create a branch specific to the issue you're working on, so that you send a PR from that branch instead of the base branch on your fork.
20-
* If you’d like to create a new issue, please go through our issue list first (open as well as closed) and make sure the issues you are reporting do not replicate the existing issues.
20+
* If you’d like to create a new issue, please go through our issue list first (open as well as closed) and make sure the issues you are reporting do not replicate the existing issues.
2121
* Have a short description on what has gone wrong (like a root cause analysis and description of the fix), if that information is not already present in the issue.
2222
* If you have issues on multiple pages, report them separately. Do not combine them into a single issue.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Fixes # [ISSUE]
4141

4242
**Code/Quality Assurance Only**
4343

44-
- [ ] My changes generate no new warnings
44+
- [ ] My changes generate no new warnings
4545
- [ ] My PR currently breaks something (fix or feature that would cause existing functionality to not work as expected)
4646
- [ ] I have added tests that prove my fix is effective or that my feature works
4747
- [ ] New and existing unit tests pass locally with my changes

.github/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ newIssueWelcomeComment: |
77
Hello there!👋 Welcome to the project!💖
88
99
Thank you and congrats 🎉 for opening your very first issue in this project.
10-
AnitaB.org Open Source is an inclusive community, committed to creating a safe and positive environment 🌸 Please follow our [Code Of Conduct](https://github.com/anitab-org/mentorship-backend/blob/develop/docs/code_of_conduct.md) 🙌
10+
AnitaB.org Open Source is an inclusive community, committed to creating a safe and positive environment 🌸 Please follow our [Code Of Conduct](https://github.com/anitab-org/mentorship-backend/blob/develop/docs/code_of_conduct.md) 🙌
1111
You can learn more about the community on [our website](https://anitab-org.github.io/) and [documentation repository](https://github.com/anitab-org/documentation#readme).
1212
1313
You may submit a PR on the same if you like!
@@ -39,7 +39,7 @@ firstPRMergeComment: |
3939
Woohoo!🎊 Congrats on merging your first contribution to [mentorship-backend](https://github.com/anitab-org/mentorship-backend)!✨
4040
Your code is officially a part of AnitaB.org Open Source now!! Time for a celebration 🙌🎉⚡️
4141
Feel free to explore more on this project.🤗
42-
Join us on [AnitaB.org Open Source Zulip](https://anitab-org.zulipchat.com/). 🤝
42+
Join us on [AnitaB.org Open Source Zulip](https://anitab-org.zulipchat.com/). 🤝
4343
We have different streams for each active repository for discussions. 👩🏽‍💻🧑🏼‍💻
4444
Do join our weekly check-in stream to share your weekly goals and the awesome work you did here.😃
4545

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ name: Lint Code and Run Tests
66
on:
77
pull_request:
88
branches: [develop]
9-
paths-ignore:
9+
paths-ignore:
1010
- '**.md'
1111
- /docs/CODEOWNERS
1212
push:
1313
branches: [develop]
14-
paths-ignore:
14+
paths-ignore:
1515
- '**.md'
1616
- /docs/CODEOWNERS
1717

@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v2
2323
- uses: actions/setup-python@v2
24-
- uses: psf/black@stable
24+
- uses: psf/black@stable
2525

2626
build:
2727
needs: lint

.isort.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.isort]
2+
profile = "black"
3+
multi_line_output = 3
4+
5+
[settings]
6+
line_length = 88
7+
multi_line_output = 3
8+
include_trailing_comma = True
9+
known_third_party = celery,django,environ,pyquery,pytz,redis,requests,rest_framework

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black
9+
rev: 21.5b1
10+
hooks:
11+
- id: black
12+
args: [--check]
13+
- repo: https://gitlab.com/pycqa/flake8
14+
rev: 3.9.2
15+
hooks:
16+
- id: flake8
17+
- repo: https://github.com/pycqa/isort
18+
rev: 5.8.0
19+
hooks:
20+
- id: isort
21+
args: [--profile, black, -c]

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,35 @@ To run black:
209209
black .
210210
```
211211

212+
#### Sorting imports with isort
213+
214+
We use [_isort_](https://pypi.org/project/isort/) to sort imports alphabetically, and automatically separated into
215+
sections and by type. To install _isort_:
216+
217+
```
218+
pip install isort
219+
```
220+
221+
To run isort:
222+
223+
```
224+
isort . --profile=black
225+
```
226+
227+
#### Automate auto-formatting tools with pre-commit
228+
229+
We use [_pre-commit_](https://pre-commit.com/) to check formatting before every commit message. To install _pre-commit_:
230+
231+
```
232+
pip install pre-commit
233+
```
234+
235+
To set up the git hook scripts:
236+
237+
```
238+
pre-commit install
239+
```
240+
212241
## Documentation
213242

214243
Documentation for the project is hosted [here](https://anitab-org.github.io/mentorship-backend/). We use Docusaurus for maintaining the documentation of the project.

app/api/api_extension.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from flask_restx import Api
22

3-
# Adding namespaces
4-
from app.api.resources.user import users_ns as user_namespace
53
from app.api.resources.admin import admin_ns as admin_namespace
64
from app.api.resources.mentorship_relation import (
75
mentorship_relation_ns as mentorship_namespace,
86
)
97
from app.api.resources.task import task_ns as task_namespace
108
from app.api.resources.task_comment import task_comment_ns as task_comment_namespace
119

10+
# Adding namespaces
11+
from app.api.resources.user import users_ns as user_namespace
12+
1213

1314
def androidlink():
1415
return "<a href=https://github.com/anitab-org/mentorship-android>Android</a>"

0 commit comments

Comments
 (0)