Quick question about creating a custom Kedro start...
# plugins-integrations
g
Quick question about creating a custom Kedro starter. How do you pass the credential you enter at prompt (kedro new --starter=mystarter) to conf/local/credentials.yml ?
d
So you need to edit prompts.yml, add the scope to
cookiecutter.json
, then use
{{variable}}
jinja sytnax to template it into your creds file
thankyou 1
Now, there is a question on whether that’s the best way to do it - I think environment variables are a better strategy heere
g
Thank you for the suggestion. I tried approach one as the following:
Copy code
# prompts.yml
my_token: 
  title: "My Token"
  text: |
    Please enter a token
# cookiecutter.json
{
    "project_name": "New Kedro Project",
    "repo_name": "{{ cookiecutter.project_name.strip().replace(' ', '-').replace('_', '-').lower() }}",
    "my_token": "{{ mytoken }}",
}
but I got an error when using token: {{my_token}} in credentials.yml
Copy code
Error: Failed to generate project when running cookiecutter.
d
is that the whole error?
g
Copy code
kedro.framework.cli.utils.KedroCliError: Failed to generate project when running cookiecutter.
Run with --verbose to see the full exception
Error: Failed to generate project when running cookiecutter.
d
can you run with --verbose
g
Copy code
raise UndefinedVariableInTemplate(msg, err, context) from err
cookiecutter.exceptions.UndefinedVariableInTemplate: Unable to render variable 'my_token'. Error message: 'mytoken' is undefined. Context: OrderedDict([('cookiecutter', OrderedDict([('project_name', 'xx'), ('repo_name', "{{ cookiecutter.project_name.strip().replace(' ', '-').replace('_', '-').lower() }}"), ('python_package', "{{ cookiecutter.project_name.strip().replace(' ', '_').replace('-', '_').lower() }}"), ('my_token', '{{ mytoken }}'), ('kedro_version', '0.18.13')])), ('_cookiecutter', {'project_name': 'xx', 'repo_name': "{{ cookiecutter.project_name.strip().replace(' ', '-').replace('_', '-').lower() }}", 'python_package': "{{ cookiecutter.project_name.strip().replace(' ', '_').replace('-', '_').lower() }}", 'my_token': '{{ mytoken }}', 'kedro_version': '0.18.13'})])
d
okay I think you need to change things:
Copy code
{
    "project_name": "New Kedro Project",
    "repo_name": "{{ cookiecutter.project_name.strip().replace(' ', '-').replace('_', '-').lower() }}",
    "my_token": "{{ cookiecutter.mytoken }}",
}
g
thanks, tried this, same error
fyi, I had
Copy code
# credentials.yml
my_cred:
      token: {{ my_token }}
d
did the cookiecutter prefix in both not help?
g
Unfortunately, no
n
I only see this now, it should be
my_token
right?
mytoken
is not defined anywhere.
Copy code
"my_token": "{{ cookiecutter.my_token }}",
g
Thanks for looking into it. It was a typo in my question. It didn't work because Kedro doesn't give access to credentials.yml except for data catalog.
d
Is there anything we could have done to make the error message clearer?