Skip to content

Commit

Permalink
Stable order in pyenv.cfg, include-system-site-packages only for ref (#…
Browse files Browse the repository at this point in the history
…1535)

Previously the order was dictionary order depdendent, so not stable
accross Python implementations, and we also set the include system
site package for all creators, should be only for ref creators.

Signed-off-by: Bernat Gabor <[email protected]>
  • Loading branch information
gaborbernat authored Feb 2, 2020
1 parent bf48544 commit 786c3d0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/1535.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Stable order within ``pyenv.cfg`` and add ``include-system-site-packages`` only for creators that reference a global
Python - by ``gaborbernat``.
23 changes: 6 additions & 17 deletions src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(self, options, interpreter):
self.interpreter = interpreter
self._debug = None
self.dest = Path(options.dest)
self.enable_system_site_package = options.system_site
self.clear = options.clear
self.pyenv_cfg = PyEnvCfg.from_folder(self.dest)

Expand All @@ -45,7 +44,6 @@ def __unicode__(self):
def _args(self):
return [
("dest", six.ensure_text(str(self.dest))),
("global", self.enable_system_site_package),
("clear", self.clear),
]

Expand All @@ -58,16 +56,9 @@ def add_parser_arguments(cls, parser, interpreter, meta):
"--clear",
dest="clear",
action="store_true",
help="clear out the non-root install and start from scratch",
help="remove the destination directory if exist before starting (will overwrite files otherwise)",
default=False,
)
parser.add_argument(
"--system-site-packages",
default=False,
action="store_true",
dest="system_site",
help="give the virtual environment access to the system site-packages dir",
)

@classmethod
def validate_dest(cls, raw_value):
Expand Down Expand Up @@ -151,13 +142,11 @@ def can_create(cls, interpreter):
return True

def set_pyenv_cfg(self):
self.pyenv_cfg.content = {
"home": self.interpreter.system_exec_prefix,
"include-system-site-packages": "true" if self.enable_system_site_package else "false",
"implementation": self.interpreter.implementation,
"version_info": ".".join(str(i) for i in self.interpreter.version_info),
"virtualenv": __version__,
}
self.pyenv_cfg.content = OrderedDict()
self.pyenv_cfg["home"] = self.interpreter.system_exec_prefix
self.pyenv_cfg["implementation"] = self.interpreter.implementation
self.pyenv_cfg["version_info"] = ".".join(str(i) for i in self.interpreter.version_info)
self.pyenv_cfg["virtualenv"] = __version__

@property
def debug(self):
Expand Down
15 changes: 15 additions & 0 deletions src/virtualenv/create/via_global_ref/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ class ViaGlobalRefApi(Creator):
def __init__(self, options, interpreter):
super(ViaGlobalRefApi, self).__init__(options, interpreter)
self.symlinks = getattr(options, "copies", False) is False
self.enable_system_site_package = options.system_site

@classmethod
def add_parser_arguments(cls, parser, interpreter, meta):
super(ViaGlobalRefApi, cls).add_parser_arguments(parser, interpreter, meta)
parser.add_argument(
"--system-site-packages",
default=False,
action="store_true",
dest="system_site",
help="give the virtual environment access to the system site-packages dir",
)
group = parser.add_mutually_exclusive_group()
if meta.can_symlink:
group.add_argument(
Expand All @@ -34,3 +42,10 @@ def add_parser_arguments(cls, parser, interpreter, meta):
dest="copies",
help="try to use copies rather than symlinks, even when symlinks are the default for the platform",
)

def _args(self):
return super(ViaGlobalRefApi, self)._args() + [("global", self.enable_system_site_package)]

def set_pyenv_cfg(self):
super(ViaGlobalRefApi, self).set_pyenv_cfg()
self.pyenv_cfg["include-system-site-packages"] = "true" if self.enable_system_site_package else "false"
5 changes: 3 additions & 2 deletions src/virtualenv/pyenv_cfg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals

import logging
from collections import OrderedDict

import six

Expand All @@ -16,12 +17,12 @@ def from_folder(cls, folder):

@classmethod
def from_file(cls, path):
content = cls._read_values(path) if path.exists() else {}
content = cls._read_values(path) if path.exists() else OrderedDict()
return PyEnvCfg(content, path)

@staticmethod
def _read_values(path):
content = {}
content = OrderedDict()
for line in path.read_text(encoding="utf-8").splitlines():
equals_at = line.index("=")
key = line[:equals_at].strip()
Expand Down

0 comments on commit 786c3d0

Please sign in to comment.