diff --git a/.github/workflows/linux_python.yml b/.github/workflows/python_test_deploy.yml similarity index 81% rename from .github/workflows/linux_python.yml rename to .github/workflows/python_test_deploy.yml index 06f84de..0a93ec3 100644 --- a/.github/workflows/linux_python.yml +++ b/.github/workflows/python_test_deploy.yml @@ -1,4 +1,4 @@ -name: linux-python +name: python on: pull_request: @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu, ] # Only Linux for _creation_] + os: [ubuntu, macos, windows] case: - python-version: 3.8 @@ -37,10 +37,15 @@ jobs: - name: Fetch git tags run: git fetch origin 'refs/tags/*:refs/tags/*' + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.case.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools_scm numpy pytest pytest-flake8 + pip install numpy pytest pytest-flake8 - name: Create, install, lint and test run: | @@ -70,26 +75,20 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: ${{ matrix.case.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip - pip install wheel setuptools_scm numpy + pip install wheel numpy - name: Create package run: | cd packages python create_python.py - - - name: Replace naming scheme - if: github.ref == 'refs/heads/main' - run: | - # Change setuptools-scm local_scheme to "no-local-version" so the - # local part of the version isn't included, making the version string - # compatible with Test PyPI. - sed --in-place 's/"root"/"local_scheme":"no-local-version","root"/g' packages/python/setup.py - cat packages/python/setup.py + echo "" + echo "Version:" + echo python python/setup.py --version - name: Build source and wheel distributions run: | diff --git a/packages/README.md b/packages/README.md index e2d1bdf..c319578 100644 --- a/packages/README.md +++ b/packages/README.md @@ -13,13 +13,12 @@ The python package is created by running python create_python.py ``` -The build requires `setuptools_scm`; the only dependency to use the package is -`numpy`. +The only dependency to use the package is `numpy`. If you want to install the package created in this manner, run ```bash -pip install python/. --use-feature=in-tree-build +pip install python/. --use-feature=in-tree-build ``` To clear it, run diff --git a/packages/create_python.py b/packages/create_python.py index a3e87f1..8918fa6 100644 --- a/packages/create_python.py +++ b/packages/create_python.py @@ -1,8 +1,18 @@ import json import shutil import pathlib +import subprocess from os.path import abspath +# Get git version +version = subprocess.check_output( + ['git', 'describe', '--tags'], stderr=subprocess.DEVNULL +).strip().decode('utf-8').split('-') +if len(version) > 1 and version[1]: + version = version[0][1:] + '.dev' + version[1] +else: + version = version[0][1:] + # Create package directory pathlib.Path(abspath("python/libdlf")).mkdir(parents=True, exist_ok=True) @@ -15,8 +25,7 @@ shutil.copyfile('../LICENSE', 'python/LICENSE') # Create setup.py -setup = """# -*- coding: utf-8 -*- -import os +setup = f"""# -*- coding: utf-8 -*- from setuptools import setup # Longer description @@ -26,6 +35,7 @@ setup( name="libdlf", + version="{version}", description="Library for Digital Linear Filters (DLF)", long_description=readme, author="The emsig community", @@ -34,15 +44,7 @@ license="CC-BY-4.0", packages=["libdlf"], include_package_data=True, - install_requires=[ - "numpy", - ], - use_scm_version={ - "root": "../../", - "relative_to": __file__, - "write_to": os.path.join("packages", "python", "libdlf", "version.py"), - }, - setup_requires=["setuptools_scm"], + install_requires=["numpy"], ) """ with open(abspath("python/setup.py"), "w") as fs: @@ -64,21 +66,15 @@ with open(abspath('python/libdlf/lib/filters.json')) as fj: lib = json.load(fj) + # Create init file with open(abspath('python/libdlf/__init__.py'), 'w') as fi: - fi.write("from datetime import datetime\n") - # Loop over transforms and add them for transform, flist in lib.items(): fi.write(f"from libdlf import {transform}\n") - fi.write( - "try:\n" - " from libdlf.version import version as __version__\n" - "except ImportError:\n" - " __version__ = 'unknown-'+datetime.today().strftime('%Y%m%d')\n" - ) + fi.write(f"\n__version__ = '{version}'\n") # Loop over transforms @@ -199,11 +195,11 @@ def test_hankel(): assert 1 == 0 # Required wavenumbers - λ = base/xt[:, None] + lambd = base/xt[:, None] # Compute values - lhs_j0 = λ*np.exp(-λ**2) - lhs_j1 = λ**2*np.exp(-λ**2) + lhs_j0 = lambd*np.exp(-lambd**2) + lhs_j1 = lambd**2*np.exp(-lambd**2) # Check if 'j0' in values: @@ -238,11 +234,11 @@ def test_fourier(): assert 1 == 0 # Required frequencies - f = base/xt[:, None] + freq = base/xt[:, None] # Compute values - lhs_sin = f*np.exp(-f**2) - lhs_cos = np.exp(-f**2) + lhs_sin = freq*np.exp(-freq**2) + lhs_cos = np.exp(-freq**2) # Check if 'sin' in values: