I've disabled the use of unsafe features (Jinja extensions, migrations, and tasks) by default and added a new CLI switch `--UNSAFE` which enables them. Templates that don't use unsafe features are unaffected by this change. But Copier will raise an error for templates that do use unsafe features unless the `--UNSAFE` flag is passed.
I've not added an interactive prompt that asks for consent for using unsafe features because I think it's not clear how to distinguish between interactive prompting and raising an error when `--UNSAFE` is not passed. For this, I think Copier would need a switch that clearly states whether interactive or non-interactive mode is desired. Currently, `--defaults` implies this for questions.
Fixes https://github.com/copier-org/copier/issues/1137
BREAKING CHANGE: Copier raises an error when a template uses unsafe features unless the `--UNSAFE` switch is passed
* refactor(tests): add type hints and clean up
* fix: import `Protocol` from `typing-extensions` when using Python 3.7
* fix: import `Literal` from `typing-extensions` when using Python 3.7
* refactor(tests): create template and subproject directory using `tmp_path_factory` fixture
* refactor(tests): use OS-agnostic file path separator
* refactor(tests): use `/` separator for `skip_if_exists` paths
* style: fix formatting error
* refactor(tests): expect POSIX path for local repo URL
In https://github.com/pypa/packaging/issues/530 the packaging project stopped suplying legacy versions when a tag wasn't valid. Then, some repos started failing because they were relying on this.
For example, see https://github.com/Tecnativa/doodba-copier-template/issues/361.
This change makes sure that invalid versions are skipped, so people can still update and those repos just keep working.
The workaround until now is to specify a `--vcs-ref` option, to avoid Copier have to checkout the latest tag automatically (which is the code that triggers the bug).
@moduon MT-2379
* refactor: check if the repository is a shallow clone
* refactor: emit a warning for shallow clones
* docs: add faq entry for high resource consumption with shallow clone
* refactor: define a specific warning for shallow clones
* fix: lint after rebase
- Provide a dev shell.
- Provide a nix package.
- Provide a nix flake.
- Development environment based on direnv.
- Docs.
- Configure Gitpod to use direnv and nix.
- Configure Cachix out of the box, and document how to use it.
- Add direnv and nix to CI.
- Satisfy some linters that came from Precommix, even when Precommix was later discarded.
- Mark some tests as impure.
- Run only pure tests when building Copier with Nix.
- Add poetry loader to direnv.
- Update contribution guide.
* fix(vcs.py): Added additional values to GIT_PREFIX to accept https:\\github.com and https:\\gitlab.com. Added handler in get_repo() to add .git to the end of the url if it didn't exist and started with one of those two prefixes. Resolves#217
Accounts for passing github or gitlab urls without the .git suffix to prevent vcs.get_repo from returning None
Resolves#217
* test(test_vcs.py): Added tests cases to support accepting https://github.com and https://gitlab.com urls in vcs.get_repo()
* test(test_vcs.py): based on #677 (comment), we expect the returned url to appropriately append .git. Updated test cases to account for this.
* fix(vcs.py): Corrected the argument being passed to the join() method in get_repo to be a single tuple of strings vice multiple strings since join() takes a single iterable as an argument.
* fix(vcs.py): Corrected the elif statement in get_repo() to join the url with ".git" vice GIT_PREFIX since GIT_PREFIX is of type tuple and join() requires an interable of strings as an argument.
* fix(vcs.py): Change GIT_POSTFIX to a string instead of a tuple.
* style(vcs.py and test_vcs.py): cleanup to pass test_lint()
* style(test_vcs.py): cleanup to pass test_lint()
* style(test_vcs.py): cleanup to pass test_lint()
- Ignore errors when executing `shutil.rmtree()`, because it seems like it's common to fail when deleting git repos on Windows, and since these are temp files, we don't really care that much there's garbage left. Any good OS should clean the temp folders automatically.
- Always find Jinja templates in `PosixPath` mode.
- Ignore `OSError` when trying to enter a possibly git root directory. This is yielded by Windows when the path is a URL and we don't really care about it.
- Fix some tests with non-windows hardcoded stuff.
- Fix a test that was using a Bash script. Modified to be Python, which should work fine cross-system.
- Remove external python dependencies (yaml, plumbum) from test task/migration files. These are available on Linux because it gets the python env from the venv, but on Windows, it uses the main python interpreter and breaks. After all, that's not very important here.
- Do not modify EOL in CI.
- Use python executable in tests instead of python3.
- Update pre-commit versions to include https://github.com/pre-commit/pre-commit-hooks/pull/509.
- Disable autorebasing.
- Disable pre-commit on CI on Windows.
- Require python 3.8 on Windows, where `tempfile` supports autoremoving directories with read-only files.