diff --git a/build_utils/version.py b/build_utils/version.py index cab731833..b38f1bd3a 100644 --- a/build_utils/version.py +++ b/build_utils/version.py @@ -1,24 +1,45 @@ from pathlib import Path import subprocess import sys +import os gits = ["git"] if sys.platform == "win32": gits += ["git.cmd", "git.exe"] +match sys.argv: + case [_, "--dist"]: + type_ = "dist" + case [_, "--dump"]: + type_ = "dump" + case [_]: + type_ = "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 else ''}" + version += f"+{dirty[0]}.{dirty[1]}{'.dirty' if len(dirty) > 2 and type_ != 'dump' else ''}" 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) diff --git a/euphonic/version.py b/euphonic/version.py index 361b2d001..446842908 100644 --- a/euphonic/version.py +++ b/euphonic/version.py @@ -1 +1 @@ -__version__ = "1.3.3a1" +__version__ = "v1.3.1a1" diff --git a/meson.build b/meson.build index 366fcc7f2..572dc63c4 100644 --- a/meson.build +++ b/meson.build @@ -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 = { @@ -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'] diff --git a/tox.ini b/tox.ini index f97b4a650..1942d99b9 100644 --- a/tox.ini +++ b/tox.ini @@ -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}