Skip to content

Commit 3a5e582

Browse files
committed
Switch eccodes python to wheelchains
1 parent 6e01ef6 commit 3a5e582

File tree

2 files changed

+50
-101
lines changed

2 files changed

+50
-101
lines changed

setup.cfg

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
[metadata]
2+
description = "eccodes-python"
3+
long_description = file: README.rst
4+
long_description_content_type = text/rst
5+
author = "European Centre for Medium-Range Weather Forecasts (ECMWF)"
6+
author_email = "[email protected]"
7+
url = "https://github.com/ecmwf/eccodes-python"
8+
keywords = ecCodes, GRIB, BUFR
9+
classifiers =
10+
Development Status :: 4 - Beta
11+
Intended Audience :: Developers
12+
License :: OSI Approved :: Apache Software License
13+
Programming Language :: Python :: 3.8
14+
Programming Language :: Python :: 3.9
15+
Programming Language :: Python :: 3.10
16+
Programming Language :: Python :: 3.11
17+
Programming Language :: Python :: Implementation :: CPython
18+
Programming Language :: Python :: Implementation :: PyPy
19+
Operating System :: OS Independent
20+
121
[aliases]
222
test = pytest
323

setup.py

+30-101
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,54 @@
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
141
import os
15-
import re
162
import sys
17-
183
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
1916

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"]
8217
if sys.version_info < (3, 7):
8318
install_requires = ["numpy<1.20"]
8419
elif sys.version_info < (3, 8):
8520
install_requires = ["numpy<1.22"]
8621
elif sys.version_info < (3, 9):
8722
install_requires = ["numpy<1.25"]
23+
else:
24+
install_requires = ["numpy"]
8825

8926
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+
]
9037

9138
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-
author_email="[email protected]",
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"],
10041
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?
10445
tests_require=[
10546
"pytest",
10647
"pytest-cov",
10748
"pytest-flakes",
10849
],
50+
# NOTE does this work?
10951
test_suite="tests",
11052
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-
],
12453
ext_modules=ext_modules,
12554
)

0 commit comments

Comments
 (0)