Skip to content

Commit

Permalink
Remove setuptools_scm (#15)
Browse files Browse the repository at this point in the history
Python: rm setuptools_scm; add macos/windows tests
  • Loading branch information
prisae committed Aug 16, 2021
1 parent 4fa3cc2 commit 3863dce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: linux-python
name: python

on:
pull_request:
Expand All @@ -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

Expand All @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
5 changes: 2 additions & 3 deletions packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 21 additions & 25 deletions packages/create_python.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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
Expand All @@ -26,6 +35,7 @@
setup(
name="libdlf",
version="{version}",
description="Library for Digital Linear Filters (DLF)",
long_description=readme,
author="The emsig community",
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3863dce

Please sign in to comment.