Skip to content

Commit

Permalink
Migrate to tox 4 (#332)
Browse files Browse the repository at this point in the history
* Migrate tox.ini to tox 4
* Remove custom install from tox.ini
* Add test for no C extension.
* Rename phonopy_reader to phonopy-reader for tox support (everywhere needed)
* Add verbose flag to tox's pip install command
* use tox 4 for release testing

---------

Co-authored-by: Adam J. Jackson <[email protected]>
  • Loading branch information
oerc0122 and ajjackson authored Dec 18, 2024
1 parent fb4549d commit 10c2639
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 137 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_upload_pypi_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ jobs:

CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""

CIBW_TEST_EXTRAS: "test,brille,phonopy_reader,matplotlib"
CIBW_TEST_COMMAND: "python {package}/tests_and_analysis/test/run_tests.py"
CIBW_TEST_EXTRAS: "test,brille,phonopy-reader,matplotlib"
CIBW_TEST_COMMAND: python {package}/tests_and_analysis/test/run_tests.py

with:
output-dir: wheelhouse
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
- name: Install from sdist
shell: bash -l {0}
run: python -m pip install $(find dist -name 'euphonic-*.tar.gz')[matplotlib,phonopy_reader,brille,test]
run: python -m pip install $(find dist -name 'euphonic-*.tar.gz')[matplotlib,phonopy-reader,brille,test]

- name: Checkout repository (for tests and test data)
uses: actions/checkout@v4
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,13 @@ jobs:
if: github.event_name != 'workflow_dispatch'
env:
TOX_SKIP_ENV: '.*?(py311).*?'
TOX_PARALLEL_NO_SPINNER: 1
shell: bash -l {0}
run: python -m tox --parallel
run: python -m tox run-parallel

- name: Run tests, workflow dispatch so test all Python versions
if: github.event_name == 'workflow_dispatch'
env:
TOX_PARALLEL_NO_SPINNER: 1
shell: bash -l {0}
run: python -m tox --parallel
run: python -m tox run-parallel

- name: Upload test results
if: always()
Expand Down Expand Up @@ -115,7 +112,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install -r tests_and_analysis/ci_requirements.txt
python -m pip install -r doc/requirements.txt
python -m pip install .[matplotlib,phonopy_reader,brille]
python -m pip install .[matplotlib,phonopy-reader,brille]
- name: Run Sphinx doctests
working-directory: ./doc
shell: bash -l {0}
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: '3.10'
channels: conda-forge,defaults
channel-priority: true
- name: Install llvm on Macos
fetch-depth: 0 # Ensure tags are fetched for versioning
- uses: actions/setup-python@v5
with:
python-version: |
3.10
3.11
3.12
- name: Install llvm on MacOS
if: startsWith(matrix.os, 'macos')
shell: bash -l {0}
env:
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ python:
path: .
extra_requirements:
- matplotlib
- phonopy_reader
- phonopy-reader
- brille
81 changes: 32 additions & 49 deletions build_utils/release_tox.ini
Original file line number Diff line number Diff line change
@@ -1,74 +1,52 @@
[tox]
# Use conda to set up the python environments to run in
requires = tox-conda
requires = tox>=4
# The python environments to run the tests in
envlist = pypi-py310-min,conda-py310-old-np,{pypi,conda}-{py310,py311,py312},pypisource-{py310,py312}
# Skip the execution of setup.py as we do it with the correct version in commands_pre below
skipsdist = True
skip_install = True

[testenv]
changedir = tests_and_analysis/test
test_command = python {toxinidir}/../tests_and_analysis/test/run_tests.py --report
requirements_dir = {toxinidir}/../tests_and_analysis
passenv =
EUPHONIC_VERSION
# The name "extras" is reserved and has its own format with newlines:
# we need a token to inject into custom commands_pre, so call it extras_str
extras_str = [test,matplotlib,phonopy-reader,brille]

# Test PyPI source distribution
[testenv:pypisource-{py310,py312}]
passenv = CC CC_LD LDFLAGS CPPFLAGS
install_command = python -m pip install {opts} {packages}
deps =
numpy
spglib # Not interested here in whether source builds of spglib work
-r{[testenv]requirements_dir}/tox_requirements.txt
passenv =
CC
CC_LD
LDFLAGS
CPPFLAGS
commands_pre =
python -m pip install \
--force-reinstall \
'euphonic[matplotlib,phonopy_reader,brille]=={env:EUPHONIC_VERSION}' \
euphonic{[testenv]extras_str}=={env:EUPHONIC_VERSION} \
--no-binary 'euphonic'
commands = {[testenv]test_command}


[testenv:pypi-{py310,py311,py312}]
install_command = python -m pip install {opts} {packages}
deps =
numpy
-r{[testenv]requirements_dir}/tox_requirements.txt
commands_pre =
python -m pip install \
--force-reinstall \
'euphonic[matplotlib,phonopy_reader,brille]=={env:EUPHONIC_VERSION}' \
euphonic{[testenv]extras_str}=={env:EUPHONIC_VERSION} \
--only-binary 'euphonic'
commands = {[testenv]test_command}

[testenv:pypi-py310-min-win-linux]
install_command = python -m pip install --force-reinstall {opts} {packages}
platform =
linux: linux
windows: win32
[testenv:pypi-py310-min]
platform = (linux)|(win32)
deps =
numpy==1.24.0
numpy==1.24
-r{toxinidir}/../tests_and_analysis/tox_requirements.txt
commands_pre =
python -m pip install --force-reinstall \
-r{[testenv]requirements_dir}/minimum_euphonic_requirements.txt
python -m pip install --force-reinstall \
-r{[testenv]requirements_dir}/tox_requirements.txt
-r{toxinidir}/../tests_and_analysis/minimum_euphonic_requirements.txt
python -m pip install \
'euphonic[matplotlib,phonopy_reader,brille]=={env:EUPHONIC_VERSION}' \
--only-binary 'euphonic'
commands = {[testenv]test_command}

[testenv:pypi-py310-min-mac]
install_command = python -m pip install --force-reinstall {opts} {packages}
platform =
mac: darwin
deps =
numpy==1.24.0
commands_pre =
python -m pip install --force-reinstall \
-r{[testenv]requirements_dir}/minimum_euphonic_requirements_mac.txt
python -m pip install --force-reinstall \
-r{[testenv]requirements_dir}/tox_requirements.txt
python -m pip install \
'euphonic[matplotlib,phonopy_reader,brille]=={env:EUPHONIC_VERSION}' \
euphonic{[testenv]extras_str}=={env:EUPHONIC_VERSION} \
--only-binary 'euphonic'
commands = {[testenv]test_command}

Expand All @@ -78,10 +56,13 @@ install_command = conda install {packages}
conda_channels =
conda-forge
default
conda_deps =
--file={[testenv]requirements_dir}/tox_requirements.txt
extras =
test
matplotlib
phonopy-reader

commands_pre =
conda install -c conda-forge euphonic={env:EUPHONIC_VERSION} matplotlib-base pyyaml h5py
conda install -c conda-forge euphonic={env:EUPHONIC_VERSION}
# Brille not available on conda
commands = {[testenv]test_command} -m "not brille"

Expand All @@ -93,10 +74,12 @@ install_command = conda install {packages}
conda_channels =
conda-forge
default
conda_deps =
--file={[testenv]requirements_dir}/tox_requirements.txt
deps = numpy==1.24
extras =
test
matplotlib
phonopy-reader
commands_pre =
conda install numpy=1.22
conda install -c conda-forge euphonic={env:EUPHONIC_VERSION} matplotlib-base pyyaml h5py
conda install -c conda-forge euphonic={env:EUPHONIC_VERSION}
# Brille not available on conda
commands = {[testenv]test_command} -m "not brille"
6 changes: 3 additions & 3 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Euphonic has optional 'extensions' which require extra dependencies for certain
They are listed below

* **matplotlib** - required for plotting
* **phonopy_reader** - required for reading Phonopy files
* **phonopy-reader** - required for reading Phonopy files
* **brille** - required for performing linear interpolation with the Brille library

To install euphonic with all the dependencies run:

.. code-block:: bash
pip install euphonic[matplotlib,phonopy_reader,brille]
pip install euphonic[matplotlib,phonopy-reader,brille]
The dependencies can also be installed individually:

Expand Down Expand Up @@ -69,7 +69,7 @@ To install with all dependencies use:

.. code-block:: bash
pip install .[matplotlib,phonopy_reader,brille]
pip install .[matplotlib,phonopy-reader,brille]
If you don't require the extra dependencies, just use:

Expand Down
2 changes: 1 addition & 1 deletion euphonic/readers/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self):
'\n\nCannot import yaml, h5py to read Phonopy files, maybe '
'they are not installed. To install the optional '
'dependencies for Euphonic\'s Phonopy reader, try:\n\n'
'pip install euphonic[phonopy_reader]\n')
'pip install euphonic[phonopy-reader]\n')

