From 6a97aa58d3ec0d51067b5dd6b1ad646819fad666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 30 Jul 2025 18:15:01 +0200 Subject: [PATCH] BLD: move static metadata to `pyproject.toml` and explicitly specify build backend and requirements --- docs/source/conf.py | 6 ++--- pyproject.toml | 33 +++++++++++++++++++++++++++ setup.py | 43 ------------------------------------ vip_hci/__init__.py | 11 +++++++-- vip_hci/config/utils_conf.py | 4 +++- 5 files changed, 47 insertions(+), 50 deletions(-) create mode 100644 pyproject.toml diff --git a/docs/source/conf.py b/docs/source/conf.py index 11be4169..13113cbc 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -17,6 +17,7 @@ # import os import sys +from importlib.metadata import version as md_version import matplotlib # fix for `ImportError: No module named _tkinter`: @@ -25,10 +26,7 @@ sys.path.insert(0, os.path.abspath('../../vip_hci/')) -with open(os.path.join(os.path.abspath('../../vip_hci/'), '__init__.py')) as init: - for line in init: - if "__version__ =" in line: - version = line.split('"')[1] +version = md_version('vip_hci') # -- General configuration ------------------------------------------------ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..b5737425 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,33 @@ +[build-system] +build-backend = "setuptools.build_meta" +requires = [ "pip", "setuptools>=77" ] + +[project] +name = "vip_hci" +version = "1.6.6" +description = "Package for astronomical high-contrast image processing." +readme = "README.rst" +license = "MIT" +license-files = ["LICENSE"] +authors = [ + { name = "Carlos Alberto Gomez Gonzalez" }, + { name = "Valentin Christiaens", email = "valentin.christiaens@uliege.be" }, +] +requires-python = ">=3.8" +classifiers = [ + "Intended Audience :: Science/Research", + "Natural Language :: English", + "Operating System :: MacOS :: MacOS X", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Topic :: Scientific/Engineering :: Astronomy", +] +urls.Homepage = "https://github.com/vortex-exoplanet/VIP" + +[tool.setuptools] +zip-safe = false +packages.find = { namespaces = false } diff --git a/setup.py b/setup.py index cfaa56b9..0ece30bf 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ #!/usr/bin/env python import os -import re from setuptools import setup try: @@ -58,52 +57,10 @@ def resource(*args): except: requirements_dev = [str(ir.req) for ir in reqs_dev] -with open(resource('README.rst')) as readme_file: - README = readme_file.read() - -with open(resource('vip_hci', '__init__.py')) as version_file: - version_file = version_file.read() - VERSION = re.search(r"""^__version__ = ['"]([^'"]*)['"]""", - version_file, re.M) - VERSION = VERSION.group(1) - - -PACKAGES = ['vip_hci', - 'vip_hci.config', - 'vip_hci.fits', - 'vip_hci.fm', - 'vip_hci.greedy', - 'vip_hci.invprob', - 'vip_hci.metrics', - 'vip_hci.objects', - 'vip_hci.preproc', - 'vip_hci.psfsub', - 'vip_hci.stats', - 'vip_hci.var'] setup( - name='vip_hci', - version=VERSION, - description='Package for astronomical high-contrast image processing.', - long_description=README, - license='MIT', - author='Carlos Alberto Gomez Gonzalez, Valentin Christiaens', - author_email='valentin.christiaens@uliege.be', - url='https://github.com/vortex-exoplanet/VIP', cmdclass={'install': InstallReqs, 'develop': InstallDevReqs}, - packages=PACKAGES, install_requires=requirements, extras_require={"dev": requirements_dev}, - zip_safe=False, - classifiers=['Intended Audience :: Science/Research', - 'License :: OSI Approved :: MIT License', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: POSIX :: Linux', - 'Natural Language :: English', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Topic :: Scientific/Engineering :: Astronomy' - ] ) diff --git a/vip_hci/__init__.py b/vip_hci/__init__.py index 8bfd541a..f7c2af04 100644 --- a/vip_hci/__init__.py +++ b/vip_hci/__init__.py @@ -1,5 +1,3 @@ -__version__ = "1.6.6" - from . import preproc from . import config from . import fits @@ -11,3 +9,12 @@ from . import var from . import objects from .vip_ds9 import * + +__version__ = "1.6.6" +# TODO: replace static __version__ with the following dynamic lookup +# (requires CI test against a built package rather than the source tree) +# def __getattr__(name: str): +# if name == '__version__': +# from importlib.metadata import version +# return version('vip_hci') +# raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/vip_hci/config/utils_conf.py b/vip_hci/config/utils_conf.py index c1ae6abb..86e04167 100644 --- a/vip_hci/config/utils_conf.py +++ b/vip_hci/config/utils_conf.py @@ -16,7 +16,6 @@ from functools import wraps import multiprocessing import warnings -from vip_hci import __version__ sep = "―" * 80 vip_figsize = (8, 5) @@ -44,6 +43,7 @@ def save(self, filename): """ + from vip_hci import __version__ # TODO: replace this with importlib.metadata.version vip_object = self.__class__.__name__ @@ -70,6 +70,8 @@ def save(self, filename): @classmethod def load(cls, filename): + from vip_hci import __version__ # TODO: replace this with importlib.metadata.version + try: data = np.load(filename, allow_pickle=True) except BaseException: