Coverage for python/lsst/utils/_packaging.py: 27%

11 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-03-09 03:04 -0800

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. 

11 

12"""Functions to help find packages.""" 

13 

14__all__ = ("getPackageDir",) 

15 

16import os 

17 

18 

19def getPackageDir(package_name: str) -> str: 

20 """Find the file system location of the EUPS package. 

21 

22 Parameters 

23 ---------- 

24 package_name : `str` 

25 The name of the EUPS package. 

26 

27 Returns 

28 ------- 

29 path : `str` 

30 The path to the root of the EUPS package. 

31 

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. 

39 

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.") 

46 

47 envvar = f"{package_name.upper()}_DIR" 

48 

49 path = os.environ.get(envvar) 

50 if path is None: 

51 raise LookupError(f"Package {package_name} not found") 

52 return path