copier icon indicating copy to clipboard operation
copier copied to clipboard

Shouldn't `_src_path` be stored as absolute path?

Open ppo opened this issue 4 years ago • 6 comments

When creating a project using a local path, shouldn't it be stored as absolute path in the answers_file?

If created using copier . /path/to/destination, it's saved as _src_path: ..

One can do it "auto-manually" using copier "$PWD" /path/to/destination.

ppo avatar Jan 30 '21 13:01 ppo

That's not by design currently, but by accident. However it seems to be a good design, because if you share the project and you know that the template resides next to it in ../template, having a relative path can be helpful.

In any case, if you end up producing a copier-answers file, it means that you support updates. And the requirements for supporting updates is that your source template is a git repo with tags (otherwise there's no way to generate a smart diff, thus the update itself will be broken), so your use case is probably wrong by design anyway.

There's still the possibility that it's a local git repo. In that case, I'm still not sure what'd be better... 🤔

yajo avatar Feb 01 '21 08:02 yajo

I guess that if you generate it from a local path, the project is not supposed to be portable/used by someone else.

If it must be portable, the template source should be an URL… otherwise it's probably only accessible by you anyway.

It could be useful to have a command to change the template source… with "use at your own risk".

BTW, is it safe to change that, just that, manually in the answers file?

ppo avatar Feb 01 '21 10:02 ppo

BTW, is it safe to change that, just that, manually in the answers file?

I think so.

In any case, this is a real issue because even if we want relative paths, those should be relative to the project, not to the CWD.

yajo avatar Feb 01 '21 15:02 yajo

As it's a choice, there should be an option, right?

Like --template-src="VALUE", where the value can be:

  • absolute
  • relative
  • the value to use

If that option is passed to update, Copier uses that instead of _src_path and the answers file is updated accordingly.

absolute|relative, are based on the template_src during creation and on the CWD during updates.

ppo avatar Feb 02 '21 06:02 ppo

I ran into the same problem. Storing the path relative to CWD (I got '.') is not of much use. Storing the path as both relative to project and as absolute would be great, then the project could be moved, either independently from the template, or they could be moved together. Adding the --template-src="VALUE" is also a good idea. And yes, generally it is a URL (which can be a file url), så maybe the _src_path should be renamed to _src_url?

lhupfeldt avatar Jul 20 '22 12:07 lhupfeldt