Skip to content

Commit

Permalink
Added versioning to dea-tools (#855)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
MatthewJA and Matthew Alger authored Sep 2, 2021
1 parent b8a6be3 commit 34e31cd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ build/*
*.egg-info/*
dist/*
*.pyc

# setuptools_scm/versioning hacks
dea_tools/__version__.py
2 changes: 1 addition & 1 deletion Tools/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include README.md LICENSE
include README.rst LICENSE
17 changes: 17 additions & 0 deletions Tools/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,27 @@ 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
----------------

If you use any of the notebooks, code or tools in this repository in your work, please reference them using the following citation:

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
1 change: 1 addition & 0 deletions Tools/dea_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .__version__ import version as __version__
4 changes: 4 additions & 0 deletions Tools/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
39 changes: 25 additions & 14 deletions Tools/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -17,7 +19,6 @@
EMAIL = '[email protected]'
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')
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down

0 comments on commit 34e31cd

Please sign in to comment.