Skip to content

Commit 8a0f25d

Browse files
committed
ops(build): replace template symlink with copy
symlinks break wheel creation after all
1 parent 757686a commit 8a0f25d

File tree

5 files changed

+190
-10
lines changed

5 files changed

+190
-10
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ __pycache__
1010
build
1111
.obsidian
1212
docs/examples
13+
src/init_python_project/template
14+
src/init_python_project/copier.yaml

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,19 @@ PKGNAME=init_python_project
111111
PKGDIR=src/${PKGNAME}
112112
BUILDDIR?=build/dist
113113
PYTHON?=python
114-
build: ## build package
114+
TEMPLATE_SRC?=./template
115+
TEMPLATE_DEST?=${PKGDIR}/template
116+
build: copy-template ## build package
115117
@${PYTHON} -m pip install --upgrade build
116118
@${PYTHON} -m build --outdir ${BUILDDIR} .
117119
install-build: build
118120
@pip uninstall -y ${PKGNAME}
119121
pip install --force-reinstall ${BUILDDIR}/*.whl
122+
copy-template:
123+
@cp -r ${TEMPLATE_SRC} ${TEMPLATE_DEST}
124+
@cp copier.yaml ${PKGDIR}/.
125+
build-clean: ## remove build artifacts
126+
rm -rf ${BUILDDIR} ${PKGDIR}/template ${PKGDIR}/copier.yaml
120127

121128

122129
.PHONY: help

noxfile.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@
55

66
nox.options.reuse_existing_virtualenvs = True
77
nox.options.stop_on_first_error
8-
nox.options.sessions = ['build', 'test']
8+
nox.options.sessions = ["build", "test"]
99

10-
source_directories = ('src')
10+
source_directories = "src"
1111

12-
supported_python_versions = ['3.11']
12+
supported_python_versions = ["3.11"]
1313

1414
root = pathlib.Path(__file__).parent
15-
build_dir = root/"build"/"dist"
15+
build_dir = root / "build" / "dist"
16+
1617

1718
@nox.session
1819
def build(session: nox.Session):
1920
if build_dir.is_dir():
2021
shutil.rmtree(build_dir)
2122
build_dir.mkdir(parents=True, exist_ok=False)
2223

23-
session.run('make', 'build' , external=True, env={'BUILDDIR': str(build_dir)})
24+
session.run("make", "build", external=True, env={"BUILDDIR": str(build_dir)})
2425

2526

2627
@nox.session(python=supported_python_versions)
2728
def test(session: nox.Session):
2829
"""Run all tests against dev and target environment."""
29-
wheel_files = sorted(build_dir.glob('*.whl'))
30+
wheel_files = sorted(build_dir.glob("*.whl"))
3031
print(wheel_files)
3132
assert len(wheel_files) == 1, "a single wheel should have been built"
3233
wheel_file = wheel_files[0]
3334
session.install(f"{wheel_file}[test]")
34-
session.run('pytest', '-k', 'test_package', *session.posargs, env={'BIN_PATH': str(session.bin)})
35+
session.run(
36+
"pytest", "-k", "test_package", *session.posargs, env={"BIN_PATH": str(session.bin)}
37+
)

src/init_python_project/copier.yaml

-1
This file was deleted.

src/init_python_project/copier.yaml

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
_subdirectory: template
2+
3+
project_name:
4+
type: str
5+
help: What is the name of your project?
6+
placeholder: Sample Project
7+
expected: Title case string, can contain spaces
8+
explanation: |
9+
The project name will be used to propose a suitable package name and [Remote Url][remote-url].
10+
It is also repeated in multiple places (Python package configuration, documentation, etc.).
11+
12+
package_name:
13+
type: str
14+
help: What is the name of your Python package?
15+
default: "{{ project_name|lower|replace(' ', '_')|replace('-', '_') }}"
16+
expected: Lowercase string, can contain underscores
17+
explanation: |
18+
This is the name of your Python package. As such, it will be used as the name of the directory containing your code.
19+
All imports of your package start with this name.
20+
21+
Example: If you choose `sample_project` as your package name, your code files would be created in
22+
23+
```
24+
./
25+
├── src
26+
│ └── sample_project
27+
│ ├── __init__.py
28+
│ ├── __main__.py
29+
│ └── some_module.py
30+
├── pyproject.toml
31+
└── ...
32+
```
33+
34+
and your imports would look like this:
35+
36+
```python
37+
from sample_project import some_module
38+
```
39+
40+
You might want to consult [PEP 423 – Naming conventions and recipes related to packaging](https://peps.python.org/pep-0423/)
41+
for guidance on Python package name conventions.
42+
43+
The cli command included with this template will be named after your package, only with dashes instead of underscores.
44+
Following the example above, your cli would then be available as
45+
46+
```console
47+
$ sample-project --help
48+
```
49+
50+
If you ever want to publish your Python package to [PyPI](https://pypi.org), the package name has to be unique to be accepted there.
51+
52+
Finally, the package name is repeated across multiple configuration and documentation files.
53+
54+
use_precommit:
55+
type: bool
56+
default: true
57+
help: Use pre-commit to run checks on each commit?
58+
explanation: |
59+
[pre-commit](../reference/tooling/pre-commit.md) is a tool that makes configuring [git hooks][git-hooks] a lot easier.
60+
61+
This template uses pre-commit hooks to ensure, all changes match the expected formatting and style.
62+
Additionally, running linters at this stage can prevent committing something that contains obvious issues.
63+
64+
Most formatters and some linters are able to fix issues automatically.
65+
So you can simply review the changes those tools made, stage them and commit again.
66+
67+
use_bumpversion:
68+
type: bool
69+
default: false
70+
help: Use bumpversion to manage semantic version across multiple files?
71+
explanation: |
72+
If you want to version your project, [bumpversion][] provides an easy way to increase version numbers across multiple files.
73+
74+
It integrates with git and helps with your release workflow by automating version bump, commit and tag creation.
75+
Used correctly, releasing a new version of your project can be done with a single command.
76+
77+
It also helps to follow [semantic versioning][semantic-versioning] guidelines when increasing your version numbers.
78+
79+
docs:
80+
type: str
81+
choices:
82+
Material for MkDocs: mkdocs
83+
Sphinx: sphinx
84+
None: none
85+
default: "mkdocs"
86+
help: Which documentation tool do you want to use?
87+
explanation: |
88+
[Documentation][documentation] is an important part of any project.
89+
90+
So far, this template supports two documentation tools: [MkDocs][mkdocs] and [Sphinx][sphinx].
91+
92+
[MkDocs][mkdocs] is a great documentation tool built around [Markdown][markdown].
93+
It is easy to use and produces a great looking documentation website with minimal overhead and configuration.
94+
95+
[Sphinx][sphinx] is a powerful tool for documentation written in [Markdown][markdown] or [reStructuredText][restructuredtext].
96+
With the [`myst_parser`][myst_parser] it is now (almost) possible to rely on Markdown only.
97+
Choose this if you want to publish your documentation in multiple formats (e.g. PDF, HTML, ePub, ...).
98+
99+
If you are not sure which one to use, simply go with the default 😉.
100+
101+
remote:
102+
choices:
103+
GitHub: github
104+
FHG Gitlab: gitlab-fhg
105+
IIS Gitlab: gitlab-iis
106+
help: Which platform will your project be hosted on?
107+
default: "github"
108+
explanation: |
109+
This template provides a CI configuration for either GitHub (Github Actions) or GitLab (Gitlab CI).
110+
111+
Also, the link to your documentation depends on which remote you choose.
112+
113+
If you want to push your project to multiple remotes, you can add them later.
114+
115+
user_name:
116+
type: str
117+
help: User name (the one you used with your hosted git provider)
118+
explanation: |
119+
This is the user name you are using with the remote provider you provided in the previous question.
120+
121+
Together with [remote][], it will be used to suggest a [remote url][remote-url] for your project.
122+
123+
remote_url:
124+
type: str
125+
help: URL of the remote repository
126+
default: git@{% if remote=='github' %}github.com{% elif remote=='gitlab-iis' %}git01.iis.fhg.de{% elif remote=='gitlab-fhg' %}gitlab.cc-asp.fraunhofer.de{% endif %}:{{user_name}}/{{project_name | lower | replace(' ', '-')}}.git
127+
expected: SSH URL to your remote repository
128+
explanation: |
129+
Apart from configuring the git remote for you, the remote URL is required to determine other values, such as
130+
131+
- Links in your README and CHANGELOG files
132+
- Links to your documentation
133+
- Link to your repository from your documentation
134+
- ...
135+
136+
If you did not create your remote repository yet (i.e. new project at GitHub or Gitlab), this might be a good time to do so.
137+
138+
!!! tip "Create empty repository"
139+
140+
Do not initialize your remote project with a LICENSE or README file.
141+
This will let you push your initial commit without merge or rebase.
142+
143+
=== "Gitlab"
144+
145+
![](https://cln.sh/gwzwgtHH+)
146+
*The SSH URL to your Gitlab repository can be found under the `Clone` dropdown (screenshot taken 23.08.23)*{.caption}
147+
148+
149+
=== "GitHub"
150+
151+
![](https://cln.sh/SscJVB6N+)
152+
*The SSH URL to your GitHub repository can be found under the `<> Code` dropdown menu (screenshot taken 23.08.23)*{.caption}
153+
154+
default_branch:
155+
type: str
156+
default: main
157+
help: Name of the initial git branch that will be created
158+
expected: Lowercase string, can contain dashes
159+
examples: [main, master, dev]
160+
explanation: |
161+
Name of the [initial branch][] of your new project.
162+
163+
This branch traditionally was called `master`, but is more often called `main` now.
164+
165+
[initial branch]: https://git-scm.com/docs/git-init#Documentation/git-init.txt---initial-branchltbranch-namegt
166+
_tasks:
167+
- "rm -rf context"
168+
- "git init --initial-branch={{default_branch}}"
169+
- "git remote add origin {{remote_url}} || true"
170+
- "{% if use_precommit %}pre-commit install || echo 'Error during installation of pre-commit hooks. Is pre-commit installed?'{% endif %}"

src/init_python_project/template

-1
This file was deleted.

0 commit comments

Comments
 (0)