MCPcopy Create free account
hub / github.com/numpy/numpy / _parse_env_order

Function _parse_env_order

numpy/distutils/system_info.py:417–498  ·  view source on GitHub ↗

Parse an environment variable `env` by splitting with "," and only returning elements from `base_order` This method will sequence the environment variable and check for their individual elements in `base_order`. The items in the environment variable may be negated via '^item' or '!ite

(base_order, env)

Source from the content-addressed store, hash-verified

415
416
417def _parse_env_order(base_order, env):
418 """ Parse an environment variable `env` by splitting with "," and only returning elements from `base_order`
419
420 This method will sequence the environment variable and check for their
421 individual elements in `base_order`.
422
423 The items in the environment variable may be negated via '^item' or '!itema,itemb'.
424 It must start with ^/! to negate all options.
425
426 Raises
427 ------
428 ValueError: for mixed negated and non-negated orders or multiple negated orders
429
430 Parameters
431 ----------
432 base_order : list of str
433 the base list of orders
434 env : str
435 the environment variable to be parsed, if none is found, `base_order` is returned
436
437 Returns
438 -------
439 allow_order : list of str
440 allowed orders in lower-case
441 unknown_order : list of str
442 for values not overlapping with `base_order`
443 """
444 order_str = os.environ.get(env, None)
445
446 # ensure all base-orders are lower-case (for easier comparison)
447 base_order = [order.lower() for order in base_order]
448 if order_str is None:
449 return base_order, []
450
451 neg = order_str.startswith('^') or order_str.startswith('!')
452 # Check format
453 order_str_l = list(order_str)
454 sum_neg = order_str_l.count('^') + order_str_l.count('!')
455 if neg:
456 if sum_neg > 1:
457 raise ValueError(f"Environment variable '{env}' may only contain a single (prefixed) negation: {order_str}")
458 # remove prefix
459 order_str = order_str[1:]
460 elif sum_neg > 0:
461 raise ValueError(f"Environment variable '{env}' may not mix negated an non-negated items: {order_str}")
462
463 # Split and lower case
464 orders = order_str.lower().split(',')
465
466 # to inform callee about non-overlapping elements
467 unknown_order = []
468
469 # if negated, we have to remove from the order
470 if neg:
471 allow_order = base_order.copy()
472
473 for order in orders:
474 if not order:

Callers 3

calc_infoMethod · 0.85
calc_infoMethod · 0.85

Calls 6

lowerMethod · 0.80
startswithMethod · 0.80
getMethod · 0.45
countMethod · 0.45
splitMethod · 0.45
copyMethod · 0.45

Tested by 1