fulcrumgenomics / fgpyo

Quality of life improvements for Bioinformatics in Python.
https://fgpyo.readthedocs.io/en/latest/
Other
25 stars 3 forks source link

Use tox so we can test multiple python versions locally #128

Open msto opened 3 months ago

msto commented 3 months ago

GHA does this, but it'd be more convenient if tests and checks could be run without pushing and the overhead of GHA

nh13 commented 3 months ago

The advantage of using GHA to do this is we get multiple concurrent jobs. I don't think that would be the case with tox.

clintval commented 3 months ago

@nh13 tox works well for this and will run multiple GHA jobs as expected:

Here's an example from a personal OSS project:

Screenshot 2024-06-06 at 9 30 27 AM

And the associated pyproject.toml config:

[tool.tox]
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = py312,py311,py310,py39,py38

[gh-actions]
python =
    3.12: py312
    3.11: py311
    3.10: py310
    3.9: py39
    3.8: py38

[testenv]
allowlist_externals = poetry
commands =
  poetry install -v
  poetry run pytest toolkit/ tests/
"""

Tox has a feature request to update their config syntax to proper TOML (instead of ini-style) but at least it's all in the pyproject.toml and not in another dotfile.

clintval commented 3 months ago

What I do locally is use pyenv, a very simple Python version management tool, to install all versions of Python on my local. I think of this as the environment layer between the system Python (which you should not touch) and deeper environments like venvs and conda environments. Of course, depending on your personal preferences, you can get multiple Python versions installed in other ways.

Once I have those Pythons, then I have the option of running poetry run pytest to run the whole test suite with whatever Python version poetry finds as default, or if I have tox installed, simply running tox and then I get parallel testing over all versions of Python. This emulates GHA quite well.