diff --git a/.gitignore b/.gitignore index 0ea7b5b6..1398dacf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ _pycache__/ build dist *.egg-info +*_version.py # documentation / sphinx docs/build diff --git a/Makefile b/Makefile index 59b8f41d..a99655bd 100644 --- a/Makefile +++ b/Makefile @@ -9,11 +9,11 @@ help: @echo "clean - remove artifacts" pypi: - python setup.py sdist bdist_wheel + python -m build --sdist --wheel twine upload dist/* pypi-test: - python setup.py sdist bdist_wheel + python -m build --sdist --wheel twine upload --repository-url https://test.pypi.org/legacy/ dist/* docs: diff --git a/README.rst b/README.rst index 4f6197e9..a52d27af 100644 --- a/README.rst +++ b/README.rst @@ -162,7 +162,7 @@ To install VIP, then simply cd into your local VIP directory, and run the instal .. code-block:: bash cd VIP - pip install -e . -r requirements-dev.txt + pip install -e .[dev] If cloned from your fork, make sure to link your VIP directory to the upstream source, to be able to easily update your local copy when a new version comes diff --git a/docs/source/conf.py b/docs/source/conf.py index 11be4169..57a4b2db 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -25,7 +25,7 @@ sys.path.insert(0, os.path.abspath('../../vip_hci/')) -with open(os.path.join(os.path.abspath('../../vip_hci/'), '__init__.py')) as init: +with open(os.path.join(os.path.abspath('../../vip_hci/'), '_version.py')) as init: for line in init: if "__version__ =" in line: version = line.split('"')[1] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1e482db9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,71 @@ +[build-system] +requires = ["setuptools", "wheel", "setuptools_scm"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +version_file = "vip_hci/_version.py" + +[project] +dynamic = ["version", "dependencies"] +name = "vip_hci" +license = {text = "MIT"} +readme = {file = "README.rst", content-type = "text/x-rst"} +requires-python = ">=3.8" +authors = [{name = "Carlos Alberto Gomez Gonzalez", email = "carlosgg33@gmail.com"}] +maintainers = [{name = "Valentin Christiaens", email = "valentinchrist@hotmail.com"}] +description = "Package for astronomical high-contrast image processing" +classifiers = [ + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: MIT License', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: POSIX :: Linux', + 'Operating System :: Microsoft :: Windows', + 'Natural Language :: English', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Topic :: Scientific/Engineering :: Astronomy' +] + +[tool.setuptools] +packages = ['vip_hci', + 'vip_hci.config', + 'vip_hci.fits', + 'vip_hci.fm', + 'vip_hci.invprob', + 'vip_hci.greedy', + 'vip_hci.metrics', + 'vip_hci.objects', + 'vip_hci.preproc', + 'vip_hci.psfsub', + 'vip_hci.stats', + 'vip_hci.var'] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[project.optional-dependencies] +dev = [ + "sphinx", + "myst-nb", + "myst-parser", + "pandoc", + "nbsphinx", + "sphinx_rtd_theme", + "jupyter_sphinx", + "pytest", + "pytest-cov ~=2.6.0", + "pytest-split", + "flake8", + "flake8-bandit", + "flake8-docstrings", + "autopep8", + "pre-commit", + "opencv-python", + "ratelimit" +] + +[project.urls] +Documentation = "https://vip.readthedocs.io/en/latest/" +Repository = "https://github.com/vortex-exoplanet/VIP" \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 2fa71d57..00000000 --- a/setup.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python - -import os -import re -from setuptools import setup -try: - # pip >=20 - from pip._internal.network.session import PipSession - from pip._internal.req import parse_requirements -except ImportError: - try: - # 10.0.0 <= pip <= 19.3.1 - from pip._internal.download import PipSession - from pip._internal.req import parse_requirements - except ImportError: - # pip <= 9.0.3 - from pip.download import PipSession - from pip.req import parse_requirements -from setuptools.command.install import install -from setuptools.command.develop import develop - - -# Hackishly override of the install method -class InstallReqs(install): - def run(self): - print(" ********************** ") - print(" *** Installing VIP *** ") - print(" ********************** ") - os.system('pip install -r requirements.txt') - install.run(self) - - -class InstallDevReqs(develop): - def run(self): - print(" **************************** ") - print(" *** Installing VIP (dev) *** ") - print(" **************************** ") - os.system('pip install -r requirements-dev.txt') - develop.run(self) - - -def resource(*args): - return os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), - *args) - - -# parse_requirements() returns generator of pip.req.InstallRequirement objects -reqs = parse_requirements(resource('requirements.txt'), session=PipSession) -try: - requirements = [str(ir.requirement) for ir in reqs] -except: - requirements = [str(ir.req) for ir in reqs] - -reqs_dev = parse_requirements(resource('requirements-dev.txt'), - session=PipSession) -try: - requirements_dev = [str(ir.requirement) for ir in reqs_dev] -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.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 db5be97f..567f816a 100644 --- a/vip_hci/__init__.py +++ b/vip_hci/__init__.py @@ -1,5 +1,3 @@ -__version__ = "1.6.4" - from . import preproc from . import config from . import fits @@ -11,3 +9,12 @@ from . import var from . import objects from .vip_ds9 import * + +try: + from ._version import __version__ +except ImportError: + from importlib.metadata import version, PackageNotFoundError + try: + __version__ = version(__name__) + except PackageNotFoundError: + __version__ = "0.0.0" # Default version diff --git a/vip_hci/config/utils_conf.py b/vip_hci/config/utils_conf.py index 2b24a9b7..77d1bd78 100644 --- a/vip_hci/config/utils_conf.py +++ b/vip_hci/config/utils_conf.py @@ -16,12 +16,15 @@ from functools import wraps import multiprocessing import warnings -from vip_hci import __version__ sep = "―" * 80 vip_figsize = (8, 5) vip_figdpi = 100 +def _get_vip_version(): + from vip_hci import __version__ # Delayed to avoid circular import + return __version__ + def print_precision(array, precision=3): """Prints an array with a given floating point precision. 3 by default.""" @@ -60,7 +63,7 @@ def save(self, filename): data["_item_{}".format(a)] = True np.savez_compressed( - filename, _vip_version=__version__, _vip_object=vip_object, **data + filename, _vip_version=_get_vip_version(), _vip_object=vip_object, **data ) else: @@ -87,7 +90,7 @@ def load(cls, filename): ) file_vip_version = data["_vip_version"].item() - if file_vip_version != __version__: + if file_vip_version != _get_vip_version(): print( "The file was saved with VIP {}. There may be some" "compatibility issues. Use with care."