diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 351c460..f1c8db5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,6 +15,7 @@ defaults: env: PACKAGE_NAME: labscript-utils + SCM_LOCAL_SCHEME: no-local-version ANACONDA_USER: labscript-suite # Configuration for a package with compiled extensions: diff --git a/docs/source/api/index.rst b/docs/source/api/index.rst index 024f52a..9e9ff9a 100644 --- a/docs/source/api/index.rst +++ b/docs/source/api/index.rst @@ -60,3 +60,4 @@ Module and File Tools double_import_denier filewatcher modulewatcher + versions diff --git a/docs/source/api/versions.rst b/docs/source/api/versions.rst new file mode 100644 index 0000000..996d686 --- /dev/null +++ b/docs/source/api/versions.rst @@ -0,0 +1,8 @@ +============================ +labscript_utils.versions +============================ + +.. automodule:: labscript_utils.versions + :members: + :undoc-members: + :private-members: \ No newline at end of file diff --git a/docs/source/conf.py b/docs/source/conf.py index 675d806..e3df35c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,6 +10,7 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # +import copy import os from pathlib import Path from m2r import MdInclude @@ -50,6 +51,23 @@ autodoc_typehints = 'description' +# mock missing site packages methods +import site +mock_site_methods = { + # Format: + # method name: return value + 'getusersitepackages': '', + 'getsitepackages': [] +} +__fn = None +for __name, __rval in mock_site_methods.items(): + if not hasattr(site, __name): + __fn = lambda *args, __rval=copy.deepcopy(__rval), **kwargs: __rval + setattr(site, __name, __fn) +del __name +del __rval +del __fn + # Prefix each autosectionlabel with the name of the document it is in and a colon autosectionlabel_prefix_document = True diff --git a/labscript_utils/modulewatcher.py b/labscript_utils/modulewatcher.py index 6b0be0e..7e33b6d 100644 --- a/labscript_utils/modulewatcher.py +++ b/labscript_utils/modulewatcher.py @@ -33,6 +33,14 @@ class ModuleWatcher(object): + """A watcher that reloads modules that have been modified on disk + + Only reloads modules imported after instantiation. Does not reload C extensions. + + Args: + debug (bool, optional): When :code:`True`, prints debugging information + when reloading modules. + """ def __init__(self, debug=False): self.debug = debug # A lock to hold whenever you don't want modules unloaded: diff --git a/labscript_utils/versions.py b/labscript_utils/versions.py index 0b84ed5..032bbf7 100644 --- a/labscript_utils/versions.py +++ b/labscript_utils/versions.py @@ -48,7 +48,20 @@ class BrokenInstall(RuntimeError): def get_import_path(import_name): """Get which entry in sys.path a module would be imported from, without importing - it.""" + it. + + Args: + import_name (str): The module name. + + Raises: + ModuleNotFoundError: Raised if the module is not installed. + NotImplementedError: Raised if the module is a "namespace package". + Support for namepsace packages is not currently availabled. + + Returns: + str: The path to the folder containing the module. + + """ spec = importlib.util.find_spec(import_name) if spec is None: raise ModuleNotFoundError(import_name) @@ -66,8 +79,22 @@ def get_import_path(import_name): def _get_metadata_version(project_name, import_path): - """Return the metadata version for a package with the given project name located at - the given import path, or None if there is no such package.""" + """Gets the package metadata version. + + Args: + project_name (str): The package name (e.g. the name used when pip installing + the package). + import_path (str): The path to the folder containing the installed package. + + Raises: + :exc:`BrokenInstall`: Raised if the package installation is corrupted (multiple + packages matching the given arguments were found). May occur if + (un)installation for a particular package version only partially completed. + + Returns: + The metadata version for a package with the given project name located at + the given import path, or None if there is no such package. + """ for finder in sys.meta_path: if hasattr(finder, 'find_distributions'): @@ -84,8 +111,14 @@ def _get_metadata_version(project_name, import_path): def _get_literal_version(filename): - """Tokenize a source file and return any __version__ = literal defined in - it. + """Tokenize a source file and return any :code:`__version__ = ` literal + defined in it. + + Args: + filename (str): The path to the file to tokenize. + + Returns: + Any version literal found matching the above criteria, or None. """ if not os.path.exists(filename): return None @@ -110,17 +143,34 @@ def _get_literal_version(filename): def get_version(import_name, project_name=None, import_path=None): - """Try very hard to get the version of a package without importing it. if - import_path is not given, first find where it would be imported from, without + """Try very hard to get the version of a package without importing it. + + If import_path is not given, first find where it would be imported from, without importing it. Then look for metadata in the same import path with the given project name (note: this is not always the same as the import name, it is the name for example you would ask pip to install). If that is found, return the version info - from it. Otherwise look for a __version__.py file in the package directory, or a - __version__ = literal defined in the package source (without executing - it). + from it. Otherwise look for a :code:`__version__.py` file in the package directory, + or a :code:`__version__ = ` literal defined in the package source (without + executing it). + + Args: + import_name (str): The module name. + project_name (str, optional): The package name (e.g. the name used when pip + installing the package). This must be specified if it does not match the + module name. + import_path (str, optional): The path to the folder containing the installed + package. + + Raises: + NotImplementedError: Raised if the module name contains a period. Only + top-level packages are supported at this time. - Return NotFound if the package cannot be found, and NoVersionInfo if the version - cannot be obtained in the above way, or if it was found but was None.""" + Returns: + The version literal of the package. + If the package cannot be found, :class:`NotFound` is returned. + If the version cannot be obtained in the above way, or if the version was found + but was :code:`None`, :class:`NoVersionInfo` is returned. + """ if project_name is None: project_name = import_name if '.' in import_name: @@ -162,15 +212,34 @@ def get_version(import_name, project_name=None, import_path=None): def check_version(module_name, at_least, less_than, version=None, project_name=None): - """Check that the version of the given module is at least and less than the given - version strings, and raise VersionException if not. Raise VersionException if the - module was not found or its version could not be determined. This function uses - get_version to determine version numbers without importing modules. In order to do - this, project_name must be provided if it differs from module_name. For example, - pyserial is imported as 'serial', but the project name, as passed to a 'pip install' - command, is 'pyserial'. Therefore to check the version of pyserial, pass in - module_name='serial' and project_name='pyserial'. You can also pass in a version - string yourself, in which case no inspection of packages will take place. + """Checks if a module version is within specified bounds. + + Checks that the version of the given module is at least and less than the given + version strings. This function uses :func:`get_version` to determine version + numbers without importing modules. In order to do this, :code:`project_name` must + be provided if it differs from :code:`module_name`. For example, pyserial is + imported as 'serial', but the project name, as passed to a 'pip install' command, + is 'pyserial'. Therefore to check the version of pyserial, pass in + :code:`module_name='serial'` and :code:`project_name='pyserial'`. + You can also pass in a version string yourself, in which case no inspection of + packages will take place. + + Args: + module_name (str): The name of the module to check. + at_least (str): The minimum acceptable module version. + less_than (str): The minimum unacceptable module version. Usually this would be + the next major version if the package follows + `semver `_. + version (str, optional): The current version of the installed package. Useful when the + package version is stored in a non-standard location. + project_name (str, optional): The package name (e.g. the name used when pip + installing the package). This must be specified if it does not match the + module name. + + Raises: + :exc:`VersionException`: if the module was not found or its version could not + be determined. + """ if version is None: version = get_version(module_name, project_name) diff --git a/pyproject.toml b/pyproject.toml index 3a1c62a..c72bd8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,3 @@ [build-system] requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=4.1.0"] build-backend = "setuptools.build_meta" - -[tool.setuptools_scm] -version_scheme = "release-branch-semver" -local_scheme = "node-and-date" diff --git a/setup.cfg b/setup.cfg index 7c93c95..f77ca06 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,6 +28,7 @@ install_requires = importlib_metadata>=1.0 h5py>=2.9 numpy>=1.15 + packaging>=20.4 pyqtgraph>=0.11.0rc0 qtutils>=2.2.3 scipy diff --git a/setup.py b/setup.py index 88857b7..a12d0a0 100644 --- a/setup.py +++ b/setup.py @@ -16,4 +16,9 @@ def run(self): self.copy_file('labscript-suite.pth', path) -setup(cmdclass={'develop': develop_command}) +VERSION_SCHEME = { + "version_scheme": os.getenv("SCM_VERSION_SCHEME", "release-branch-semver"), + "local_scheme": os.getenv("SCM_LOCAL_SCHEME", "node-and-date"), +} + +setup(use_scm_version=VERSION_SCHEME, cmdclass={'develop': develop_command}) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy