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

Simple install tests on Travis CI #23

Closed
wants to merge 25 commits into from
Closed

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Apr 17, 2018

Something to get started with for #18.

Example output: https://travis-ci.org/hugovk/get-pip/builds/367577764

.travis.yml Outdated
language: python

python:
- "3.7-dev"
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member

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 cats script or wgets it

Copy link
Member

@webknjaz webknjaz Apr 18, 2018

Choose a reason for hiding this comment

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

@hugovk

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;
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

@webknjaz webknjaz left a 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 .
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

@webknjaz
Copy link
Member

@hugovk it looks like this got folder, so copying it here:

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

.travis.yml Outdated
- source helpers.sh

install:
- if [ $TRAVIS_PYTHON_VERSION == 3.6 ]; then pip install flake8; fi
Copy link
Member

@webknjaz webknjaz Apr 18, 2018

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.

@webknjaz
Copy link
Member

@hugovk I've sent you a few patches via hugovk#1

@webknjaz
Copy link
Member

@hugovk ^^ I've fixed a few bugs in my PR above, it's now ready to be merged-in to your branch.

@webknjaz
Copy link
Member

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
Copy link
Contributor Author

hugovk commented Apr 18, 2018

hugovk#1 is merged into this, thanks!

@webknjaz
Copy link
Member

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
Copy link
Member

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. :)

Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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.

@pradyunsg
Copy link
Member

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.

@hugovk
Copy link
Contributor Author

hugovk commented Apr 20, 2018

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!

@webknjaz
Copy link
Member

webknjaz commented Apr 20, 2018

I think, it might be better to accept pre-commit change first and go for travis stuff then.

@webknjaz
Copy link
Member

@hugovk It turned out I've already put everything in a single commit :)

@webknjaz
Copy link
Member

@pradyunsg do you want me to cherry-pick linter fixes to #28 also?

@pradyunsg
Copy link
Member

@pradyunsg do you want me to cherry-pick linter fixes to #28 also?

Sure!

@webknjaz
Copy link
Member

done

@webknjaz
Copy link
Member

@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?

@webknjaz
Copy link
Member

@hugovk I believe linter fixes should also go away

@hugovk
Copy link
Contributor Author

hugovk commented Apr 24, 2018

Rebased on master (and removed the last two unnecessary revert and regenerate commits).

@pfmoore
Copy link
Member

pfmoore commented Apr 24, 2018

#31 is more like what I had in mind for a test suite (I've still to add Travis and Appveyor config for it).

@webknjaz
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

@pfmoore
Copy link
Member

pfmoore commented Apr 24, 2018

See #18 (comment) for more detailed comments. I personally don't think the changes here are the right way to go.

@hugovk hugovk closed this Aug 9, 2019
@hugovk hugovk deleted the travis-ci branch August 9, 2019 08:12
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.

None yet

4 participants