Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: access dst_path in question context? #1050

Open
tlambert03 opened this issue Mar 22, 2023 · 2 comments
Open

feature: access dst_path in question context? #1050

tlambert03 opened this issue Mar 22, 2023 · 2 comments

Comments

@tlambert03
Copy link
Contributor

Is your feature request related to a problem? Please describe.

I'd like to be able to provide a default project name, based on the name of the destination path that the user provided on the cli

This looks a lot like the discussion in #20 ... but that was closed, and it's not entirely clear to me whether/how the intended goal was achieved.

Describe the solution you'd like
I'd like to be able to use something like this, to initialize a value based on the command line dest path arguments

project_name:
  help: Name of your project
  default: "{{ dst_path | basename }}"

Describe alternatives you've considered

I've considered using the context hook extensions to hack at sys.argv

Additional context

@sisp
Copy link
Member

sisp commented Mar 22, 2023

I’m afraid it’s currently not possible to access the destination path in the questionnaire.

A question only has access to answers to other questions:

copier/copier/main.py

Lines 363 to 368 in 42a34bf

question = Question(
answers=result,
jinja_env=self.jinja_env,
var_name=var_name,
**details,
)

Additional variables such as _folder_name, which is what you’re interested in, are currently only available in the render context after the questionnaire has been completed:

copier/copier/main.py

Lines 252 to 259 in 42a34bf

return dict(
DEFAULT_DATA,
**self.answers.combined,
_copier_answers=self._answers_to_remember(),
_copier_conf=conf,
_folder_name=self.subproject.local_abspath.name,
_copier_python=sys.executable,
)

But I believe it‘s possible to extend Copier to provide at least a subset of these variables also to the render context of a question.

I think it’s an interesting use case.

WDYT, @yajo?

@yajo
Copy link
Member

yajo commented Apr 7, 2023

Yes, makes sense. At least for the things that are known at that point.

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

No branches or pull requests

3 participants