Skip to content

Commit

Permalink
Merge pull request #531 from nerdvegas/issue_528_pkg_tracking
Browse files Browse the repository at this point in the history
Issue 528 pkg tracking
  • Loading branch information
nerdvegas authored Oct 9, 2018
2 parents beb6501 + 2e67210 commit 8247757
Show file tree
Hide file tree
Showing 17 changed files with 443 additions and 2,037 deletions.
21 changes: 11 additions & 10 deletions src/rez/cli/context.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'''
Print information about the current rez context, or a given context file.
'''

# Disable context tracking. Use of rez-context doesn't really indicate usage of
# the packages in the context; and tracking this causes doubling up, ie most
# rez-env invocations do a rez-context immediately after. So turning this off
# cuts down on the amount of data getting tracked, and is more indicative of
# actual package use.
#
import os
os.environ["REZ_CONTEXT_TRACKING_HOST"] = ''

import json
import sys
from rez.rex import OutputStyle

try:
# part of Python since 2.6
import json
except ImportError:
try:
# for Python < 2.6
import simplejson as json
except ImportError:
json = None


def setup_parser(parser, completions=False):
from rez.system import system
Expand Down
56 changes: 45 additions & 11 deletions src/rez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,26 @@ def _validate(self, data):
if self.key in self.config.overrides:
return data

# next, env-var
if self._env_var_name and not self.config.locked:
if not self.config.locked:

# next, env-var
value = os.getenv(self._env_var_name)
if value is not None:
return self._parse_env_var(value)

# next, JSON-encoded env-var
varname = self._env_var_name + "_JSON"
value = os.getenv(varname)
if value is not None:
from rez.utils import json

try:
return json.loads(value)
except ValueError:
raise ConfigurationError(
"Expected $%s to be JSON-encoded string." % varname
)

# next, data unchanged
if data is not None:
return data
Expand Down Expand Up @@ -121,9 +135,10 @@ def _parse_env_var(self, value):
try:
return int(value)
except ValueError:
raise ConfigurationError("expected %s to be an integer"
raise ConfigurationError("Expected %s to be an integer"
% self._env_var_name)


class Bool(Setting):
schema = Schema(bool)
true_words = frozenset(["1", "true", "yes", "y", "on"])
Expand All @@ -138,7 +153,7 @@ def _parse_env_var(self, value):
return False
else:
raise ConfigurationError(
"expected $%s to be one of: %s"
"Expected $%s to be one of: %s"
% (self._env_var_name, ", ".join(self.all_words)))


Expand All @@ -160,12 +175,28 @@ class Dict(Setting):

def _parse_env_var(self, value):
items = value.split(",")
try:
return dict([item.split(":") for item in items])
except ValueError:
raise ConfigurationError(
"expected dict string in form 'k1:v1,k2:v2,...kN:vN': %s"
% value)
result = {}

for item in items:
if ':' not in item:
raise ConfigurationError(
"Expected dict string in form 'k1:v1,k2:v2,...kN:vN': %s"
% value
)

k, v = item.split(':', 1)

try:
v = int(v)
except ValueError:
try:
v = float(v)
except ValueError:
pass

result[k] = v

return result


class OptionalDict(Dict):
Expand All @@ -177,7 +208,6 @@ class OptionalDictOrDictList(Setting):
schema = Or(And(None, Use(lambda x: [])),
And(dict, Use(lambda x: [x])),
[dict])
_env_var_name = None


class SuiteVisibility_(Str):
Expand Down Expand Up @@ -236,6 +266,7 @@ def _parse_env_var(self, value):
"parent_variables": StrList,
"resetting_variables": StrList,
"release_hooks": StrList,
"context_tracking_context_fields": StrList,
"prompt_release_message": Bool,
"critical_styles": OptionalStrList,
"error_styles": OptionalStrList,
Expand Down Expand Up @@ -283,6 +314,7 @@ def _parse_env_var(self, value):
"alias_fore": OptionalStr,
"alias_back": OptionalStr,
"package_preprocess_function": OptionalStr,
"context_tracking_host": OptionalStr,
"build_thread_count": BuildThreadCount_,
"resource_caching_maxsize": Int,
"max_package_changelog_chars": Int,
Expand Down Expand Up @@ -333,6 +365,8 @@ def _parse_env_var(self, value):
"variant_select_mode": VariantSelectMode_,
"package_filter": OptionalDictOrDictList,
"new_session_popen_args": OptionalDict,
"context_tracking_amqp": OptionalDict,
"context_tracking_extra_fields": OptionalDict,

# GUI settings
"use_pyside": Bool,
Expand Down
Loading

0 comments on commit 8247757

Please sign in to comment.