|
14 | 14 | import glob
|
15 | 15 | import os
|
16 | 16 | import sys
|
17 |
| -from pprint import pprint |
18 | 17 |
|
19 | 18 | import pkgconfig
|
20 | 19 | from pybind11.setup_helpers import (
|
|
23 | 22 | build_ext,
|
24 | 23 | naive_recompile,
|
25 | 24 | )
|
26 |
| -from setuptools import find_packages, setup |
| 25 | +from setuptools import setup |
27 | 26 |
|
28 | 27 | ParallelCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install()
|
29 | 28 |
|
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__))) |
32 | 30 |
|
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, |
38 | 33 | )
|
39 | 34 |
|
40 |
| -__version__ = "1.0.0" |
| 35 | +validate_libsemigroups() |
41 | 36 |
|
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)) |
111 | 44 |
|
112 | 45 | print("Include directories are:")
|
113 |
| -pprint(include_path) |
| 46 | +print(include_dirs) |
114 | 47 |
|
115 |
| -print("Extra link args are:") |
116 |
| -pprint(extra_link_args()) |
| 48 | +print("Library directories args are:") |
| 49 | +print(libsemigroups_info["library_dirs"]) |
117 | 50 |
|
118 | 51 | ext_modules = [
|
119 | 52 | Pybind11Extension(
|
120 | 53 | "_libsemigroups_pybind11",
|
121 | 54 | glob.glob("src/*.cpp"),
|
122 |
| - include_dirs=include_path, |
| 55 | + include_dirs=include_dirs, |
| 56 | + library_dirs=libsemigroups_info["library_dirs"], |
123 | 57 | language="c++",
|
124 | 58 | libraries=["semigroups"],
|
125 |
| - extra_link_args=extra_link_args(), |
126 | 59 | ),
|
127 | 60 | ]
|
128 | 61 |
|
129 |
| -with open(os.path.join(__dir__, "README.md"), "r", encoding="utf-8") as readme: |
130 |
| - long_description = readme.read() |
131 |
| - |
132 | 62 | 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", |
141 | 63 | 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"], |
152 | 64 | cmdclass={"build_ext": build_ext},
|
153 |
| - zip_safe=False, |
154 |
| - python_requires=">=3.9.0", |
155 | 65 | )
|
0 commit comments