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 Tox for easily testing with multiple Python interpreters #372

Closed
wants to merge 3 commits into from

Conversation

undu
Copy link

@undu undu commented Feb 15, 2019

Tox makes it very easy to test packages in customized virtual environments.

I thought it would be useful to be able to test the package in preparation for python 3 compatibility: #78

Right now there are 2 tests failing: one fails because some url parameters are out of order and the other one I need to investigate further, seems like the environment cannot access cdrdao

Let me know if you like this approach so I can continue working on this. In the end if the developers don't use it, there's not much point in doing this.

@welcome
Copy link

welcome bot commented Feb 15, 2019

💖 Thanks for opening your first pull request here! 💖

@JoeLametta JoeLametta changed the base branch from master to develop February 16, 2019 11:17
@JoeLametta JoeLametta requested a review from Freso February 16, 2019 11:32
@JoeLametta
Copy link
Collaborator

I've changed the base branch of this pull request from master to develop (all pull requests should target that branch). Right now whipper in develop is broken: #369. We're working to fix that...

I thought it would be useful to be able to test the package in preparation for python 3 compatibility: #78

Keep in mind that after we've completed the port to Python 3, we'll end supporting Python 2. Right now whipper is unusable under Python 3. So, at the end, this would be used only to test whipper under different Python 3 versions.

Let's hear what's the opinion of @Freso about this one.

undu added 3 commits February 16, 2019 12:07
 now the minimum version is the same one as the one used in travis
Signed-off-by: Pau Ruiz i Safont <unduthegun@gmail.com>
Copy link
Member

@Freso Freso left a comment

Choose a reason for hiding this comment

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

Overall, I like the idea of using tox (or something else) to help with testing. Thanks for your work on this!

One thing I find lacking is explanations for your choices in what you've done. Other than a commit title, your commits have no additional information. Feel free to write short stories in them so it's possible to tell in 5 years what you were thinking as you made the changes. Most of my comments on/questions to the actual code changes below should have been/be answered by consulting the relevant commit message.

You should also really split up your commits more, please. E.g., 1f85298 both moves requirements.txt's information into setup.py, as expected from its title: "Incorporate dependencies in setup.py"—but it also does a number of changes to .travis.yml and seemingly unrelated changes to README.md (also some obviously related changes, those are fine). This one commit should like be at least 2 separate commits.

Also, c58630e is an empty commit(?) and 84f1077 needs to get signed-off.

(I hope this doesn't scare you off! 🙈)

@@ -1,30 +1,31 @@
dist: xenial
Copy link
Member

Choose a reason for hiding this comment

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

Why? Up until now we've generally tried to support as old versions of things as possible, and I didn't see a change in that mentioned anywhere, so switching to a newer distro version should probably be explained/argued for in more detail.

Copy link
Author

Choose a reason for hiding this comment

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

I updated to Xenial because the version of gobject-introspection packed in Trusty was incompatible with the version of PyGObject that pip pulls with the current restrictions.

I could make it go back to manually install the os-packaged versions, but then we lose the poer of having a single source for dependency definition. I could look into how to define versions of libraries to install depending on a library version in the OS.

Since that is not trivial I preferred to update from trusty to xenial, as trusty is going out of support on April. I also didn't occur to me this was also testing the package in a specifically old version on purpose, I though it was only used to run the unit tests. Making the tests to pass more important than the environment this happened on.

'PyGObject',
'requests']
TEST_DEPS = ['Twisted']
LINT_DEPS = ['flake8']
Copy link
Member

Choose a reason for hiding this comment

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

What's the point of putting these in "constants" like this rather than just adding them directly to the _requires? It puts the data further away from where it's used, and AFAICT it's not needed for reuse anywhere else either.

Copy link
Author

Choose a reason for hiding this comment

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

I think it's a tradeoff of locality against structural clarity. More complex rules of versions can be added later on, and it seem they might be needed in some cases. n the end it's a matter of preference.

mutagen
pycdio>0.20
PyGObject
requests
Copy link
Member

Choose a reason for hiding this comment

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

It might be an idea to replace the with a single line -e .? See https://caremad.io/posts/2013/07/setup-vs-requirement/ for some thoughts.

Copy link
Author

Choose a reason for hiding this comment

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

That would be good for not breaking compatibility with existing users. I do not like the idea of keeping a requirements.txt that is not used for doing a deployment with a particular version of each dependency.

In the article "application" refers to a web-app, where the environment can be controlled and the versions of the dependencies can be frozen. For terminal applications this might not be the case since users might end up having an environment where several applications share dependencies.

Progress is happening in the tooling to avoid using shared environments (pipx) but this is not true for most users.

I'll change it to -e . unless you tell me otherwise


`pip install -r requirements.txt`
`python2 -m pip install -e .`
Copy link
Member

Choose a reason for hiding this comment

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

Why the -m invocation instead of calling pip directly?

Copy link
Author

Choose a reason for hiding this comment

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

