1
1
# Example Python Project
2
2
3
3
This is how I like to lay my Python projects out. You don't have to do it
4
- this way, but this way works for me. If you think it's bad or out of date
5
- feel free to create an issue or even a pull request.
4
+ this way, but this way works for me.
5
+
6
+ You can use it as a template, if you're reading this on GitHub then push the
7
+ "Use this template" button
6
8
7
9
## To run me
8
10
9
11
make dev
10
12
11
- Then open the project dir in Visual Studio code, if you like to use an IDE.
13
+ Then open the project dir in Visual Studio code, if you like to use an IDE. I
14
+ only use it for debugging my tests, I use ` vim ` most of the time.
12
15
13
16
## Project structure
14
17
15
18
### Makefile
16
19
17
20
I like to use a ` Makefile ` to install my dependencies, build env, run tests
18
- and create packages. I get tab completion and it doesn't matter what CI
19
- platform I use, I just run ` make stuff ` and let GNU Make deal with it.
21
+ and create packages. I get tab completion in my IDE and it doesn't matter what
22
+ CI platform I use, I just run ` make stuff ` and let GNU Make deal with it.
23
+
20
24
` Makefile ` s are of course an ancient curse, but if you don't use them you'll
21
25
have to live in interesting times, which is a far worse curse.
22
26
43
47
44
48
### Linting and commit checks
45
49
46
- I'm using ` ruff ` now for formatting and linting.
50
+ I'm using ` ruff ` now for formatting and linting, dropping the ` flake8 ` , ` black `
51
+ and ` isort ` mess that I used before.
47
52
48
53
Part of the ` make dev ` setup installs ` pre-commit ` , which will make sure that
49
54
commits are up to a certain standard. The provided config file runs the code
50
- formatters, linters and a few other checks. Have a look at
51
- ` .pre-commit-config.yaml ` to see what's going on in there. pre-commit is very
52
- slow and very annoying, but it forces code quality on us which makes up for the
53
- inconvenience.
55
+ formatters, linters and a few other checks. Read ` .pre-commit-config.yaml ` and
56
+ see what's going on in there. ` pre-commit ` is very slow and very annoying, but
57
+ it forces code quality on us which mostly makes up for the inconvenience of it
58
+ blocking your commits.
59
+
60
+ You can use ` git commit -n ` to skip the pre-commit tests.
54
61
55
62
### IDE
56
63
57
- I'm using VS Code when I use an IDE because it works everywhere and supports
58
- all the things that I need. I commit my config to source control so
59
- anyone can open the project dir and start hacking with a working debugger and
60
- tests auto-detected. This is a nice new paradigm where the IDE settings don't
61
- belong to the user, they belong to the project, so it's appropriate to put
62
- them in source control. If your
64
+ I'm using VS Code when I use an IDE. It works everywhere and supports all the
65
+ things that I need. I commit my config to source control so anyone can open the
66
+ project dir and start hacking with a working debugger and tests auto-detected.
67
+
68
+ This modern paradigm where the IDE settings belong to the project rather than
69
+ the user means it's appropriate to put them in source control. If your
70
+ colleagues disagree, they're wrong.
63
71
64
72
The config also provides recommendations for extensions, which you'll be
65
73
prompted to install when you open the project for the first time.
66
74
67
75
I could (and sometimes do) go one step further and use devcontainers, but at
68
- time of writing it's still a bit fiddly to get set up.
76
+ time of writing it's still a bit fiddly to get set up. Plus I've not been stuck
77
+ in Windows for a while. If you're in Windows, install WSL and get a proper
78
+ console.
69
79
70
80
### Package layout
71
81
72
- Under the ` example_package ` dir there's a ` pyproject.toml ` that defines the
73
- package and its dependencies. Then there's ` src ` and ` test ` dirs that contain
74
- the code and tests.
82
+ There's a ` pyproject.toml ` here at the root dependencies.
75
83
76
84
The layout is as-per the pypi packaging guidelines. When referencing stuff in
77
85
the code I tend to use the full ` package.module ` names because otherwise imports
@@ -96,23 +104,16 @@ Run `make coverage` for a test coverage report.
96
104
### CI and CD
97
105
98
106
There's a couple of workflows in the ` .github ` dir, one to run the unit tests
99
- and one to release the project to pypi. The first
100
-
101
- The release process runs whenever you
102
- push tag changes to GitHub.
103
-
104
- Before the release process will work you
105
- need to get a key from pypi and add
106
-
107
- there's a couple of workflows, one that runs the
108
- ` make test ` any time a commit is pushed. This
107
+ and one to release the project to pypi. The unit tests one runs on every push,
108
+ the release one runs on
109
109
110
110
### Documentation
111
111
112
112
You'll see a ` mkdocs ` config in the root. This is combined with the ` make docs `
113
- script to make the github pages documentation for the project. If you look at
114
- this README.md file you'll see it's actually a symlink to the one in the package
115
- dir, and it's also symlinked from
113
+ script to make the github pages documentation for the project.
114
+
115
+ I don't use this anymore as I have my own docs script for my website - it
116
+ pushes a new commit to my github pages website. If I remember to, I'll
116
117
117
118
## Some opinionated stuff
118
119
@@ -127,6 +128,9 @@ stubs, test data, functional and integration tests, infrastructure code,
127
128
architecture diagrams and specs - everything you need to actually understand
128
129
the project in one place.
129
130
131
+ Unfortunately you can't ` pip install ` a path within a git repository, so
132
+ everything is still at the root in this one.
133
+
130
134
## Docs in Markdown
131
135
132
136
Did you know that you can add a ` README.md ` to any dir and it'll get rendered
@@ -138,3 +142,17 @@ general rule, up to a point anyway. The project wiki is somewhere else, it goes
138
142
out of sync, it's difficult to see what the docs were on a specific release
139
143
tag. Docs in the codebase can be edited alongside new features and have a much
140
144
richer history.
145
+
146
+ ## License choice
147
+
148
+ I'm using the WTFPL with a warranty clause as an experiment I've been running
149
+ for years. I wouldn't recommend you do the same unless you understand the risks
150
+ and think it's worth it.
151
+
152
+ My thinking is that you're a human being, I'm a human being. I agree to share my
153
+ code as long as you don't blame me, an agreement in plain English not legalese.
154
+ If you sue me, you broke that agreement. Doesn't matter how you put it, in plain
155
+ English you're blaming me and don't have rights to use it. Any judge ruling
156
+ against me would be making a statement that their court does not serve the
157
+ public. I don't think they'd do that, and if they were forced to by case law
158
+ then it'd go all the way to the top. And I'd defend myself.
0 commit comments