Skip to content

Commit e43a4a5

Browse files
authored
Merge pull request #84 from Preocts/preocts
Structure refinement
2 parents dd1c1c3 + 24a8b86 commit e43a4a5

8 files changed

Lines changed: 220 additions & 62 deletions

File tree

CONTRIBUTING.md

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,25 @@ Create your own fork of this repo that you will make your changes on.
1919

2020
## Creating your feature
2121

22-
Always base your changes off the `main` branch, it is the most up to date.
22+
Always base your changes off the `main` branch unless otherwise asked.
2323

2424
## Pull Request
2525

26-
Once the feature is tested and ready, open a pull request to the `main` branch.
26+
All pull requests must:
2727

28-
Please ensure your tests are passing in your local environment and any new
29-
features are have appropriate tests added. Untested code will not be approved.
28+
- Pass all linting and formatting checks
29+
- Have tests that cover all branches of the added feature
30+
- If the PR is a bug fix there must be a test that duplicates the bug, proving
31+
it is fixed
3032

3133
## Code Style
3234

3335
Follow the patterns seen in the code. Walk where others have walked.
3436

35-
The majority of code style nits will be met simply by passing `pre-commit`
36-
checks prior to submitting a pull request.
37+
The majority of code style nits will be met when passing `pre-commit` checks
38+
prior to submitting a pull request.
3739

38-
- ### Do
39-
40-
- snake_case modules, variables, methods, and functions
41-
- PascalCase classes
42-
- Type-hint function/method signatures
43-
- Use verbs for getters/setters (`get_`, `fetch_`, `pull_`, `save_`, `put_`)
44-
- Use singular form for objects
45-
- Use plural form for lists/sequences
46-
47-
- ### Do Not
48-
49-
- Fight `black` formatting
50-
51-
- ### Comments
52-
53-
- Keep comments short and to the point
54-
- Let code explain "what" and comments explain "why"
55-
- All modules, functions, class, and methods must have a doc-string
56-
- Doc-strings are optional in tests when the test name explains "what"
57-
58-
- ### Tests
40+
## Tests
5941

6042
- Smaller tests are easier to work with
6143
- Mock at a minimum

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ COPY requirements/ /src/requirements/
1414
RUN python3.8 -m pip install --upgrade -r requirements/requirements-dev.txt -r requirements/requirements-test.txt --no-cache-dir
1515

1616
COPY . /src
17-
RUN python3.8 -m pip install .
17+
RUN python3.8 -m pip install . --no-cache-dir
1818

