copier icon indicating copy to clipboard operation
copier copied to clipboard

dst_path has inconsistent behavior

Open MigQ2 opened this issue 1 year ago • 2 comments

Describe the problem

I am creating a template where I am trying to use {{ _copier_conf.dst_path | basename }} to get the name of the repository that is rendering the template

When I copy the project intially, it gets correctly rendered as the repo name

However, when I run an update, it gets replaced with something like copier.main.new_copy.nstvyoqn

Is this by design or is this a bug?

I didn't find detailed documentation about dst_path, I see it's used in this example but I don't see it formally documented in the available settings

Expected behavior

I would like {{ _copier_conf.dst_path | basename }} to always be rendered as my destination repo name

Operating system

Linux

Operating system distribution and version

Ubuntu 22.04.3 LTS (running on WSL)

Copier version

9.4.1

Python version

3.10

Installation method

pipx+pypi

MigQ2 avatar Oct 29 '24 23:10 MigQ2

It isn't advisable to use the dst_path variable in most cases because its value isn't stable as you noticed and even less so because the path might differ when you moved your local project directory to a different location or another developer cloned the project elsewhere. The example you linked to merely uses the dst_path variable in a message template; that's a different use case.

What's your use case? Does it happen to be related to #1839 and #1617? Are you migrating from Cookiecutter?

sisp avatar Nov 04 '24 15:11 sisp

Note that there is an (undocumented) template variable called _folder_name, which should provide what you are looking for.

lkubb avatar Nov 08 '24 12:11 lkubb