Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use packaging/pkg_resources to check minversion #4379

Merged

Conversation

hoylemd
Copy link
Contributor

@hoylemd hoylemd commented Nov 12, 2018

Checklist:

  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.
  • Target the master branch for bug fixes, documentation updates and trivial changes.
  • Target the features branch for new features and removals/deprecations.
  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Add yourself to AUTHORS in alphabetical order;

Fix #4315

Tasks from The issue:

  • use packaging or pkg_ressources
  • add a acceptance-test

I couldn't figure out the best way to add an acceptance test, but I found that testing/test_config.py::TestParseIni.test_tox_ini_wrong_version was already checking the behaviour. I tried to add a 'right version' test by copying that one and changing the minver in the generated ini to 3.0, but whenever I ran it I'd be getting errors about reading from stdin. I couldn't figure out what was causing the errors, so I just moved on.

note: I tested this with python 3.7, not 3.6 - it was pretty easy to get that to work. Easier than setting 3.6 up in my dev environment at least. I assume CI will do 3.6, so we'll still have all the coverage and I don't anticipate any issues cropping up.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @hoylemd!

@codecov
Copy link

codecov bot commented Nov 12, 2018

Codecov Report

Merging #4379 into master will increase coverage by 0.6%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #4379     +/-   ##
=========================================
+ Coverage   95.88%   96.48%   +0.6%     
=========================================
  Files         111      111             
  Lines       25008    28297   +3289     
  Branches     2438     2917    +479     
=========================================
+ Hits        23979    27303   +3324     
+ Misses        725      706     -19     
+ Partials      304      288     -16
Flag Coverage Δ
#docs 30% <50%> (-0.09%) ⬇️
#doctesting 30% <50%> (-0.09%) ⬇️
#linting 30% <50%> (-0.09%) ⬇️
#linux 96.32% <100%> (+0.6%) ⬆️
#nobyte 93.3% <100%> (+0.65%) ⬆️
#numpy 94.06% <100%> (+0.63%) ⬆️
#pexpect 41.43% <50%> (-0.45%) ⬇️
#py27 94.67% <100%> (+0.66%) ⬆️
#py34 92.92% <100%> (+0.82%) ⬆️
#py35 92.95% <100%> (+0.83%) ⬆️
#py36 92.97% <100%> (+0.82%) ⬆️
#py37 94.84% <100%> (+0.75%) ⬆️
#trial 94.06% <100%> (+0.63%) ⬆️
#windows 94.78% <100%> (+0.67%) ⬆️
#xdist 94.72% <100%> (+0.75%) ⬆️
Impacted Files Coverage Δ
src/_pytest/config/__init__.py 95.41% <100%> (+0.4%) ⬆️
src/_pytest/capture.py 93.42% <0%> (-0.46%) ⬇️
testing/test_nose.py 98.55% <0%> (-0.38%) ⬇️
testing/test_runner_xunit.py 100% <0%> (ø) ⬆️
testing/deprecated_test.py 100% <0%> (ø) ⬆️
testing/test_stepwise.py 100% <0%> (ø) ⬆️
src/_pytest/python.py 95.3% <0%> (+0.02%) ⬆️
testing/test_collection.py 99.83% <0%> (+0.03%) ⬆️
testing/test_cacheprovider.py 99.79% <0%> (+0.08%) ⬆️
testing/test_config.py 99.58% <0%> (+0.15%) ⬆️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a281d66...1568e38. Read the comment docs.

@blueyed
Copy link
Contributor

blueyed commented Nov 12, 2018

Note that "packaging" was used for pytest-sugar: https://github.com/Frozenball/pytest-sugar/pull/160/files#diff-5205b06d924f1150750e0cc9f8326313R17
No idea what's better, @RonnyPfannschmidt ?

@asottile
Copy link
Member

what's the rationale for switching at all -- distutils.version is standard library (zero dependencies)

@blueyed
Copy link
Contributor

blueyed commented Nov 13, 2018

Just for reference: Teemu/pytest-sugar#160 (comment)
/cc @jaraco

@jaraco
Copy link
Contributor

jaraco commented Nov 13, 2018

Packaging is preferable here. pkg_resources only wraps packaging (and incidentally has to vendor it).

distutils.version is standard library (zero dependencies)

Also, distutils is deprecated. I'd recommend not importing it at all if possible.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per #4379 (comment), please use packaging instead. 👍

@asottile
Copy link
Member