1919
CMD ["tox", "-r"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Preocts
3+
Copyright (c) 2023 Preocts
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.PHONY: install
2-
install:
3-
python -m pip install --upgrade .
4-
51
.PHONY: install-dev
62
install-dev:
73
python -m pip install --upgrade --editable .[dev,test]
@@ -18,21 +14,11 @@ upgrade-dev:
1814
coverage:
1915
coverage run -m pytest tests/
2016
coverage report -m
21-
coverage html
22-
@# This should work for most linux and windows users
23-
@# python -c "import os;import webbrowser; webbrowser.open(f'{os.getcwd()}/htmlcov/index.html')"
24-
25-
@# WSL users can use this (change Ubuntu-20.04 to your distro name)
26-
python -c "import os;import webbrowser; webbrowser.open(f'file://wsl.localhost/Ubuntu-20.04{os.getcwd()}/htmlcov/index.html')"
2717

2818
.PHONY: docker-test
2919
docker-test:
30-
docker build -t docker-test .
31-
docker run --rm docker-test
32-
33-
.PHONY: docker-clean
34-
docker-clean:
35-
docker system prune -f
20+
docker build -t pydocker-test .
21+
docker run --rm pydocker-test
3622

3723
.PHONY: build-dist
3824
build-dist:

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77

88
# python-src-template
99

10-
## Playing around with a new structure. See the releases for previous structures.
10+
A template I use for most projects and is setup to jive with my environment at the company I work with.
1111

12-
## A template I use for most projects.
12+
This is not the one-shot solution to project structure or packaging. This is
13+
just what works well for one egg on the Internet. Feel free to use it as you see
14+
fit.
1315

14-
Straight forward to use!
15-
16-
**Kind of...**
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.
1722

1823
---
1924

@@ -90,10 +95,16 @@ Run pre-commit on all files:
9095
$ pre-commit run --all-files
9196
```
9297

93-
Run tests:
98+
Run tests (quick):
99+
100+
```console
101+
$ pytest
102+
```
103+
104+
Run tests (slow):
94105

95106
```console
96-
$ tox [-r] [-e py3x]
107+
$ tox
97108
```
98109

99110
Build dist:
@@ -143,13 +154,11 @@ This repo has a Makefile with some quality of life scripts if the system
143154
supports `make`. Please note there are no checks for an active `venv` in the
144155
Makefile.
145156

146-
| PHONY | Description |
147-
| -------------- | ------------------------------------------------------------------------------------------ |
148-
| `install` | install the project |
149-
| `install-dev` | install development/test requirements and project as editable install |
150-
| `upgrade-dev` | update all dependencies, regenerate requirements.txt (disabled by default) |
151-
| `coverage` | Run tests with coverage, generate html report, and open browser (double check based on os) |
152-
| `docker-test' | Run coverage and tests in a docker container. |
153-
| `docker-clean` | Run `docker system prune -f` |
154-
| `build-dist` | Build source distribution and wheel distribution |
155-
| `clean` | Deletes build, tox, coverage, pytest, mypy, cache, and pyc artifacts |
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/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ubuntu:focal
2+
3+
RUN apt-get update
4+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common
5+
RUN add-apt-repository -y 'ppa:deadsnakes/ppa'
6+
RUN DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends python3.8 python3.8-venv
7+
RUN rm -rf /var/lib/apt/lists/*
8+
9+
WORKDIR /src
10+
11+
ENV PATH=/venv/bin:$PATH
12+
RUN python3.8 -m venv /venv
13+
14+
COPY . /src
15+
RUN python3.8 -m pip install . --no-cache-dir
16+
17+
CMD ["tox", "-r"]

alt_files/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: install-dev
2+
install-dev:
3+
python -m pip install --upgrade --editable .[dev,test]
4+
pre-commit install
5+
6+
.PHONY: coverage
7+
coverage:
8+
coverage run -m pytest tests/
9+
coverage report -m
10+
11+
.PHONY: docker-test
12+
docker-test:
13+
docker build -t pydocker-test .
14+
docker run --rm pydocker-test
15+
16+
.PHONY: build-dist
17+
build-dist:
18+
python -m pip install --upgrade build
19+
python -m build
20+
21+
.PHONY: clean
22+
clean:
23+
find . -name '*.pyc' -exec rm -f {} +
24+
find . -name '*.pyo' -exec rm -f {} +
25+
find . -name '__pycache__' -exec rm -rf {} +
26+
find . -name '.mypy_cache' -exec rm -rf {} +
27+
rm -rf .tox
28+
rm -f coverage.xml
29+
rm -f coverage.json
30+
rm -rf htmlcov
31+
rm -rf .coverage
32+
rm -rf .coverage.*
33+
find . -name '.pytest_cache' -exec rm -rf {} +
34+
rm -rf dist
35+
rm -rf build

alt_files/pyproject.toml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "module-name"
7+
version = "0.1.0"
8+
requires-python = ">=3.7"
9+
description = "Module Description"
10+
readme = "README.md"
11+
license = { file = "LICENSE" }
12+
authors = [
13+
{ email = "yourname@email.invalid", name = "[YOUR NAME]" }
14+
]
15+
maintainers = []
16+
keywords = []
17+
classifiers = [
18+
"License :: OSI Approved :: MIT License",
19+
"Programming Language :: Python :: 3",
20+
"Programming Language :: Python :: 3 :: Only",
21+
"Programming Language :: Python :: Implementation :: CPython"
22+
]
23+
24+
dependencies = []
25+
26+
[project.optional-dependencies]
27+
dev = [
28+
"pre-commit",
29+
"black",
30+
"mypy",
31+
"flake8",
32+
"flake8-builtins",
33+
"flake8-pep585",
34+
]
35+
test = [
36+
"pytest",
37+
"pytest-randomly",
38+
"coverage",
39+
"tox"
40+
]
41+
42+
[project.urls]
43+
homepage = "https://github.com/[ORG NAME]/[REPO NAME]"
44+
# documentation = ""
45+
# repository = ""
46+
# changelog = ""
47+
48+
# CLI scripts if needed
49+
# [project.scripts]
50+
# python-src-example = "module_name.sample:main"
51+
52+
[tool.setuptools.package-data]
53+
"module_name" = ["py.typed"]
54+
55+
[tool.mypy]
56+
check_untyped_defs = true
57+
disallow_any_generics = true
58+
disallow_incomplete_defs = true
59+
disallow_untyped_defs = true
60+
no_implicit_optional = true
61+
warn_redundant_casts = true
62+
warn_unused_ignores = true
63+
64+
[[tool.mypy.overrides]]
65+
module = "tests.*"
66+
disallow_incomplete_defs = false
67+
disallow_untyped_defs = false
68+
warn_unused_ignores = false
69+
70+
[tool.coverage.run]
71+
branch = true
72+
source = [
73+
"tests",
74+
]
75+
source_pkgs = [
76+
"module_name",
77+
]
78+
79+
[tool.coverage.paths]
80+
source = [
81+
"src/",
82+
"*/site-packages",
83+
]
84+
test = [
85+
"tests/",
86+
"*/tests",
87+
]
88+
89+
[tool.coverage.report]
90+
exclude_lines =[
91+
"pragma: no cover",
92+
"raise NotImplementedError",
93+
"if __name__ == .__main__.:",
94+
"\\.\\.\\.",
95+
"if TYPE_CHECKING:",
96+
]
97+
98+
# This is ignored by flake8, here in case they decide to add it in the future
99+
[tool.flake8]
100+
ignore = "W503,E203"
101+
max-line-length = 88
102+
103+
[tool.tox]
104+
legacy_tox_ini = """
105+
[tox]
106+
envlist = py37,py38,py39,py310,py311,py312,coverage,mypy
107+
skip_missing_interpreters = true
108+
isolated_build = True
109+
110+
[testenv]
111+
deps =
112+
.[test]
113+
commands =
114+
coverage run -p -m pytest tests/
115+
116+
[testenv:coverage]
117+
depends = py37,py38,py39,py310,py311,py312
118+
parallel_show_output = true
119+
commands =
120+
python -m coverage combine
121+
python -m coverage report -m --fail-under=50
122+
python -m coverage json
123+
124+
[testenv:mypy]
125+
deps =
126+
mypy
127+
commands =
128+
mypy -p module_name --no-incremental
129+
"""

0 commit comments

Comments
 (0)