def __str__(self):
return self.message
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ documentation = "https://euphonic.readthedocs.io/en/stable/"

[project.optional-dependencies]
matplotlib = ["matplotlib>=3.8.0"]
phonopy_reader = ["h5py>=3.6.0", "PyYAML>=6.0"]
phonopy_reader = ["h5py>=3.6.0", "PyYAML>=6.0"] # Deprecated, will be removed in future versions.
phonopy-reader = ["h5py>=3.6.0", "PyYAML>=6.0"]
brille = ["brille>=0.7.0"]
test = ["mock", "pytest~=7.0", "coverage", "pytest-mock", "pytest-lazy-fixture", "pytest-xvfb"]
test = ["mock", "pytest~=7.0", "coverage", "pytest-mock", "pytest-lazy-fixture", "pytest-xvfb", "python-slugify"]
ci = ["tox==4.32.2"]

[project.scripts]
euphonic-brille-convergence = "euphonic.cli.brille_convergence:main"
Expand Down
2 changes: 1 addition & 1 deletion tests_and_analysis/ci_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tox==3.28.0
tox==4.23.2
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def test_with_use_c_false_doesnt_raise_error_or_warn(
fc.calculate_qpoint_phonon_modes(get_test_qpts(), use_c=False)
assert len(warn_record) == 0


@pytest.mark.c_extension
class TestForceConstantsCalculateQPointPhononModesWithCExtensionInstalled:

@pytest.fixture
Expand Down
1 change: 1 addition & 0 deletions tests_and_analysis/test/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ markers =
matplotlib: requires euphonic[matplotlib] extra to be installed
brille: requires euphonic[brille] extra to be installed
multiple_extras: requires any combination of the above extras e.g. phonopy_reader and matplotlib
c_extension: Requires c extension compiled
Loading

0 comments on commit 10c2639

Please sign in to comment.