-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refactor wheel.move_wheel_files to use updated distlib #6763
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
Merged
pradyunsg
merged 4 commits into
pypa:master
from
chrahunt:maint/use-new-distlib-in-wheel
Sep 8, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Switch to new ``distlib`` wheel script template. This should be functionally | ||
equivalent for end users. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
from pip._vendor import pkg_resources | ||
from pip._vendor.distlib.scripts import ScriptMaker | ||
from pip._vendor.distlib.util import get_export_entry | ||
from pip._vendor.packaging.utils import canonicalize_name | ||
from pip._vendor.six import StringIO | ||
|
||
|
@@ -311,6 +312,22 @@ def get_csv_rows_for_installed( | |
return installed_rows | ||
|
||
|
||
class MissingCallableSuffix(Exception): | ||
pass | ||
|
||
|
||
def _raise_for_invalid_entrypoint(specification): | ||
entry = get_export_entry(specification) | ||
if entry is not None and entry.suffix is None: | ||
raise MissingCallableSuffix(str(entry)) | ||
|
||
|
||
class PipScriptMaker(ScriptMaker): | ||
def make(self, specification, options=None): | ||
_raise_for_invalid_entrypoint(specification) | ||
return super(PipScriptMaker, self).make(specification, options) | ||
|
||
|
||
def move_wheel_files( | ||
name, # type: str | ||
req, # type: Requirement | ||
|
@@ -473,7 +490,7 @@ def is_entrypoint_wrapper(name): | |
dest = scheme[subdir] | ||
clobber(source, dest, False, fixer=fixer, filter=filter) | ||
|
||
maker = ScriptMaker(None, scheme['scripts']) | ||
maker = PipScriptMaker(None, scheme['scripts']) | ||
|
||
# Ensure old scripts are overwritten. | ||
# See https://github.com/pypa/pip/issues/1800 | ||
|
@@ -489,36 +506,7 @@ def is_entrypoint_wrapper(name): | |
# See https://bitbucket.org/pypa/distlib/issue/32/ | ||
maker.set_mode = True | ||
|
||
# Simplify the script and fix the fact that the default script swallows | ||
# every single stack trace. | ||
# See https://bitbucket.org/pypa/distlib/issue/34/ | ||
# See https://bitbucket.org/pypa/distlib/issue/33/ | ||
def _get_script_text(entry): | ||
if entry.suffix is None: | ||
raise InstallationError( | ||
"Invalid script entry point: %s for req: %s - A callable " | ||
"suffix is required. Cf https://packaging.python.org/en/" | ||
"latest/distributing.html#console-scripts for more " | ||
"information." % (entry, req) | ||
) | ||
return maker.script_template % { | ||
"module": entry.prefix, | ||
"import_name": entry.suffix.split(".")[0], | ||
"func": entry.suffix, | ||
} | ||
# ignore type, because mypy disallows assigning to a method, | ||
# see https://github.com/python/mypy/issues/2427 | ||
maker._get_script_text = _get_script_text # type: ignore | ||
maker.script_template = r"""# -*- coding: utf-8 -*- | ||
import re | ||
import sys | ||
|
||
from %(module)s import %(import_name)s | ||
|
||
if __name__ == '__main__': | ||
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) | ||
sys.exit(%(func)s()) | ||
""" | ||
scripts_to_generate = [] | ||
|
||
# Special case pip and setuptools to generate versioned wrappers | ||
# | ||
|
@@ -556,29 +544,32 @@ def _get_script_text(entry): | |
pip_script = console.pop('pip', None) | ||
if pip_script: | ||
if "ENSUREPIP_OPTIONS" not in os.environ: | ||
spec = 'pip = ' + pip_script | ||
generated.extend(maker.make(spec)) | ||
scripts_to_generate.append('pip = ' + pip_script) | ||
|
||
if os.environ.get("ENSUREPIP_OPTIONS", "") != "altinstall": | ||
spec = 'pip%s = %s' % (sys.version_info[0], pip_script) | ||
generated.extend(maker.make(spec)) | ||
scripts_to_generate.append( | ||
'pip%s = %s' % (sys.version_info[0], pip_script) | ||
) | ||
|
||
spec = 'pip%s = %s' % (get_major_minor_version(), pip_script) | ||
generated.extend(maker.make(spec)) | ||
scripts_to_generate.append( | ||
'pip%s = %s' % (get_major_minor_version(), pip_script) | ||
) | ||
# Delete any other versioned pip entry points | ||
pip_ep = [k for k in console if re.match(r'pip(\d(\.\d)?)?$', k)] | ||
for k in pip_ep: | ||
del console[k] | ||
easy_install_script = console.pop('easy_install', None) | ||
if easy_install_script: | ||
if "ENSUREPIP_OPTIONS" not in os.environ: | ||
spec = 'easy_install = ' + easy_install_script | ||
generated.extend(maker.make(spec)) | ||
scripts_to_generate.append( | ||
'easy_install = ' + easy_install_script | ||
) | ||
|
||
spec = 'easy_install-%s = %s' % ( | ||
get_major_minor_version(), easy_install_script, | ||
scripts_to_generate.append( | ||
'easy_install-%s = %s' % ( | ||
get_major_minor_version(), easy_install_script | ||
) | ||
) | ||
generated.extend(maker.make(spec)) | ||
# Delete any other versioned easy_install entry points | ||
easy_install_ep = [ | ||
k for k in console if re.match(r'easy_install(-\d\.\d)?$', k) | ||
|
@@ -587,25 +578,37 @@ def _get_script_text(entry): | |
del console[k] | ||
|
||
# Generate the console and GUI entry points specified in the wheel | ||
if len(console) > 0: | ||
generated_console_scripts = maker.make_multiple( | ||
['%s = %s' % kv for kv in console.items()] | ||
) | ||
generated.extend(generated_console_scripts) | ||
scripts_to_generate.extend( | ||
'%s = %s' % kv for kv in console.items() | ||
) | ||
|
||
gui_scripts_to_generate = [ | ||
'%s = %s' % kv for kv in gui.items() | ||
] | ||
|
||
generated_console_scripts = [] # type: List[str] | ||
|
||
if warn_script_location: | ||
msg = message_about_scripts_not_on_PATH(generated_console_scripts) | ||
if msg is not None: | ||
logger.warning(msg) | ||
try: | ||
generated_console_scripts = maker.make_multiple(scripts_to_generate) | ||
generated.extend(generated_console_scripts) | ||
|
||
if len(gui) > 0: | ||
generated.extend( | ||
maker.make_multiple( | ||
['%s = %s' % kv for kv in gui.items()], | ||
{'gui': True} | ||
) | ||
maker.make_multiple(gui_scripts_to_generate, {'gui': True}) | ||
) | ||
except MissingCallableSuffix as e: | ||
entry = e.args[0] | ||
raise InstallationError( | ||
"Invalid script entry point: {} for req: {} - A callable " | ||
"suffix is required. Cf https://packaging.python.org/en/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting that we may want to re-wrap this text, so that the URL isn't wrapped. |
||
"latest/distributing.html#console-scripts for more " | ||
"information.".format(entry, req) | ||
) | ||
|
||
if warn_script_location: | ||
msg = message_about_scripts_not_on_PATH(generated_console_scripts) | ||
if msg is not None: | ||
logger.warning(msg) | ||
|
||
# Record pip as the installer | ||
installer = os.path.join(info_dir[0], 'INSTALLER') | ||
temp_installer = os.path.join(info_dir[0], 'INSTALLER.pip') | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.