-
Notifications
You must be signed in to change notification settings - Fork 301
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
Simple install tests on Travis CI #23
Conversation
.travis.yml
Outdated
language: python | ||
|
||
python: | ||
- "3.7-dev" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't really need quotes or tab here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a problem with 3.7-dev, nor with any of the current Python versions (will there be a Python 3.10?), but it's good practice because:
In YAML, - 7.10 would evaluate to version 7.1, and not 7.10. ...
In YAML, 7.8 is a float, "7.8" is a string. Software version numbers should be strings, not floats.
travis-ci/docs-travis-ci-com#1537
But happy to remove them, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's just my personal preference, because it looks cleaner. And I use it this way everywhere, so I can tell you that it doesn't cause problems in my experience.
curl-install.sh
Outdated
#!/usr/bin/env bash | ||
|
||
# Exit on error, run verbose | ||
set -ev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about adding -uo pipefail
?
local-install.sh
Outdated
# Run from a script to make sure Travis CI handles failures properly: | ||
# http://steven.casagrande.io/articles/travis-ci-and-if-statements/ | ||
|
||
if [ $TRAVIS_PYTHON_VERSION == 2.6 ]; then python 2.6/get-pip.py; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, these two scripts could be turned into one: they are 90% copy-paste with just one variable thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can have a function which either cat
s script or wget
s it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smth like helpers.sh
:
function cat_get_pip() {
local version="$1"
local path="get-pip.py"
[[ -n "$version" ]] && path="$version/$path"
local src="$2"
local cmd=cat
if [[ "$src" == "remote" ]]
then
path="https://bootstrap.pypa.io/$path"
cmd='wget -O - '
elif [[ "$src" != "local" ]]
>&2 echo Wrong source argument: $src
exit 1
fi
$cmd $path
}
and then have:
before_script:
- source helpers.sh
script:
- cat_get_pip "$TRAVIS_PYTHON_VERSION" "$SCRIPT_SRC" | python -
matrix:
global:
- SCRIPT_SRC=local
- SCRIPT_SRC=remote
curl-install.sh
Outdated
# Run from a script to make sure Travis CI handles failures properly: | ||
# http://steven.casagrande.io/articles/travis-ci-and-if-statements/ | ||
|
||
if [ $TRAVIS_PYTHON_VERSION == 2.6 ]; then curl https://bootstrap.pypa.io/2.6/get-pip.py | python; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell scripts don't require semi-colons in the the end of lines: \n
is already a separator itself.
curl-install.sh
Outdated
@@ -0,0 +1,15 @@ | |||
#!/usr/bin/env bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nipick: I'd prefer having space after #!
for the sake of readability.
.travis.yml
Outdated
|
||
script: | ||
# Simple test runs | ||
- ./local-install.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local/remote could be put into env var and then reused in matrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to mix these things in a single job. Having them separate helps understand what fails better and faster.
.travis.yml
Outdated
- ./curl-install.sh | ||
|
||
after_script: | ||
# Static analysis: for info, won't fail the build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, maybe it should fail the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's just a few linting errors, so why don't we get rid of them and make sure they won't happen to be repeated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good effort @hugovk, I like it!
Another thing, I'd like to add (maybe in subsequent PR) is automating deployment (how does it get to bootstrap.pypa.io? this could be even hosted on GitHub Pages) and automating bundling of pip zip blob to the end of the scripts.
.travis.yml
Outdated
- pip install pyflakes pycodestyle | ||
- pyflakes . | ||
- pycodestyle --statistics --count . | ||
- flake8 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You known that flake8 uses pyflakes with a bit permissive config, right?
Oh, and how about using black
?
Also idea: there's a nice project pre-commit.com, which enables users to have local hook in git as well as repeat that in CI. It supports running all linters above (and more) and I can help configuring it if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched to flake8 because pyflakes doesn't respect the # noqa
comments. But now flake8 doesn't install for all Python versions. But we don't need to run it on all, just a recent one. Will update.
Black could be good too, but I'd probably wait until it's at least in beta, as things are still changing there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add extra allowed to fail job for black
@hugovk it looks like this got folder, so copying it here: Smth like function cat_get_pip() {
local version="$1"
local path="get-pip.py"
[[ -n "$version" ]] && path="$version/$path"
local src="$2"
local cmd=cat
if [[ "$src" == "remote" ]]
then
path="https://bootstrap.pypa.io/$path"
cmd='wget -O - '
elif [[ "$src" != "local" ]]
>&2 echo Wrong source argument: $src
exit 1
fi
$cmd $path
} and then have: before_script:
- source helpers.sh
script:
- cat_get_pip "$TRAVIS_PYTHON_VERSION" "$SCRIPT_SRC" | python -
matrix:
global:
- SCRIPT_SRC=local
- SCRIPT_SRC=remote |
.travis.yml
Outdated
- source helpers.sh | ||
|
||
install: | ||
- if [ $TRAVIS_PYTHON_VERSION == 3.6 ]; then pip install flake8; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use matrix.include
or jobs.include
instead.
@hugovk ^^ I've fixed a few bugs in my PR above, it's now ready to be merged-in to your branch. |
As for real tests (future PR to not block this initial one), it's possible to use bats test framework https://github.com/sstephenson/bats |
hugovk#1 is merged into this, thanks! |
Hello @dstufft, This requires your attention. I suggest that you merge this right away and then we'd have some follow-up PRs improving things. (unless there's smth critical you want to fix in this one). |
requirements.txt
Outdated
@@ -1,2 +1,3 @@ | |||
invoke | |||
packaging | |||
pre-commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel all the pre-commit hooks should be moved to a separate PR; it'll make things easier to review. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I can do this.
.travis.yml
Outdated
- "2.6" | ||
|
||
.helpers: | ||
- &reset_steps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not use YAML magic and have a verbose .travis.yml instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not magic, lot's of people use it and it really helps to not get lost in copy-pasted things, thus I'm very opinionated about this.
Thanks for this @hugovk! :) It'd be nice if the pre-commit hooks (and related cleanups) would be moved to another PR and only the CI check for basic installation is kept in this PR. It'll be easier to review both those PRs then. |
Hi @webknjaz, do you think you'd be able to split this up? Perhaps two new PRs starting from this branch, or whatever's easiest. Thank you! |
I think, it might be better to accept pre-commit change first and go for travis stuff then. |
@hugovk It turned out I've already put everything in a single commit :) |
@pradyunsg do you want me to cherry-pick linter fixes to #28 also? |
Sure! |
done |
@hugovk would you mind to rip off linting-related commits from this branch, so that it would be easier for @pradyunsg to accept it faster? |
@hugovk I believe linter fixes should also go away |
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
Rebased on master (and removed the last two unnecessary revert and regenerate commits). |
#31 is more like what I had in mind for a test suite (I've still to add Travis and Appveyor config for it). |
It looks interesting. I'll review it more closely later today. But maybe we could accept this PR and then add yours on top of it or vice versa? |
|
||
env: | ||
- SCRIPT_SRC=local | ||
- SCRIPT_SRC=remote |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not at all sure that we should be testing "remote" here. The tests should be testing what's in the repository - for example, the test runs for a PR shouldn't fail because the published version was broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move tests for remote to run only when triggered manually (or via API) and not PR. Deal? I don't want to completely eliminate them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I care much, TBH. As noted, I'm against this approach (of using a shell script) anyway.
fi | ||
|
||
>&2 echo Version $1 requires following script: $path | ||
$cmd $path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you testing an install into an environment that currently doesn't have pip installed? I can't tell (but I don't think you are)... Someone who has pip installed can simply do python -m pip install -U pip
. (Sure, we have to support that case, but the key use case is someone trying to bootstrap pip into an empty environment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, pip is uninstalled at the start: https://github.com/hugovk/get-pip/blob/c7bbeb9da01074f9f5b1ec0fedd1273aee8460dc/.travis.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for the pointer.
See #18 (comment) for more detailed comments. I personally don't think the changes here are the right way to go. |
Something to get started with for #18.
Example output: https://travis-ci.org/hugovk/get-pip/builds/367577764