comparison env/lib/python3.9/site-packages/pip/_internal/operations/build/wheel_legacy.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import logging
2 import os.path
3
4 from pip._internal.cli.spinners import open_spinner
5 from pip._internal.utils.setuptools_build import make_setuptools_bdist_wheel_args
6 from pip._internal.utils.subprocess import (
7 LOG_DIVIDER,
8 call_subprocess,
9 format_command_args,
10 )
11 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
12
13 if MYPY_CHECK_RUNNING:
14 from typing import List, Optional
15
16 logger = logging.getLogger(__name__)
17
18
19 def format_command_result(
20 command_args, # type: List[str]
21 command_output, # type: str
22 ):
23 # type: (...) -> str
24 """Format command information for logging."""
25 command_desc = format_command_args(command_args)
26 text = f'Command arguments: {command_desc}\n'
27
28 if not command_output:
29 text += 'Command output: None'
30 elif logger.getEffectiveLevel() > logging.DEBUG:
31 text += 'Command output: [use --verbose to show]'
32 else:
33 if not command_output.endswith('\n'):
34 command_output += '\n'
35 text += f'Command output:\n{command_output}{LOG_DIVIDER}'
36
37 return text
38
39
40 def get_legacy_build_wheel_path(
41 names, # type: List[str]
42 temp_dir, # type: str
43 name, # type: str
44 command_args, # type: List[str]
45 command_output, # type: str
46 ):
47 # type: (...) -> Optional[str]
48 """Return the path to the wheel in the temporary build directory."""
49 # Sort for determinism.
50 names = sorted(names)
51 if not names:
52 msg = (
53 'Legacy build of wheel for {!r} created no files.\n'
54 ).format(name)
55 msg += format_command_result(command_args, command_output)
56 logger.warning(msg)
57 return None
58
59 if len(names) > 1:
60 msg = (
61 'Legacy build of wheel for {!r} created more than one file.\n'
62 'Filenames (choosing first): {}\n'
63 ).format(name, names)
64 msg += format_command_result(command_args, command_output)
65 logger.warning(msg)
66
67 return os.path.join(temp_dir, names[0])
68
69
70 def build_wheel_legacy(
71 name, # type: str
72 setup_py_path, # type: str
73 source_dir, # type: str
74 global_options, # type: List[str]
75 build_options, # type: List[str]
76 tempd, # type: str
77 ):
78 # type: (...) -> Optional[str]
79 """Build one unpacked package using the "legacy" build process.
80
81 Returns path to wheel if successfully built. Otherwise, returns None.
82 """
83 wheel_args = make_setuptools_bdist_wheel_args(
84 setup_py_path,
85 global_options=global_options,
86 build_options=build_options,
87 destination_dir=tempd,
88 )
89
90 spin_message = f'Building wheel for {name} (setup.py)'
91 with open_spinner(spin_message) as spinner:
92 logger.debug('Destination directory: %s', tempd)
93
94 try:
95 output = call_subprocess(
96 wheel_args,
97 cwd=source_dir,
98 spinner=spinner,
99 )
100 except Exception:
101 spinner.finish("error")
102 logger.error('Failed building wheel for %s', name)
103 return None
104
105 names = os.listdir(tempd)
106 wheel_path = get_legacy_build_wheel_path(
107 names=names,
108 temp_dir=tempd,
109 name=name,
110 command_args=wheel_args,
111 command_output=output,
112 )
113 return wheel_path