Skip to content

Commit c6dda2a

Browse files
authored
Migrate to a modern (mostly) declarative setuptools config (#63)
This migrates the packaging infra to a modern mostly declarative setuptools configuration, almost literally following the best practices layed out in the setuptools documentation; see https://setuptools.pypa.io/ The version info has moved to a ‘result.__version__’ attribute (in the ‘__init__.py’ file), which is a common pattern in many packages, and setuptools reads it from there (single source of truth). Run black+isort on the file while at it. The new packages can be built the modern way using the PEP517 compliant ‘build’ tool via ‘python -m build’ after a ‘pip install build’. Reflect this in RELEASING.md. The remaining setup.py file is almost empty, but it is not removed because it is still needed for --editable development installs. See setuptools docs and this article for details: https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html Also added a packaging build step to the CI to ensure packaging keeps working.
1 parent 05bc244 commit c6dda2a

File tree

6 files changed

+53
-32
lines changed

6 files changed

+53
-32
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ jobs:
3737
restore-keys: |
3838
${{ runner.os }}-pip-py${{ matrix.python }}-
3939
- name: Install dev dependencies
40-
run: pip install -r requirements-dev.txt
40+
run: pip install --requirement requirements-dev.txt
4141

4242
# Install library
4343
- name: Install result
44-
run: pip install -e .
44+
run: pip install --editable .
4545

4646
# Tests
4747
- name: Run tests
@@ -52,6 +52,12 @@ jobs:
5252
- name: Run mypy on result.py
5353
run: mypy result/result.py
5454

55+
# Packaging
56+
- name: Build packages
57+
run: |
58+
pip install --upgrade build pip setuptools wheel
59+
python -m build
60+
5561
# Coverage
5662
- name: Upload coverage to codecov.io
5763
uses: codecov/codecov-action@v1

RELEASING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ Do a signed commit and signed tag of the release:
1919

2020
Build source and binary distributions:
2121

22-
python3 setup.py sdist
23-
python3 setup.py bdist_wheel
22+
python3 -m build
2423

2524
Sign files:
2625

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"

result/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
from .result import Result, Ok, Err, UnwrapError, OkErr
2-
__all__ = ['Result', 'Ok', 'Err', 'UnwrapError', 'OkErr']
1+
from .result import Err, Ok, OkErr, Result, UnwrapError
2+
3+
__all__ = [
4+
"Err",
5+
"Ok",
6+
"OkErr",
7+
"Result",
8+
"UnwrapError",
9+
]
10+
__version__ = "0.7.0.dev"

setup.cfg

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
[metadata]
2+
name = result
3+
version = attr: result.__version__
4+
description = A Rust-like result type for Python
5+
long_description = file: README.rst
6+
keywords = rust, result, enum
7+
author = Danilo Bargen
8+
author_email = mail@dbrgn.ch
9+
maintainer = rustedpy github org members (https://github.com/rustedpy)
10+
url = https://github.com/rustedpy/result
11+
license = MIT
212
license_file = LICENSE
13+
classifiers =
14+
Development Status :: 4 - Beta
15+
License :: OSI Approved :: MIT License
16+
Programming Language :: Python :: 3
17+
Programming Language :: Python :: 3.6
18+
Programming Language :: Python :: 3.7
19+
Programming Language :: Python :: 3.8
20+
Programming Language :: Python :: 3.9
21+
Programming Language :: Python :: 3.10
22+
Programming Language :: Python :: 3 :: Only
23+
24+
[options]
25+
include = result
26+
include_package_data = True
27+
packages = find:
28+
python_requires = >=3.6
29+
zip_safe = True
30+
31+
[options.package_data]
32+
result = py.typed
333

434
[tool:pytest]
535
addopts = --flake8 --tb=short --cov=.

setup.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
11
from setuptools import setup
22

3-
readme = open('README.rst').read()
4-
5-
setup(name='result',
6-
version='0.7.0-dev',
7-
description='A rust-like result type for Python',
8-
author='Danilo Bargen',
9-
author_email='mail@dbrgn.ch',
10-
url='https://github.com/rustedpy/result',
11-
packages=['result'],
12-
package_data={'result': ['py.typed']},
13-
zip_safe=True,
14-
include_package_data=True,
15-
license='MIT',
16-
keywords='rust result enum',
17-
long_description=readme,
18-
classifiers=[
19-
'Development Status :: 4 - Beta',
20-
'License :: OSI Approved :: MIT License',
21-
'Programming Language :: Python :: 3',
22-
'Programming Language :: Python :: 3.6',
23-
'Programming Language :: Python :: 3.7',
24-
'Programming Language :: Python :: 3.8',
25-
'Programming Language :: Python :: 3.9',
26-
'Programming Language :: Python :: 3.10',
27-
'Programming Language :: Python :: 3 :: Only',
28-
])
3+
setup()

0 commit comments

Comments
 (0)