String inputs to packaged python transforms in marketplace

I have a transform in a python code repository that I would like to package in marketplace and deploy to test/prod environments. Some of my code has environment-specific logic (e.g. append the name of the environment to certain resources, don’t make API calls in test environment, etc), so when I deploy my marketplace product I would like to pass in the name of the environment as a parameter. What is the best way to accomplish this?

Hi @dherls,

You can get Gradle to create a file with the variable for you, by adding something like this to your build.gradle:

task generateNamespaceConfig {
    def outputFile = file("python/python_functions/_config.py")
    outputs.file(outputFile)
    outputs.upToDateWhen { false }

    doLast {
        def namespaceUrls = [
            "dev"    : "https://dev.somethingsomething.com",
            "staging" : "https://staging.somethingsomething.com/"
        ]
        def url = namespaceUrls[project.repositoryOrg]
        if (url == null) {
            throw new GradleException("Unknown namespace: ${project.repositoryOrg}")
        }
        outputFile.text = "NAMESPACE_URL = \"${url}\"\n"
    }
}

build.dependsOn generateNamespaceConfig
check.dependsOn generateNamespaceConfig

You then import NAMESPACE_URL from _config.py and use that in your code. It will create/overwrite that file with the URL from the mapping. Or you can return project.repsitoryOrg if you want to handle the mapping elsewhere.

Note that given how git works in Foundry, you might need to commit the new file after the first build, but that’s a one time thing.