From 34e31cd8dcb297c1c1721cc8511a8f51060c5f53 Mon Sep 17 00:00:00 2001 From: Matthew Alger Date: Thu, 2 Sep 2021 10:03:39 +1000 Subject: [PATCH] Added versioning to dea-tools (#855) * Added versioning to dea-tools * Added wheel and backend to pyproject.toml * Fixes for setup.py and manifest * Added build steps to readme * Reverted the local versioning * Fixes from Kirill Co-authored-by: Matthew Alger --- Tools/.gitignore | 3 +++ Tools/MANIFEST.in | 2 +- Tools/README.rst | 17 ++++++++++++++++ Tools/dea_tools/__init__.py | 1 + Tools/pyproject.toml | 4 ++++ Tools/setup.py | 39 ++++++++++++++++++++++++------------- 6 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 Tools/pyproject.toml diff --git a/Tools/.gitignore b/Tools/.gitignore index 12ce113c6..d4143bfee 100644 --- a/Tools/.gitignore +++ b/Tools/.gitignore @@ -2,3 +2,6 @@ build/* *.egg-info/* dist/* *.pyc + +# setuptools_scm/versioning hacks +dea_tools/__version__.py diff --git a/Tools/MANIFEST.in b/Tools/MANIFEST.in index 64ad321df..0c738421d 100644 --- a/Tools/MANIFEST.in +++ b/Tools/MANIFEST.in @@ -1 +1 @@ -include README.md LICENSE +include README.rst LICENSE diff --git a/Tools/README.rst b/Tools/README.rst index fd6925f25..8fb38b9fd 100644 --- a/Tools/README.rst +++ b/Tools/README.rst @@ -26,6 +26,7 @@ Install from the source on any other system with `pip`: pip install --extra-index-url="https://packages.dea.ga.gov.au" git+https://github.com/GeoscienceAustralia/dea-notebooks.git#subdirectory=Tools + Citing DEA Tools ---------------- @@ -33,3 +34,19 @@ If you use any of the notebooks, code or tools in this repository in your work, Krause, C., Dunn, B., Bishop-Taylor, R., Adams, C., Burton, C., Alger, M., Chua, S., Phillips, C., Newey, V., Kouzoubov, K., Leith, A., Ayers, D., Hicks, A., DEA Notebooks contributors 2021. Digital Earth Australia notebooks and tools repository. Geoscience Australia, Canberra. https://doi.org/10.26186/145234 + +Building and Releasing +---------------------- + +This section is only relevant to you if you are a developer of this package. + +Building and releasing dea-tools requires that the package is built in-place. Either build with an editable pip installation or with `pip>=21.2` and `--use-feature=in-tree-build`. Building will generate a file, `dea_tools/__version__.py`, that is dynamic on release. It should not be committed. `setup.py` will detect if `__version__.py` exists and change its behaviour accordingly. + +Build instructions: + +.. code-block:: bash + cd Tools + rm dea_tools/__version__.py # if necessary + pip install . --use-feature=in-tree-build + python -m build + diff --git a/Tools/dea_tools/__init__.py b/Tools/dea_tools/__init__.py index e69de29bb..86d34b089 100644 --- a/Tools/dea_tools/__init__.py +++ b/Tools/dea_tools/__init__.py @@ -0,0 +1 @@ +from .__version__ import version as __version__ \ No newline at end of file diff --git a/Tools/pyproject.toml b/Tools/pyproject.toml new file mode 100644 index 000000000..dba2f7b3f --- /dev/null +++ b/Tools/pyproject.toml @@ -0,0 +1,4 @@ +[build-system] +# Minimum requirements for the build system to execute. +requires = ["setuptools>=42", "setuptools_scm[toml]>=3.4", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/Tools/setup.py b/Tools/setup.py index 4620538fa..beb9bb9e8 100644 --- a/Tools/setup.py +++ b/Tools/setup.py @@ -7,8 +7,10 @@ import os import sys from shutil import rmtree +from pathlib import Path from setuptools import find_packages, setup, Command +import setuptools_scm # Package meta-data. NAME = 'dea-tools' @@ -17,7 +19,6 @@ EMAIL = 'dea@ga.gov.au' AUTHOR = 'Geoscience Australia' REQUIRES_PYTHON = '>=3.6.0' -VERSION = '0.1.0' # Where are we? IS_SANDBOX = os.getenv('JUPYTER_IMAGE', default='').startswith('geoscienceaustralia/sandbox') @@ -83,16 +84,7 @@ except FileNotFoundError: long_description = DESCRIPTION -# Load the package's __version__.py module as a dictionary. -about = {} -if not VERSION: - project_slug = NAME.lower().replace("-", "_").replace(" ", "_") - with open(os.path.join(here, project_slug, '__version__.py')) as f: - exec(f.read(), about) -else: - about['__version__'] = VERSION - - + class UploadCommand(Command): """Support setup.py upload.""" @@ -130,13 +122,32 @@ def run(self): sys.exit() +# Versioning magic. +VERSION_FILE_PATH = Path('dea_tools/__version__.py') +about = {} +try: + version = setuptools_scm.get_version( + root='..', + write_to='Tools' / VERSION_FILE_PATH, + relative_to=__file__) +except (LookupError, FileNotFoundError): + # python -m build will trip the FNFError + try: + # no .git folder, so read from __version__.py + with open(VERSION_FILE_PATH) as f_version: + exec(f_version.read(), about) + version = about['version'] + except FileNotFoundError: + # No __version__.py, yikes + raise RuntimeError('Build in-place with --use-feature=in-tree-build.') + # Where the magic happens: setup( name=NAME, - version=about['__version__'], + version=version, description=DESCRIPTION, long_description=long_description, - long_description_content_type='text/markdown', + long_description_content_type='text/x-rst', author=AUTHOR, author_email=EMAIL, python_requires=REQUIRES_PYTHON, @@ -156,7 +167,7 @@ def run(self): 'License :: OSI Approved :: Apache Software License', 'Development Status :: 3 - Alpha', 'Intended Audience :: Science/Research', - 'Topic :: Scientific/Engineering :: GIS' + 'Topic :: Scientific/Engineering :: GIS', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.6',