From cc1f090c2b5afd1001b2ae77ca22cb4fe2e92f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20L=C3=B8iten?= Date: Mon, 21 Dec 2020 21:52:12 +0100 Subject: [PATCH 1/3] Added automatic release --- .github/workflows/python_publish.yml | 27 +++++++++++++++++++++++++++ setup.py | 19 ++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/python_publish.yml diff --git a/.github/workflows/python_publish.yml b/.github/workflows/python_publish.yml new file mode 100644 index 0000000..ee6730c --- /dev/null +++ b/.github/workflows/python_publish.yml @@ -0,0 +1,27 @@ +name: Upload Python Package + +on: + # Only run when a release is created + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/setup.py b/setup.py index 5de0663..4e8246d 100644 --- a/setup.py +++ b/setup.py @@ -10,22 +10,11 @@ init_path = root_path.joinpath(name, '__init__.py') readme_path = root_path.joinpath('README.md') -# https://packaging.python.org/guides/single-sourcing-package-version/ -with init_path.open('r') as f: - version_file = f.read() - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", - version_file, re.M) - if version_match: - version = version_match.group(1) - else: - raise RuntimeError('Unable to find version string.') - with readme_path.open('r') as f: long_description = f.read() setuptools.setup( name=name, - version=version, author='Ben Dudson et al.', description='Python package containing BOUT++ utils', long_description=long_description, @@ -44,13 +33,17 @@ 'data-extraction', 'data-analysis', 'data-visualization'], + use_scm_version=True, + setup_requires=['setuptools>=42', + 'setuptools_scm[toml]>=3.4', + 'setuptools_scm_git_archive'], install_requires=['numpy', 'matplotlib', 'scipy', 'h5py', - 'boututils', 'future', - 'netCDF4'], + 'netCDF4' + "importlib-metadata ; python_version<'3.8'"], extras_require={ 'mayavi': ['mayavi', 'PyQt5']}, classifiers=[ From a65d9a7339188b13facaee990d013f2759c169be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20L=C3=B8iten?= Date: Mon, 21 Dec 2020 22:37:38 +0100 Subject: [PATCH 2/3] Updates from review #1 --- pyproject.toml | 2 ++ requirements.txt | 1 + 2 files changed, 3 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ec95545 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.setuptools_scm] +write_to = "boututils/_version.py" diff --git a/requirements.txt b/requirements.txt index 7f6d297..9e85c88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ future==0.18.2 PyQt5==5.12.2 [mayavi] mayavi==4.6.2 [mayavi] netCDF4==1.5.3 +setuptools_scm==5.0.1 From b9045e40cb6505bdc4620f559279d9798ffd7569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20L=C3=B8iten?= Date: Tue, 22 Dec 2020 06:58:16 +0100 Subject: [PATCH 3/3] Fixes from reveiw 2 --- boututils/__init__.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/boututils/__init__.py b/boututils/__init__.py index 2b3a54d..54eb75b 100644 --- a/boututils/__init__.py +++ b/boututils/__init__.py @@ -38,5 +38,23 @@ do_import.append('View3D') __all__ = do_import -__version__ = '0.1.4' __name__ = 'boututils' + +try: + from importlib.metadata import version, PackageNotFoundError +except ModuleNotFoundError: + from importlib_metadata import version, PackageNotFoundError +try: + __version__ = version(__name__) +except PackageNotFoundError: + try: + from setuptools_scm import get_version + except ModuleNotFoundError as e: + error_info = ( + "'setuptools_scm' is required to get the version number when running " + "boututils from the git repo. Please install 'setuptools_scm'." + ) + print(error_info) + raise ModuleNotFoundError(str(e) + ". " + error_info) + else: + __version__ = get_version(root="..", relative_to=__file__)