Skip to content

Commit

Permalink
Revert tox ini
Browse files Browse the repository at this point in the history
  • Loading branch information
oerc0122 committed Nov 22, 2024
1 parent 0a5b42d commit 44d1712
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 39 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build_upload_pypi_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure tags are fetched for versioning
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install llvm on Macos
if: startsWith(matrix.os, 'macos')
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure tags are fetched for versioning
- uses: actions/setup-python@v5
with:
python-version: |
Expand Down
53 changes: 39 additions & 14 deletions build_utils/version.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
"""Script to compute version from git tags.
Provides 3 means of updating:
- python version.py
Print computed version to stdout
- python version.py --dump
Update version in `euponic/version.py`
- python version.py --dist
Update versions in both `euphonic/version.py` and in meson sdist build directory.
"""

from pathlib import Path
import subprocess
import sys
import os

if new_dir := os.getenv("MESON_SOURCE_ROOT"):
os.chdir(new_dir)

gits = ["git"]
if sys.platform == "win32":
gits += ["git.cmd", "git.exe"]

match sys.argv:
case [_, "--dist"]:
type_ = "dist"
COMMAND = "dist"
case [_, "--dump"]:
type_ = "dump"
COMMAND = "dump"
case [_]:
type_ = "print"
COMMAND = "print"

version_file = Path(__file__).parent.parent / "euphonic" / "version.py"

for gitcmd in gits:
try:
proc = subprocess.run([gitcmd, "describe", "--tags", "--dirty"], capture_output=True, check=True, text=True)
version, *dirty = proc.stdout.strip().split("-")
if dirty:
version += f"+{dirty[0]}.{dirty[1]}{'.dirty' if len(dirty) > 2 and type_ != 'dump' else ''}"
break

except (OSError, subprocess.CalledProcessError) as err:
proc = subprocess.run([gitcmd, "describe", "--tags", "--dirty"],
capture_output=True, check=True, text=True)
except subprocess.CalledProcessError as err:
print(f"Tried {gitcmd}, returned: {err}", file=sys.stderr)
print(f"Stdout: '{err.stdout.strip()}'", file=sys.stderr)
print(f"Stdout: '{err.stderr.strip()}'", file=sys.stderr)
continue

version, *dirty = proc.stdout.strip().split("-")
if dirty:
version += f"+{dirty[0]}.{dirty[1]}{'.dirty' if len(dirty) > 2 and COMMAND != 'dump' else ''}"

Check notice on line 52 in build_utils/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build_utils/version.py#L52

Line too long (102/100)
break

else: # Can't use git
version = version_file.read_text().split("=")[1].strip('"\n ')

match type_:
match COMMAND:
case "dist":
version_file.write_text(f'__version__ = "{version}"', encoding="utf-8")
dist_path = os.getenv("MESON_DIST_ROOT")
version_file = Path(dist_path) / "euphonic" / "version.py"
version_file.parent.mkdir(parents=True, exist_ok=True)
version_file.write_text(f'__version__ = "{version}"', encoding="utf-8")
dist_version_file = Path(dist_path) / "euphonic" / "version.py"
dist_version_file.parent.mkdir(parents=True, exist_ok=True)
dist_version_file.write_text(f'__version__ = "{version}"', encoding="utf-8")

case "dump":
version_file.write_text(f'__version__ = "{version}"', encoding="utf-8")
Expand Down
68 changes: 47 additions & 21 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,79 +1,105 @@
[tox]
# The python environments to run the tests in
envlist = py310,py311,py312,py310-{base,matplotlib,phonopy_reader,brille,all},py310-minrequirements-linux
isolated_build = true
# Skip the execution of setup.py as we do it with the correct arg in commands_pre below
# skipsdist = True
skipsdist = True
whitelist_externals = git

[testenv]
changedir = tests_and_analysis/test
test_command = python run_tests.py --report
passenv = CC CC_LD LDFLAGS CPPFLAGS

[testenv:{py310,py311,py312}]
install_command =
python -m pip install -v \
python -m pip install \
--force-reinstall \
--upgrade \
--upgrade-strategy eager \
{opts} \
{packages}

[testenv:{py310,py311,py312}]
extras =
matplotlib
phonopy_reader
brille
deps =
numpy
-r{toxinidir}/tests_and_analysis/tox_requirements.txt
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[matplotlib,phonopy_reader,brille]'
commands =
{[testenv]test_command} --cov

# Test with no extras
[testenv:py310-base]
install_command = {[testenv:py310]install_command}
deps = {[testenv:py310]deps}
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}'
commands = {[testenv]test_command} --cov -m "not (phonopy_reader or matplotlib or brille)"

# Test with matplotlib extra only
[testenv:py310-matplotlib]
install_command = {[testenv:py310]install_command}
deps = {[testenv:py310]deps}
extras = matplotlib
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[matplotlib]'
commands = {[testenv]test_command} --cov -m "matplotlib and not multiple_extras"

# Test with phonopy_reader extra only
[testenv:py310-phonopy_reader]
install_command = {[testenv:py310]install_command}
deps = {[testenv:py310]deps}
extras = phonopy_reader
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[phonopy_reader]'
commands = {[testenv]test_command} --cov -m "phonopy_reader and not multiple_extras"

# Test with brille extra only
[testenv:py310-brille]
install_command = {[testenv:py310]install_command}
deps = {[testenv:py310]deps}
extras = brille
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[brille]'
commands = {[testenv]test_command} --cov -m "brille and not multiple_extras"

# Run remaining tests that require multiple extras
[testenv:py310-all]
install_command = {[testenv:py310]install_command}
deps = {[testenv:py310]deps}
extras =
phonopy_reader
matplotlib
brille
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[phonopy_reader,matplotlib,brille]'
commands =
{[testenv]test_command} --cov -m multiple_extras

[testenv:py310-minrequirements-linux]
whitelist_externals = rm
skipsdist = True
install_command =
python -m pip install --upgrade pip --force-reinstall -v {opts} {packages}
python -m pip install --force-reinstall {opts} {packages}
platform =
linux: linux
deps =
numpy==1.24.0
-r{toxinidir}/tests_and_analysis/minimum_euphonic_requirements.txt
-r{toxinidir}/tests_and_analysis/tox_requirements.txt
{[testenv:py310]deps}
commands_pre =
python -m pip install --force-reinstall \
-r{toxinidir}/tests_and_analysis/minimum_euphonic_requirements.txt
python -m pip install --force-reinstall \
-r{toxinidir}/tests_and_analysis/tox_requirements.txt
# Force rebuild of euphonic extension to avoid Numpy clash
rm -rf {toxinidir}/build
python -m pip install -v -r '{toxinidir}/tests_and_analysis/minimum_euphonic_requirements.txt' '{toxinidir}[test,matplotlib,phonopy_reader,brille]'
python -m pip install '{toxinidir}[matplotlib,phonopy_reader,brille]'
commands = {[testenv]test_command}

0 comments on commit 44d1712

Please sign in to comment.