question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trouble deploying Extra context example using the Advanced Usage docs

See original GitHub issue

I am having difficulty running the Advanced example Defaults + Extra Context, using the docs.

I have created a minimal reproducible example using this project.

$ mkdir cookiecutter-fabric-esneor
$ cd cookiecutter-fabric-esneor
$ mkdir {{cookiecutter.directory_name}}
$ cd {{cookiecutter.directory_name}}

Here is my cookiecutter.json:

    {
    "fabric_type": "Vbox",
    "username": "Tom Smith",
    "user": "{{cookiecutter.username.lower().replace(' ','')}}",
    "timestamp": "{{cookiecutter.timestamp}}"
    }

Here is my cookiecutter_runner.py (based on this):

from cookiecutter.main import cookiecutter

from datetime import datetime

cookiecutter(
    'Hello',
    extra_context={'timestamp': datetime.utcnow().isoformat()}
)

My tree is (based on this layout):

$ cd ~
$ tree
cookiecutter-fabric-esneor/
├── {{cookiecutter.directory_name}}/
    └── {{cookiecutter.directory_name}}.sh
└── cookiecutter.json
└── cookiecutter_runner.py

This is the contents of {{cookiecutter.directory_name}}.sh:

#!/bin/bash
echo "{{cookiecutter.timestamp}}"

When I run

$ cd ~
$ cookiecutter cookiecutter-fabric-esneor

I get this:

fabric_type [Vbox]:
username [Tom Smith]:
user [tomsmith]:
directory_name [fab_dir]:
Unable to render variable 'timestamp'
Error message: 'dict object' has no attribute 'timestamp'
Context: {
    "cookiecuttter": {
    .
    .
    .
    "timestamp": "{{cookiecutter.timestamp}}"
    }
}

It’s a pretty basic project and I’ve followed the documentation instructions but it seems like something is missing in the {{cookiecutter.directory_name}} directory.

Is there another page in the documentation that has a full example of how to use the Extra Context?

  • Cookiecutter version: 1.6.0
  • Python version: 2.7.14
  • Operating System: Ubuntu 17.10

EDIT: I hope you don’t mind me adding the 2 proposed labels to the title. I thought it would be helpful when reading this post.

cookiecutter.json is missing: "directory_name": "fab_dir"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hackebrotcommented, Nov 28, 2017

Based on the information that you provided cookiecutter_runner.py will not be executed when running cookiecutter. What you want to do is run the script directly rather than calling cookiecutter directly from the CLI and update the template argument accordingly.

from datetime import datetime

from cookiecutter.main import cookiecutter

def run():
    template = os.path.dirname(os.path.realpath(__file__))

    cookiecutter(
        template,
        extra_context={
            'timestamp': datetime.utcnow().isoformat(),
        },
    )


if __name__ == '__main__':
    run()
$ python cookiecutter-fabric-esneor/cookiecutter_runner.py
0reactions
edeszcommented, Jun 18, 2021

Apologies for the late reply…this issue was based on an advanced example from the docs. So, I think that it might not be very useful for most uses of cookiecutter. Also, there is a new context format in development (see #1566) - it may be a good idea to wait until that is implemented and see if that helps with your workflow (maybe you don’t need to use the approach from this issue when the new format takes effect).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble deploying Extra context example using the Advanced ...
I am having difficulty running the Advanced example Defaults + Extra Context, using the docs. I have created a minimal reproducible example ......
Read more >
Protect your business with Context-Aware Access
Using Context -Aware Access, you can create granular access control security policies for apps based on attributes such as user identity, location, ...
Read more >
Access Context Manager Overview | Google Cloud
Access Context Manager allows Google Cloud organization administrators to define fine-grained, attribute based access control for projects and resources in ...
Read more >
Manage functions | Cloud Functions for Firebase - Google
You can deploy, delete, and modify functions using Firebase CLI commands or by ... If your project contains more than 5 functions, we...
Read more >
Environments and deployments - GitLab Docs
However, when you use this format, you can group similar environments. Some variables cannot be used as environment names or URLs. For more...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found