Skip to content

feat: Add resolved template repository path as _repo_dir to the context#1771

Merged
ericof merged 2 commits intocookiecutter:mainfrom
tmeckel:feat/context-repo-dir
Sep 9, 2022
Merged

feat: Add resolved template repository path as _repo_dir to the context#1771
ericof merged 2 commits intocookiecutter:mainfrom
tmeckel:feat/context-repo-dir

Conversation

@tmeckel
Copy link
Copy Markdown
Contributor

@tmeckel tmeckel commented Aug 31, 2022

This PR contains a small change, which includes the resolved repository path from the determine_repo_dir as item _repo_dir to the Cookiecutter context.

This allows to define Python packages in the template and to reference them by extending the sys.path with normal import statements, e.g. in hook scripts.

Sample:

import os
import requests
import shutil
import sys

from dateutil import parser as dateparser

from subprocess import Popen

sys.path.append("{{ cookiecutter._repo_dir }}")  # <= extend sys.path

from utils.version import Version # <= use module from internal package

# Get the root project directory
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)

def _error_exit(msg):
    # exits with status 1 to indicate failure
    sys.stderr.write("ERROR: %s\n" % msg)
    sys.exit(1)

* Add resolved template repository path as _repo_dir to the context
* corrected test test_echo_undefined_variable_error to check for new context item _repo_dir
@tmeckel
Copy link
Copy Markdown
Contributor Author

tmeckel commented Sep 7, 2022

Someone @audreyfeldroy, @browniebroke, @ericof, @hackebrot, @insspb, @pydanny, @simobasso, @ssbarnea up to for a review of this mini PR, consisting of one line? 😁

Copy link
Copy Markdown
Member

@ericof ericof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ericof ericof merged commit cf81d63 into cookiecutter:main Sep 9, 2022
@tmeckel tmeckel deleted the feat/context-repo-dir branch September 9, 2022 12:05
@tmeckel
Copy link
Copy Markdown
Contributor Author

tmeckel commented Sep 9, 2022

@ericof Érico when will this be available in a new release i.e. when will there be a new release?

@ericof
Copy link
Copy Markdown
Member

ericof commented Sep 9, 2022

@tmeckel We will sprint on the next weeks to get a new release out

@klaraward
Copy link
Copy Markdown

Hoping for this change in a new release soon :)

@klaraward
Copy link
Copy Markdown

Before this is released, is there any workaround whatsoever to get access to this in a hooks script?

@klaraward
Copy link
Copy Markdown

@ericof any hope a of release soon? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants