Skip to content

Commit 3fe86a7

Browse files
Modernise packaging
1 parent 7b03cf8 commit 3fe86a7

File tree

3 files changed

+112
-128
lines changed

3 files changed

+112
-128
lines changed

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
include src/*.hpp
1+
graft src
2+
include tests/*.py

pyproject.toml

Lines changed: 93 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,99 @@
1-
[tool.black]
2-
line-length = 80
3-
[tool.ruff]
4-
lint.select = ["E", "F", "B"]
5-
lint.ignore = ["F401"]
6-
line-length = 100
7-
[tool.pylint]
8-
disable = ["R0801", "fixme"]
1+
# TODO:
2+
# * Run check-manifest
3+
# * Use ruff?
4+
# * Remove .codespellrc
5+
# * Decide on good configurations for tools
6+
# * Remove requirements.txt
7+
# * Use pre-commit
8+
# * Use MyPy
99
[build-system]
1010
requires = [
11-
"setuptools==75.6.0",
12-
"wheel",
13-
"pybind11==2.11.1",
14-
"pkgconfig>=1.5.5",
15-
"packaging==23.2",
11+
"setuptools>=64",
12+
"setuptools-scm>=8",
13+
"pybind11",
14+
"pkgconfig",
15+
"packaging",
1616
]
17-
1817
build-backend = "setuptools.build_meta"
1918

20-
[tool.pytest.ini_options]
21-
markers = [
22-
"quick",
23-
"standard",
24-
"extreme",
25-
"fail",
19+
[project]
20+
name = "libsemigroups_pybind11"
21+
dynamic = ["version"]
22+
description = "A python package for the libsemigroups C++ library."
23+
readme = "README.md"
24+
authors = [
25+
{ name = "Joseph Edwards", email = "jde1@st-andrews.ac.uk" },
26+
{ name = "James Mitchell", email = "jdm3@st-andrews.ac.uk" },
27+
{ name = "Maria Tsalakou", email = "mt200@st-andrews.ac.uk" },
28+
{ name = "Murray Whyte", email = "mw231@st-andrews.ac.uk" },
2629
]
30+
# TODO: Uncomment and update
31+
# maintainers = [{ name = "My Organization", email = "myemail@email.com" }]
32+
requires-python = ">=3.9"
33+
dependencies = ["graphviz", "numpy", "typing_extensions"]
34+
classifiers = [
35+
"Development Status :: 5 - Production/Stable",
36+
"Programming Language :: Python :: 3 :: Only",
37+
"Programming Language :: Python :: 3.9",
38+
"Programming Language :: Python :: 3.10",
39+
"Programming Language :: Python :: 3.11",
40+
"Programming Language :: Python :: 3.12",
41+
"Programming Language :: Python :: 3.13",
42+
"Intended Audience :: Science/Research",
43+
"Topic :: Scientific/Engineering :: Mathematics",
44+
"Natural Language :: English",
45+
]
46+
license = "GPL-3.0-or-later"
47+
license-files = ["LICENSE"]
48+
49+
[project.urls]
50+
Homepage = "https://github.com/libsemigroups/libsemigroups_pybind11"
51+
Documentation = "https://libsemigroups.github.io/libsemigroups_pybind11/"
52+
Issues = "https://github.com/libsemigroups/libsemigroups_pybind11/issues"
53+
Changelog = "https://libsemigroups.github.io/libsemigroups_pybind11/changelog.html"
54+
55+
[project.optional-dependencies]
56+
test = ["pytest"]
57+
docs = [
58+
"six",
59+
"sphinx_rtd_theme",
60+
"sphinx >=8.2",
61+
"sphinx-copybutton",
62+
"sphinxcontrib-bibtex",
63+
]
64+
65+
[tool.setuptools.packages.find]
66+
where = ["src"]
67+
68+
[tool.setuptools_scm]
69+
version_file = "src/libsemigroups_pybind11/_version.py"
70+
71+
[tool.black]
72+
line-length = 80
73+
74+
[tool.ruff]
75+
line-length = 100
76+
lint.ignore = ["F401", "E402"]
77+
lint.select = ["E", "F", "B"]
78+
lint.extend-select = ["B", "I", "UP"]
79+
80+
[tool.ruff.format]
81+
docstring-code-format = true
82+
83+
[tool.pytest.ini_options]
84+
minversion = "6.0"
85+
markers = ["quick", "standard", "extreme", "fail"]
86+
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
87+
xfail_strict = true
88+
filterwarnings = ["error"]
89+
log_cli_level = "info"
90+
testpaths = ["tests"]
91+
92+
[tool.pylint.miscellaneous]
93+
# List of note tags to take in consideration, separated by a comma.
94+
# notes = ["TODO", "FIXME", "REVIEW"]
95+
disable = ["R0801", "fixme"]
96+
notes = []
97+
98+
[tool.pylint.similarities]
99+
ignore-imports = "yes"

setup.py

Lines changed: 17 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import glob
1515
import os
1616
import sys
17-
from pprint import pprint
1817

1918
import pkgconfig
2019
from pybind11.setup_helpers import (
@@ -23,133 +22,44 @@
2322
build_ext,
2423
naive_recompile,
2524
)
26-
from setuptools import find_packages, setup
25+
from setuptools import setup
2726

2827
ParallelCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install()
2928

30-
__dir__ = os.path.abspath(os.path.dirname(__file__))
31-
sys.path.insert(0, __dir__ + "/libsemigroups_pybind11")
29+
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
3230

33-
from tools import ( # pylint: disable=import-error, wrong-import-position # noqa: E402
34-
compare_version_numbers,
35-
extra_link_args,
36-
libsemigroups_version,
37-
minimum_libsemigroups_version,
31+
from build_tools import ( # pylint: disable=wrong-import-position
32+
validate_libsemigroups,
3833
)
3934

40-
__version__ = "1.0.0"
35+
validate_libsemigroups()
4136

42-
DISCLAIMER = """(You should not see this message unless you are installing
43-
libsemigroups_pybind11 from its sources. If you are not installing from the
44-
sources, please raise an issue at:
45-
https://github.com/libsemigroups/libsemigroups_pybind11)"""
46-
47-
if not pkgconfig.exists("libsemigroups"):
48-
raise ImportError(
49-
f"""cannot locate the libsemigroups library.
50-
For more information about installing the libsemigroups library see
51-
https://libsemigroups.github.io/libsemigroups_pybind11/install.html.
52-
53-
If libsemigroups is installed, then it cannot be located by pkg-config, perhaps
54-
you should add the directory containing `libsemigroups.pc' to the
55-
\"PKG_CONFIG_PATH\". The file `libsemigroups.pc' might be in one of the
56-
following directories:
57-
* /usr/local/lib/pkgconfig
58-
* $CONDA_PREFIX/lib/pkgconfig if your active conda environment has pkgconfig
59-
installed, and libsemigroups was installed with conda/mamba in this
60-
environment.
61-
{DISCLAIMER}"""
62-
)
63-
64-
if not compare_version_numbers(
65-
libsemigroups_version(), minimum_libsemigroups_version()
66-
):
67-
raise ImportError(
68-
f"libsemigroups version at least {minimum_libsemigroups_version()}"
69-
+ f" is required, found {libsemigroups_version()}"
70-
)
71-
72-
73-
class GetPyBind11Include: # pylint: disable=too-few-public-methods
74-
"""
75-
Helper class to determine the pybind11 include path
76-
77-
The purpose of this class is to postpone importing pybind11
78-
until it is actually installed, so that the ``get_include()``
79-
method can be invoked.
80-
"""
81-
82-
def __init__(self, user=False):
83-
self.user = user
84-
85-
def __str__(self):
86-
import pybind11 # pylint: disable=import-outside-toplevel
87-
88-
return pybind11.get_include(self.user)
89-
90-
91-
include_path = [
92-
GetPyBind11Include(),
93-
GetPyBind11Include(user=True),
94-
]
95-
96-
for lib in ("libsemigroups", "eigen3", "fmt"):
97-
try:
98-
cflags_only_I = pkgconfig.cflags(lib) # pylint: disable=invalid-name
99-
except pkgconfig.pkgconfig.PackageNotFoundError:
100-
continue
101-
102-
cflags_only_I = [
103-
x[2:] for x in cflags_only_I.split(" ") if x.startswith("-I")
104-
]
105-
106-
include_path.extend(cflags_only_I)
107-
if lib == "libsemigroups":
108-
include_path.extend(
109-
[os.path.join(x, "libsemigroups") for x in cflags_only_I]
110-
)
37+
libsemigroups_info = pkgconfig.parse("libsemigroups")
38+
extra_libs = set(libsemigroups_info["libraries"])
39+
extra_libs.remove("semigroups")
40+
include_dirs = set(libsemigroups_info["include_dirs"])
41+
for lib in extra_libs:
42+
include_dirs.update(set(pkgconfig.parse(lib)["include_dirs"]))
43+
include_dirs = sorted(list(include_dirs))
11144

11245
print("Include directories are:")
113-
pprint(include_path)
46+
print(include_dirs)
11447

115-
print("Extra link args are:")
116-
pprint(extra_link_args())
48+
print("Library directories args are:")
49+
print(libsemigroups_info["library_dirs"])
11750

11851
ext_modules = [
11952
Pybind11Extension(
12053
"_libsemigroups_pybind11",
12154
glob.glob("src/*.cpp"),
122-
include_dirs=include_path,
55+
include_dirs=include_dirs,
56+
library_dirs=libsemigroups_info["library_dirs"],
12357
language="c++",
12458
libraries=["semigroups"],
125-
extra_link_args=extra_link_args(),
12659
),
12760
]
12861

129-
with open(os.path.join(__dir__, "README.md"), "r", encoding="utf-8") as readme:
130-
long_description = readme.read()
131-
13262
setup(
133-
name="libsemigroups_pybind11",
134-
version=__version__,
135-
author="Joseph Edwards, James Mitchell, Maria Tsalakou, Murray Whyte",
136-
author_email="jdm3@st-andrews.ac.uk",
137-
url="https://github.com/libsemigroups/libsemigroups_pybind11",
138-
description="A python package for the libsemigroups C++ library",
139-
long_description=long_description,
140-
long_description_content_type="text/markdown",
14163
ext_modules=ext_modules,
142-
packages=find_packages(),
143-
setup_requires=["pkgconfig>=1.5.5"],
144-
install_requires=[
145-
"packaging>=20.4",
146-
"pkgconfig>=1.5.5",
147-
"pybind11>=2.13.0",
148-
"graphviz>=0.20.1",
149-
"numpy>=1.26.0",
150-
],
151-
tests_require=["pytest==8.0.0"],
15264
cmdclass={"build_ext": build_ext},
153-
zip_safe=False,
154-
python_requires=">=3.9.0",
15565
)

0 commit comments

Comments
 (0)