Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

asottile
Copy link
Contributor

The ipaddress module became a standard module in python3.3.

This uses environment markers to only select the ipaddress module
in python2.7. In setuptools, the most compatible way to accomplish this is
through the extras_require field (as suggested in the wheel docs).

The ipaddress module became a standard module in python3.3.

This uses [environment markers][pep508] to only select the `ipaddress` module
in python2.7.  In setuptools, the most compatible way to accomplish this is
through the `extras_require` field (as suggested in the [wheel][wheel] docs).

[pep508]: https://www.python.org/dev/peps/pep-0508/#id23
[wheel]: https://wheel.readthedocs.io/en/latest/#defining-conditional-dependencies
@asottile
Copy link
Contributor Author

CC @yliaog @roycaihw -- would love a review :)

@yliaog yliaog self-assigned this Apr 13, 2018
@yliaog
Copy link
Contributor

yliaog commented Apr 13, 2018

could you please write a test case for it?

@asottile
Copy link
Contributor Author

I'm not sure how I would test this, it's really only a quality of the installation itself -- generally setup.py isn't really testable (either it installs or it doesn't!). tox covers this behaviour (it invokes the installation).

I've noted in travis-ci that the python2.7 is still installing ipaddress and the py35 / py36 installs are not -- meaning it works as intended.

if ';' in line:
requirement, _, specifier = line.partition(';')
for_specifier = EXTRAS.setdefault(':{}'.format(specifier), [])
for_specifier.append(requirement)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the purpose of "for_specifier.append(requirement)" but for_specifier is not kept anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for_specifier is the list inside EXTRAS[f":{spec}"] -- I'd use collections.defaultdict(list) here but setuptools requires specific types here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The trick here is setdefault

@yliaog
Copy link
Contributor

yliaog commented Apr 13, 2018

would you be able to add a line in test-requirements.txt to test it?

@asottile
Copy link
Contributor Author

would you be able to add a line in test-requirements.txt to test it?

the setup.py is invoked by tox already, so no need to add anything here

@yliaog
Copy link
Contributor

yliaog commented Apr 13, 2018

i think it's possible to write a test case to check which python version is run, and if python version is 2.7, then check if ipaddress module is installed, and also where it is installed, etc.

But i agree manually checking that it works is probably good enough.

@asottile
Copy link
Contributor Author

Presumably the tests would crash on an ImportError for ipaddress if it weren't being installed. I think that's covered :)

@yliaog yliaog merged commit e057f27 into kubernetes-client:master Apr 13, 2018
@asottile asottile deleted the only_ipaddress_python_2 branch April 14, 2018 00:58
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.

2 participants