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 cd17894
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.pyver }}
- run: python setup.py sdist
- run: pip install 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
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[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 = [
"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 cd17894

Please sign in to comment.