Skip to content

Commit c501dc7

Browse files
committed
update so we can install from git url, and move scripts dir too
1 parent bc854cc commit c501dc7

25 files changed

Lines changed: 155 additions & 56 deletions

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-toml
66
- id: check-symlinks
@@ -10,26 +10,26 @@ repos:
1010
- id: mixed-line-ending
1111
- id: trailing-whitespace
1212
- repo: https://github.com/psf/black
13-
rev: 22.10.0
13+
rev: 24.10.0
1414
hooks:
1515
- id: black
1616
- repo: https://github.com/PyCQA/isort
17-
rev: 5.10.1
17+
rev: 5.13.2
1818
hooks:
1919
- id: isort
2020
- repo: https://github.com/PyCQA/flake8
21-
rev: 5.0.4
21+
rev: 7.1.1
2222
hooks:
2323
- id: flake8
2424
- repo: https://github.com/shellcheck-py/shellcheck-py
25-
rev: v0.8.0.4
25+
rev: v0.10.0.1
2626
hooks:
2727
- id: shellcheck
2828
- repo: https://github.com/jackdewinter/pymarkdown
29-
rev: v0.9.8
29+
rev: v0.9.25
3030
hooks:
3131
- id: pymarkdown
3232
- repo: https://github.com/cmake-lint/cmake-lint
33-
rev: 1.4.2
33+
rev: 1.4.3
3434
hooks:
3535
- id: cmakelint

.vscode/extensions.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"recommendations": [
33
"ms-python.python",
4-
"davidanson.vscode-markdownlint"
4+
"davidanson.vscode-markdownlint",
5+
"ms-vscode.makefile-tools",
6+
"ms-python.flake8"
57
]
68
}

.vscode/settings.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"python.linting.enabled": true,
66
"python.testing.pytestEnabled": true,
77
"python.testing.unittestEnabled": false,
8-
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python3",
9-
"python.envFile": "${workspaceFolder}/.env"
8+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
9+
"python.analysis.extraPaths": ["${workspaceFolder}/merge-files/src"],
10+
"python.envFile": "${workspaceFolder}/.env",
11+
"[python]": {
12+
"editor.defaultFormatter": "ms-python.black-formatter"
13+
},
14+
"python.formatting.provider": "none"
1015
}

LICENSE.txt renamed to LICENSE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# WTFPL + Warranty
2+
13
Licensed under the WTFPL with one additional clause:
24

35
1. Don't blame me.

Makefile

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,53 @@
33
pre-commit update-pre-commit
44

55

6-
all: dev coverage ## builds everything
6+
PROJECT_NAME := example_package
77

8-
install: .venv/.installed ## installs the venv and the project packages
98

10-
dev: .venv/.installed-dev pre-commit ## prepare local repo and venv for dev
9+
all: dev coverage ## builds everything
10+
11+
install: .venv/.installed ## installs the venv and the project packages
12+
13+
dev: .venv/.installed-dev pre-commit ## prepare local repo and venv for dev
1114

1215
test: .venv/.installed-dev ## run the project's tests
13-
build/test.sh
16+
scripts/test.sh $(PROJECT_NAME)
1417

15-
coverage: .venv/.installed-dev build/coverage.sh ## build the html coverage report
16-
build/coverage.sh
18+
coverage: .venv/.installed-dev scripts/coverage.sh ## build the html coverage report
19+
scripts/coverage.sh $(PROJECT_NAME)
20+
21+
docs: .docs/index.html ## build the documentation
1722

1823
clean: ## delete caches and the venv
19-
build/clean.sh
24+
scripts/clean.sh
2025

21-
pre-commit: .git/hooks/pre-commit ## install pre-commit into the git repo
26+
pre-commit: .git/hooks/pre-commit ## install pre-commit into the git repo
2227

23-
update-pre-commit: build/update-pre-commit.sh ## autoupdate pre-commit
24-
build/update-pre-commit.sh
28+
update-pre-commit: scripts/update-pre-commit.sh ## autoupdate pre-commit
29+
scripts/update-pre-commit.sh
2530

31+
dist: scripts/dist.sh ## build the distributable files
32+
scripts/dist.sh $(PROJECT_NAME)
2633

34+
release: scripts/release.sh ## publish to pypi
35+
scripts/release.sh $(PROJECT_NAME)
2736

2837
# Caching doesn't work if we depend on PHONY targets
2938

30-
.venv/.installed: */pyproject.toml .venv/bin/activate build/install.sh
31-
build/install.sh
39+
.docs/index.html: .venv/.installed-dev scripts/docs.sh mkdocs.yml $(shell find -name '*.md')
40+
scripts/docs.sh $(PROJECT_NAME)
41+
42+
.venv/.installed: pyproject.toml .venv/bin/activate scripts/install.sh $(shell find src -name '*.py')
43+
scripts/install.sh $(PROJECT_NAME)
3244

33-
.venv/.installed-dev: */pyproject.toml .venv/bin/activate build/install-dev.sh
34-
build/install-dev.sh
45+
.venv/.installed-dev: pyproject.toml .venv/bin/activate scripts/install-dev.sh
46+
scripts/install-dev.sh $(PROJECT_NAME)
3547

3648
.venv/bin/activate:
37-
build/venv.sh
49+
scripts/venv.sh
3850

