|
1 |
| -#!/usr/bin/env python |
2 |
| -# |
3 |
| -# (C) Copyright 2017- ECMWF. |
4 |
| -# |
5 |
| -# This software is licensed under the terms of the Apache Licence Version 2.0 |
6 |
| -# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
7 |
| -# |
8 |
| -# In applying this licence, ECMWF does not waive the privileges and immunities |
9 |
| -# granted to it by virtue of its status as an intergovernmental organisation nor |
10 |
| -# does it submit to any jurisdiction. |
11 |
| -# |
12 |
| - |
13 |
| -import io |
14 | 1 | import os
|
15 |
| -import re |
16 | 2 | import sys
|
17 |
| - |
18 | 3 | import setuptools
|
| 4 | +from setup_utils import parse_dependencies, ext_kwargs |
| 5 | + |
| 6 | +# TODO this needs to be automated, in particular: |
| 7 | +# - handle the dependency preparation, similarly to how wheelmaker/prepare_deps.sh does it |
| 8 | +# - possibly include a buildconfig file here as well |
| 9 | +# - wheel linux needs only to invoke uv run --python python3.11 python -m build --installer uv --wheel . |
| 10 | +# - reqs: pythonpath to setup_utils, name, version, libdir, incdir |
| 11 | +# - version probably directly from eccodes themselves? |
| 12 | +# - can we restrict setuptools version without pyproject? Do we need the setuptools upperbound? See the NOTEs below |
| 13 | +# - the whole github action needs to be redone |
| 14 | +# - deal with the naming oddities. Name the eccodes so package `libs`? Probably rename to libs globally, and fix the findlibs invocations in odc and in eccodes |
| 15 | +# - simplify the findlibs invocations in the codebase |
19 | 16 |
|
20 |
| - |
21 |
| -def read(path): |
22 |
| - file_path = os.path.join(os.path.dirname(__file__), *path.split("/")) |
23 |
| - return io.open(file_path, encoding="utf-8").read() |
24 |
| - |
25 |
| - |
26 |
| -# single-sourcing the package version using method 1 of: |
27 |
| -# https://packaging.python.org/guides/single-sourcing-package-version/ |
28 |
| -def parse_version_from(path): |
29 |
| - version_pattern = ( |
30 |
| - r"^__version__ = [\"\'](.*)[\"\']" # More permissive regex pattern |
31 |
| - ) |
32 |
| - version_file = read(path) |
33 |
| - version_match = re.search(version_pattern, version_file, re.M) |
34 |
| - if version_match is None or len(version_match.groups()) > 1: |
35 |
| - raise ValueError("couldn't parse version") |
36 |
| - return version_match.group(1) |
37 |
| - |
38 |
| - |
39 |
| -# for the binary wheel |
40 |
| -libdir = os.path.realpath("install/lib") |
41 |
| -incdir = os.path.realpath("install/include") |
42 |
| -libs = ["eccodes"] |
43 |
| - |
44 |
| -if "--binary-wheel" in sys.argv: |
45 |
| - sys.argv.remove("--binary-wheel") |
46 |
| - |
47 |
| - # https://setuptools.pypa.io/en/latest/userguide/ext_modules.html |
48 |
| - ext_modules = [ |
49 |
| - setuptools.Extension( |
50 |
| - "eccodes._eccodes", |
51 |
| - sources=["eccodes/_eccodes.cc"], |
52 |
| - language="c++", |
53 |
| - libraries=libs, |
54 |
| - library_dirs=[libdir], |
55 |
| - include_dirs=[incdir], |
56 |
| - extra_link_args=["-Wl,-rpath," + libdir], |
57 |
| - ) |
58 |
| - ] |
59 |
| - |
60 |
| - def shared(directory): |
61 |
| - result = [] |
62 |
| - for path, dirs, files in os.walk(directory): |
63 |
| - for f in files: |
64 |
| - result.append(os.path.join(path, f)) |
65 |
| - return result |
66 |
| - |
67 |
| - # Paths must be relative to package directory... |
68 |
| - shared_files = ["versions.txt"] |
69 |
| - shared_files += [x[len("eccodes/") :] for x in shared("eccodes/copying")] |
70 |
| - |
71 |
| - if os.name == "nt": |
72 |
| - for n in os.listdir("eccodes"): |
73 |
| - if n.endswith(".dll"): |
74 |
| - shared_files.append(n) |
75 |
| - |
76 |
| -else: |
77 |
| - ext_modules = [] |
78 |
| - shared_files = [] |
79 |
| - |
80 |
| - |
81 |
| -install_requires = ["numpy"] |
82 | 17 | if sys.version_info < (3, 7):
|
83 | 18 | install_requires = ["numpy<1.20"]
|
84 | 19 | elif sys.version_info < (3, 8):
|
85 | 20 | install_requires = ["numpy<1.22"]
|
86 | 21 | elif sys.version_info < (3, 9):
|
87 | 22 | install_requires = ["numpy<1.25"]
|
| 23 | +else: |
| 24 | + install_requires = ["numpy"] |
88 | 25 |
|
89 | 26 | install_requires += ["attrs", "cffi", "findlibs"]
|
| 27 | +ext_modules = [ |
| 28 | + setuptools.Extension( |
| 29 | + "eccodes._eccodes", |
| 30 | + sources=["eccodes/_eccodes.cc"], |
| 31 | + language="c++", |
| 32 | + libraries=["eccodes"], |
| 33 | + library_dirs=[os.environ["LIBDIR"]], |
| 34 | + include_dirs=[os.environ["INCDIR"]], |
| 35 | + ) |
| 36 | +] |
90 | 37 |
|
91 | 38 | setuptools.setup(
|
92 |
| - name="eccodes", |
93 |
| - version=parse_version_from("gribapi/bindings.py"), |
94 |
| - description="Python interface to the ecCodes GRIB and BUFR decoder/encoder", |
95 |
| - long_description=read("README.rst") + read("CHANGELOG.rst"), |
96 |
| - author="European Centre for Medium-Range Weather Forecasts (ECMWF)", |
97 |
| - |
98 |
| - license="Apache License Version 2.0", |
99 |
| - url="https://github.com/ecmwf/eccodes-python", |
| 39 | + name=os.environ["NAME"], |
| 40 | + version=os.environ["VERSION"], |
100 | 41 | packages=setuptools.find_packages(),
|
101 |
| - include_package_data=True, |
102 |
| - package_data={"": shared_files}, |
103 |
| - install_requires=install_requires, |
| 42 | + install_requires=parse_dependencies() + install_requires, |
| 43 | + **ext_kwargs[sys.platform], |
| 44 | + # NOTE does this work? Move to extras? |
104 | 45 | tests_require=[
|
105 | 46 | "pytest",
|
106 | 47 | "pytest-cov",
|
107 | 48 | "pytest-flakes",
|
108 | 49 | ],
|
| 50 | + # NOTE does this work? |
109 | 51 | test_suite="tests",
|
110 | 52 | zip_safe=True,
|
111 |
| - keywords="ecCodes GRIB BUFR", |
112 |
| - classifiers=[ |
113 |
| - "Development Status :: 4 - Beta", |
114 |
| - "Intended Audience :: Developers", |
115 |
| - "License :: OSI Approved :: Apache Software License", |
116 |
| - "Programming Language :: Python :: 3.8", |
117 |
| - "Programming Language :: Python :: 3.9", |
118 |
| - "Programming Language :: Python :: 3.10", |
119 |
| - "Programming Language :: Python :: 3.11", |
120 |
| - "Programming Language :: Python :: Implementation :: CPython", |
121 |
| - "Programming Language :: Python :: Implementation :: PyPy", |
122 |
| - "Operating System :: OS Independent", |
123 |
| - ], |
124 | 53 | ext_modules=ext_modules,
|
125 | 54 | )
|
0 commit comments