77
88# python-src-template
99
10- A template I use for most projects and is setup to jive with my environment at the company I work with.
10+ A template I use for most projects and is setup to jive with my environment at
11+ the company I work with.
1112
1213This is not the one-shot solution to project structure or packaging. This is
1314just what works well for one egg on the Internet. Feel free to use it as you see
1415fit.
1516
16- The primary setup here uses dynamically loaded requirement files from the
17- ` ./requirements ` directory in the pyproject.toml file. This is ideal for
18- micro-services, applications, or scripts that need all requirements pinned.
19- Pinning is handled by ` pip-compile ` . The files in ` ./alt_files ` offer an
20- alternative where all requirements are kept within the pyproject.toml file and
21- any pinning is manually managed.
22-
2317---
2418
2519# Local developer installation
@@ -47,13 +41,31 @@ the desired version while creating the `venv`. (e.g. `python3` or `python3.8`)
4741
4842## Installation steps
4943
44+ ### Makefile
45+
46+ This repo has a Makefile with some quality of life scripts if the system
47+ supports ` make ` . Please note there are no checks for an active ` venv ` in the
48+ Makefile. If you are on Windows you can install make using scoop or chocolatey.
49+
50+ | PHONY | Description |
51+ | ------------- | --------------------------------------------------------------------- |
52+ | ` install-dev ` | install development/test requirements and project as editable install |
53+ | ` update-dev ` | regenerate requirements-* .txt (will keep existing pins) |
54+ | ` upgrade-dev ` | attempt to update all dependencies, regenerate requirements-* .txt |
55+ | ` coverage ` | Run tests with coverage, generate console report |
56+ | ` docker-test ` | Run coverage and tests in a docker container. |
57+ | ` build-dist ` | Build source distribution and wheel distribution |
58+ | ` clean ` | Deletes build, tox, coverage, pytest, mypy, cache, and pyc artifacts |
59+
60+
5061Clone this repo and enter root directory of repo:
5162
5263``` console
5364$ git clone https://github.com/[ORG NAME]/[REPO NAME]
5465$ cd [REPO NAME]
5566```
5667
68+
5769Create the ` venv ` :
5870
5971``` console
@@ -75,6 +87,14 @@ call the version of the interpreter used to create the `venv`
7587
7688Install editable library and development requirements:
7789
90+ ### With Makefile:
91+
92+ ``` console
93+ make install-dev
94+ ```
95+
96+ ### Without Makefile:
97+
7898``` console
7999$ python -m pip install --editable .[dev,test]
80100```
@@ -120,19 +140,48 @@ To deactivate (exit) the `venv`:
120140``` console
121141$ deactivate
122142```
143+
123144---
124145
125- ## Note on flake8:
146+ ## Updating dependencies
147+
148+ New dependencys can be added to the ` requirements-*.in ` file. It is recommended
149+ to only use pins when specific versions or upgrades beyond a certain version are
150+ to be avoided. Otherwise, allow ` pip-compile ` to manage the pins in the
151+ generated ` requirements-*.txt ` files.
152+
153+ Once updated following the steps below, the package can be installed if needed.
154+
155+ ### With Makefile
156+
157+ To update the generated files with a dependency:
126158
127- ` flake8 ` is included in the ` requirements-dev.txt ` of the project. However it
128- disagrees with ` black ` , the formatter of choice, on max-line-length and two
129- general linting errors. ` .pre-commit-config.yaml ` is already configured to
130- ignore these. ` flake8 ` doesn't support ` pyproject.toml ` so be sure to add the
131- following to the editor of choice as needed.
159+ ``` console
160+ make update-dev
161+ ```
162+
163+ To attempt to upgrade all generated dependencies:
164+
165+ ``` console
166+ make upgrade-dev
167+ ```
168+
169+ ### Without Makefile
132170
133- ``` ini
134- --ignore =W503,E203
135- --max-line-length =88
171+ To update the generated files with a dependency:
172+
173+ ``` console
174+ pip-compile --resolver=backtracking --no-emit-index-url requirements.in
175+ pip-compile --resolver=backtracking --no-emit-index-url requirements-dev.in
176+ pip-compile --resolver=backtracking --no-emit-index-url requirements-test.in
177+ ```
178+
179+ To attempt to upgrade all generated dependencies:
180+
181+ ``` console
182+ pip-compile --resolver=backtracking --upgrade --no-emit-index-url requirements.in
183+ pip-compile --resolver=backtracking --upgrade --no-emit-index-url requirements-dev.in
184+ pip-compile --resolver=backtracking --upgrade --no-emit-index-url requirements-test.in
136185```
137186
138187---
@@ -147,18 +196,3 @@ any code submitted for review already passes all selected pre-commit checks.
147196with ` git ` hooks.
148197
149198---
150-
151- ## Makefile
152-
153- This repo has a Makefile with some quality of life scripts if the system
154- supports ` make ` . Please note there are no checks for an active ` venv ` in the
155- Makefile.
156-
157- | PHONY | Description |
158- | ------------- | --------------------------------------------------------------------- |
159- | ` install-dev ` | install development/test requirements and project as editable install |
160- | ` upgrade-dev ` | update all dependencies, regenerate requirements.txt |
161- | ` coverage ` | Run tests with coverage, generate console report |
162- | ` docker-test ` | Run coverage and tests in a docker container. |
163- | ` build-dist ` | Build source distribution and wheel distribution |
164- | ` clean ` | Deletes build, tox, coverage, pytest, mypy, cache, and pyc artifacts |
0 commit comments