brechtm / rinohtype

The Python document processor
http://www.mos6581.org/rinohtype
GNU Affero General Public License v3.0
499 stars 59 forks source link

Update noxutil.py #359

Closed mforbes closed 1 year ago

mforbes commented 2 years ago

Add python parameter to get_version() allowing one to limit versions based on the python version.

This allows one to parse multiple requirements like

Sphinx = [
  {version = ">=3.4.2,<6.0.0", python = "<3.9"},
  {version = ">=3.4.2,!=3.5.*,!=4.0.*,!=4.1.*,<6.0.0", python = ">=3.10"}
]
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

codecov[bot] commented 1 year ago

Codecov Report

Merging #359 (d2b4ce8) into master (fa69083) will decrease coverage by 0.02%. The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #359      +/-   ##
==========================================
- Coverage   77.48%   77.46%   -0.03%     
==========================================
  Files          92       92              
  Lines       14633    14633              
  Branches     3274     3274              
==========================================
- Hits        11338    11335       -3     
- Misses       2853     2854       +1     
- Partials      442      444       +2     
Flag Coverage Δ
3.10 77.45% <ø> (-0.02%) :arrow_down:
3.11.0-alpha 46.92% <ø> (-30.13%) :arrow_down:
3.7 45.75% <ø> (-30.84%) :arrow_down:
3.8 46.91% <ø> (-30.08%) :arrow_down:
3.9 46.91% <ø> (ø)
Linux 77.02% <ø> (ø)
Windows 46.90% <ø> (-30.11%) :arrow_down:
macOS 77.43% <ø> (ø)
pypy-3.9 77.02% <ø> (ø)
regression-3.10 75.87% <ø> (-0.02%) :arrow_down:
regression-3.11 ?
regression-3.7 ?
regression-3.8 ?
regression-pypy3 75.42% <ø> (ø)
unit-3.10 46.91% <ø> (ø)
unit-3.11 46.92% <ø> (ø)
unit-3.7 45.75% <ø> (ø)
unit-3.8 46.91% <ø> (ø)
unit-3.9 46.91% <ø> (ø)
unit-pypy3 46.93% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/rinoh/style.py 84.95% <0.00%> (-0.27%) :arrow_down:
src/rinoh/table.py 93.30% <0.00%> (-0.24%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

brechtm commented 1 year ago

Thanks @mforbes!

It's not obvious to me how this can be used. Do you happen to have an example noxfile.py where this is used? I suspect I may be able to use it here: https://github.com/brechtm/rinohtype/blob/5de15f0d6e9247491a7e0b268a3b4a82df5fb975/noxfile.py#L70

brechtm commented 1 year ago

My first test: get_versions('sphinx', 'minor', python='x.y') always returns the same list of Sphinx versions, regardless of x and y.

EDIT: Ah, now I see that the python version corresponds to the python version specified for the dependency in my pyproject.toml.

mforbes commented 1 year ago

Sorry, yes, an example noxfile.py would probably have been useful. I am doing something like this, since there does not seem to be a better way of determining the python version at the time that the decorator is called. It is a bit ugly:

sys.path.append(".")
from noxutils import get_versions

python_versions = ["3.6", "3.7", "3.8", "3.9", "3.10"]
@session(reuse_venv=True)
@nox.parametrize("python,sphinx",
                 sum([[(python, sphinx)
                       for sphinx in get_versions("sphinx", "minor", python=python)]
                      for python in python_versions],
                     []),
                 )
def test(session, sphinx):
    # nox_poetry uses the info in poetry.lock but you need to specify the test
    # dependencies here:
    session.install("sphinx-testing", "pytest-cov", ".")
    # Override sphinx, but using get_versions() makes sure this is consistent
    session.run("pip", "install", f"sphinx=={sphinx}")
    session.run("pytest")

I am a bit confused: your example get_versions('sphinx', 'minor', python='x.y') should work. What was going wrong?

brechtm commented 1 year ago

Thanks! I was able to get closer to get it working once I realized that I needed to set python-version dependent Sphinx requirements in my pyproject.toml (as you suggested in your original comment). I needed to upgrade Poetry because I ran into an issue with it generating an invalid version constraint (I forgot the details, unfortunately), but now I'm running into https://github.com/python-poetry/poetry-plugin-export/issues/118, so I'll first need to fix that before I can start using this.

brechtm commented 1 year ago

Merged. Many thanks for taking the time to make this PR!