Skip to content

Commit

Permalink
support entry point paths with space (#1660)
Browse files Browse the repository at this point in the history
fix creation of entry points when path contains spaces

Co-authored-by: Bernát Gábor <[email protected]>
  • Loading branch information
nsoranzo and gaborbernat authored Feb 26, 2020
1 parent c3453b6 commit 13ab07c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1660.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix creation of entry points when path contains spaces - by :user:`nsoranzo`.
9 changes: 5 additions & 4 deletions src/virtualenv/seed/via_app_data/pip_install/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from tempfile import mkdtemp
from threading import Lock

# noinspection PyProtectedMember
from distlib.scripts import ScriptMaker, _enquote_executable
from six import PY3, add_metaclass

from virtualenv.util import ConfigParser
Expand Down Expand Up @@ -129,13 +131,12 @@ def _console_scripts(self):

def _create_console_entry_point(self, name, value, to_folder, version_info):
result = []
from distlib.scripts import ScriptMaker

maker = ScriptMaker(None, str(to_folder))
maker.clobber = True # overwrite
maker.variants = {""}
maker.variants = {""} # set within patch_distlib_correct_variants
maker.set_mode = True # ensure they are executable
maker.executable = str(self._creator.exe)
# calling private until https://bitbucket.org/pypa/distlib/issues/135/expose-_enquote_executable-as-public
maker.executable = _enquote_executable(str(self._creator.exe))
specification = "{} = {}".format(name, value)
with self.patch_distlib_correct_variants(version_info, maker):
new_files = maker.make(specification)
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/seed/test_boostrap_link_via_app_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@


@pytest.mark.slow
@pytest.mark.parametrize("copies", [True, False] if fs_supports_symlink() else [True])
@pytest.mark.parametrize("copies", [False, True] if fs_supports_symlink() else [True])
def test_base_bootstrap_link_via_app_data(tmp_path, coverage_env, current_fastest, copies):
current = PythonInfo.current_system()
bundle_ver = BUNDLE_SUPPORT[current.version_release_str]
create_cmd = [
ensure_text(str(tmp_path / "env")),
ensure_text(str(tmp_path / "en v")), # space in the name to ensure generated scripts work when path has space
"--seeder",
"app-data",
"--extra-search-dir",
Expand Down Expand Up @@ -64,9 +64,7 @@ def test_base_bootstrap_link_via_app_data(tmp_path, coverage_env, current_fastes
assert not process.returncode

remove_cmd = [
str(result.creator.exe),
"-m",
"pip",
str(result.creator.script("pip")),
"--verbose",
"--disable-pip-version-check",
"uninstall",
Expand All @@ -89,6 +87,9 @@ def test_base_bootstrap_link_via_app_data(tmp_path, coverage_env, current_fastes
files_post_second_create = list(site_package.iterdir())
assert files_post_first_create == files_post_second_create

# Windows does not allow removing a executable while running it, so when uninstalling pip we need to do it via
# python -m pip
remove_cmd = [str(result.creator.exe), "-m", "pip"] + remove_cmd[1:]
process = Popen(remove_cmd + ["pip", "wheel"])
_, __ = process.communicate()
assert not process.returncode
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ force_grid_wrap = 0
line_length = 120
known_standard_library = ConfigParser
known_first_party = virtualenv
known_third_party = _subprocess,appdirs,coverage,docutils,filelock,git,packaging,pytest,setuptools,six,sphinx,sphinx_rtd_theme,sphinxarg
known_third_party = _subprocess,appdirs,coverage,distlib,docutils,filelock,git,packaging,pytest,setuptools,six,sphinx,sphinx_rtd_theme,sphinxarg

[flake8]
max-complexity = 22
Expand Down

0 comments on commit 13ab07c

Please sign in to comment.