I understand that packaging is the future but I don't think that's enough reason to not use distutils.version. I understand distutils "the packaging components" are being replaced by setuptools / packaging / etc. Sure it doesn't support all of the versioning specs of the equivalent packaging Version, but pytest doesn't use those flavors of version either. I think we should consider the trade off on introducing another dependency

@hoylemd
Copy link
Contributor Author

hoylemd commented Nov 13, 2018

I tried to change it to use packaging, by adding `"packaging >=18.0",' to setup.py's INSTALL_REQUIRES, but when I run tox with

tox -e py37 -- testing/test_config.py

it fails with ModuleNotFoundError: No module named 'packaging'. Is there a second place I have to add it?

(note, I used py37 because I'm using python 3.7 in my dev environment)

@nicoddemus
Copy link
Member

I think we should consider the trade off on introducing another dependency

Oh I was under the impression we already depended on packaging.

If that's not the case I agree with @asottile's view that it doesn't seem worthwhile just because a very small bit of functionality like parse version, but on the other hand I'm not a PyPA expert like @jaraco and @RonnyPfannschmidt, so I will defer that decision to them if they know it is the right one.

@asottile
Copy link
Member

@hoylemd when changing dependencies you'll probably need -r (recreate) when invoking tox

@hoylemd
Copy link
Contributor Author

hoylemd commented Nov 13, 2018

@asottile thanks! that got it.

Pushed up a commit using packaging. If y'all decide you'd prefer pkg_resources, I'll just drop the commit.

@hoylemd hoylemd changed the title Use pkg_resources to check minversion Use packaging/pkg_resources to check minversion Nov 13, 2018
Copy link
Contributor

@blueyed blueyed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the bike-shedding.

I think we should leave the check as-is (i.e. do not apply anything from this PR).

From #4315 the only issue left would be to have a test for this.

I'll close this for now, please do not hesitate from commenting/re-opening.

@blueyed blueyed closed this Nov 18, 2018
@jaraco
Copy link
Contributor

jaraco commented Nov 18, 2018

I understand distutils "the packaging components" are being replaced by setuptools / packaging / etc.

I'd go further to say that use of distutils is generally discouraged if not yet formally deprecated, even modules and functionality that's not specifically related to packaging (like the shell/filesystem utilities). It will likely be years before distutils is actually deprecated, but it would be helpful if packages like pytest and efforts like the one proposed could be accepted as a gesture and example of best practices. I don't feel strongly about it.

@blueyed
Copy link
Contributor

blueyed commented Nov 18, 2018

@jaraco
Thanks for the additional input.

As for pytest this is really only about getting its own version parsing more straight (it failed with 4.10 after all).

We'll pretty sure adjust to any DeprecationWarning etc, but installing another package just for this feels overbloated currently to me.

I don't feel strongly about it.

Me neither.

@RonnyPfannschmidt
Copy link
Member

im just revisiting this pr as im taking a closer look and i am quite saddened by the history of this one - we should as soon as possible and as quickly as possible remove the need for distutils

as long as we require pkg_resources internally anyway, its the perfect source for a sound non-distutils version parser that adds no extra dependency - i would like to merge the original pr as it was

@blueyed
Copy link
Contributor

blueyed commented Nov 18, 2018

Ok.

@hoylemd
Please remove the 7ae5681 commit then, squash it into a single commit and force-push here.

Let me know if I should do it.

@blueyed blueyed reopened this Nov 18, 2018
@RonnyPfannschmidt RonnyPfannschmidt changed the title Use packaging/pkg_resources to check minversion WIP: Use packaging/pkg_resources to check minversion Nov 18, 2018
@RonnyPfannschmidt
Copy link
Member

marked as wip to prevent accidents

Use pkg_resources.parse_version in minver check

Add meself to AUTHORS & changelog

Format CHANGELOG
@hoylemd hoylemd force-pushed the improve_minversion_again branch from 00c6242 to 1568e38 Compare November 19, 2018 16:26
@hoylemd
Copy link
Contributor Author

hoylemd commented Nov 19, 2018

@blueyed Done!

@RonnyPfannschmidt RonnyPfannschmidt changed the title WIP: Use packaging/pkg_resources to check minversion Use packaging/pkg_resources to check minversion Nov 19, 2018
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the followup well done at bringing it back to the original state

@RonnyPfannschmidt RonnyPfannschmidt merged commit 45c33c4 into pytest-dev:master Nov 19, 2018
@hoylemd hoylemd deleted the improve_minversion_again branch November 20, 2018 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enhance minversion check further
6 participants