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 Python 3 in example #2397

Merged
merged 3 commits into from
Jan 22, 2020
Merged

Use Python 3 in example #2397

merged 3 commits into from
Jan 22, 2020

Conversation

methane
Copy link
Contributor

@methane methane commented Jun 25, 2019

Python 2 will be EOL at 2020-01-01. Please recommend people to use Python 3.

Copy link
Contributor

@BanzaiMan BanzaiMan left a comment

Choose a reason for hiding this comment

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

what is wrong with the current documentation? Our python builds generally use virtualenv to manage the run times, and I believe $HOME/.local/bin is a better choice than /opt/….

@methane
Copy link
Contributor Author

methane commented Jun 26, 2019

what is wrong with the current documentation?

Please read this article: https://dev.to/methane/use-pip3-to-install-awscli-44pk

Our python builds generally use virtualenv to manage the run times,

Note that this is not a Python build. What is the preferred way to use Python 3 & pip on non Python builds?

@BanzaiMan
Copy link
Contributor

We should fix the example if it's broken, but that should be independent of the use of Python 2 or 3.

@takluyver
Copy link
Contributor

A bit more context: projects are looking at package download statistics to evaluate when it's reasonable to drop Python 2 compatibility. But for some use cases - like awscli - you can use either Python 2 or 3, with no visible difference (for now). We'd like to push these use cases to Python 3, so that the statistics show more accurately how many people want/need to run Python 2, rather than using it by default because it's what examples point to.

Unfortunately, there doesn't seem to be any simple way to use Python 3 on a non-Python build without calling pyenv. Python 3 is already present in both the trusty and xenial environments by default, but pip isn't directly usable (pip3 gives a pyenv error because there isn't a Python 3 environment active, python3 -m pip gives "No module named pip").

So maybe the first step is to tweak the build environments to make it easy to use pip on Python 3. Python tools are starting to drop Python 2 support, and I'd expect many more to do so in the next year, so this is a good time to make it easy to use Python 3.

@Pezi777
Copy link
Contributor

Pezi777 commented Jul 9, 2019

Show available Python runtimes #1763 has been open for quite some time. @BanzaiMan Should I close this one as we have this one, too?

@takluyver
Copy link
Contributor

I think that's a separate question - I don't follow it entirely, but it looks like it's about the list of Python versions available which can be specified in a .travis.yml file.

The example in question here involves using Python in a non-Python build, i.e. where you're building software in some other language, and you need some tool which happens to be written in Python.

@@ -11,14 +11,17 @@ This example has 2 build stages:
Here's what the `.travis.yml` config could look like:

```yaml
dist: xenial
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is now optional as xenial is the default distro.

env:
global:
# include $HOME/.local/bin for `aws`
- PATH=$HOME/.local/bin:$PATH

before_install:
# set up awscli packages
- pip install --user awscli
- pyenv global 3.7.1
Copy link
Contributor

@cclauss cclauss Aug 14, 2019

Choose a reason for hiding this comment

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

Why not just put at the top of the script:

language: python
python: 3.7

Or leave out the second line to default to Python 3.6.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the example is meant to work regardless of the language setting, because people may want to use the technique on projects in various languages.

Copy link
Contributor

@cclauss cclauss Aug 14, 2019

Choose a reason for hiding this comment

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

Thanks. Now I understand. Pyenv is superslow so what about this approach which works on Trustry, Xenial, and Bionic?

- python3 -m pip || wget -qO- https://bootstrap.pypa.io/get-pip.py | sudo -H python3
- python3 -m pip install --user awscli
- aws --version  # aws-cli/1.16.217 Python/3.5.2 Linux/4.15.0-1028-gcp botocore/1.12.207

Copy link
Contributor

Choose a reason for hiding this comment

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

No module named pip

I set up a tiny test repository to experiment with what is possible on Travis. I couldn't find any way to use pip on Python 3 without either invoking pyenv or installing pip first - I assume either of those options is unwanted hassle. Feel free to play around and see if there's something I missed, though.

So I think before this example can be changed, it would be necessary to change the default Travis build images, e.g. to include the python3-pip package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, it works if you install pip first. But I'd imagine people won't especially want an extra install-the-installer step given that the example as it stands works without that.

Copy link
Contributor

@cclauss cclauss Aug 14, 2019

Choose a reason for hiding this comment

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

pyenv takes a minute and a half to build Python 3. I'd imagine people won't especially want an extra slow install-a-language-that-I-don't-need-and-is-already-present step...

Also, pip install -U pip is effectively install-the-installer

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, compared to the example as it currently is, using Python 2.

Copy link
Contributor

Choose a reason for hiding this comment

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

I had a go at adding pip-on-Python 3 to the default images, but I don't really know the infrastructure, I just found a likely looking bit of code:

travis-ci/travis-cookbooks#1055

# set up awscli packages
- pip install --user awscli
- pyenv global 3.7.1
- pip install -U pip
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to more explicitly use --upgrade than -U to avoid confusion because pip also has a --user option.

@BanzaiMan
Copy link
Contributor

Has the new example in this PR been tested? If so, please provide a link. I also note that it should be tested under different circumstances (with respect to language, os, etc.).

@methane
Copy link
Contributor Author

methane commented Nov 5, 2019

@cclauss
Copy link
Contributor

cclauss commented Nov 5, 2019

It would be nice if pyenv in Travis was upgraded to allow Python 3.8 to work in this fashion.

@cclauss
Copy link
Contributor

cclauss commented Nov 7, 2019

it should be tested under different circumstances (with respect to language, os, etc.).

.travis.yml in https://github.com/cclauss/Travis-CI-languages-by-operating-system might be a good starting point for exploration.

BanzaiMan added a commit to BanzaiMan/travis_production_test that referenced this pull request Jan 22, 2020
@Pezi777 Pezi777 merged commit 2c4caae into travis-ci:master Jan 22, 2020
gitandhub1 pushed a commit to gitandhub1/docs-travis-ci-com that referenced this pull request Jun 5, 2020
* Use Python 3 in example

* Update share-files-s3.md

Co-authored-by: Petra <[email protected]>
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.

5 participants