Environment variables supported by the PEX runtime.
| 175 | |
| 176 | |
| 177 | class Variables(object): |
| 178 | """Environment variables supported by the PEX runtime.""" |
| 179 | |
| 180 | @classmethod |
| 181 | def process_pydoc(cls, pydoc): |
| 182 | # type: (Optional[str]) -> Tuple[str, str] |
| 183 | if pydoc is None: |
| 184 | return "Unknown", "Unknown" |
| 185 | pydoc_lines = pydoc.splitlines() |
| 186 | variable_type = pydoc_lines[0] |
| 187 | variable_text = " ".join(filter(None, (line.strip() for line in pydoc_lines[2:]))) |
| 188 | return variable_type, variable_text |
| 189 | |
| 190 | @classmethod |
| 191 | def iter_help(cls): |
| 192 | # type: () -> Iterator[Tuple[str, str, str]] |
| 193 | for variable_name, value in sorted(cls.__dict__.items()): |
| 194 | if not variable_name.startswith("PEX_"): |
| 195 | continue |
| 196 | value = value._func if isinstance(value, DefaultedProperty) else value |
| 197 | variable_type, variable_text = cls.process_pydoc(getattr(value, "__doc__")) |
| 198 | yield variable_name, variable_type, variable_text |
| 199 | |
| 200 | @classmethod |
| 201 | def from_rc(cls, rc=None): |
| 202 | # type: (Optional[str]) -> Dict[str, str] |
| 203 | """Read pex runtime configuration variables from a pexrc file. |
| 204 | |
| 205 | :param rc: an absolute path to a pexrc file. |
| 206 | :return: A dict of key value pairs found in processed pexrc files. |
| 207 | """ |
| 208 | ret_vars = {} # type: Dict[str, str] |
| 209 | rc_locations = [ |
| 210 | os.path.join(os.sep, "etc", "pexrc"), |
| 211 | os.path.join("~", ".pexrc"), |
| 212 | os.path.join(os.path.dirname(sys.argv[0]), ".pexrc"), |
| 213 | ] |
| 214 | if rc: |
| 215 | rc_locations.append(rc) |
| 216 | for filename in rc_locations: |
| 217 | try: |
| 218 | with open(os.path.expanduser(filename)) as fh: |
| 219 | rc_items = map(cls._get_kv, fh) |
| 220 | ret_vars.update(dict(filter(None, rc_items))) |
| 221 | except IOError: |
| 222 | continue |
| 223 | return ret_vars |
| 224 | |
| 225 | @classmethod |
| 226 | def _get_kv(cls, variable): |
| 227 | kv = variable.strip().split("=") |
| 228 | if len(list(filter(None, kv))) == 2: |
| 229 | return kv |
| 230 | |
| 231 | @staticmethod |
| 232 | def _maybe_get_bool_var( |
| 233 | name, # type: str |
| 234 | env, # type: Mapping[str, Optional[str]] |
no outgoing calls