Coverage for python/lsst/utils/_packaging.py: 27%
11 statements
« prev ^ index » next coverage.py v6.4, created at 2022-06-02 03:24 -0700
« prev ^ index » next coverage.py v6.4, created at 2022-06-02 03:24 -0700
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."""
14__all__ = ("getPackageDir",)
16import os
19def getPackageDir(package_name: str) -> str:
20 """Find the file system location of the EUPS package.
22 Parameters
23 ----------
24 package_name : `str`
25 The name of the EUPS package.
27 Returns
28 -------
29 path : `str`
30 The path to the root of the EUPS package.
32 Raises
33 ------
34 LookupError
35 Raised if no product of that name could be found.
36 ValueError
37 The supplied package name was either not a string or was
38 a string of zero-length.
40 Notes
41 -----
42 Does not use EUPS directly. Uses the environment.
43 """
44 if not package_name or not isinstance(package_name, str):
45 raise ValueError(f"EUPS package name '{package_name}' is not of a suitable form.")
47 envvar = f"{package_name.upper()}_DIR"
49 path = os.environ.get(envvar)
50 if path is None:
51 raise LookupError(f"Package {package_name} not found")
52 return path