Skip to content

Commit 71fca8c

Browse files
nejchJohnVillalovos
authored andcommitted
refactor(build): build project using PEP 621
BREAKING CHANGE: python-gitlab now stores metadata in pyproject.toml as per PEP 621, with setup.py removed. pip version v21.1 or higher is required if you want to perform an editable install.
1 parent 59d6a88 commit 71fca8c

File tree

7 files changed

+84
-79
lines changed

7 files changed

+84
-79
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ repos:
4040
- responses==0.23.1
4141
- types-PyYAML==6.0.12
4242
- types-requests==2.28.11.2
43-
- types-setuptools==65.5.0.1
4443
- repo: https://github.com/pre-commit/pygrep-hooks
4544
rev: v1.10.0
4645
hooks:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM python:3.11-${PYTHON_FLAVOR} AS build
33

44
WORKDIR /opt/python-gitlab
55
COPY . .
6-
RUN python setup.py bdist_wheel
6+
RUN pip install build && python -m build
77

88
FROM python:3.11-${PYTHON_FLAVOR}
99

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "python-gitlab"
7+
description="A python wrapper for the GitLab API"
8+
readme = "README.rst"
9+
authors = [
10+
{name = "Gauvain Pocentek", email= "gauvain@pocentek.net"}
11+
]
12+
maintainers = [
13+
{name = "John Villalovos", email="john@sodarock.com"},
14+
{name = "Max Wittig", email="max.wittig@siemens.com"},
15+
{name = "Nejc Habjan", email="nejc.habjan@siemens.com"},
16+
{name = "Roger Meier", email="r.meier@siemens.com"}
17+
]
18+
requires-python = ">=3.8.0"
19+
dependencies = [
20+
"requests>=2.25.0",
21+
"requests-toolbelt>=0.10.1",
22+
]
23+
classifiers = [
24+
"Development Status :: 5 - Production/Stable",
25+
"Environment :: Console",
26+
"Intended Audience :: System Administrators",
27+
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
28+
"Natural Language :: English",
29+
"Operating System :: POSIX",
30+
"Operating System :: Microsoft :: Windows",
31+
"Programming Language :: Python",
32+
"Programming Language :: Python :: 3",
33+
"Programming Language :: Python :: 3.8",
34+
"Programming Language :: Python :: 3.9",
35+
"Programming Language :: Python :: 3.10",
36+
"Programming Language :: Python :: 3.11"
37+
]
38+
keywords = ["api", "client", "gitlab", "python", "python-gitlab", "wrapper"]
39+
license = {text = "LGPL-3.0-or-later"}
40+
dynamic = ["version"]
41+
42+
[project.optional-dependencies]
43+
autocompletion = ["argcomplete>=1.10.0,<3"]
44+
yaml = ["PyYaml>=6.0.1"]
45+
46+
[project.scripts]
47+
gitlab = "gitlab.cli:main"
48+
49+
[project.urls]
50+
Homepage = "https://github.com/python-gitlab/python-gitlab"
51+
Changelog = "https://github.com/python-gitlab/python-gitlab/blob/main/CHANGELOG.md"
52+
Documentation = "https://python-gitlab.readthedocs.io"
53+
Source = "https://github.com/python-gitlab/python-gitlab"
54+
55+
[tool.setuptools.packages.find]
56+
exclude = ["docs*", "tests*"]
57+
58+
[tool.setuptools.dynamic]
59+
version = { attr = "gitlab._version.__version__" }
60+
161
[tool.isort]
262
profile = "black"
363
multi_line_output = 3

requirements-test.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ pytest-github-actions-annotate-failures==0.2.0
77
pytest==7.4.2
88
PyYaml==6.0.1
99
responses==0.23.3
10-
setuptools==68.2.2
1110
wheel==0.41.2

setup.py

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

tests/smoke/test_dists.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
import tarfile
22
import zipfile
3+
import subprocess
4+
import sys
35
from pathlib import Path
4-
from sys import version_info
6+
57

68
import pytest
7-
from setuptools import sandbox
89

910
from gitlab._version import __title__, __version__
1011

11-
DIST_DIR = Path("dist")
1212
DOCS_DIR = "docs"
1313
TEST_DIR = "tests"
1414
SDIST_FILE = f"{__title__}-{__version__}.tar.gz"
15-
WHEEL_FILE = (
16-
f"{__title__.replace('-', '_')}-{__version__}-py{version_info.major}-none-any.whl"
17-
)
15+
WHEEL_FILE = f"{__title__.replace('-', '_')}-{__version__}-py{sys.version_info.major}-none-any.whl"
16+
17+
18+
@pytest.fixture(scope="session")
19+
def build(tmp_path_factory: Path):
20+
temp_dir = tmp_path_factory.mktemp("build")
21+
subprocess.run([sys.executable, "-m", "build", "--outdir", temp_dir], check=True)
22+
return temp_dir
1823

1924

20-
@pytest.fixture(scope="function")
21-
def build() -> None:
22-
sandbox.run_setup("setup.py", ["--quiet", "clean", "--all"]) # type: ignore[no-untyped-call]
23-
sandbox.run_setup("setup.py", ["--quiet", "sdist", "bdist_wheel"]) # type: ignore[no-untyped-call]
25+
def test_sdist_includes_docs_and_tests(build: subprocess.CompletedProcess) -> None:
26+
sdist = tarfile.open(build / SDIST_FILE, "r:gz")
27+
sdist_dir = f"{__title__}-{__version__}"
2428

29+
docs_dir = sdist.getmember(f"{sdist_dir}/{DOCS_DIR}")
30+
test_dir = sdist.getmember(f"{sdist_dir}/{TEST_DIR}")
31+
readme = sdist.getmember(f"{sdist_dir}/README.rst")
2532

26-
def test_sdist_includes_tests(build):
27-
sdist = tarfile.open(DIST_DIR / SDIST_FILE, "r:gz")
28-
test_dir = sdist.getmember(f"{__title__}-{__version__}/{TEST_DIR}")
33+
assert docs_dir.isdir()
2934
assert test_dir.isdir()
35+
assert readme.isfile()
3036

3137

32-
def test_wheel_excludes_docs_and_tests(build):
33-
wheel = zipfile.ZipFile(DIST_DIR / WHEEL_FILE)
38+
def test_wheel_excludes_docs_and_tests(build: subprocess.CompletedProcess) -> None:
39+
wheel = zipfile.ZipFile(build / WHEEL_FILE)
3440
assert not any(file.startswith((DOCS_DIR, TEST_DIR)) for file in wheel.namelist())

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ commands =
6565
[testenv:twine-check]
6666
basepython = python3
6767
deps = -r{toxinidir}/requirements.txt
68+
build
6869
twine
6970
commands =
70-
python3 setup.py sdist bdist_wheel
71+
python -m build
7172
twine check dist/*
7273

7374
[testenv:venv]

0 commit comments

Comments
 (0)