39-
.git/hooks/pre-commit: build/install-pre-commit.sh
40-
build/install-pre-commit.sh
51+
.git/hooks/pre-commit: scripts/install-pre-commit.sh
52+
scripts/install-pre-commit.sh
4153

4254

4355
help: ## Show this help

README.md

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The trick is:
2424

2525
1. Have each step run one script that has a good name, so they're documented
2626
by that script and its name, and can be run without `make` - like from
27-
your editor or whatever. I keep mine in `./build/`. The reason for having
27+
your editor or whatever. I keep mine in `./scripts/`. The reason for having
2828
them as separate scripts is because you might want to bypass dependencies
2929
in a CI pipeline.
3030
2. Have the dependencies for the step be the script itself plus one file
@@ -47,9 +47,15 @@ I like `flake8` for linting because it's not as harsh as `pylint`, and is
4747
supported by my IDE of choice.
4848

4949
Part of the `make dev` setup installs `pre-commit`, which will make sure that
50-
commits are up to a certain standard. The provided config file runs code
50+
commits are up to a certain standard. The provided config file runs the code
5151
formatters, linters and a few other checks. Have a look at
52-
`.pre-commit-config.yaml` to see what's going on in there.
52+
`.pre-commit-config.yaml` to see what's going on in there. pre-commit is very
53+
slow and very annoying, but it forces code quality on us which makes up for the
54+
inconvenience.
55+
56+
See the `.flake8` config for some ignored rules where flake8 and black get into
57+
a fight, and there's `isort` and `black` conflict rules in the pre-commit
58+
config too.
5359

5460
### IDE
5561

@@ -62,6 +68,9 @@ belong to the project, so it's appropriate to put them in source control.
6268
The config also provides recommendations for extensions, which you'll be
6369
prompted to install when you open the project for the first time.
6470

71+
I could (and sometimes do) go one step further and use devcontainers, but at
72+
time of writing it's still a bit fiddly to get set up.
73+
6574
### Package layout
6675

6776
Under the `example_package` dir there's a `pyproject.toml` that defines the
@@ -71,19 +80,43 @@ the code and tests.
7180
The layout is as-per the pypi packaging guidelines. When referencing stuff in
7281
the code I tend to use the full `package.module` names because otherwise imports
7382
tend to break in weird ways in different environments, and it means I can
74-
reference stuff in parent directories without ripping my hair out.
83+
reference stuff in parent directories without ripping my hair out. It makes the
84+
imports look a bit Java-y but it's staying that way until implicit imports are
85+
removed from Python.
7586

7687
### Testing
7788

78-
I use `pytest` and write tests in a functional style, and develop using TDD.
79-
If you get into the habit of actually running a new piece of code from a new
80-
unit test then you'll find yourself writing testable code. Tests are
89+
I use `pytest` and write tests in a functional style, and develop largely using
90+
TDD. If you get into the habit of actually running a new piece of code from a
91+
new unit test then you'll find yourself writing testable code. Tests are
8192
fundamentally just other pieces of code, so if a function is difficult to test
82-
then it's probably difficult to reuse too.
93+
then it's probably difficult to reuse too. But it doesn't work all the time;
94+
testing filesystem interactions and external services have a heavy
95+
test-development overhead, which hinders rather than helps refactoring efforts;
96+
your mileage may vary.
97+
98+
Run `make coverage` for a test coverage report.
99+
100+
### CI and CD
101+
102+
There's a couple of workflows in the `.github` dir, one to run the unit tests
103+
and one to release the project to pypi. The first
104+
105+
The release process runs whenever you
106+
push tag changes to GitHub.
107+
108+
Before the release process will work you
109+
need to get a key from pypi and add
110+
111+
there's a couple of workflows, one that runs the
112+
`make test` any time a commit is pushed. This
113+
114+
### Documentation
83115

84-
Run `make coverage` for a test coverage report. I like to keep my coverage at
85-
100%. Not sure if that's a taste thing or a side-effect of the way I'm
86-
developing, but I like it.
116+
You'll see a `mkdocs` config in the root. This is combined with the `make docs`
117+
script to make the github pages documentation for the project. If you look at
118+
this README.md file you'll see it's actually a symlink to the one in the package
119+
dir, and it's also symlinked from
87120

88121
## Some opinionated stuff
89122

build/clean.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ dev = [
1313
"flake8",
1414
"pre-commit",
1515
"pytest",
16-
"coverage"
16+
"coverage",
17+
"pytest-cov"
1718
]
1819

1920
[build-system]

scripts/clean.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
rm -r .venv 2>/dev/null
4+
rm .coverage 2>/dev/null
5+
rm -r htmlcov 2>/dev/null
6+
rm .git/hooks/pre-commit 2>/dev/null
7+
find . -name '__pycache__' -exec rm -rv {} \; 2>/dev/null
8+
find . -name '*.egg-info' -exec rm -rv {} \; 2>/dev/null
9+
find . -name '.pytest_cache' -exec rm -rv {} \; 2>/dev/null
10+
rm ./*/dist -r 2>/dev/null
11+
12+
echo Cleaned project
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
source .venv/bin/activate
44

5-
coverage run -m pytest ./*/tests
6-
coverage html
5+
pytest --cov="src/$1" --cov-report=html .

0 commit comments

Comments
 (0)