Skip to content

Commit c0212ab

Browse files
authored
Merge pull request #80 from Preocts/preocts
experimenting with a dockerfile
2 parents a986604 + a9ae860 commit c0212ab

11 files changed

Lines changed: 219 additions & 112 deletions

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
venv/
2+
Dockerfile
3+
.dockerignore
4+
build/
5+
.tox/
6+
.pytest_cache/
7+
.mypy_cache/
8+
.github/
9+
*.egg-info/

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
COPY requirements/ /src/requirements/
14+
RUN python3.8 -m pip install --upgrade -r requirements/requirements-dev.txt -r requirements/requirements-test.txt --no-cache-dir
15+
16+
COPY . /src
17+
RUN python3.8 -m pip install .
18+
19+
CMD ["tox", "-r"]

Makefile

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
.PHONY: init
2-
init:
3-
python -m pip install --upgrade pip
4-
51
.PHONY: install
62
install:
73
python -m pip install --upgrade .
84

95
.PHONY: install-dev
106
install-dev:
11-
python -m pip install --editable .[dev,test]
7+
python -m pip install --upgrade --editable .[dev,test]
128
pre-commit install
139

14-
# Optional: use requirements.in to manage requirements
15-
# Use optional dynamic field in pyproject.toml
16-
# .PHONY: upgrade-dev
17-
# upgrade-dev:
18-
# python -m pip install pip-tools
19-
# pip-compile --upgrade
20-
# python -m pip install --upgrade --editable .[dev,test]
10+
.PHONY: upgrade-dev
11+
upgrade-dev:
12+
python -m pip install --upgrade pip-tools
13+
pip-compile --resolver=backtracking requirements/requirements.in
14+
pip-compile --resolver=backtracking requirements/requirements-dev.in
15+
pip-compile --resolver=backtracking requirements/requirements-test.in
2116

2217
.PHONY: coverage
2318
coverage:
@@ -30,6 +25,15 @@ coverage:
3025
@# WSL users can use this (change Ubuntu-20.04 to your distro name)
3126
python -c "import os;import webbrowser; webbrowser.open(f'file://wsl.localhost/Ubuntu-20.04{os.getcwd()}/htmlcov/index.html')"
3227

28+
.PHONY: docker-test
29+
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
36+
3337
.PHONY: build-dist
3438
build-dist:
3539
python -m pip install --upgrade build

README.md

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,14 @@
77

88
# python-src-template
99

10+
## Playing around with a new structure. See the releases for previous structures.
11+
1012
## A template I use for most projects.
1113

1214
Straight forward to use!
1315

1416
**Kind of...**
1517

16-
While this is the way I usually start my Python project setup this is far from
17-
the only way to do things. I invite you to use my template. I also challenge
18-
you to craft the structure that works both for your project and you, creating
19-
your own template. The amount of learning in doing so is well worth the effort.
20-
21-
---
22-
23-
### Quick setup:
24-
25-
Clone the repo or click the "Use this template" button in GitHub
26-
27-
If you clone the repo instead of using it as a template; be sure to delete the
28-
`.git` folder and run `git init` before making any changes.
29-
30-
Run the `init_template.py` script found in the root of the repo. You will be
31-
prompted for details and the steps listed below completed for you. You may then
32-
delete the `init_template.py` file, commit all changes, and dev on.
33-
34-
---
35-
36-
### What to change for manual setup:
37-
38-
* Remove the following place-holder files:
39-
* `src/module_name/sample_data`
40-
* `src/module_name/sample.py`
41-
* `tests/test_sample.py`
42-
* Raname `src/module_name` to the desired project name
43-
* Update `pyproject.toml`:
44-
* `[project]` section:
45-
* `name`, `version`, `description`, `authors`
46-
* `dependencies`
47-
* see alternative for requirements.in if desired
48-
* `[project.urls]`
49-
* Update github homepage values
50-
* `[tool.coverage.run]`
51-
* `source_pkgs` : Update to reflect new `module_name` and any additional
52-
modules
53-
* Update `README.md` - Badges:
54-
* Update owner and repo name of urls for `pre-commit.ci` badge
55-
* Update owner and repo name of urls for `python tests` badge
56-
* Update `README.md` - Content:
57-
* Replace title and this setup information
58-
* Under **Local developer installation**
59-
* Replace `{{ORG_NAME}}` with github name
60-
* Replace `{{REPO_NAME}}` with repo name
61-
62-
### Why `src/` structure:
63-
64-
The benefit I get from this project structure comes from testing. The `src/`
65-
structure forces us to test on the installed version of the modules within
66-
`site-packages/` and not our local code. Even though these files are symlinked
67-
in most cases with the dev install, the calls and import references are the
68-
same. This ensures we are testing on what will be setup in the not-my machine.
69-
7018
---
7119

