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

Upgrade pip/setuptools in venv to versions from base environment #740

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,23 @@ def build_venv(cls, path):

build(path)

# make sure pip and setuptools are on the same version as the base environment
from pip import __version__ as pip_version
from setuptools import __version__ as setuptools_version

the_venv = VirtualEnv(Path(path))
the_venv.run(
"python", "-m", "pip", "install", "--upgrade", "pip=={}".format(pip_version)
)
the_venv.run(
"python",
Copy link
Contributor

@brycedrennan brycedrennan Aug 21, 2019

Choose a reason for hiding this comment

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

This would mean that the creation of new environments would require internet access. I think we need to either

  • solve this in the ensurepip library in a way that works without internet or
  • have this be hidden behind a command line flag /setting.

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. I'll check what can be done. Since we are trying to update to the version available in the base environment there should be some way to get along w/o internet connection.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it seems like there should be a way but the discussion on the python bug tracker seems to think its trickier than it sounds. I hope you find a way though! I wonder if you should be making a pull request into ensurepip instead though.

https://bugs.python.org/issue30628

"-m",
"pip",
"install",
"--upgrade",
"setuptools=={}".format(setuptools_version),
)

@classmethod
def get_base_prefix(cls): # type: () -> Path
if hasattr(sys, "real_prefix"):
Expand Down
50 changes: 25 additions & 25 deletions tests/fixtures/simple_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[tool.poetry]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
license = "MIT"

readme = "README.rst"

homepage = "https://poetry.eustace.io"
repository = "https://github.com/sdispater/poetry"
documentation = "https://poetry.eustace.io/docs"

keywords = ["packaging", "dependency", "poetry"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry]
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats changing in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There should not be any changes, looks like somehow Windows line endings slipped in. I'll revert this.

name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
license = "MIT"
readme = "README.rst"
homepage = "https://poetry.eustace.io"
repository = "https://github.com/sdispater/poetry"
documentation = "https://poetry.eustace.io/docs"
keywords = ["packaging", "dependency", "poetry"]
classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]
# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
42 changes: 41 additions & 1 deletion tests/utils/test_env.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
import pytest
import shutil
from re import sub

from poetry.utils._compat import Path
from poetry.utils.env import Env
from poetry.utils.env import VirtualEnv
from poetry.utils.env import EnvCommandError

MINIMAL_SCRIPT = """\

print("Minimal Output"),
"""

Expand Down Expand Up @@ -82,3 +82,43 @@ def test_run_with_input_non_zero_return(tmp_dir, tmp_venv):
result = tmp_venv.run("python", "-", input_=ERRORING_SCRIPT)

assert processError.value.e.returncode == 1


def test_virtualenvs_pip_and_setuptools_versions(tmp_dir):
from pip import __version__ as pip_version
from setuptools import __version__ as setuptools_version

if pip_version == "10.0.1" and setuptools_version == "39.0.1":
pytest.skip(
"System 'pip' and 'setuptools' are default versions from 'ensurepip'."
"Will not detect if they do not get updated after 'venv' creation."
)

venv_path = Path(tmp_dir) / "CheckPipSetuptools"

Env.build_venv(str(venv_path))

venv = VirtualEnv(venv_path)

from pip import __version__ as pip_version

venv_pip_version = venv.run(
"python",
"-c",
'"from __future__ import print_function;from pip import __version__; print(__version__)"',
shell=True,
)
venv_pip_version = sub(r"\s", "", venv_pip_version)

venv_setuptools_version = venv.run(
"python",
"-c",
'"from __future__ import print_function;from setuptools import __version__; print(__version__)"',
shell=True,
)
venv_setuptools_version = sub(r"\s", "", venv_setuptools_version)

assert (
venv_pip_version == pip_version
and venv_setuptools_version == setuptools_version
)