Skip to content

Commit a8d27b5

Browse files
authored
Merge pull request #1 from boltronics/use_hatch
Replace setuptools with Hatch
2 parents 054eee6 + c172299 commit a8d27b5

File tree

14 files changed

+163
-174
lines changed

14 files changed

+163
-174
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
15+
python-version: ["3.11", "3.12", "3.13"]
1616

1717
steps:
1818
- uses: actions/checkout@v3
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
path: ~/.cache/pip # This path is specific to Ubuntu
3131
# Check for a cache hit for the corresponding dev requirements file
32-
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.dev.txt') }}-${{ hashFiles('requirements.txt') }}
32+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
3333
restore-keys: |
3434
${{ runner.os }}-pip-
3535
${{ runner.os }}-
@@ -39,8 +39,8 @@ jobs:
3939
- name: Check example project
4040
run: |
4141
cd example
42-
pip install -r requirements.dev.txt
43-
pip install .
42+
make venv
43+
. venv/bin/activate
4444
make help
4545
make style
4646
make check-style

README.rst

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ the following items:
3434
developer documentation.
3535
- An empty ``CHANGELOG.rst`` file. This file gets included in the user
3636
documentation.
37-
- A ``LICENSE`` file (or ``COPYING`` for GNU licenses) that defaults
38-
to the Apache License version 2.0.
37+
- An option ``LICENSE`` file (or ``COPYING`` for GNU licenses).
3938
- An ``examples`` directory with a minimal quickstart example script. This
4039
script imports the package and prints the package version. It is also
4140
called by the unit test suite to ensure it always works.
@@ -77,9 +76,9 @@ cookiecutter using ``pip``. The example below shows how to do this.
7776

7877
.. code-block:: console
7978
80-
$ python -m venv ccvenv --prompt cc
79+
$ python -m venv --prompt cc ccvenv
8180
$ source ccvenv/bin/activate
82-
(cc) $ pip install pip -U # update pip to avoid any warnings
81+
(cc) $ pip install -U pip # update pip to avoid any warnings
8382
(cc) $ pip install cookiecutter
8483
8584
You are now ready to create a new Python project from the Cookiecutter
@@ -132,11 +131,12 @@ using the new project.
132131
ReadTheDocs then remove any links to those sites. Affected files are:
133132

134133
- README.rst
135-
- setup.py
136134
- docs/source/index.rst
135+
- pyproject.toml
137136

138-
- Update any additional useful classifiers in ``setup.py``. The list of
139-
available classifiers can be found `here <https://pypi.python.org/pypi?:action=list_classifiers>`_.
137+
- Update any additional useful classifiers in ``pyproject.toml``. The
138+
list of available classifiers can be found `here
139+
<https://pypi.python.org/pypi?:action=list_classifiers>`_.
140140

141141

142142
Example
@@ -162,24 +162,26 @@ Python package name.
162162
.. code-block:: console
163163
164164
(cc) $ cookiecutter ../cookiecutter-python-project/
165-
package_display_name [Package-Name]: abc 123
166-
package_name [abc_123]:
167-
package_short_description [A description of the package]: This is my abc 123 package.
168-
version [0.0.1]:
169-
full_name [Your Name]: First Last
170-
email []:
171-
github_user_name [GithubUserName]: flast
172-
github_repo_name [abc_123]:
173-
Select license:
174-
1 - Apache License, Version 2.0
175-
2 - Expat License
176-
3 - GNU GPL version 2
177-
4 - GNU GPL version 3
178-
5 - GNU AGPL version 3
179-
6 - Modified BSD license (3-clause)
180-
7 - Not licensed for distribution (no license)
181-
Choose from 1, 2, 3, 4, 5, 6, 7 [1]:
182-
year [2023]:
165+
[1/10] package_display_name (Package-Name): abc 123
166+
[2/10] package_name (abc_123):
167+
[3/10] package_short_description (A description of the package): This is my abc 123 package.
168+
[4/10] version (0.0.1):
169+
[5/10] full_name (Your Name): First Last
170+
[6/10] email ():
171+
[7/10] github_user_name (GithubUserName): flast
172+
[8/10] github_repo_name (abc_123):
173+
[9/10] Select license
174+
1 - Not licensed for distribution (no license)
175+
2 - AGPL-3.0-only
176+
3 - AGPL-3.0-or-later
177+
4 - Apache-2.0
178+
5 - BSD-3-Clause
179+
6 - GPL-2.0-only
180+
7 - GPL-2.0-or-later
181+
8 - GPL-3.0-only
182+
9 - GPL-3.0-or-later
183+
Choose from [1/2/3/4/5/6/7/8/9] (1):
184+
[10/10] year (2024):
183185
184186
The project has been created in the ``abc_123`` directory.
185187

cookiecutter.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
"github_user_name": "GithubUserName",
99
"github_repo_name": "{{cookiecutter.package_name}}",
1010
"license": [
11-
"Apache License, Version 2.0",
12-
"Expat License",
13-
"GNU GPL version 2",
14-
"GNU GPL version 3",
15-
"GNU AGPL version 3",
16-
"Modified BSD license (3-clause)",
17-
"Not licensed for distribution (no license)"
11+
"Not licensed for distribution (no license)",
12+
"AGPL-3.0-only",
13+
"AGPL-3.0-or-later",
14+
"Apache-2.0",
15+
"BSD-3-Clause",
16+
"GPL-2.0-only",
17+
"GPL-2.0-or-later",
18+
"GPL-3.0-only",
19+
"GPL-3.0-or-later"
1820
],
1921
"year": "{% now 'utc', '%Y' %}"
2022
}

hooks/post_gen_project.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@
1313
LICENSE_SELECTED = "{{ cookiecutter.license }}"
1414

1515

16-
def deploy_license():
16+
def deploy_license() -> None:
1717
"""Move the selected license file into the project root
1818
1919
Licenses not selected for the project are removed.
2020
"""
21+
sources: set[Path] = set()
22+
selected_source = None
2123
with LICENSE_CONFIG.open(mode="r", encoding="utf-8") as config_file:
2224
config = json.load(config_file)
2325
for license_option, license_data in config.items():
26+
source_path = LICENSE_DIR.joinpath(license_data["source"])
2427
if license_option == LICENSE_SELECTED:
25-
LICENSE_DIR.joinpath(license_data["source"]).rename(
26-
PROJECT_DIR.joinpath(license_data["destination"])
27-
)
28-
else:
29-
LICENSE_DIR.joinpath(license_data["source"]).unlink()
28+
selected_source = source_path
29+
destination_path = PROJECT_DIR.joinpath(license_data["destination"])
30+
source_path.rename(destination_path)
31+
sources.discard(source_path)
32+
elif license_data["source"] != selected_source:
33+
sources.add(source_path)
34+
for source in sources:
35+
source.unlink()
3036
LICENSE_CONFIG.unlink()
3137
LICENSE_DIR.rmdir()
3238

{{cookiecutter.package_name}}/.github/workflows/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
16+
python-version: ["3.11", "3.12", "3.13"]
1717

1818
steps:
1919
- uses: actions/checkout@v3
@@ -23,15 +23,14 @@ jobs:
2323
python-version: ${{ matrix.python-version }}
2424
- name: Install dependencies
2525
run: |
26-
python -m pip install --upgrade pip
27-
pip install -r requirements.dev.txt
28-
pip install -r requirements.txt
26+
python -m pip install -U pip
27+
python -m pip install .[dev]
2928
- name: Cache pip dependencies
3029
uses: actions/cache@v3
3130
with:
3231
path: ~/.cache/pip # This path is specific to Ubuntu
33-
# Check for a cache hit for the corresponding dev requirements file
34-
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.dev.txt') }}-${{ hashFiles('requirements.txt') }}
32+
# Check for a cache hit for the corresponding pyproject.toml file
33+
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
3534
restore-keys: |
3635
${{ runner.os }}-pip-
3736
${{ runner.os }}-

{{cookiecutter.package_name}}/Makefile

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
# python command links to the appropriate virtual environment Python.
44

55
MAKEFLAGS += --no-print-directory
6+
GIT := $(shell command -v git)
7+
8+
9+
define CHECK_GIT
10+
$(if $(GIT),,$(error "git command not available."))
11+
$(if $(wildcard .git),,$(error "Not a git repository."))
12+
endef
13+
614

715
# Do not remove this block. It is used by the 'help' rule when
816
# constructing the help output.
917
# help:
1018
# help: {{cookiecutter.package_display_name}} Makefile help
1119
# help:
1220

21+
1322
# help: help - display makefile help information
1423
.PHONY: help
1524
help:
@@ -21,10 +30,9 @@ help:
2130

