mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-04 19:29:43 +00:00
Allow passing options to pip
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
c31780f62f
commit
ca07ea0802
|
@ -25,7 +25,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
from mbedtls_dev import typing_util
|
from mbedtls_dev import typing_util
|
||||||
|
|
||||||
def pylint_doesn_t_notice_that_certain_types_are_used_in_annotations(
|
def pylint_doesn_t_notice_that_certain_types_are_used_in_annotations(
|
||||||
|
@ -74,8 +74,16 @@ class Requirements:
|
||||||
for req in self.requirements:
|
for req in self.requirements:
|
||||||
out.write(req + '\n')
|
out.write(req + '\n')
|
||||||
|
|
||||||
def install(self) -> None:
|
def install(
|
||||||
|
self,
|
||||||
|
pip_general_options: Optional[List[str]] = None,
|
||||||
|
pip_install_options: Optional[List[str]] = None,
|
||||||
|
) -> None:
|
||||||
"""Call pip to install the requirements."""
|
"""Call pip to install the requirements."""
|
||||||
|
if pip_general_options is None:
|
||||||
|
pip_general_options = []
|
||||||
|
if pip_install_options is None:
|
||||||
|
pip_install_options = []
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
# This is more complicated than it needs to be for the sake
|
# This is more complicated than it needs to be for the sake
|
||||||
# of Windows. Use a temporary file rather than the command line
|
# of Windows. Use a temporary file rather than the command line
|
||||||
|
@ -86,8 +94,10 @@ class Requirements:
|
||||||
req_file_name = os.path.join(temp_dir, 'requirements.txt')
|
req_file_name = os.path.join(temp_dir, 'requirements.txt')
|
||||||
with open(req_file_name, 'w') as req_file:
|
with open(req_file_name, 'w') as req_file:
|
||||||
self.write(req_file)
|
self.write(req_file)
|
||||||
subprocess.check_call([sys.executable, '-m', 'pip',
|
subprocess.check_call([sys.executable, '-m', 'pip'] +
|
||||||
'install', '-r', req_file_name])
|
pip_general_options +
|
||||||
|
['install'] + pip_install_options +
|
||||||
|
['-r', req_file_name])
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
@ -96,9 +106,20 @@ def main() -> None:
|
||||||
parser.add_argument('--no-act', '-n',
|
parser.add_argument('--no-act', '-n',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Don't act, just print what will be done")
|
help="Don't act, just print what will be done")
|
||||||
|
parser.add_argument('--pip-install-option',
|
||||||
|
action='append', dest='pip_install_options',
|
||||||
|
help="Pass this option to pip install")
|
||||||
|
parser.add_argument('--pip-option',
|
||||||
|
action='append', dest='pip_general_options',
|
||||||
|
help="Pass this general option to pip")
|
||||||
|
parser.add_argument('--user',
|
||||||
|
action='append_const', dest='pip_install_options',
|
||||||
|
const='--user',
|
||||||
|
help="Install to the Python user install directory"
|
||||||
|
" (short for --pip-install-option --user)")
|
||||||
parser.add_argument('files', nargs='*', metavar='FILE',
|
parser.add_argument('files', nargs='*', metavar='FILE',
|
||||||
help="Requirement files"
|
help="Requirement files"
|
||||||
"(default: requirements.txt in the script's directory)")
|
" (default: requirements.txt in the script's directory)")
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
if not options.files:
|
if not options.files:
|
||||||
options.files = [os.path.join(os.path.dirname(__file__),
|
options.files = [os.path.join(os.path.dirname(__file__),
|
||||||
|
@ -108,7 +129,8 @@ def main() -> None:
|
||||||
reqs.add_file(filename)
|
reqs.add_file(filename)
|
||||||
reqs.write(sys.stdout)
|
reqs.write(sys.stdout)
|
||||||
if not options.no_act:
|
if not options.no_act:
|
||||||
reqs.install()
|
reqs.install(pip_general_options=options.pip_general_options,
|
||||||
|
pip_install_options=options.pip_install_options)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue