Skip to content

Commit 8affad4

Browse files
authored
Migrate away from setup.py to pyproject.toml (#164)
* remove green dependency * [wip] switch to pyproject build * Add more links to documentation (fixes #106) * Further progress on migration to pyproject.toml * Final changes to remove setup.py * Switch to proper toml parsing * Fix black formatting issues * Minor fixes to MANIFEST.in and pyproject.toml * [wip] switch to pyproject build * Add more links to documentation (fixes #106) * Further progress on migration to pyproject.toml * Final changes to remove setup.py * Switch to proper toml parsing * Fix black formatting issues * Minor fixes to MANIFEST.in and pyproject.toml
1 parent dc5a245 commit 8affad4

10 files changed

Lines changed: 144 additions & 178 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ jobs:
5454
with:
5555
python-version: '3.10'
5656

57-
- name: Update setuptools
58-
run: pip install -U setuptools
57+
- name: Update setuptools and build
58+
run: pip install -U setuptools build
5959

6060
- name: Build sdist
61-
run: python setup.py sdist
61+
run: python -m build --sdist
6262

6363
- uses: actions/upload-artifact@v4
6464
with:

MANIFEST.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
include setup.py
21
include README.md
32
include CHANGELOG.md
43
include LICENSE
5-
include requirements.txt
6-
recursive-include clevercsv *.py
4+
recursive-include clevercsv *.py *.pyi
75
recursive-include src *.c
86
recursive-include bin *
97
recursive-include tests/test_unit *.py

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ help:
2828
.PHONY: inplace install
2929

3030
inplace:
31-
$(PYTHON) setup.py build_ext -i
31+
$(PYTHON) -m pip install -e .
3232

3333
install: dist ## Install for the current user using the default python command
3434
$(PYTHON) -m pip install --user ./dist/$(PACKAGE)-*.tar.gz
@@ -42,19 +42,20 @@ install: dist ## Install for the current user using the default python command
4242
release: ## Make a release
4343
$(PYTHON) make_release.py
4444

45-
dist: man ## Make Python source distribution
46-
$(PYTHON) setup.py sdist
45+
dist: man venv ## Make Python source distribution
46+
source $(VENV_DIR)/bin/activate && python -m build
4747

4848
###########
4949
# Testing #
5050
###########
5151

5252
.PHONY: test integration integration_partial
5353

54-
test: mypy green pytest
54+
test: mypy unit pytest
5555

56-
green: venv ## Run unit tests
57-
source $(VENV_DIR)/bin/activate && green -a -vv ./tests/test_unit
56+
unit: venv ## Run unit tests
57+
source $(VENV_DIR)/bin/activate && \
58+
python -m unittest discover -vv ./tests/test_unit
5859

5960
pytest: venv ## Run unit tests with PyTest
6061
source $(VENV_DIR)/bin/activate && pytest -ra -m 'not network'
@@ -89,7 +90,7 @@ doc: venv ## Build documentation with Sphinx
8990

9091
man: venv ## Build man pages using Wilderness
9192
source $(VENV_DIR)/bin/activate && \
92-
python setup.py build_manpages
93+
python build_manpages.py
9394

9495
#######################
9596
# Virtual environment #

build_manpages.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
from wilderness import build_manpages
3+
4+
from clevercsv.console import build_application
5+
6+
if __name__ == "__main__":
7+
build_manpages(build_application())

clevercsv/_optional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class OptionalDependency(NamedTuple):
2929
min_version: str
3030

3131

32-
# update this when changing setup.py
32+
# update this when changing pyproject.toml
3333
OPTIONAL_DEPENDENCIES: List[OptionalDependency] = [
3434
OptionalDependency("tabview", "tabview", "1.4"),
3535
OptionalDependency("pandas", "pandas", "0.24.1"),

make_release.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727

2828
import colorama
2929

30+
try:
31+
import tomllib
32+
except ImportError:
33+
try:
34+
import tomli as tomllib
35+
except ImportError:
36+
tomllib = None
37+
3038
URLS = {
3139
"RTD": "https://readthedocs.org/projects/clevercsv/builds/",
3240
"CI": "https://github.com/alan-turing-institute/CleverCSV/actions",
@@ -72,11 +80,16 @@ def wait_for_enter():
7280

7381

7482
def get_package_name():
75-
with open("./setup.py", "r") as fp:
76-
nameline = next(
77-
(line.strip() for line in fp if line.startswith("NAME = ")), None
78-
)
79-
return nameline.split("=")[-1].strip().strip('"')
83+
if tomllib is None:
84+
with open("./pyproject.toml", "r") as fp:
85+
for line in fp:
86+
if line.strip().startswith("name = "):
87+
return line.split("=")[-1].strip().strip('"').strip("'")
88+
return None
89+
90+
with open("./pyproject.toml", "rb") as fp:
91+
data = tomllib.load(fp)
92+
return data.get("project", {}).get("name")
8093

8194

8295
def get_package_version(pkgname):

pyproject.toml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
1+
[project]
2+
name = "clevercsv"
3+
authors = [
4+
{name = "Gertjan van den Burg", email = "gertjanvandenburg@gmail.com"},
5+
]
6+
description = "A Python package for handling messy CSV files"
7+
readme = "README.md"
8+
requires-python = ">=3.9.0"
9+
keywords = ["csv"]
10+
license = {text = "MIT"}
11+
classifiers = [
12+
"Programming Language :: Python",
13+
"Programming Language :: Python :: 3",
14+
"Programming Language :: Python :: 3.9",
15+
"Programming Language :: Python :: 3.10",
16+
"Programming Language :: Python :: 3.11",
17+
"Programming Language :: Python :: 3.12",
18+
"Programming Language :: Python :: 3.13",
19+
"Programming Language :: Python :: 3.14",
20+
"Programming Language :: Python :: Implementation :: CPython",
21+
"Programming Language :: Python :: Implementation :: PyPy",
22+
"License :: OSI Approved :: MIT License",
23+
]
24+
dependencies = [
25+
"chardet>=3.0",
26+
"regex>=2018.11",
27+
"packaging>=23.0",
28+
]
29+
dynamic = ["version"]
30+
31+
[project.optional-dependencies]
32+
full = [
33+
"faust-cchardet>=2.1.18",
34+
"pandas>=1.0.0",
35+
"tabview>=1.4",
36+
"wilderness>=0.1.5",
37+
]
38+
docs = [
39+
"sphinx",
40+
"m2r2",
41+
"furo",
42+
]
43+
test = [
44+
"clevercsv[full]",
45+
"pytest>=2.6",
46+
]
47+
dev = [
48+
"clevercsv[docs]",
49+
"clevercsv[test]",
50+
"pytest>=2.6",
51+
"termcolor",
52+
"mypy",
53+
"setuptools",
54+
"build",
55+
]
56+
precommit = [
57+
"wilderness>=0.1.5",
58+
]
59+
60+
[project.scripts]
61+
clevercsv = "clevercsv.__main__:main"
62+
63+
[project.urls]
64+
homepage = "https://github.com/alan-turing-institute/CleverCSV/"
65+
documentation = "https://clevercsv.readthedocs.io/en/latest/"
66+
changelog = "https://github.com/alan-turing-institute/CleverCSV/blob/master/CHANGELOG.md"
67+
68+
[build-system]
69+
requires = ["setuptools>=74.1.0"]
70+
build-backend = "setuptools.build_meta"
71+
172
[tool.black]
273
line-length=79
374

@@ -30,3 +101,26 @@ disallow_untyped_defs = false
30101
[[tool.mypy.overrides]]
31102
packages = ["stubs", "clevercsv"]
32103
disallow_incomplete_defs = true
104+
105+
[tool.setuptools]
106+
include-package-data = true
107+
108+
[tool.setuptools.packages.find]
109+
exclude = ["tests*", "*.tests*"]
110+
111+
[tool.setuptools.package-data]
112+
clevercsv = ["py.typed"]
113+
114+
[tool.setuptools.data-files]
115+
"man/man1" = ["man/*.1"]
116+
117+
[[tool.setuptools.ext-modules]]
118+
name = "clevercsv.cparser"
119+
sources = ["src/cparser.c"]
120+
121+
[[tool.setuptools.ext-modules]]
122+
name = "clevercsv.cabstraction"
123+
sources = ["src/abstraction.c"]
124+
125+
[tool.setuptools.dynamic]
126+
version = {attr = "clevercsv.__version__.__version__"}

setup.py

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

0 commit comments

Comments
 (0)