0

Finding the pipeline configuration path

Hi,

I'm using this bit of code to find the pipeline config path :

tk = sgtk.Sgtk(somepath)

print tk.pipeline_configuration.get_all_os_paths()

 

The problem is that the docstring of sgtk states :

pipeline_configuration

Internal Use Only - We provide no guarantees that this method

will be backwards compatible. The returned objects are also

subject to change and are not part of the public Sgtk API.

 

 

So what is the officially supported way of getting the pipeline config path ?

 

Regards

 

8 comments

  • 0
    Avatar
    Permanently deleted user

    Hello there Donat!

    Thanks for trying to respect our internal boundary and reading doc strings! :) Sometimes Python makes it hard to create a boundary between private and public facing parts of an API, without having to jump through hoops.

    We don't have a good way to access the pipeline path at the moment - one of the reason is that we are trying to keep the physical location of the pipeline configuration a bit closer to our chest than other system properties. The reason for this is that we are not sure it is something that will stay in its current form forever. Last year, we started to talk about cloud based storage for Toolkit and we have some ideas where the filesystem configuration paths that you can see for a Pipeline Configuration Entity in Shotgun will only be one way out of several to control where your config is. This is still strategic territory for us and we are not sure about the exact direction forward, but we are thinking that in the future, it will be possible to for example say that a pipeline configuration should be tracking a git or github repository, or even grab an uploaded or pre-packaged zip file from within shotgun. Toolkit would then automatically download, manage and deploy updates to the config - essentially making the actual path to the pipeline configuration a more internal detail in the setup - something which may be different on different machines etc.

    Hope this makes sense and gives you some insights into what we have been thinking. Having said that, we also want to be pragmatic and agile with things and not cause friction for our technical users :) What sort of use case did you have in mind for using this path? I am wondering if there is some other way we could provide the functionality you ultimately need! Or we can perhaps expose the path more officially! In any case, hearing more about your use case would be really helpful for us!

    Thanks!
    Manne

  • 0
    Avatar
    Donat Van Bellinghen

    Hi,

    I'm asking this because I'm still trying to adapt this script :

    https://support.shotgunsoftware.com/entries/95440797

    for new toolkit projects using a localized core.

     

    (see earlier discussion https://support.shotgunsoftware.com/entries/95444928

     

    I'm currently 

    1/ Adding a centralised location containing the core api to the sys.path

    2/ Import sgtk

    3/ Use the sgtk methods to find the pipeline config path from a work file path (in my case the .nk file passed from as an argument from the cmd line)

    4/ removing the previous path (/1) from the sys.path

    5/ Add the localised core path to the sys.path

    6/ reload the sgtk

    7/ Launch Nuke

     

    I'm not sure this is the best method. I'm not sure importing a module then reloading it is safe/fast.

     

    Regards

    Donat

  • 0
    Avatar
    Permanently deleted user

    Hello Donat,

    Would it be possible to use Shotgun to perform the lookup for you? That's what toolkit is doing behind the scenes pretty much! Here's a pseudo algorithm:

    1. get all local storages in Shotgun

    2. get Project.tank_name from all projects

    3. construct all permutations of the above to get all possible project roots

    4. look at the path you have and determine which root it belongs to

    5. see which project this root belongs to

    6. get the list of pipeline configurations for that project

    Here's something more concrete: 

    def pipeline_config_from_path(sg, path):
      """
      Resolves the pipeline configs for a path
      """
    
      platform_lookup = {"linux2": "linux_path", "win32": "windows_path", "darwin": "mac_path" }
    
      # get all local storages for this site
      local_storages = sg.find("LocalStorage",
                              [],
                              ["id", "code", "windows_path", "mac_path", "linux_path"])
    
      # get all pipeline configurations (and their associated projects) for this site
      pipeline_configs = sg.find("PipelineConfiguration",
                                [["project.Project.tank_name", "is_not", None]],
                                ["id", "code", "windows_path", "linux_path", "mac_path", "project", "project.Project.tank_name"])
    
    
      # extract all storages for the current os
      storages = []
      for storage in local_storages:
        current_os_storage_path = storage[ platform_lookup[sys.platform] ]
        if current_os_storage_path:
          storages.append(current_os_storage_path)
    
      # build a dict of storage project paths and associate with project id
      project_paths = collections.defaultdict(list)
      for pc in data["pipeline_configurations"]:
        for s in storages:
          # all pipeline configurations are associated
          # with a project which has a tank_name set
          project_path = os.path.join(s, pc["project.Project.tank_name"])
          # associate this path with the pipeline configuration
          project_paths[project_path].append(pc)
    
      # look at the path we passed in - see if any of the computed
      # project folders are determined to be a parent path
      for project_path in project_paths:
        # (like the SG API, this logic is case preserving, not case insensitive)
        if path.lower().startswith(project_path.lower()):
          # found a match! Return the associated list of pipeline configurations
          return project_paths[project_path]
    

     Do you think something like that would work? (beware, the above code is untested!

    Thanks!
    Manne

  • 0
    Avatar
    Donat Van Bellinghen

    Thanks for the bit of code

     

    Regards

    Donat

  • 0
    Avatar
    Donat Van Bellinghen

    Hi again Manne,

     

    I followed your advice and I'm now using the shotgun api to request the pipeline configurations for my project. What I now have :

     

    My custom hook to submit a .nk file to the render farm. This hook finds the current shotgun project id and transmits this information to the nuke render clients using an env var.

    When the nuke render clients are started they get this env var and using the shotgun api they get the associated pipeline configurations.

     

    This works nicely but what happens if I have more than one pipeline configuration ? What I'd like is to get the name of the current pipeline configuration path and transmit it to the render clients. So if I launch Nuke using a cloned config and then submit the script to the render farm, then the render clients will open the script with this same cloned config. 

     

    So I'm again looking at a proper way to find the current pipeline config being used in the currently running nuke engine. I've found a few 'dirty' ways to get this info but I hope there's an official way for this.

     

    Regards

    Donat

  • 0
    Avatar
    Permanently deleted user

    Hello Donat!

    How about including the name of the pipeline configuration in that env var where you are passing the project id? Then you can include that in your find query to limit the list of pipeline configurations that are returned from Shotgun!

  • 0
    Avatar
    Donat Van Bellinghen

    Yes, that's what I intend to do. In my submitter hook I want to retrieve the name of the currently used pipeline config. How do I retrieve this name ? I did not find a proper/official/documented way to do it... perhaps I did not look in the right place ?

    My current workaround is to fetch the current context, serialize it, then use a regex to find the pipeline config path inside the serialized context. 

    Regards

     

    Donat

     

  • 0
    Avatar
    Permanently deleted user

    Good point! :)

    My suggestion would be to use tk.pipeline_configuration.get_name() for the time being. I'll add a ticket to make sure this is exposed in more official way.

    Thanks for all the great questions!

    Manne

Please sign in to leave a comment.