Skip to content

Commit e7ea91d

Browse files
committed
1 parent e54c094 commit e7ea91d

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

python/tk-core/python/tank/pipelineconfig_factory.py

+47-24
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
log = LogManager.get_logger(__name__)
2828

29+
2930
def from_entity(entity_type, entity_id):
3031
"""
3132
Factory method that constructs a pipeline configuration given a Shotgun Entity.
@@ -87,19 +88,20 @@ def _from_entity(entity_type, entity_id, force_reread_shotgun_cache):
8788
# figure out if we are running a tank command / api from a local
8889
# pipeline config or from a studio level install
8990
config_context_path = _get_configuration_context()
91+
config_context_id = _get_configuration_id()
9092

91-
if config_context_path:
93+
if config_context_id and config_context_path:
9294
# we are running the tank command or python core API directly from a configuration
9395
#
9496
# make sure that the tank command we are launching from belong to a shotgun project
9597
# that the input entity type/id is associated with.
96-
if config_context_path not in [x["path"] for x in all_pc_data]:
98+
if config_context_id not in [x["id"] for x in all_pc_data]:
9799
# the tank command / api proxy that this session was launched for is *not*
98100
# associated with the given entity type and entity id!
99-
raise TankError("The pipeline configuration in '%s' is is associated with a different "
101+
raise TankError("The pipeline configuration in '%s' with id %s is is associated with a different "
100102
"project from %s %s. To see which pipeline configurations are available "
101103
"for a project, open the pipeline configurations page "
102-
"in Shotgun." % (config_context_path, entity_type, entity_id))
104+
"in Shotgun." % (config_context_path, config_context_id, entity_type, entity_id))
103105

104106
# ok we got a pipeline config matching the tank command from which we launched.
105107
# because we found the pipeline config in the list of PCs for this project,
@@ -124,8 +126,8 @@ def _from_entity(entity_type, entity_id, force_reread_shotgun_cache):
124126
# incorrectly re-using the same paths.
125127

126128
pcs_msg = ", ".join([
127-
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
128-
for x in primary_pc_data])
129+
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
130+
for x in primary_pc_data])
129131

130132
raise TankError("More than one primary pipeline configuration is associated "
131133
"with the entity %s %s. This happens if more than one pipeline configuration "
@@ -137,7 +139,6 @@ def _from_entity(entity_type, entity_id, force_reread_shotgun_cache):
137139
return PipelineConfiguration(primary_pc_data[0]["path"])
138140

139141

140-
141142
def from_path(path):
142143
"""
143144
Factory method that constructs a pipeline configuration given a path on disk.
@@ -221,21 +222,21 @@ def _from_path(path, force_reread_shotgun_cache):
221222
# figure out if we are running a tank command / api from a
222223
# local pipeline config or from a studio level install
223224
config_context_path = _get_configuration_context()
225+
config_context_id = _get_configuration_id()
224226

225-
if config_context_path:
227+
if config_context_id and config_context_path:
226228

227229
# we are running the tank command or python core API directly from a configuration
228230
#
229-
# now if this tank command is associated with the path, the registered path should be in
231+
# now if this tank command is associated with the id, the registered id should be in
230232
# in the pipeline configuration data coming from
231-
if config_context_path not in [x["path"] for x in all_pc_data]:
232-
233+
if config_context_id not in [x["id"] for x in all_pc_data]:
233234
pcs_msg = ", ".join([
234-
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
235-
for x in all_pc_data])
235+
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
236+
for x in all_pc_data])
236237

237238
raise TankError("You are trying to start Toolkit using the pipeline configuration "
238-
"located in '%s'. The path '%s' you are trying to load is not "
239+
"located in '%s' with id '%s'. The path '%s' you are trying to load is not "
239240
"associated with that configuration. Instead, it is "
240241
"associated with the following pipeline configurations: %s. "
241242
"Please use the tank command or Toolkit API in any of those "
@@ -244,7 +245,7 @@ def _from_path(path, force_reread_shotgun_cache):
244245
"the 'tank move_configuration command'. It can also occur if you "
245246
"are trying to use a tank command associated with one Project "
246247
"to try to operate on a Shot or Asset that belongs to another "
247-
"project." % (config_context_path, path, pcs_msg))
248+
"project." % (config_context_path, config_context_id, path, pcs_msg))
248249

