Closed dhaynespls closed 7 years ago
I want to set aside some time to do a live usage test before merging, but this looks good to me otherwise. Thank you for doing this!
Did you find any notable differences or "gotchas" for environment setup in py3 compared to py2? In other words would a new user on py3 need additional/different steps than a py2 user when creating a virtual environment, etc? (besides specifically calling python3 vs python2)
There shouldn't be anything additional that someone would need to do depending on what version of Python they use.
A situation that comes to mind is if in the future someone decides to contribute code that utilizes a Python 3 specific feature such as ipaddress
or asyncio
. In that case, in order to ensure Python 2 users aren't affected, they would need to include a back-ported package as a requirement. Luckily the repo in it's current state uses almost exclusively the Python standard library which is fairly interoperable on py2/3.
I would suggest adding the travis-ci bot to PRs to do this checking as well as noting in documentation that contributions must be backwards compatible.
I've made some changes to get things working on travis-ci, please rebase (or re-merge upstream/master) when you get a chance. Thanks!
Nevermind, I was able to resolve the conflicts through github.
Huh, a pass in 3.6 but fail in 3.5. I'll look a it.
b'<LoginRequest password="nxpassword" user-id="nxadmin"/>' != b'<LoginRequest user-id="nxadmin" password="nxpassword"/>'
You can replicate the issue with:
[~/d/nexpose-client-python]─[⎇ 4-py3-backwards-compat]─> python
Python 2.7.13 (default, Jun 26 2017, 10:20:05)
[GCC 7.1.1 20170622 (Red Hat 7.1.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d = {'x': 1, 'y': 2}
>>> d.items()
[('y', 2), ('x', 1)]
The test assertion may be too strict as the Nexpose API doesn't actually care about the order of the attributes, but that is interesting to see it behave differently on 3.5 specifically!
I think I'm okay with ignoring that failure for now and dealing with it another time.
As for testing, today I started using pyenv and pyenv-virtualenv to install and manage multiple python versions. Give it a try if you don't like waiting on travis-ci runs.
Oh cool I wasn't aware of those tools, I'll have to check them out.
If it's no big deal then I won't worry about it, I was just trying to be thorough and not merge in any huge bugs.
Did some local testing; Even with OrderedDict it's doing odd stuff and only on 3.5 (although I didn't check 3.3 or 3.4). It doesn't happen on every run either.
I think this can be "fixed" from a testing standpoint by setting the PYTHONHASHSEED
environment variable to a static value in travis-ci. Locally it seems to work out that way at least.
You can probably just remove the OrderedDict change and then change .travis.yml
like so:
script:
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then export PYTHONHASHSEED=3140657756; fi
- py.test tests
Re-ran it a few times on travis and it passed on the last try 🙄
passed on the last try
Oh wow that's interesting..
I think the ideal solution should be to:
1) Revert the OrderedDict commit 2) Refactor that test to check for either:
<LoginRequest password="nxpassword" user-id="nxadmin"/>
<LoginRequest user-id="nxadmin" password="nxpassword"/>
Given that the Nexpose API does not care about ordering, just that the attributes are present.
Worst case then fall back to:
script:
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then export PYTHONHASHSEED=3140657756; fi
- py.test tests
Should be good now.
pyenv
was a lifesaver there thanks for the share.
Description
Given the fact that Python 2 will be EOL as of 2020, it is a good idea to move development of new libraries to Python 3. Ensuring backwards compatibility with Python 2 is essential however since there are a number of developers who are in a situation where they do not have control over the environment and also to ensure that the Python 3 port won't break existing installs. This PR migrates the library to a state where it can be run 100% on Python 3 & 2.
Motivation and Context
See above.
How Has This Been Tested?
By running unit testing in both environments:
Python 2
Python 3
Screenshots (if appropriate):
See above.
Types of changes
Checklist:
Closes #4