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
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-22 14:29 +0100
1import os
3from typing import FrozenSet, Optional, Mapping
6class DebOptionsAndProfiles:
7 """Accessor to common environment related values
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 """
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')
27 @staticmethod
28 def instance():
29 global _INSTANCE
30 return _INSTANCE
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())
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
45 @property
46 def deb_build_profiles(self) -> FrozenSet[str]:
47 """A set-like view of all build profiles active during the build
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']
59 """
60 return self._deb_build_profiles
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
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']
84 """
85 return self._deb_build_options
88_INSTANCE = DebOptionsAndProfiles()