-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
260 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
35 changes: 35 additions & 0 deletions
35
pipenv/patched/notpip/_internal/operations/build/metadata.py
This file contains 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,35 @@ | ||
"""Metadata generation logic for source distributions. | ||
""" | ||
|
||
import os | ||
|
||
from pipenv.patched.notpip._vendor.pep517.wrappers import Pep517HookCaller | ||
|
||
from pipenv.patched.notpip._internal.build_env import BuildEnvironment | ||
from pipenv.patched.notpip._internal.utils.subprocess import runner_with_spinner_message | ||
from pipenv.patched.notpip._internal.utils.temp_dir import TempDirectory | ||
|
||
|
||
def generate_metadata(build_env, backend): | ||
# type: (BuildEnvironment, Pep517HookCaller) -> str | ||
"""Generate metadata using mechanisms described in PEP 517. | ||
Returns the generated metadata directory. | ||
""" | ||
metadata_tmpdir = TempDirectory( | ||
kind="modern-metadata", globally_managed=True | ||
) | ||
|
||
metadata_dir = metadata_tmpdir.path | ||
|
||
with build_env: | ||
# Note that Pep517HookCaller implements a fallback for | ||
# prepare_metadata_for_build_wheel, so we don't have to | ||
# consider the possibility that this hook doesn't exist. | ||
runner = runner_with_spinner_message("Preparing wheel metadata") | ||
with backend.subprocess_runner(runner): | ||
distinfo_dir = backend.prepare_metadata_for_build_wheel( | ||
metadata_dir | ||
) | ||
|
||
return os.path.join(metadata_dir, distinfo_dir) |
74 changes: 74 additions & 0 deletions
74
pipenv/patched/notpip/_internal/operations/build/metadata_legacy.py
This file contains 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,74 @@ | ||
"""Metadata generation logic for legacy source distributions. | ||
""" | ||
|
||
import logging | ||
import os | ||
|
||
from pipenv.patched.notpip._internal.build_env import BuildEnvironment | ||
from pipenv.patched.notpip._internal.exceptions import InstallationError | ||
from pipenv.patched.notpip._internal.utils.setuptools_build import make_setuptools_egg_info_args | ||
from pipenv.patched.notpip._internal.utils.subprocess import call_subprocess | ||
from pipenv.patched.notpip._internal.utils.temp_dir import TempDirectory | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _find_egg_info(directory): | ||
# type: (str) -> str | ||
"""Find an .egg-info subdirectory in `directory`. | ||
""" | ||
filenames = [ | ||
f for f in os.listdir(directory) if f.endswith(".egg-info") | ||
] | ||
|
||
if not filenames: | ||
raise InstallationError( | ||
f"No .egg-info directory found in {directory}" | ||
) | ||
|
||
if len(filenames) > 1: | ||
raise InstallationError( | ||
"More than one .egg-info directory found in {}".format( | ||
directory | ||
) | ||
) | ||
|
||
return os.path.join(directory, filenames[0]) | ||
|
||
|
||
def generate_metadata( | ||
build_env, # type: BuildEnvironment | ||
setup_py_path, # type: str | ||
source_dir, # type: str | ||
isolated, # type: bool | ||
details, # type: str | ||
): | ||
# type: (...) -> str | ||
"""Generate metadata using setup.py-based defacto mechanisms. | ||
Returns the generated metadata directory. | ||
""" | ||
logger.debug( | ||
'Running setup.py (path:%s) egg_info for package %s', | ||
setup_py_path, details, | ||
) | ||
|
||
egg_info_dir = TempDirectory( | ||
kind="pip-egg-info", globally_managed=True | ||
).path | ||
|
||
args = make_setuptools_egg_info_args( | ||
setup_py_path, | ||
egg_info_dir=egg_info_dir, | ||
no_user_config=isolated, | ||
) | ||
|
||
with build_env: | ||
call_subprocess( | ||
args, | ||
cwd=source_dir, | ||
command_desc='python setup.py egg_info', | ||
) | ||
|
||
# Return the .egg-info directory. | ||
return _find_egg_info(egg_info_dir) |
This file contains 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,38 @@ | ||
import logging | ||
import os | ||
from typing import Optional | ||
|
||
from pipenv.patched.notpip._vendor.pep517.wrappers import Pep517HookCaller | ||
|
||
from pipenv.patched.notpip._internal.utils.subprocess import runner_with_spinner_message | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def build_wheel_pep517( | ||
name, # type: str | ||
backend, # type: Pep517HookCaller | ||
metadata_directory, # type: str | ||
tempd, # type: str | ||
): | ||
# type: (...) -> Optional[str] | ||
"""Build one InstallRequirement using the PEP 517 build process. | ||
Returns path to wheel if successfully built. Otherwise, returns None. | ||
""" | ||
assert metadata_directory is not None | ||
try: | ||
logger.debug('Destination directory: %s', tempd) | ||
|
||
runner = runner_with_spinner_message( | ||
f'Building wheel for {name} (PEP 517)' | ||
) | ||
with backend.subprocess_runner(runner): | ||
wheel_name = backend.build_wheel( | ||
tempd, | ||
metadata_directory=metadata_directory, | ||
) | ||
except Exception: | ||
logger.error('Failed building wheel for %s', name) | ||
return None | ||
return os.path.join(tempd, wheel_name) |
110 changes: 110 additions & 0 deletions
110
pipenv/patched/notpip/_internal/operations/build/wheel_legacy.py
This file contains 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,110 @@ | ||
import logging | ||
import os.path | ||
from typing import List, Optional | ||
|
||
from pipenv.patched.notpip._internal.cli.spinners import open_spinner | ||
from pipenv.patched.notpip._internal.utils.setuptools_build import make_setuptools_bdist_wheel_args | ||
from pipenv.patched.notpip._internal.utils.subprocess import ( | ||
LOG_DIVIDER, | ||
call_subprocess, | ||
format_command_args, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def format_command_result( | ||
command_args, # type: List[str] | ||
command_output, # type: str | ||
): | ||
# type: (...) -> str | ||
"""Format command information for logging.""" | ||
command_desc = format_command_args(command_args) | ||
text = f'Command arguments: {command_desc}\n' | ||
|
||
if not command_output: | ||
text += 'Command output: None' | ||
elif logger.getEffectiveLevel() > logging.DEBUG: | ||
text += 'Command output: [use --verbose to show]' | ||
else: | ||
if not command_output.endswith('\n'): | ||
command_output += '\n' | ||
text += f'Command output:\n{command_output}{LOG_DIVIDER}' | ||
|
||
return text | ||
|
||
|
||
def get_legacy_build_wheel_path( | ||
names, # type: List[str] | ||
temp_dir, # type: str | ||
name, # type: str | ||
command_args, # type: List[str] | ||
command_output, # type: str | ||
): | ||
# type: (...) -> Optional[str] | ||
"""Return the path to the wheel in the temporary build directory.""" | ||
# Sort for determinism. | ||
names = sorted(names) | ||
if not names: | ||
msg = ( | ||
'Legacy build of wheel for {!r} created no files.\n' | ||
).format(name) | ||
msg += format_command_result(command_args, command_output) | ||
logger.warning(msg) | ||
return None | ||
|
||
if len(names) > 1: | ||
msg = ( | ||
'Legacy build of wheel for {!r} created more than one file.\n' | ||
'Filenames (choosing first): {}\n' | ||
).format(name, names) | ||
msg += format_command_result(command_args, command_output) | ||
logger.warning(msg) | ||
|
||
return os.path.join(temp_dir, names[0]) | ||
|
||
|
||
def build_wheel_legacy( | ||
name, # type: str | ||
setup_py_path, # type: str | ||
source_dir, # type: str | ||
global_options, # type: List[str] | ||
build_options, # type: List[str] | ||
tempd, # type: str | ||
): | ||
# type: (...) -> Optional[str] | ||
"""Build one unpacked package using the "legacy" build process. | ||
Returns path to wheel if successfully built. Otherwise, returns None. | ||
""" | ||
wheel_args = make_setuptools_bdist_wheel_args( | ||
setup_py_path, | ||
global_options=global_options, | ||
build_options=build_options, | ||
destination_dir=tempd, | ||
) | ||
|
||
spin_message = f'Building wheel for {name} (setup.py)' | ||
with open_spinner(spin_message) as spinner: | ||
logger.debug('Destination directory: %s', tempd) | ||
|
||
try: | ||
output = call_subprocess( | ||
wheel_args, | ||
cwd=source_dir, | ||
spinner=spinner, | ||
) | ||
except Exception: | ||
spinner.finish("error") | ||
logger.error('Failed building wheel for %s', name) | ||
return None | ||
|
||
names = os.listdir(tempd) | ||
wheel_path = get_legacy_build_wheel_path( | ||
names=names, | ||
temp_dir=tempd, | ||
name=name, | ||
command_args=wheel_args, | ||
command_output=output, | ||
) | ||
return wheel_path |
This file contains 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
This file contains 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