Coverage for debputy/_deb_options_profiles.py: 0%

29 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-22 14:29 +0100

1import os 

2 

3from typing import FrozenSet, Optional, Mapping 

4 

5 

6class DebOptionsAndProfiles: 

7 """Accessor to common environment related values 

8 

9 >>> env = DebOptionsAndProfiles(environ={'DEB_BUILD_PROFILES': 'noudeb nojava'}) 

10 >>> 'noudeb' in env.deb_build_profiles 

11 True 

12 >>> 'nojava' in env.deb_build_profiles 

13 True 

14 >>> 'nopython' in env.deb_build_profiles 

15 False 

16 >>> sorted(env.deb_build_profiles) 

17 ['nojava', 'noudeb'] 

18 """ 

19 

20 def __init__(self, *, environ=None): 

21 if environ is None: 

22 environ = dict(os.environ) 

23 self.environ = environ 

24 self._deb_build_profiles = self._parse_set_from_environ('DEB_BUILD_PROFILES') 

25 self._deb_build_options = self._parse_dict_from_environ('DEB_BUILD_OPTIONS') 

26 

27 @staticmethod 

28 def instance(): 

29 global _INSTANCE 

30 return _INSTANCE 

31 

32 def _parse_set_from_environ(self, env_name, default_value=''): 

33 return frozenset(x for x in self.environ.get(env_name, default_value).split()) 

34 

35 def _parse_dict_from_environ(self, env_name, default_value='') -> Mapping[str, str]: 

36 res = {} 

37 for kvish in self.environ.get(env_name, default_value).split(): 

38 if '=' in kvish: 

39 key, value = kvish.split('=', 1) 

40 res[key] = value 

41 else: 

42 res[kvish] = None 

43 return res 

44 

45 @property 

46 def deb_build_profiles(self) -> FrozenSet[str]: 

47 """A set-like view of all build profiles active during the build 

48 

49 >>> env = DebOptionsAndProfiles(environ={'DEB_BUILD_PROFILES': 'noudeb nojava'}) 

50 >>> 'noudeb' in env.deb_build_profiles 

51 True 

52 >>> 'nojava' in env.deb_build_profiles 

53 True 

54 >>> 'nopython' in env.deb_build_profiles 

55 False 

56 >>> sorted(env.deb_build_profiles) 

57 ['nojava', 'noudeb'] 

58 

59 """ 

60 return self._deb_build_profiles 

61 

62 @property 

63 def deb_build_options(self) -> Mapping[str, Optional[str]]: 

64 """A set-like view of all build profiles active during the build 

65 

66 >>> env = DebOptionsAndProfiles(environ={'DEB_BUILD_OPTIONS': 'nostrip parallel=4'}) 

67 >>> 'nostrip' in env.deb_build_options 

68 True 

69 >>> 'parallel' in env.deb_build_options 

70 True 

71 >>> 'noautodbgsym' in env.deb_build_options 

72 False 

73 >>> env.deb_build_options['nostrip'] is None 

74 True 

75 >>> env.deb_build_options['parallel'] 

76 '4' 

77 >>> env.deb_build_options['noautodbgsym'] 

78 Traceback (most recent call last): 

79 ... 

80 KeyError: 'noautodbgsym' 

81 >>> sorted(env.deb_build_options) 

82 ['nostrip', 'parallel'] 

83 

84 """ 

85 return self._deb_build_options 

86 

87 

88_INSTANCE = DebOptionsAndProfiles()