Skip to content

Commit dd098a5

Browse files
committed
Fixes .pth file has no effect in editable install
Fixes #43 The .pth file is now copied during `labscript-profile-create` if it does not exist in the site-packages dir (where the .egg-info files exist) and if it the .pth file exists in the package structure (aka labscript-utils it is an editable install) The labscript-suite.pth file has been updated to not raise an exception if labscript-suite has been uninstalled (so we do not have to worry about cleanup). Also updated the `labscript_profile.add_userlib_and_pythonlib` function to use the `site` library for adding userlib and pythonlib to the system path.
1 parent f77525f commit dd098a5

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

labscript-suite.pth

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import labscript_profile; labscript_profile.add_userlib_and_pythonlib()
2-
import labscript_profile; labscript_profile.add_development_directories()
1+
import sys; exec("try: import labscript_profile; labscript_profile.add_userlib_and_pythonlib()\nexcept ModuleNotFoundError: pass")
2+
import sys; exec("try: import labscript_profile; labscript_profile.add_development_directories()\nexcept ModuleNotFoundError: pass")

labscript_profile/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import site
12
import sys
23
import os
34
from configparser import ConfigParser, NoSectionError, NoOptionError
@@ -56,8 +57,7 @@ def add_userlib_and_pythonlib():
5657
except (NoSectionError, NoOptionError):
5758
paths = []
5859
for path in paths:
59-
if os.path.exists(path):
60-
sys.path.append(path)
60+
site.addsitedir(path)
6161

6262

6363
def add_development_directories():

labscript_profile/create.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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
89

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

5455

5556
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+
5666
src = Path(DEFAULT_PROFILE_CONTENTS)
5767
dest = Path(LABSCRIPT_SUITE_PROFILE)
5868
# Profile directory may exist already, but we will error if it contains any of the

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ install_requires =
3333
scipy
3434
setuptools_scm
3535
zprocess>=2.18.0
36+
desktop-app>=0.2.5
3637

3738
[options.extras_require]
3839
docs =

0 commit comments

Comments
 (0)