7220
# Local developer installation
@@ -123,10 +71,6 @@ call the version of the interpreter used to create the `venv`
12371
Install editable library and development requirements:
12472

12573
```console
126-
# Update pip and tools
127-
$ python -m pip install --upgrade pip
128-
129-
# Install editable version of library
13074
$ python -m pip install --editable .[dev,test]
13175
```
13276

@@ -199,12 +143,13 @@ This repo has a Makefile with some quality of life scripts if the system
199143
supports `make`. Please note there are no checks for an active `venv` in the
200144
Makefile.
201145

202-
| PHONY | Description |
203-
| ------------- | ------------------------------------------------------------------------------------------ |
204-
| `init` | Update pip to newest version |
205-
| `install` | install the project |
206-
| `install-dev` | install development/test requirements and project as editable install |
207-
| `upgrade-dev` | update all dependencies, regenerate requirements.txt (disabled by default) |
208-
| `coverage` | Run tests with coverage, generate html report, and open browser (double check based on os) |
209-
| `build-dist` | Build source distribution and wheel distribution |
210-
| `clean` | Deletes build, tox, coverage, pytest, mypy, cache, and pyc artifacts |
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 |

pyproject.toml

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,14 @@ classifiers = [
2020
"Programming Language :: Python :: 3 :: Only",
2121
"Programming Language :: Python :: Implementation :: CPython"
2222
]
23-
# Define dependencies directly
24-
dependencies = []
25-
26-
# Optional use requirements.txt as input (generated from pip-tools pip-compile)
27-
# 20221003 - Does not presently support hashes
28-
# dynamic = ["dependencies"]
29-
# [tool.setuptools.dynamic]
30-
# dependencies = {file = ["requirements.txt"]}
31-
32-
[project.optional-dependencies]
33-
dev = [
34-
"pre-commit",
35-
"black",
36-
"mypy",
37-
"flake8",
38-
"flake8-builtins",
39-
"flake8-pep585",
40-
]
41-
test = [
42-
"pytest",
43-
"pytest-randomly",
44-
"coverage",
45-
"tox"
46-
]
23+
dynamic = ["dependencies", "optional-dependencies"]
24+
25+
[tool.setuptools.dynamic.dependencies]
26+
file = ["requirements/requirements.txt"]
27+
28+
[tool.setuptools.dynamic.optional-dependencies]
29+
dev = {file = ["requirements/requirements-dev.txt"]}
30+
test = {file = ["requirements/requirements-test.txt"]}
4731

4832
[project.urls]
4933
homepage = "https://github.com/[ORG NAME]/[REPO NAME]"
@@ -115,12 +99,13 @@ max-line-length = 88
11599
[tool.tox]
116100
legacy_tox_ini = """
117101
[tox]
118-
envlist = py37,py38,py39,py310,py311,py312,coverage,mypy,pre-commit
102+
envlist = py37,py38,py39,py310,py311,py312,coverage,mypy
119103
skip_missing_interpreters = true
120104
isolated_build = True
121105
122106
[testenv]
123-
deps = .[test]
107+
deps =
108+
.[test]
124109
commands =
125110
coverage run -p -m pytest tests/
126111
@@ -137,11 +122,4 @@ deps =
137122
mypy
138123
commands =
139124
mypy -p module_name --no-incremental
140-
141-
[testenv:pre-commit]
142-
depends = coverage
143-
parallel_show_output = true
144-
skip_install = true
145-
deps = pre-commit
146-
commands = pre-commit run --all-files --show-diff-on-failure
147125
"""

