Debian Codegraph @

flit_core/bootstrap_install.py

raw
1 """Install flit_core without using any other tools.
2
3 Normally, you would install flit_core with pip like any other Python package.
4 This script is meant to help with 'bootstrapping' other packaging
5 systems, where you may need flit_core to build other packaging tools.
6
7 Use 'python -m flit_core.wheel' to make a wheel, then:
8
9 python bootstrap_install.py flit_core-3.6.0-py3-none-any.whl
10
11 To install for something other than the Python running the script, pass a
12 site-packages or equivalent directory with the --installdir option.
13 """
14 import argparse
15 import sys
16 import sysconfig
17 from pathlib import Path
18 from zipfile import ZipFile
19
20 def extract_wheel(whl_path, dest):
21 print("Installing to", dest)
22 with ZipFile(whl_path) as zf:
23 zf.extractall(dest)
24
25 if __name__ == "__main__":
26 parser = argparse.ArgumentParser()
27 parser.add_argument(
28 'wheel',
29 type=Path,
30 help='flit_core wheel to install (.whl file)',
31 )
32 purelib = Path(sysconfig.get_path('purelib')).resolve()
33 parser.add_argument(
34 '--installdir',
35 '-i',
36 type=Path,
37 default=purelib,
38 help=f'installdir directory (defaults to {purelib})',
39 )
40 parser.add_argument(
41 '--install-root',
42 type=Path,
43 default=None,
44 help='if given, installdir is considered to be under this'
45 )
46
47 args = parser.parse_args()
48
49 if not args.wheel.name.startswith('flit_core-'):
50 sys.exit("Use this script only for flit_core wheels")
51 if args.install_root:
52 installdir = args.install_root / args.installdir.relative_to("/")
53 else:
54 installdir = args.installdir
55
56 installdir.mkdir(parents=True, exist_ok=True)
57 extract_wheel(args.wheel, installdir)