Debian Codegraph @

debian/build.py

raw
1 #!/usr/bin/env python3
2
3 # Symlink install flit & flit_core for development.
4 # Most projects can do the same with 'flit install --symlink'.
5 # But that doesn't work until Flit is installed, so we need some bootstrapping.
6
7 import argparse
8 import logging
9 import os
10 import os.path as osp
11 from pathlib import Path
12 import shutil
13 import sys
14
15 my_dir = Path(__file__).parent
16 os.chdir(str(my_dir))
17 sys.path.insert(0, 'flit_core')
18
19 from flit.install import Installer
20
21 logging.basicConfig(level=logging.INFO)
22 log = logging.getLogger(__name__)
23
24 class DebianInstaller(Installer):
25 def install_directly(self):
26 """Install a module/package into package directory, and create its scripts.
27 """
28 dirs = self._get_dirs(user=self.user)
29 dirs['purelib'] = 'debian/flit/' + dirs['stdlib'] + '/dist-packages'
30 dirs['scripts'] = 'debian/flit'+ dirs['scripts']
31 os.makedirs(dirs['purelib'], exist_ok=True)
32 os.makedirs(dirs['scripts'], exist_ok=True)
33
34 dst = osp.join(dirs['purelib'], osp.basename(self.module.path))
35 if osp.lexists(dst):
36 if osp.isdir(dst) and not osp.islink(dst):
37 shutil.rmtree(dst)
38 else:
39 os.unlink(dst)
40
41 # Install requirements to target environment
42 # self.install_requirements()
43
44 # Install requirements to this environment if we need them to
45 # get docstring & version number.
46 #if self.python != sys.executable:
47 # self.install_reqs_my_python_if_needed()
48
49 src = str(self.module.path)
50 if self.symlink:
51 log.info("Symlinking %s -> %s", src, dst)
52 os.symlink(osp.abspath(self.module.path), dst)
53 self.installed_files.append(dst)
54 elif self.pth:
55 # .pth points to the the folder containing the module (which is
56 # added to sys.path)
57 pth_target = osp.dirname(osp.abspath(self.module.path))
58 pth_file = pathlib.Path(dst).with_suffix('.pth')
59 log.info("Adding .pth file %s for %s", pth_file, pth_target)
60 with pth_file.open("w") as f:
61 f.write(pth_target)
62 self.installed_files.append(pth_file)
63 elif self.module.is_package:
64 log.info("Copying directory %s -> %s", src, dst)
65 shutil.copytree(src, dst)
66 self._record_installed_directory(dst)
67 else:
68 log.info("Copying file %s -> %s", src, dst)
69 shutil.copy2(src, dst)
70 self.installed_files.append(dst)
71
72 scripts = self.ini_info.entrypoints.get('console_scripts', {})
73 self.install_scripts(scripts, dirs['scripts'])
74
75 self.write_dist_info(dirs['purelib'])
76
77 install_kwargs = {'user': False, 'symlink': False}
78 # Install flit_core
79 DebianInstaller.from_ini_path(
80 my_dir / 'flit_core' / 'pyproject.toml', **install_kwargs
81 ).install_directly()
82 print("Linked flit_core into site-packages.")
83
84 # Install flit
85 DebianInstaller.from_ini_path(
86 my_dir / 'pyproject.toml', **install_kwargs
87 ).install_directly()
88 print("Linked flit into site-packages.")