Skip to content

Commit 8247757

Browse files
authored
Merge pull request #531 from nerdvegas/issue_528_pkg_tracking
Issue 528 pkg tracking
2 parents beb6501 + 2e67210 commit 8247757

File tree

17 files changed

+443
-2037
lines changed

17 files changed

+443
-2037
lines changed

src/rez/cli/context.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
'''
22
Print information about the current rez context, or a given context file.
33
'''
4+
5+
# Disable context tracking. Use of rez-context doesn't really indicate usage of
6+
# the packages in the context; and tracking this causes doubling up, ie most
7+
# rez-env invocations do a rez-context immediately after. So turning this off
8+
# cuts down on the amount of data getting tracked, and is more indicative of
9+
# actual package use.
10+
#
11+
import os
12+
os.environ["REZ_CONTEXT_TRACKING_HOST"] = ''
13+
14+
import json
415
import sys
516
from rez.rex import OutputStyle
617

7-
try:
8-
# part of Python since 2.6
9-
import json
10-
except ImportError:
11-
try:
12-
# for Python < 2.6
13-
import simplejson as json
14-
except ImportError:
15-
json = None
16-
1718

1819
def setup_parser(parser, completions=False):
1920
from rez.system import system

src/rez/config.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,26 @@ def _validate(self, data):
5959
if self.key in self.config.overrides:
6060
return data
6161

62-
# next, env-var
63-
if self._env_var_name and not self.config.locked:
62+
if not self.config.locked:
63+
64+
# next, env-var
6465
value = os.getenv(self._env_var_name)
6566
if value is not None:
6667
return self._parse_env_var(value)
6768

69+
# next, JSON-encoded env-var
70+
varname = self._env_var_name + "_JSON"
71+
value = os.getenv(varname)
72+
if value is not None:
73+
from rez.utils import json
74+
75+
try:
76+
return json.loads(value)
77+
except ValueError:
78+
raise ConfigurationError(
79+
"Expected $%s to be JSON-encoded string." % varname
80+
)
81+
6882
# next, data unchanged
6983
if data is not None:
7084
return data
@@ -121,9 +135,10 @@ def _parse_env_var(self, value):
121135
try:
122136
return int(value)
123137
except ValueError:
124-
raise ConfigurationError("expected %s to be an integer"
138+
raise ConfigurationError("Expected %s to be an integer"
125139
% self._env_var_name)
126140

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

144159

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

161176
def _parse_env_var(self, value):
162177
items = value.split(",")
163-
try:
164-
return dict([item.split(":") for item in items])
165-
except ValueError:
166-
raise ConfigurationError(
167-
"expected dict string in form 'k1:v1,k2:v2,...kN:vN': %s"
168-
% value)
178+
result = {}
179+
180+
for item in items:
181+
if ':' not in item:
182+
raise ConfigurationError(
183+
"Expected dict string in form 'k1:v1,k2:v2,...kN:vN': %s"
184+
% value
185+
)
186+
187+
k, v = item.split(':', 1)
188+
189+
try:
190+
v = int(v)
191+
except ValueError:
192+
try:
193+
v = float(v)
194+
except ValueError:
195+
pass
196+
197+
result[k] = v
198+
199+
return result
169200

170201

171202
class OptionalDict(Dict):
@@ -177,7 +208,6 @@ class OptionalDictOrDictList(Setting):
177208
schema = Or(And(None, Use(lambda x: [])),
178209
And(dict, Use(lambda x: [x])),
179210
[dict])
180-
_env_var_name = None
181211

182212

183213
class SuiteVisibility_(Str):
@@ -236,6 +266,7 @@ def _parse_env_var(self, value):
236266
"parent_variables": StrList,
237267
"resetting_variables": StrList,
238268
"release_hooks": StrList,
269+
"context_tracking_context_fields": StrList,
239270
"prompt_release_message": Bool,
240271
"critical_styles": OptionalStrList,
241272
"error_styles": OptionalStrList,
@@ -283,6 +314,7 @@ def _parse_env_var(self, value):
283314
"alias_fore": OptionalStr,
284315
"alias_back": OptionalStr,
285316
"package_preprocess_function": OptionalStr,
317+
"context_tracking_host": OptionalStr,
286318
"build_thread_count": BuildThreadCount_,
287319
"resource_caching_maxsize": Int,
288320
"max_package_changelog_chars": Int,
@@ -333,6 +365,8 @@ def _parse_env_var(self, value):
333365
"variant_select_mode": VariantSelectMode_,
334366
"package_filter": OptionalDictOrDictList,
335367
"new_session_popen_args": OptionalDict,
368+
"context_tracking_amqp": OptionalDict,
369+
"context_tracking_extra_fields": OptionalDict,
336370

337371
# GUI settings
338372
"use_pyside": Bool,

0 commit comments

Comments
 (0)