sometime pip is not on the user's path, or it might be python3's pip.

This means that novice users cipypasting the instruction will have a lesser chance of encountering situations where things subtly break, at least in my opinion. (I can change if you want me to)

script:
- if [ ! "$FLAKE8" = true ]; then python -m unittest discover; fi
- if [ "$FLAKE8" = true ]; then flake8 --benchmark --statistics; fi
script: tox
Copy link
Member

Choose a reason for hiding this comment

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

This approach fails to take advantage of Travis' parallel building and that the whole of the test will either fail or pass, rather than (currently) code style check and unit tests pass or fail independently of each other.

Copy link
Author

Choose a reason for hiding this comment

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

I agree. I don't think that linting takes so much time that the shaving of time is substantial, it saves resources too as the installation of dependencies only happens once.

In any case, once testing for several python interpreters is enabled in this file these will happen on parallel.

I can look on how to run linting and unittesting in parallel


```bash
python2 -m whipper -h
python2 -m pip install --user -e .
Copy link
Member

Choose a reason for hiding this comment

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

You're changing the meaning and purpose of this section. Is this intentional? Also, you're not installing whipper here (as the description preceding the command claims), only its dependencies.

Copy link
Author

Choose a reason for hiding this comment

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

It's intentional, with the changes centered on building whipper as a package it makes sense to try to use it as much as possible to depend more on the dependencies being installed by pip.

The command does install the package on live mode. This means that any change in the code is instantly picked up as part of the package. This is done through symlinks, instead of the usual copying of files that happens when installing files.

This is something that would not be used in the long run, as tox would replace this workflow: it can be change to run a specific test with a specific python interpreter. I would need to check how tests are organized to make this happen, though.

- sudo make install
- cd ..
- popd
#
Copy link
Member

Choose a reason for hiding this comment

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

?

Suggested change
#

Copy link
Author

Choose a reason for hiding this comment

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

I don't know why it was added either

envlist =
py{27,34,35,36,37,py,py3}-unit,
py{27,34,35,36,37,py,py3}-lint,
skip_missing_interpreters = True
Copy link
Member

Choose a reason for hiding this comment

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

We're not supporting Python 3 (yet) or PyPy (yet?), so there's no reason to run or care for tests for those. Wouldn't it be better to just not list them rather than ignore them if non-existent?

Copy link
Author

Choose a reason for hiding this comment

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

On travis this are not run because only the environment is set up for python 2.7.

For local dev the tests never get tun on pypy nor py3 because the package is dfefined as a python 2.7 only package.

I'll remove the line, I don't think it hurts knowing this will be useful for the porting effort.

- cd ..

# Installing
- sudo python setup.py install
Copy link
Member

Choose a reason for hiding this comment

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

We probably still want to test whether installing works at all. We don't have a lot of functionality tests as it is (do we have any?), only unit tests, and this seems like a fairly basic one to have…

Copy link
Author

Choose a reason for hiding this comment

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

This command is run by tox as part of the process it uses to run commands.

It generate a source distribution of the package, a virtual environment and then installs the package onto the virtual environment.

Excerpt from a tox command:

$ tox -e py27-lint
GLOB sdist-make: /home/pau/code/tui/whipper/setup.py
py27-lint create: /home/pau/code/tui/whipper/.tox/py27-lint
py27-lint inst: /home/pau/code/tui/whipper/.tox/.tmp/package/1/whipper-0.7.4.dev50+gcb3515c.zip
py27-lint installed: DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.,certifi==2018.11.29,chardet==3.0.4,configparser==3.7.1,entrypoints==0.3,enum34==1.1.6,flake8==3.7.5,functools32==3.2.3.post2,idna==2.8,mccabe==0.6.1,musicbrainzngs==0.6,mutagen==1.42.0,pycairo==1.18.0,pycdio==2.0.0,pycodestyle==2.5.0,pyflakes==2.1.0,PyGObject==3.30.4,requests==2.21.0,typing==3.6.6,urllib3==1.24.1,whipper==0.7.4.dev50+gcb3515c

@JoeLametta
Copy link
Collaborator

Is this pull request still alive and relevant (#411)?

@JoeLametta
Copy link
Collaborator

@Freso I suppose this pull request can now be closed, am I right? (because of #433)

@Freso
Copy link
Member

Freso commented Dec 15, 2019

Not really. #433 didn’t do what this PR set out to do (namely, use tox for testing), it just expanded the Python versions being tested on.

As for whether it’s still “alive and relevant"… 🤷‍♂️

I think moving to tox would be a good thing, but this PR does seem particularly stale, so I’d be happy to close this. If @undu wants to return to this, it can be reopened or a new PR can be made.

@JoeLametta
Copy link
Collaborator

@undu Thanks for the pull request, as it seems to be stale I'm closing it. If I'm wrong feel free to reopen it or to submit a new one.

@JoeLametta JoeLametta closed this Dec 17, 2019
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.

3 participants