Coverage for python/lsst/utils/_packaging.py: 31%
12 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-25 09:27 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-25 09:27 +0000
1# This file is part of utils.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12"""Functions to help find packages."""
14from __future__ import annotations
16__all__ = ("getPackageDir",)
18import os
21def getPackageDir(package_name: str) -> str:
22 """Find the file system location of the EUPS package.
24 Parameters
25 ----------
26 package_name : `str`
27 The name of the EUPS package.
29 Returns
30 -------
31 path : `str`
32 The path to the root of the EUPS package.
34 Raises
35 ------
36 LookupError
37 Raised if no product of that name could be found.
38 ValueError
39 The supplied package name was either not a string or was
40 a string of zero-length.
42 Notes
43 -----
44 Does not use EUPS directly. Uses the environment.
45 """
46 if not package_name or not isinstance(package_name, str):
47 raise ValueError(f"EUPS package name '{package_name}' is not of a suitable form.")
49 envvar = f"{package_name.upper()}_DIR"
51 path = os.environ.get(envvar)
52 if path is None:
53 raise LookupError(f"Package {package_name} not found")
54 return path