2231
# help: venv - create a dev virtual environment
2332
PIP_CMDS = \
24-
source venv/bin/activate && \
25-
pip install pip --upgrade && \
26-
pip install -r requirements.dev.txt && \
27-
pip install -e .
33+
source venv/bin/activate && \
34+
pip install -U pip && \
35+
pip install -e .[dev]
2836
.PHONY: venv
2937
venv:
3038
@rm -Rf venv
@@ -34,17 +42,18 @@ venv:
3442
"\n\n\t$ source venv/bin/activate\n"
3543

3644

37-
3845
# help: clean - clean all files using .gitignore rules
3946
.PHONY: clean
4047
clean:
41-
@git clean -X -f -d
48+
$(call CHECK_GIT)
49+
@$(GIT) clean -X -f -d
4250

4351

4452
# help: scrub - clean all files, even untracked files
4553
.PHONY: scrub
4654
scrub:
47-
git clean -x -f -d
55+
$(call CHECK_GIT)
56+
@$(GIT) clean -x -f -d
4857

4958

5059
# help: test - run tests
@@ -114,8 +123,7 @@ check-lint:
114123
@pylint --rcfile=.pylintrc \
115124
{{cookiecutter.package_name}} \
116125
examples \
117-
tests \
118-
setup.py
126+
tests
119127

120128

121129
# help: check-static-analysis - check code style compliance
@@ -149,7 +157,7 @@ serve-docs:
149157
# help: dist - create a wheel distribution package
150158
.PHONY: dist
151159
dist:
152-
@python setup.py bdist_wheel
160+
@hatch build
153161

154162

155163
# help: dist-test - test a wheel distribution package

{{cookiecutter.package_name}}/licenses/EXPAT

Lines changed: 0 additions & 20 deletions
This file was deleted.

{{cookiecutter.package_name}}/licenses/GPL2

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Version 2, June 1991
33

44
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5+
<https://fsf.org/>
66
Everyone is permitted to copy and distribute verbatim copies
77
of this license document, but changing it is not allowed.
88

@@ -304,8 +304,7 @@ the "copyright" line and a pointer to where the full notice is found.
304304
GNU General Public License for more details.
305305

306306
You should have received a copy of the GNU General Public License along
307-
with this program; if not, write to the Free Software Foundation, Inc.,
308-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
307+
with this program; if not, see <https://www.gnu.org/licenses/>.
309308

310309
Also add information on how to contact you by electronic and paper mail.
311310

@@ -329,8 +328,8 @@ necessary. Here is a sample; alter the names:
329328
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330329
`Gnomovision' (which makes passes at compilers) written by James Hacker.
331330

332-
<signature of Ty Coon>, 1 April 1989
333-
Ty Coon, President of Vice
331+
<signature of Moe Ghoul>, 1 April 1989
332+
Moe Ghoul, President of Vice
334333

335334
This General Public License does not permit incorporating your program into
336335
proprietary programs. If your program is a subroutine library, you may
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
2-
"Apache License, Version 2.0": {"source": "APACHE-2.0", "destination": "LICENSE"},
3-
"Expat License": {"source": "EXPAT", "destination": "LICENSE"},
4-
"GNU GPL version 3": {"source": "GPL3", "destination": "COPYING"},
5-
"GNU GPL version 2": {"source": "GPL2", "destination": "COPYING"},
6-
"GNU AGPL version 3": {"source": "AGPL3", "destination": "COPYING"},
7-
"Modified BSD license (3-clause)": {"source": "BSD-3-CLAUSE", "destination": "LICENSE"}
2+
"AGPL-3.0-only": {"source": "AGPL3", "destination": "COPYING"},
3+
"AGPL-3.0-or-later": {"source": "AGPL3", "destination": "COPYING"},
4+
"Apache-2.0": {"source": "APACHE-2.0", "destination": "LICENSE"},
5+
"BSD-3-Clause": {"source": "BSD-3-CLAUSE", "destination": "LICENSE"},
6+
"GPL-2.0-only": {"source": "GPL2", "destination": "COPYING"},
7+
"GPL-2.0-or-later": {"source": "GPL2", "destination": "COPYING"},
8+
"GPL-3.0-only": {"source": "GPL3", "destination": "COPYING"},
9+
"GPL-3.0-or-later": {"source": "GPL3", "destination": "COPYING"}
810
}

{{cookiecutter.package_name}}/mypi.ini

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)