Skip to content

Remove unused modules, version checks, and PY2 compat. #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions labscript_profile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
LABSCRIPT_SUITE_PROFILE = None


def hostname():
if sys.platform == 'darwin':
return check_output(['scutil', '--get', 'LocalHostName']).decode('utf8').strip()
else:
return socket.gethostname()


def default_labconfig_path():
if LABSCRIPT_SUITE_PROFILE is None:
return None
if sys.platform == 'darwin':
cmd = ['scutil', '--get', 'LocalHostName']
hostname = check_output(cmd).decode('utf8').strip()
else:
hostname = socket.gethostname()
labconfig = LABSCRIPT_SUITE_PROFILE / 'labconfig' / f'{hostname}.ini'
return labconfig
return LABSCRIPT_SUITE_PROFILE / 'labconfig' / f'{hostname()}.ini'


def add_userlib_and_pythonlib():
Expand All @@ -46,23 +47,22 @@ def add_userlib_and_pythonlib():
labscript_utils, since we dont' want to import something like labscript_utils every
time the interpreter starts up"""
labconfig = default_labconfig_path()
if labconfig is None or not os.path.exists(labconfig):
return
config = ConfigParser()
config.read(labconfig)
for option in ['userlib', 'pythonlib']:
try:
paths = config.get('DEFAULT', option).split(',')
except (NoSectionError, NoOptionError):
paths = []
for path in paths:
if os.path.exists(path):
sys.path.append(path)
if labconfig is not None and labconfig.exists():
config = ConfigParser()
config.read(labconfig)
for option in ['userlib', 'pythonlib']:
try:
paths = config.get('DEFAULT', option).split(',')
except (NoSectionError, NoOptionError):
paths = []
for path in paths:
if os.path.exists(path):
sys.path.append(path)


def add_development_directories():
"""Prepend directories in <labscript_suite_profile>/dev to the search path, if they
are listed in the file <labscript_suite_profile>/dev/enabled (if that file
"""Prepend directories in <LABSCRIPT_SUITE_PROFILE>/dev to the search path, if they
are listed in the file <LABSCRIPT_SUITE_PROFILE>/dev/enabled (if that file
exists)."""
if LABSCRIPT_SUITE_PROFILE is None:
return
Expand Down
32 changes: 7 additions & 25 deletions labscript_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@

import sys
import os
import traceback
from pathlib import Path
import importlib

from .versions import get_version, NoVersionInfo
from .__version__ import __version__

PY2 = sys.version_info[0] == 2

from labscript_profile import LABSCRIPT_SUITE_PROFILE

if not os.path.exists(LABSCRIPT_SUITE_PROFILE):
Expand All @@ -32,8 +28,6 @@
import labscript_profile
labscript_profile.add_userlib_and_pythonlib()

# labscript_suite_install_dir alias for backward compatibility:
labscript_suite_profile = labscript_suite_install_dir = str(LABSCRIPT_SUITE_PROFILE)

# This folder
labscript_utils_dir = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -46,19 +40,13 @@ def import_or_reload(modulename):
"""
# see if the proposed module is already loaded
# if so, we will need to re-run the code contained in it
import importlib
if not PY2:
reload = importlib.reload
if modulename in sys.modules.keys():
reload(sys.modules[modulename])
importlib.reload(sys.modules[modulename])
return sys.modules[modulename]
module = importlib.import_module(modulename)
return module


from labscript_utils.versions import get_version, VersionException, check_version


def dedent(s):
"""Remove leading spaces from the first line of a string, all common leading
indentation (spaces only) from subsequent lines, strip trailing spaces from all
Expand Down Expand Up @@ -103,14 +91,8 @@ def dedent(s):
import labscript_utils.double_import_denier
labscript_utils.double_import_denier.enable()

try:
# If zprocess is new enough, disable the 'quick edit' feature of Windows' cmd.exe,
# which causes console applicatons to freeze if their console windows are merely
# clicked on. This causes all kinds of headaches, so we disable it in all labscript
# programs:
import zprocess
if hasattr(zprocess, 'disable_quick_edit'):
# Feature is present in zprocess > 2.10.0, but if not present we just ignore.
zprocess.disable_quick_edit()
except ImportError:
pass
# Disable the 'quick edit' feature of Windows' cmd.exe, which causes console applicatons
# to freeze if their console windows are merely clicked on. This causes all kinds of
# headaches, so we disable it in all labscript programs:
import zprocess
zprocess.disable_quick_edit()
7 changes: 0 additions & 7 deletions labscript_utils/camera_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@
# for the full license. #
# #
#####################################################################
from __future__ import division, unicode_literals, print_function, absolute_import
from labscript_utils import PY2
if PY2:
str = unicode

import sys
import time
import zprocess
from labscript_utils import check_version
import labscript_utils.shared_drive
# importing this wraps zlock calls around HDF file openings and closings:
import labscript_utils.h5_lock
import h5py
import numpy as np
check_version('zprocess', '1.3.3', '3.0')

# This file implements the protocol for a camera server, that is, a program
# that BLACS can interface with to control cameras. It contains a class that
Expand Down
222 changes: 0 additions & 222 deletions labscript_utils/clean_repo_hook.py

This file was deleted.

4 changes: 0 additions & 4 deletions labscript_utils/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# #
#####################################################################

from __future__ import division, unicode_literals, print_function, absolute_import
import labscript_utils.h5_lock, h5py
import labscript_utils.properties
import logging
Expand All @@ -22,9 +21,6 @@
from labscript_utils.dict_diff import dict_diff
import sys
from zprocess import raise_exception_in_thread
from labscript_utils import PY2
if PY2:
str = unicode

def _ensure_str(s):
"""convert bytestrings and numpy strings to python strings"""
Expand Down
Loading