7
7
8
8
# python-src-template
9
9
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.
11
12
12
13
This is not the one-shot solution to project structure or packaging. This is
13
14
just what works well for one egg on the Internet. Feel free to use it as you see
14
15
fit.
15
16
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
-
23
17
---
24
18
25
19
# Local developer installation
@@ -47,13 +41,31 @@ the desired version while creating the `venv`. (e.g. `python3` or `python3.8`)
47
41
48
42
## Installation steps
49
43
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
+
50
61
Clone this repo and enter root directory of repo:
51
62
52
63
``` console
53
64
$ git clone https://github.com/[ORG NAME]/[REPO NAME]
54
65
$ cd [REPO NAME]
55
66
```
56
67
68
+
57
69
Create the ` venv ` :
58
70
59
71
``` console
@@ -75,6 +87,14 @@ call the version of the interpreter used to create the `venv`
75
87
76
88
Install editable library and development requirements:
77
89
90
+ ### With Makefile:
91
+
92
+ ``` console
93
+ make install-dev
94
+ ```
95
+
96
+ ### Without Makefile:
97
+
78
98
``` console
79
99
$ python -m pip install --editable .[dev,test]
80
100
```
@@ -120,19 +140,48 @@ To deactivate (exit) the `venv`:
120
140
``` console
121
141
$ deactivate
122
142
```
143
+
123
144
---
124
145
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:
126
158
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
132
170
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
136
185
```
137
186
138
187
---
@@ -147,18 +196,3 @@ any code submitted for review already passes all selected pre-commit checks.
147
196
with ` git ` hooks.
148
197
149
198
---
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