Wrong Python version invoked when using `alias`

My build config is like this:

language: python

dist: bionic

  - linux

  - "2.7"
  - "3.5"
  - "3.6"
  - "3.7"
  - "3.8"
  - "3.8-dev"
  - "nightly"
  - "pypy3"

    - name: "Python 3.7 on macOS"
      os: osx
      osx_image: xcode11.2
      language: shell
        - alias python='python3'
    - python: "3.8-dev"
    - python: "nightly"

  # Upgrade pip
  - python -m pip install --upgrade pip

  - python --version
  - python setup.py install
  - python setup.py test

As you can see, I have a project and it is tested with pytest. Everything goes well until my osx build. (The build didn’t even fail on the Python2.7 Bionic Ubuntu environment.)

The special configuration of osx is pasted and modified from the documentation. But python failed to install my pytest framework on the python setup.py install sentence.

The error goes like:

Searching for pytest
Reading https://pypi.org/simple/pytest/
Downloading https://files.pythonhosted.org/packages/d4/d1/61dbeb5e6d6a694c4d024043ad67a01ba236c54d253558b3019b6fac2c68/pytest-6.1.0.tar.gz#sha256=d010e24666435b39a4cf48740b039885642b6c273a3f77be3e7e03554d2806b7
Best match: pytest 6.1.0
Processing pytest-6.1.0.tar.gz
Writing /var/folders/17/5mc7816d3mndxjqgplq6057w0000gn/T/easy_install-jhPaOa/pytest-6.1.0/setup.cfg
Running pytest-6.1.0/setup.py -q bdist_egg --dist-dir /var/folders/17/5mc7816d3mndxjqgplq6057w0000gn/T/easy_install-jhPaOa/pytest-6.1.0/egg-dist-tmp-4xoTGJ
  File "build/bdist.macosx-10.14-x86_64/egg/pytest/collect.py", line 24
    def __init__(self) -> None:
SyntaxError: invalid syntax

PS: The dependencies are declared in setuptools.setup(tests_require=[...]).
PS2: The python --version shows that python2 is still actually executed.

As you can see, the problem is your alias has no effect for some reason. I’d need to see the build to understand why exactly, but why not do smth like this instead?

  - python3 -m pip install virtualenv
  - python3 -m virtualenv v
  - source v/bin/activate

This will make python point to virtualenv like in Linux with language: python.

@native-api It errored again:

$ python3 -m virtualenv v
/usr/local/opt/python/bin/python3.7: No module named virtualenv
The command "python3 -m virtualenv v" failed and exited with 1 during .

Maybe I should try tox.

PS: raw log.

Then you need to install it first. I thought it was preinstalled.

This is creepy. Your (@native-api ) PR does not work.
And this is more creepy: https://travis-ci.com/github/proj-cfpm/cfpm/jobs/394532440.

No idea what you are talking about with “PR”. I forked your repo to see why alias has no effect.

Mistake. Sorry.
Actually, this configuration works: https://travis-ci.com/github/proj-cfpm/cfpm/jobs/394777541.

But I still wonder why alias doesn’t work.

1 Like

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt