Skip to content

Commit 0ba48e0

Browse files
authored
Use Hatch (#48)
* mike likes hatch so move to it * update release pipeline * there is no more setup.py * improve description of release arg * version is now stored in init, not pyproject, so commit right file * install packages before using them, since doing opposite tends to not work
1 parent 4e00430 commit 0ba48e0

File tree

6 files changed

+39
-110
lines changed

6 files changed

+39
-110
lines changed

.github/workflows/release.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ on:
55
workflow_dispatch:
66
inputs:
77
version:
8-
description: 'Version to use. Leave default to use the current version'
8+
description: |
9+
Version to publish.
10+
Leave default to publish the current version.
11+
To change version pass the number or a segment like path, minor, major, etc. See https://hatch.pypa.io/1.12/version/#supported-segments for all available segments.
912
required: true
1013
default: '~~version~~'
1114

@@ -22,44 +25,47 @@ jobs:
2225

2326
steps:
2427
- name: Checkout repo
25-
uses: actions/checkout@v2
28+
uses: actions/checkout@v4
2629

2730
- name: Set up python
28-
uses: actions/setup-python@v2
31+
uses: actions/setup-python@v5
2932
with:
30-
python-version: "3.9"
33+
python-version: "3.13"
34+
35+
- name: Install required packages
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip --version
39+
pip install hatch twine
40+
pip list
3141
3242
- name: Set version
3343
# A specific version was set in the action trigger.
3444
# Change the version in pyproject.toml to that version
3545
if: ${{ github.event.inputs.version != '~~version~~' }}
3646
run: |
37-
python .github/workflows/scripts/update_version.py --set-version ${{ github.event.inputs.version }}
47+
hatch version ${{ github.event.inputs.version }}
3848
3949
- name: Commit version change
4050
# If the pyproject.toml version was changed, commit it.
4151
if: ${{ github.event.inputs.version != '~~version~~' }}
4252
uses: sqlalchemyorg/git-auto-commit-action@sa
4353
with:
4454
commit_message: Version ${{ github.event.inputs.version }}
45-
file_pattern: pyproject.toml
55+
file_pattern: zimports/__init__.py
4656

4757
- name: Get version
4858
# Get current version
4959
id: get-version
5060
run: |
51-
version=`grep 'version =' pyproject.toml | awk '{print $NF}'`
61+
version=`hatch version`
5262
echo $version
5363
echo "::set-output name=version::$version"
5464
5565
- name: Create distribution
5666
# Create wheel and sdist
5767
run: |
58-
python -m pip install --upgrade pip
59-
pip --version
60-
pip install build
61-
pip list
62-
python -m build --sdist --wheel .
68+
python -m hatch build
6369
6470
- name: Create release
6571
# Create github tag and release and upload the distribution wheels and sdist
@@ -75,13 +81,13 @@ jobs:
7581
- name: Next version
7682
# Update the version to the next version
7783
run: |
78-
python .github/workflows/scripts/update_version.py --update-version
84+
hatch version patch
7985
8086
- name: Get version
8187
# Get new current version
8288
id: get-new-version
8389
run: |
84-
version=`grep 'version =' pyproject.toml | awk '{print $NF}'`
90+
version=`hatch version`
8591
echo $version
8692
echo "::set-output name=version::$version"
8793
@@ -90,7 +96,7 @@ jobs:
9096
uses: sqlalchemyorg/git-auto-commit-action@sa
9197
with:
9298
commit_message: Start work on ${{ steps.get-new-version.outputs.version }}
93-
file_pattern: pyproject.toml
99+
file_pattern: zimports/__init__.py
94100

95101
- name: Publish distribution
96102
# Publish to pypi
@@ -100,5 +106,4 @@ jobs:
100106
# TWINE_PASSWORD: ${{ secrets.test_pypi_token }}
101107
TWINE_PASSWORD: ${{ secrets.pypi_token }}
102108
run: |
103-
pip install -U twine
104109
twine upload --skip-existing dist/*

.github/workflows/scripts/update_version.py

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

pyproject.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
build-backend = 'setuptools.build_meta'
3-
requires = ['setuptools >= 44', 'wheel']
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
44

55
[project]
66
name = "zimports"
7-
version = "0.6.2"
7+
dynamic = ["version"]
88
dependencies = [
99
"pyflakes",
1010
"flake8-import-order",
@@ -40,6 +40,17 @@ Issues = "https://github.com/sqlalchemyorg/zimports/issues"
4040
[project.scripts]
4141
zimports = "zimports:main"
4242

43+
[tool.hatch.build.targets.sdist]
44+
include = ["zimports*"]
45+
46+
[tool.hatch.version]
47+
path = "zimports/__init__.py"
48+
49+
[tool.hatch.envs.test]
50+
dependencies = [
51+
"pytest"
52+
]
53+
4354
[tool.black]
4455
line-length = 79
4556
target-version = ['py39']
@@ -49,9 +60,6 @@ exclude = './test_files'
4960
addopts = "--tb native -v -r sfxX --maxfail=25 -p no:warnings -p no:logging"
5061
python_files = ["tests.py"]
5162

52-
[tool.setuptools.packages.find]
53-
include = ["zimports*"]
54-
5563
[tool.zimports]
5664
black-line-length = 79
5765
keep-unused-type-checking = true

setup.py

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

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ deps=
2929
pygments
3030
black==25.1.0
3131
commands =
32-
flake8 ./zimports setup.py
33-
black --check ./zimports setup.py
32+
flake8 ./zimports
33+
black --check ./zimports
3434

3535

3636
# "pep8" env was renamed to "lint".

zimports/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .cli import main # noqa
2+
3+
__version__ = "0.6.2"

0 commit comments

Comments
 (0)