249250
# okay so this pipeline config is valid!
250251
return PipelineConfiguration(config_context_path)
@@ -253,20 +254,18 @@ def _from_path(path, force_reread_shotgun_cache):
253254
# we are running a studio level tank command.
254255
# find the primary pipeline configuration in the list of matching configurations.
255256
if len(primary_pc_data) == 0:
256-
257257
pcs_msg = ", ".join([
258-
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
259-
for x in all_pc_data])
258+
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
259+
for x in all_pc_data])
260260

261261
raise TankError("Cannot find a primary pipeline configuration for path '%s'. "
262262
"The following pipeline configurations are associated with the "
263263
"path, but none of them is marked as Primary: %s" % (path, pcs_msg))
264264

265265
if len(primary_pc_data) > 1:
266-
267266
pcs_msg = ", ".join([
268-
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
269-
for x in primary_pc_data])
267+
"'%s' (Pipeline config id %s, Project id %s)" % (x["path"], x["id"], x["project_id"])
268+
for x in primary_pc_data])
270269

271270
raise TankError("The path '%s' is associated with more than one Primary pipeline "
272271
"configuration. This can happen if there is ambiguity in your project setup, where "
@@ -315,6 +314,30 @@ def _get_configuration_context():
315314
return val
316315

317316

317+
def _get_configuration_id():
318+
"""
319+
Returns a id if the API was invoked via a configuration context, otherwise None.
320+
321+
If this session was involved (tank command or python API) from a studio level API,
322+
e.g. with no connection to any config, None is returned.
323+
324+
In the case the session was started via a python proxy API or tank command
325+
connected to a configuration, the id to that configuration root is returned.
326+
The id returned should reflect the exact value stored in the pipeline configuration
327+
entry in shotgun.
328+
329+
:returns: id or None
330+
"""
331+
# default for studio level tank command/API
332+
val = None
333+
if "TANK_CURRENT_PC" in os.environ:
334+
config_path = os.environ["TANK_CURRENT_PC"]
335+
pc = PipelineConfiguration(config_path)
336+
data = pc._get_metadata()
337+
val = data["pc_id"]
338+
return val
339+
340+
318341
def _get_pipeline_configuration_data(sg_pipeline_configs):
319342
"""
320343
Helper method. Given a list of Shotgun Pipeline configuration entity data, return a
@@ -462,7 +485,7 @@ def _get_pipeline_configs_for_path(path, data):
462485
# in the pipeline config before associating it here.
463486
if pc not in project_paths[project_path]:
464487
project_paths[project_path].append(pc)
465-
488+
466489
# step 3 - look at the path we passed in - see if any of the computed
467490
# project folders are determined to be a parent path
468491
all_matching_pcs = []
@@ -520,7 +543,6 @@ def _get_pipeline_configs_for_project(project_id, data):
520543
return matching_pipeline_configs
521544

522545

523-
524546
#################################################################################################################
525547
# methods relating to maintaining a small cache to speed up initialization
526548

@@ -629,6 +651,7 @@ def _get_pipeline_configs(force=False):
629651

630652
return data
631653

654+
632655
def _load_lookup_cache():
633656
"""
634657
Load lookup cache file from disk.
@@ -652,6 +675,7 @@ def _load_lookup_cache():
652675

653676
return cache_data
654677

678+
655679
@filesystem.with_cleared_umask
656680
def _add_to_lookup_cache(key, data):
657681
"""
@@ -688,7 +712,6 @@ def _add_to_lookup_cache(key, data):
688712
)
689713

690714

691-
692715
def _get_cache_location():
693716
"""
694717
Get the location of the initializtion lookup cache.

0 commit comments

Comments
 (0)