Debian Codegraph @

debugger/setup.py

raw
1 import os
2
3 import setuptools
4 from setuptools.command.install import install
5
6
7 # Copied from setuptools:
8 # (https://github.com/pypa/setuptools/blob/7c859e017368360ba66c8cc591279d8964c031bc/setup.py#L40C6-L82)
9 class install_with_pth(install):
10 """Custom install command to install a .pth file for distutils patching.
11
12 This hack is necessary because there's no standard way to install behavior
13 on startup (and it's debatable if there should be one). This hack (ab)uses
14 the `extra_path` behavior in Setuptools to install a `.pth` file with
15 implicit behavior on startup to give higher precedence to the local version
16 of `distutils` over the version from the standard library.
17
18 Please do not replicate this behavior.
19 """
20
21 _pth_name = "briefcase_debugger"
22 _pth_contents = (
23 "import briefcase_debugger; briefcase_debugger.start_remote_debugger()"
24 )
25
26 def initialize_options(self):
27 install.initialize_options(self)
28 self.extra_path = self._pth_name, self._pth_contents
29
30 def finalize_options(self):
31 install.finalize_options(self)
32 self._restore_install_lib()
33
34 def _restore_install_lib(self):
35 """Undo secondary effect of `extra_path` adding to `install_lib`"""
36 suffix = os.path.relpath(self.install_lib, self.install_libbase)
37
38 if suffix.strip() == self._pth_contents.strip():
39 self.install_lib = self.install_libbase
40
41
42 setuptools.setup(
43 cmdclass={"install": install_with_pth},
44 )