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

Stable order in pyenv.cfg, include-system-site-packages only for ref #1535

Merged
merged 1 commit into from
Feb 2, 2020
Merged
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
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