Skip to content

Commit 1aea746

Browse files
authored
Merge pull request #97 from Preocts/preocts
Refinement of the template
2 parents ad2e523 + f295a71 commit 1aea746

18 files changed

+165
-294
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
extend-ignore =
3+
W503
4+
E203
5+
max-line-length = 88

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repos:
3636
rev: 1.13.0
3737
hooks:
3838
- id: blacken-docs
39-
additional_dependencies: [black>=22.12.0]
39+
additional_dependencies: [black>=23.3.0]
4040

4141
# Flake8 for linting, line-length adjusted to match Black default
4242
- repo: https://github.com/PyCQA/flake8

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ install-dev:
33
python -m pip install --upgrade --editable .[dev,test]
44
pre-commit install
55

6+
.PHONY: update-dev
7+
update-dev:
8+
python -m pip install --upgrade pip-tools
9+
pip-compile --resolver=backtracking --no-emit-index-url requirements.in
10+
pip-compile --resolver=backtracking --no-emit-index-url requirements-dev.in
11+
pip-compile --resolver=backtracking --no-emit-index-url requirements-test.in
12+
613
.PHONY: upgrade-dev
714
upgrade-dev:
815
python -m pip install --upgrade pip-tools
9-
pip-compile --resolver=backtracking requirements/requirements.in
10-
pip-compile --resolver=backtracking requirements/requirements-dev.in
11-
pip-compile --resolver=backtracking requirements/requirements-test.in
16+
pip-compile --resolver=backtracking --upgrade --no-emit-index-url requirements.in
17+
pip-compile --resolver=backtracking --upgrade --no-emit-index-url requirements-dev.in
18+
pip-compile --resolver=backtracking --upgrade --no-emit-index-url requirements-test.in
19+
1220

1321
.PHONY: coverage
1422
coverage:

README.md

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
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

1213
This is not the one-shot solution to project structure or packaging. This is
1314
just what works well for one egg on the Internet. Feel free to use it as you see
1415
fit.
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+
5061
Clone 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+
5769
Create the `venv`:
5870

5971
```console
@@ -75,6 +87,14 @@ call the version of the interpreter used to create the `venv`
7587

7688
Install 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.
147196
with `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 |

alt_files/Makefile

Lines changed: 0 additions & 35 deletions
This file was deleted.

alt_files/pyproject.toml

Lines changed: 0 additions & 129 deletions
This file was deleted.

init_template.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,6 @@ def get_input(prompt: str) -> str:
7171
return input(prompt)
7272

7373

74-
def select_project_type() -> None:
75-
"""Select whether alt_files should be used."""
76-
user_input = get_input("Switch to dependencies in pyproject.toml? (y/N) : ")
77-
if user_input.lower() == "y":
78-
for file in ALT_FILE_DIR.iterdir():
79-
file.replace(file.name)
80-
81-
# Remove requirements directory and all contents
82-
for file in REQUIREMENTS_DIR.iterdir():
83-
os.remove(file)
84-
os.rmdir(REQUIREMENTS_DIR)
85-
86-
# Remove alt_files directory and all contents
87-
for file in ALT_FILE_DIR.iterdir():
88-
os.remove(file)
89-
os.rmdir(ALT_FILE_DIR)
90-
91-
9274
def get_project_data() -> ProjectData:
9375
"""Query user for details on the project. This is the quiz."""
9476
data = ProjectData()
@@ -138,14 +120,12 @@ def rename_module_folder(name: str) -> None:
138120
if __name__ == "__main__":
139121
print("Eggcellent template setup:\n")
140122

141-
select_project_type()
142-
143123
project_data = get_project_data()
144124

145125
replace_pyproject_values(project_data)
146126
replace_readme_values(project_data)
147127

148-
rename_module_folder(project_data.name)
149-
150128
delete_placeholder_files()
151129
delete_placeholder_directories()
130+
131+
rename_module_folder(project_data.name)

0 commit comments

Comments
 (0)