Skip to content

Commit

Permalink
build: Migrate from setup.py to pyproject.toml
Browse files Browse the repository at this point in the history
Using `setup.py` is deprecated and the new recommanded way is to declare
a `pyproject.toml` file (see PEP 517 [^1]).

This commit proposes to use setuptools to achieve that, because
setuptools is already used by localstripe, is standard and referenced by
the official Python packaging documentation [^2], and seems to be the
most lightweight solution.

For some period, the `setup.py` file will be kept (although almost
empty), to allow old tools versions to keep working.

I have done the same migration for yamllint 7 months ago [^3] and it
appeared to work well.

[^1]: https://peps.python.org/pep-0517/
[^2]: https://packaging.python.org/en/latest/tutorials/installing-packages/
[^3]: adrienverge/yamllint#566
  • Loading branch information
adrienverge committed Nov 30, 2023
1 parent 42a0eae commit 09c8071
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
File renamed without changes.
11 changes: 6 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.12
- run: pip install flake8 flake8-import-order doc8 Pygments
Expand All @@ -36,12 +36,13 @@ jobs:
- '3.12'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.pyver }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.pyver }}
- run: python setup.py sdist
- run: pip install 'pip >=23' build
- run: python -m build
- run: pip install dist/localstripe-*.tar.gz
- run: python -m localstripe &
# Wait for server to be up:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ To quickly build and run localstripe from source:
.. code:: shell
python setup.py sdist
python -m build
pip install --user --upgrade dist/localstripe-*.tar.gz
localstripe
Expand Down
49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[project]
name = "localstripe"
description = """
A fake but stateful Stripe server that you can run locally, for \
testing purposes."""
readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">=3.8"
license = {text = "GPL-3.0-or-later"}
authors = [{name = "Adrien Vergé"}]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
]
dependencies = [
"aiohttp >=2.3.2",
"python-dateutil >=2.6.1",
]
dynamic = ["version"]

[project.optional-dependencies]
dev = [
"doc8",
"flake8",
"flake8-import-order",
]

[project.scripts]
localstripe = "localstripe.server:start"

[project.urls]
homepage = "https://github.com/adrienverge/localstripe"
repository = "https://github.com/adrienverge/localstripe"
documentation = "https://github.com/adrienverge/localstripe"

[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools >= 61"]

[tool.setuptools]
packages = ["localstripe"]

[tool.setuptools.package-data]
localstripe = ["localstripe-v3.js"]

[tool.setuptools.dynamic]
version = {attr = "localstripe.__version__"}
25 changes: 3 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@

from setuptools import setup

from localstripe import __author__, __version__


setup(
name='localstripe',
version=__version__,
author=__author__,
url='https://github.com/adrienverge/localstripe',
description=('A fake but stateful Stripe server that you can run locally, '
'for testing purposes.'),

packages=['localstripe'],
entry_points={'console_scripts':
['localstripe=localstripe.server:start']},
package_data={
'localstripe': ['localstripe-v3.js'],
},
install_requires=[
'aiohttp >=2.3.2',
'python-dateutil >=2.6.1',
],
)
# This is only kept for backward-compatibility with older versions that don't
# support new packaging standards (e.g. PEP 517 or PEP 660):
setup()

0 comments on commit 09c8071

Please sign in to comment.