The `.tmpl` suffix doesn't seem to be a very widely adopted standard on the Jinja world. Others like `.jinja` or `.j2` usually have better IDE integration.
It's not like `.tmpl` is a wrong default, so here I'm leaving it as a default but letting template developers to change it to another one that fits better their environment.
Apart from this, if you really had to produce any `.tmpl` files in your copies, having files that ended with `.tmpl.tmpl` seemed a bit weird, while now you can change that suffix to whatever fits better your project.
@Tecnativa TT20357
Without this patch, a full traceback is printed when the user hits <kbd>Ctrl</kbd> + <kbd>C</kbd>.
Now it's more elegant. Other exceptions supported also.
@Tecnativa TT20357
The initial implementation in https://github.com/pykong/copier/pull/103 was calling the file logfile, but it was renamed to copier-answers later.
However I discovered there are still a few remainders of the old implementation.
Here I remove them.
@Tecnativa TT20357
Fix#89 and fix#89 by adding a new extended syntax to make prompts way more usable.
Leverages plumbum's helpers, so prompt code is removed from Copier codebase, making it smaller BTW.
See README and the new test to understand the new features.
@Tecnativa TT20357
Continues the job started in #104:
- Configure more languages for VSCode to format on save.
- Recommend extensions for VSCode.
- Remove settings from `.prettierrc.yml` that are duplicated in `.editorconfig` (which prettier uses by default).
- Add ignore comment on `BaseModel` instances that are correctly following what `pydantic` wants, to let flake8-bugbear be happy.
- Remove unused import.
OK, now this diff is very big, but it's actually modifying only style, not code functions themselves. From now on, this won't have to happen again.
Basically I just ran `pre-commit run --all-files` and committed that. I hope you like how it looks now!
Pre-commit by default adds a single `\n` EOF to all files, but we have some tests that make sure that isn't done by Copier itself.
This specific behavior is committed separately to keep track of it. I'm adding an exclusion filter for files named `whatever.noeof.suffix`, and those are skipped by the `end-of-file-fixer` hook.
Also tests had to be changed accordingly. Nothing too special.
For those new to pre-commit, tl;dr:
- `pre-commit install` will enable a git hook to forbid committing violating code.
- If `git commit` fails, just `git commit -a` again.
This beautiful tool will convert all our source code to a pleasure to be read and written.
Some insights:
- `make install` now enables pre-commit by default.
- Important hooks:
- Black, the 21th century Python code autoformatter.
- isort, to sort imports automatically.
- mypy, which was also being used anyways.
- Prettier, for non-python files (markdown and YAML in this repo).
- Flake8 with bugbear, which reveals some extra coding mistakes.
- Other common checkers & fixers.
- Used as linter in travis.
- Replaced `make flake` for `make lint`.
This is a totally breaking PR. It had to come sooner or later...
Before this patch, copier had some ugly problems:
- If a file was called `--exclude`, you couldn't add it to `--extra-paths` due to using `nargs='*'` in an option. It is a weird thing that `ArgumentParser` allows to do, but can potentially lead to unfixable problems.
- Argument parsing was a little bit handycraft work.
Meet [Plumbum](https://plumbum.readthedocs.io/), the swiss army knife for CLI packages:
- CLI has been refactored as a plumbum application.
- Tests for CLI parsing removed, since they were incompatible and we are using a well-tested CLI parsing library now after all.
- The application now includes 2 subcommands: `copy` and `update`.
- If called without args, or with 1, it will use `update`.
- If called with 2 args, it will use `copy` (this preserves old usage unchanged, unless you are copying from a template called `copy` or `update`; in such corner case, just call it as `copier copy copy destination` instead).
- `copier --help` and `copier --help-all` are more useful now.
And you might be wondering... Adding such a big dependency just for that? Well, actually plumbum supports more than just CLI applications: supports sane execution of local & remote commands, sane output coloring, sane user prompting... Possibly it will make Copier go to the next level as we keep on using it more. Just take a look at its docs! You'll love it 😉
Of course, all that new CLI had to be reflected in API changes:
- `src_path` is now optional (`None` by default). In such case, copier will try to guess the `src_path` from the `.copier-answers.yml` file in the copy, or fail otherwise.
- `dst_path` is also now optional (`.` by default), meaning that without a `src_path`, you'll be trying to copy anything else to current `$PWD`.
- The builtin `_log` variable, which contains all necessary data for copy updates, now has also a `_src_path` key that points to the original source. This only happens when it was copied from a git repo or from an absolute path in the local disk, as relative paths are not easily reproducible in next updates (they depend on the user's CWD when running copier).
- A new `original_src_path` variable goes around, indicating the git repo or abs system path passed to `src_path` on the initial call. This is just to be stored in `_log` as explained.
```bash
copier gh:example/template destination
cd destination
echo my changes >> anywhere
git commit -m changing .
copier # Equals to `copier update .`
git commit -m 'copier update' .
```
🎉 You're updated!
This is an importan step to complete #88.
@Tecnativa TT20357
- If the copy destination exists and has a `.copier-answers.yml`, all questions asked in the template `copier.yml` file will get the answer found in `.copier-answers.yml` by default.
- For now, there are no `_private` variables in the copier-answers, but in the future there might be, so I'm documenting that now.
- Add docs for some of Copier's hidden features.
- Add `to_nice_yaml` filter, to be able to dump beautiful YAML. [This name matches that on Ansible](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data) just in case somebody wants to share templates among both engines, although do not take that as an official support statement.
- Add a test that copies a folder with default data, then copies with altered data, and then copies again with default data and still the altered values have been used.
- This is a partial improvement towards completion of #88.
@Tecnativa TT20357
- Alter comments syntax to match project templating syntax: `[# This is a comment now #]`.
- Document and test the way to restore Jinja2 default syntax. This is not obvious otherwise.
- Update Jinja docs location.
@Tecnativa TT20357