requirements/requirements-dev.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Development Requirements - linting, formatting, etc.
2+
# --index-url=http://pypi.example.com/simple
3+
# --no-cache-dir
4+
5+
pre-commit
6+
black
7+
mypy
8+
flake8
9+
flake8-builtins
10+
flake8-pep585

requirements/requirements-dev.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --resolver=backtracking requirements/requirements-dev.in
6+
#
7+
black==23.1.0
8+
# via -r requirements/requirements-dev.in
9+
cfgv==3.3.1
10+
# via pre-commit
11+
click==8.1.3
12+
# via black
13+
distlib==0.3.6
14+
# via virtualenv
15+
filelock==3.9.0
16+
# via virtualenv
17+
flake8==6.0.0
18+
# via
19+
# -r requirements/requirements-dev.in
20+
# flake8-builtins
21+
flake8-builtins==2.1.0
22+
# via -r requirements/requirements-dev.in
23+
flake8-pep585==0.1.6
24+
# via -r requirements/requirements-dev.in
25+
identify==2.5.18
26+
# via pre-commit
27+
mccabe==0.7.0
28+
# via flake8
29+
mypy==1.0.0
30+
# via -r requirements/requirements-dev.in
31+
mypy-extensions==1.0.0
32+
# via
33+
# black
34+
# mypy
35+
nodeenv==1.7.0
36+
# via pre-commit
37+
packaging==23.0
38+
# via black
39+
pathspec==0.11.0
40+
# via black
41+
platformdirs==3.0.0
42+
# via
43+
# black
44+
# virtualenv
45+
pre-commit==3.0.4
46+
# via -r requirements/requirements-dev.in
47+
pycodestyle==2.10.0
48+
# via flake8
49+
pyflakes==3.0.1
50+
# via flake8
51+
pyyaml==6.0
52+
# via pre-commit
53+
tomli==2.0.1
54+
# via
55+
# black
56+
# mypy
57+
typing-extensions==4.5.0
58+
# via
59+
# black
60+
# mypy
61+
virtualenv==20.19.0
62+
# via pre-commit
63+
64+
# The following packages are considered to be unsafe in a requirements file:
65+
# setuptools

requirements/requirements-test.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Testing Requirements - pytest, tox, etc.
2+
# --index-url=http://pypi.example.com/simple
3+
# --no-cache-dir
4+
5+
pytest
6+
pytest-randomly
7+
coverage
8+
tox

requirements/requirements-test.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --resolver=backtracking requirements/requirements-test.in
6+
#
7+
attrs==22.2.0
8+
# via pytest
9+
cachetools==5.3.0
10+
# via tox
11+
chardet==5.1.0
12+
# via tox
13+
colorama==0.4.6
14+
# via tox
15+
coverage==7.1.0
16+
# via -r requirements/requirements-test.in
17+
distlib==0.3.6
18+
# via virtualenv
19+
exceptiongroup==1.1.0
20+
# via pytest
21+
filelock==3.9.0
22+
# via
23+
# tox
24+
# virtualenv
25+
importlib-metadata==6.0.0
26+
# via pytest-randomly
27+
iniconfig==2.0.0
28+
# via pytest
29+
packaging==23.0
30+
# via
31+
# pyproject-api
32+
# pytest
33+
# tox
34+
platformdirs==3.0.0
35+
# via
36+
# tox
37+
# virtualenv
38+
pluggy==1.0.0
39+
# via
40+
# pytest
41+
# tox
42+
pyproject-api==1.5.0
43+
# via tox
44+
pytest==7.2.1
45+
# via
46+
# -r requirements/requirements-test.in
47+
# pytest-randomly
48+
pytest-randomly==3.12.0
49+
# via -r requirements/requirements-test.in
50+
tomli==2.0.1
51+
# via
52+
# pyproject-api
53+
# pytest
54+
# tox
55+
tox==4.4.5
56+
# via -r requirements/requirements-test.in
57+
virtualenv==20.19.0
58+
# via tox
59+
zipp==3.13.0
60+
# via importlib-metadata

requirements/requirements.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Requirements
2+
# --index-url=http://pypi.example.com/simple
3+
# --no-cache-dir

0 commit comments

Comments
 (0)