Skip to content

Commit

Permalink
Experiments with version
Browse files Browse the repository at this point in the history
  • Loading branch information
oerc0122 committed Nov 21, 2024
1 parent 77a194d commit 0a5b42d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 51 deletions.
27 changes: 24 additions & 3 deletions build_utils/version.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
from pathlib import Path

Check notice on line 1 in build_utils/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build_utils/version.py#L1

Missing module docstring
import subprocess
import sys
import os

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

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

Check notice on line 12 in build_utils/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build_utils/version.py#L12

Constant name "type_" doesn't conform to UPPER_CASE naming style
case [_, "--dump"]:
type_ = "dump"

Check notice on line 14 in build_utils/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build_utils/version.py#L14

Constant name "type_" doesn't conform to UPPER_CASE naming style
case [_]:
type_ = "print"

Check notice on line 16 in build_utils/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build_utils/version.py#L16

Constant name "type_" doesn't conform to UPPER_CASE naming style

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)

Check notice on line 22 in build_utils/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build_utils/version.py#L22

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

Check notice on line 25 in build_utils/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build_utils/version.py#L25

Line too long (104/100)
break

except (OSError, subprocess.CalledProcessError) as err:
print(f"Tried {gitcmd}, returned: {err}", file=sys.stderr)
else: # Can't use git
version_file = Path(__file__).parent.parent / "euphonic" / "version.py"
version = version_file.read_text().split("=")[1].strip('"\n ')

match type_:
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")

case "dump":
version_file.write_text(f'__version__ = "{version}"', encoding="utf-8")

print(version)
case "print":
print(version)
2 changes: 1 addition & 1 deletion euphonic/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.3a1"
__version__ = "v1.3.1a1"

Check notice on line 1 in euphonic/version.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

euphonic/version.py#L1

Missing module docstring
7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ project('euphonic',

build = get_option('python_only') ? disabler() : []

fs = import('fs')
py = import('python').find_installation(pure: false)

py_dep = py.dependency()

py_src = {
Expand Down Expand Up @@ -34,10 +36,13 @@ foreach folder, sources : py_src
py.install_sources(inc, subdir: folder)
endforeach

version_script = files('./build_utils/version.py')
meson.add_dist_script('python', version_script, '--dist')

# If building from sdist not under git so will be read from last version
version = configure_file(input: 'build_utils/version.py.in',
output: 'version.py',
configuration: {'VERSION': meson.project_version()})

py.install_sources(version, 'CITATION.cff', 'LICENSE', subdir: 'euphonic')

src = ['c/_euphonic.c', 'c/dyn_mat.c', 'c/util.c', 'c/py_util.c', 'c/load_libs.c']
Expand Down
67 changes: 21 additions & 46 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,104 +1,79 @@
[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

[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 \
python -m pip install -v \
--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}
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[matplotlib]'
extras = 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}
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[phonopy_reader]'
extras = 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}
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[brille]'
extras = 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}
commands_pre =
python -m pip install \
--upgrade \
--upgrade-strategy eager \
'{toxinidir}[phonopy_reader,matplotlib,brille]'
extras =
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 --force-reinstall {opts} {packages}
python -m pip install --upgrade pip --force-reinstall -v {opts} {packages}
platform =
linux: linux
deps =
numpy==1.24.0
{[testenv:py310]deps}
-r{toxinidir}/tests_and_analysis/minimum_euphonic_requirements.txt
-r{toxinidir}/tests_and_analysis/tox_requirements.txt
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 '{toxinidir}[matplotlib,phonopy_reader,brille]'
python -m pip install -v -r '{toxinidir}/tests_and_analysis/minimum_euphonic_requirements.txt' '{toxinidir}[test,matplotlib,phonopy_reader,brille]'
commands = {[testenv]test_command}

0 comments on commit 0a5b42d

Please sign in to comment.