File: build.py

package info (click to toggle)
flit 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,080 kB
  • sloc: python: 3,934; makefile: 161; sh: 16
file content (101 lines) | stat: -rw-r--r-- 3,464 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3

# Symlink install flit & flit_core for development.
# Most projects can do the same with 'flit install --symlink'.
# But that doesn't work until Flit is installed, so we need some bootstrapping.

import argparse
import logging
import os
import os.path as osp
from pathlib import Path
import shutil
import sys

my_dir = Path(__file__).parent
os.chdir(str(my_dir))
sys.path.insert(0, 'flit_core')

from flit_core import build_thyself
from flit_core.config import LoadedConfig
from flit.install import Installer

#ap = argparse.ArgumentParser()
#ap.add_argument('--user')
#args = ap.parse_args()

logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)

class DebianInstaller(Installer):
    def install_directly(self):
        """Install a module/package into package directory, and create its scripts.
        """
        dirs = self._get_dirs(user=self.user)
        dirs['purelib'] = 'debian/flit/' + dirs['stdlib'] + '/dist-packages'
        dirs['scripts'] = 'debian/flit'+ dirs['scripts']
        os.makedirs(dirs['purelib'], exist_ok=True)
        os.makedirs(dirs['scripts'], exist_ok=True)

        dst = osp.join(dirs['purelib'], osp.basename(self.module.path))
        if osp.lexists(dst):
            if osp.isdir(dst) and not osp.islink(dst):
                shutil.rmtree(dst)
            else:
                os.unlink(dst)

        # Install requirements to target environment
        # self.install_requirements()

        # Install requirements to this environment if we need them to
        # get docstring & version number.
        #if self.python != sys.executable:
        #    self.install_reqs_my_python_if_needed()

        src = str(self.module.path)
        if self.symlink:
            log.info("Symlinking %s -> %s", src, dst)
            os.symlink(osp.abspath(self.module.path), dst)
            self.installed_files.append(dst)
        elif self.pth:
            # .pth points to the the folder containing the module (which is
            # added to sys.path)
            pth_target = osp.dirname(osp.abspath(self.module.path))
            pth_file = pathlib.Path(dst).with_suffix('.pth')
            log.info("Adding .pth file %s for %s", pth_file, pth_target)
            with pth_file.open("w") as f:
                f.write(pth_target)
            self.installed_files.append(pth_file)
        elif self.module.is_package:
            log.info("Copying directory %s -> %s", src, dst)
            shutil.copytree(src, dst)
            self._record_installed_directory(dst)
        else:
            log.info("Copying file %s -> %s", src, dst)
            shutil.copy2(src, dst)
            self.installed_files.append(dst)

        scripts = self.ini_info.entrypoints.get('console_scripts', {})
        self.install_scripts(scripts, dirs['scripts'])

        self.write_dist_info(dirs['purelib'])


# Construct config for flit_core
core_config = LoadedConfig()
core_config.module = 'flit_core'
core_config.metadata = build_thyself.metadata_dict
core_config.reqs_by_extra['.none'] = build_thyself.metadata.requires_dist

install_kwargs = {'user': False, 'symlink': False}
# Install flit_core
DebianInstaller(
    my_dir / 'flit_core', core_config, **install_kwargs
).install_directly()
print("Linked flit_core into site-packages.")

# Install flit
DebianInstaller.from_ini_path(
    my_dir / 'pyproject.toml', **install_kwargs
).install_directly()
print("Linked flit into site-packages.")