Skip to content

Commit ed76901

Browse files
Move copying of .pth file into setup.py
Use a custom develop command to copy the .pth file into site-packages when `python setup.py develop` is run - this is what pip does under the hood for `pip install -e`. No longer need desktop-app to locate site-packages, as the setuptools command class knows it as `self.install_dir`. The file is not removed by `pip uninstall`, but due to the `try: except:`s in the `.pth` file, leaving it behind is harmless. It is removed if the user runs whatever `setup.py` command undoies
1 parent 894e245 commit ed76901

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

labscript_profile/create.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pathlib import Path
66
from subprocess import check_output
77
from labscript_profile import LABSCRIPT_SUITE_PROFILE, default_labconfig_path
8-
import desktop_app
98

109
_here = os.path.dirname(os.path.abspath(__file__))
1110
DEFAULT_PROFILE_CONTENTS = os.path.join(_here, 'default_profile')
@@ -54,15 +53,6 @@ def make_labconfig_file():
5453

5554

5655
def create_profile():
57-
# copy the .pth file if necessary (only needed for ediatble installs)
58-
pth_src = Path(_here).parent / 'labscript-suite.pth'
59-
site_dir = desktop_app.environment.get_install_directory('labscript_profile')
60-
if site_dir is not None and pth_src.parent != site_dir:
61-
pth_dest = site_dir / 'labscript-suite.pth'
62-
if pth_src.exists() and not pth_dest.exists():
63-
shutil.copy2(pth_src, pth_dest)
64-
print(f'Copied labscript-suite.pth file to {pth_dest}')
65-
6656
src = Path(DEFAULT_PROFILE_CONTENTS)
6757
dest = Path(LABSCRIPT_SUITE_PROFILE)
6858
# Profile directory may exist already, but we will error if it contains any of the

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ install_requires =
3333
scipy
3434
setuptools_scm
3535
zprocess>=2.18.0
36-
desktop-app>=0.2.6
3736

3837
[options.extras_require]
3938
docs =

setup.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import os
22
from setuptools import setup
3+
from setuptools.command.develop import develop
4+
from distutils import log
5+
6+
7+
class develop_command(develop):
8+
"""Custom develop command which installs the .pth file to site-packages for editable
9+
installs."""
10+
def run(self):
11+
path = os.path.join(self.install_dir, 'labscript-suite.pth')
12+
super().run()
13+
if not self.uninstall:
14+
log.info(f'Copying labscript-suite.pth to {path}')
15+
if not self.dry_run:
16+
self.copy_file('labscript-suite.pth', path)
17+
318

419
VERSION_SCHEME = {
520
"version_scheme": os.getenv("SCM_VERSION_SCHEME", "guess-next-dev"),
621
"local_scheme": os.getenv("SCM_LOCAL_SCHEME", "node-and-date"),
722
}
823

9-
setup(use_scm_version=VERSION_SCHEME)
24+
setup(use_scm_version=VERSION_SCHEME, cmdclass={'develop': develop_command})

0 commit comments

Comments
 (0)