Skip to content
This repository was archived by the owner on Dec 19, 2021. It is now read-only.

Commit 82a8f7c

Browse files
authored
Python style enforced with pre-commit hook (#185)
* Add dependencies for formatting/styling Added flake8-bugbear, pre-commit and black. Contributing.py will have to be updated to reflect new command to install the deps: `pipenv install -d --pre` * Add Flake8 config file This is so that team members can use the same Flake8 configuration with their editor, before trying to commit. Setting up their editor to lint with Flake8 should save on some headaches when trying to commit. * Add pre-commit config file This is the file that sets up the pre-commit formatting and linting. To install, team members will have to run `pre-commit install` once. * Exclude __init__.py files from Flake8 for now Some of the __init__.py files are used for imports. Flake8 raises an unused import error for these and also complains if the import was a * import. The unused import error can be resolved by putting the name of the class or function being imported into __all__, but there will still be an error if a * import is used. Since we are still actively creating fixtures and other tests that might be imported through these __init__ files, I think we should leave the files be for now and just have Flake8 skip over them during the pre-commit check. * Add pre-commit instructions to Contributing.md * Add custom pipenv script for installing dev deps Now you can run `pipenv run dev-install` instead of `pipenv install -d --pre`
1 parent 0d1d5f0 commit 82a8f7c

File tree

99 files changed

+2625
-1895
lines changed

Some content is hidden

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

99 files changed

+2625
-1895
lines changed

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 80
3+
select = C,E,F,W,B,B950
4+
ignore = E203,E501,W503

.pre-commit-config.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- repo: https://github.com/psf/black
8+
rev: 20.8b1
9+
hooks:
10+
- id: black
11+
language_version: python3.8
12+
- repo: https://gitlab.com/pycqa/flake8
13+
rev: 3.8.4
14+
hooks:
15+
- id: flake8
16+
args: [
17+
--max-line-length=80,
18+
'--select=C,E,F,W,B,B950',
19+
'--ignore=E203,E501,W503',
20+
]
21+
additional_dependencies: [
22+
'flake8-bugbear',
23+
]
24+
exclude: '^.*/__init__.py$'

CONTRIBUTING.md

+19-11
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,24 @@ NOTE: Database is SQLite3 via SQLAlchemy
7676
2. Install [pipenv](https://pipenv.pypa.io/en/latest/#install-pipenv-today)
7777
- Note: It is not necessary to install python before installing pipenv.
7878
- Please install pipenv according to their docs for your OS.
79-
3. Install dependencies `pipenv install -d`
79+
3. Install dependencies `pipenv run dev-install`
8080
- Note: Pipenv may prompt you to install Python if it cannot find the correct version on your system. You should select Yes.
8181
- Note: If you get the error `ImportError: cannot import name 'Feature' from 'setuptools'`, your setuptools version might be at 46 or later. You may be able to get it to work using version 45 (e.g. `pip3 install setuptools==45`)
82-
4. copy the contents of the `.env.example` to a new file called `.env`
82+
4. Install our pre-commit hook:
83+
- Run: `pipenv run pre-commit install`
84+
5. copy the contents of the `.env.example` to a new file called `.env`
8385
- `cp .env.example .env`
84-
5. Create and Seed the database
86+
6. Create and Seed the database
8587
- Run: `pipenv run flask db create`
8688

8789
- Some other userful commands are:
8890
- To re-seed the database from scratch run: `pipenv run flask db recreate`
8991
- To find other database set-up commands run: `pipenv run flask db --help`
9092
- To drop the database run: `pipenv run flask db drop`
91-
6. Start the server using the flask environment (required every time the project is re-opened):
93+
7. Start the server using the flask environment (required every time the project is re-opened):
9294
- Run: `pipenv run flask run`
9395
- Run and restart the server on changes: `pipenv run flask run --reload`
94-
7. Test the server and view coverage reports. Use of coverage reporting is recommended to indicate test suite completeness and to locate defunct code in the code base.
96+
8. Test the server and view coverage reports. Use of coverage reporting is recommended to indicate test suite completeness and to locate defunct code in the code base.
9597
- Run all the tests: `pipenv run pytest --cov .`
9698
- Run tests in a particular directory: `pipenv run pytest --cov [path to directory]`
9799
- Example: Just the integration tests: `pipenv run pytest --cov tests/integration`
@@ -127,19 +129,19 @@ If you don't see something similar, you may have several versions of Python inst
127129

128130
### Database migrations.
129131

130-
Database migrations are not used for development. Please ignore do not use migrations during development.
132+
Database migrations are not used for development. Please ignore do not use migrations during development.
131133

132-
Database migrations are managed through [Alembic](https://alembic.sqlalchemy.org/en/latest/index.html). After making a change to a model, a database migration is necessary.
134+
Database migrations are managed through [Alembic](https://alembic.sqlalchemy.org/en/latest/index.html). After making a change to a model, a database migration is necessary.
133135

134136
- The first step is to create a revision: `pipenv run alembic revision --autogenerate -m "message"`
135137
- The second step is to upgrade: `pipenv run alembic upgrade head`
136138

137-
To return to a previous version, a downgrade is necessary. Run:
139+
To return to a previous version, a downgrade is necessary. Run:
138140
`pipenv run alembic downgrade -n` where n is the number of versions to downgrade.
139141

140-
To downgrade to the very beginning run: `pipenv run alembic downgrade base`
142+
To downgrade to the very beginning run: `pipenv run alembic downgrade base`
141143

142-
The reversion are maintained as Python files in ``./migrations/versions/`
144+
The reversion are maintained as Python files in ``./migrations/versions/`
143145

144146
### Contributing
145147

@@ -160,6 +162,12 @@ How to contribute to this project.
160162

161163
(Step #3 creates a new branch titled <name of branch> and navigates you to that branch)
162164

165+
4. Commit your changes (and resolve commit errors)
166+
- Our pre-commit hook is designed to be strict in order to ensure all code being committed to the codebase is as clean and uniform as possible. Commit errors are a good thing, and completely expected!
167+
- The pre-commit hook will check your code every time you try to commit. If your code needs re-formatting, that will happen automatically. If you have non-formatting errors in your code, these will be printed to the terminal with the error, filename and line number. You will need to resolve these yourself.
168+
- After your code has been reformatted and/or you have resolved other errors, you will need to add and commit those files again (because they have been modified).
169+
- Successful commits can then be pushed to your remote branch like normal.
170+
163171
#### Updating development branch
164172

165173
To update your development branch with the latest changes:
@@ -172,7 +180,7 @@ To update your development branch with the latest changes:
172180
- `git pull origin development`
173181

174182
3. After pulling fresh copy it is a good habit to install any new deps and rebuild the database. Run the following two commands:
175-
- `pipenv run install -d`
183+
- `pipenv run dev-install`
176184
- `pipenv run flask db recreate`
177185

178186
4. Finally - run the tests to ensure everything is passing.

Pipfile

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pytest-watch = "*"
1414
python-dotenv = "*"
1515
pytest = "*"
1616
atomicwrites = "*"
17+
flake8-bugbear = "*"
18+
pre-commit = "*"
19+
black = "*"
1720

1821
[packages]
1922
Flask = "==1.1.1"
@@ -36,3 +39,7 @@ python_version = "3.8"
3639

3740
[scripts]
3841
view_coverage = "coverage report -m"
42+
dev-install = "pipenv install -d --pre"
43+
44+
[pipenv]
45+
allow_prereleases = true

0 commit comments

Comments
 (0)