76 Commits

Author SHA1 Message Date
Sigurd Spieckermann
ef5ea4b212 refactor: rename internal modules with a _ prefix 2025-04-22 13:52:51 +02:00
Sigurd Spieckermann
b42a032f7b style: fix formatter and linter errors 2025-04-22 12:20:23 +02:00
Axel H.
1dabe8eb1e
feat(context): expose a _copier_phase context variable 2025-03-02 16:40:57 +01:00
danieleades
1c2f8d8b08
style: use pathlib 2025-02-26 17:42:21 +01:00
Sigurd Spieckermann
b5ef194328 feat: add support for dynamic choices 2024-10-18 19:41:34 +01:00
Sigurd Spieckermann
2421d77e08 fix: validate answers to secret questions 2024-09-21 06:52:16 +01:00
Sigurd Spieckermann
0258635da7 fix: support Git config without user identity 2024-07-30 13:40:17 +02:00
Andras Gefferth
10fbbccaa7
fix: do not overwrite identical files (#1576) 2024-04-21 11:54:45 +02:00
danieleades
0c6b0b96fe
build(typing): enable 'strict' mypy linting (#1527)
---------

Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
2024-03-23 12:58:20 +01:00
Sigurd Spieckermann
4ff30e8a98 feat: add support for validating multi-select choice answers 2024-03-09 20:06:02 +00:00
Sigurd Spieckermann
475c12008f fix: preserve choices order in answers to multi-select choice questions 2024-02-26 15:10:56 +01:00
danieleades
878c4d4f40
style: add 'flake-future-annotations' lint group (#1506)
* add ruff 'flake8-future-annotations' (FA) lint group
2024-02-22 06:19:17 +00:00
danieleades
74bba547c2
chore(ruff): add pygrep lint group (#1505)
* add 'pygrep' lint group

* fixup
2024-02-11 14:37:11 +01:00
Sigurd Spieckermann
e97d6732b8 fix: fix answer validation for type: str questions 2023-10-01 12:27:14 +01:00
ChaCha
e38caa20cc
fix: version guess from tags that don't start with v, but are still PEP440 compliant (#1048)
Without this change, Dunamai by default needs tags to be prefixed with a 'v'. ie: v0.1.2 v1.1.2 ...

Fixes https://github.com/copier-org/copier/issues/1042.

Co-authored-by: cclecle <clement.chastanier@gmail.com>
Co-authored-by: Jairo Llopis <yajo.sk8@gmail.com>
2023-10-01 07:32:31 +00:00
Sigurd Spieckermann
75b893108b fix: fix answer validation against conditional choices with duplicate values 2023-07-11 07:42:16 +02:00
Sigurd Spieckermann
83f44cb4b6
feat: disable unsafe features by default and add --UNSAFE switch (#1171)
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
2023-06-01 18:22:40 +00:00
Jairo Llopis
6996b9cc7a feat: add recopy command and function
This new command allows to reapply a template, keeping old answers but discarding subproject evolution.

It is useful when there are bugs replaying an old version of the template, or when the subproject has drifted too much from the template and you need to reset it.

BREAKING CHANGE: All CLI calls to Copier must now include the subcommand as the 1st argument. For example, `copier` must become now `copier update`; also `copier ./tpl ./dst` must become `copier copy ./tpl ./dst`.

BREAKING CHANGE: All flags must go after the subcommand now. For example, `copier -r HEAD update ./dst` must now become `copier update -r HEAD ./dst` or `copier update ./dst -r HEAD`.

BREAKING CHANGE: Automatic mode removed. Since now subcommands are required, the automatic mode is removed.

BREAKING CHANGE: Deprecated `copier.copy` function is removed. Use `copier.run_copy`, `copier.run_update` or `copier.run_recopy` explicitly as needed.

Fix https://github.com/copier-org/copier/issues/1081
Close https://github.com/copier-org/copier/issues/1082
2023-05-17 11:56:13 +01:00
Sigurd Spieckermann
f6f37ab4fb
feat: support conditional choices (#1010)
Choices can now be validated with a custom inline jinja template.

Disabled choices won't be selectable, and they display a message telling why.
2023-05-04 09:13:18 +01:00
Sigurd Spieckermann
d16f49ae57 fix: work around Pydantic bug when parsing choices 2023-05-02 15:48:11 +01:00
Sigurd Spieckermann
aca16a020b
fix: skip validating question and generating its default value when its skip condition is met
I've indirectly fixed the validation of answers to questions for which the skip condition is met. Before, a question with a truthy skip condition was not properly skipped such that (a) its default value (if present) was still validated and could cause a validation error or (b) an error was raised that the question was required although it should have been skipped. As a side effect of the previous implementation (which didn't properly skip questions), answers of skipped questions were recorded in the answers file which IMO makes no sense.

I've changed the way skipped questions are handled such that the skip condition is evaluated early and the question is immediately skipped when the skip condition is truthy. To prevent records of such answers in the answers file, e.g. when they originate from previous runs, when they are provided by the user via the `--data` flag, etc., any answers in the internal answers map are removed (or rather marked as removed). As a result, I needed to adapt a few tests and even removed one that specifically tested for the presence of those records in the answers file.

This new behavior should be backwards compatible and is more logical in my opinion. As a side effect, some slightly confusing code block could be removed which handled some special case of using a templated default answer.

Fixes #1125.
2023-05-02 15:45:44 +01:00
Sigurd Spieckermann
ed38f24487
feat: validate default values (#1075)
BREAKING CHANGE: default values must be of the same type than the question.
2023-04-23 06:31:06 +01:00
Sigurd Spieckermann
14fa78a1dc fix: fix using a branch name as VCS ref 2023-04-19 17:30:31 +01:00
Sigurd Spieckermann
bd450b5db6
fix: answer validation for question with complex choices (#1110)
I've fixed a bug related to answer validation of questions with complex choices. Previously, choice values were collected in a set which requires the choice values to be hashable. But complex choice values such as dict or list values aren't hashable. Now, they are collected in a list.

Fixes #1108.
2023-04-19 06:02:32 +01:00
Sigurd Spieckermann
065d6ba1d0
fix: require answer for questions without default value (#958)
When questions didn't have a default answer, the interactive behavior was confusing.

Fixes https://github.com/copier-org/copier/issues/355.

BREAKING CHANGE: All default answers must be explicit now.
2023-04-07 08:09:27 +01:00
Adrian Freund
0f610be801
feat: support preserving symlinks when copying templates (#938)
* feat: Preserve symlinks when copying templates

* test: Add tests for symlink copying
2023-04-07 08:03:17 +01:00
Sigurd Spieckermann
b352841046 test: add return type hints 2023-03-31 06:27:36 +01:00
Sigurd Spieckermann
5029b6e7a9
test: add type hints and clean up (#985)
* 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
2023-03-21 16:31:11 +00:00
Sigurd Spieckermann
37388f9637
feat: validate answers given via CLI/API 2023-02-14 09:19:58 +00:00
Raphael Krupinski
20a13b98f4
feat: add native OS directory separator variable in _copier_conf.sep to allow generating dynamic directory structures
* feat(Worker): make sure the parent directory of the target file exists before writing to it
* feat(_copier_conf): add directory separator (os.sep) to _copier_conf

Fix #692
2023-01-27 12:11:11 +00:00
Jairo Llopis
67cc4ffde3
feat: nix support
- 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.
2023-01-18 09:40:08 +00:00
Jairo Llopis
04c99e85a9 feat: support getting template commit hash with {{ _copier_conf.vcs_ref_hash }}
When targeting reproducible builds, we need to have exact and immutable hashes.

Until now, there was only one way to get template commit. You could only get the tag, or the best serializable approach to obtain a commit from a tag.

Using this new helper, you can get what you need.
2022-06-13 10:44:04 +01:00
mshafer-NI
dc042a385a
fix: ignore non-PEP-440-compliant tags (#676)
* test: make test that on-version tags are ignored

* fix: don't assume tags are valid versions

* fix: test naming

* test: using non-version tag as vcs-ref

Fixes https://github.com/copier-org/copier/issues/675.
2022-05-26 17:17:27 +01:00
Jairo Llopis
e3d8e2e170 fix: inherit permissions
When copying a file, make sure its permissions are the same as those of the file in the template.

Fixes https://github.com/copier-org/copier/issues/361.
2021-07-02 16:24:41 +01:00
Dennis Roche
a1fcccf906 test: Replace force=True with defaults=True, overwrite=True 2021-07-02 15:34:51 +01:00
Jairo Llopis
1482de4972
wip 2021-03-05 17:33:11 +00:00
Jairo Llopis
b3190c2abf Ensure empty-named dirs work as expected
Fix #285 and fix #350.
2021-02-12 08:28:47 +00:00
Jairo Llopis
0441b86f0c
Refactor (#314)
* Refactor
* Fix #110.
* Rewrite test_config_exclude, test_config_exclude_overridden and test_config_include. These tests were badly designed, using a monkeypatch that would never happen in the real world, and actually producing false positives. I moved them to test_exclude.py and rewritten to test the what and not the how.
* Fix #214 by removing skip option. Relevant tests use the better skip_if_exists=["**"].
* Remove subdirectory flag from API/CLI. It was confusing and could lead to bad maintenance situations. Fixes #315.
* Remove extra_paths and fix #321
* Remember that you cannot use _copier_conf.src_path as a path now
* use dataclasses
* Create errors module, simplify some tests, fix many others
* Fix some tests, complete EnvOps removal
* Fix #214 and some tests related to it
* Reorder code
* Update docs and imports
* Modularize test_complex_questions
* Interlink worker and questionary a bit better
* Removal of Questionary class, which only had 1 meaningful method that is now merged into Worker to avoid circular dependencies.
* Fix #280 in a simple way: only user answers are type-casted inside API, and CLI transforms all `--data` using YAML always. Predictable.
* Use prereleases correctly.
* Reorder AnswersMap to have a more significative repr.
* Simpler cache for old `Question.get_choices()` method (renamed now).
* fix wrong test
* Fix test_subdirectory
* Fix test_tasks (and remove tests/demo_tasks)
* Fix path filter tests, and move it to test_exclude, where it belongs
* Make test_config pass
* Fix more wrongly designed tests
* Use cached_property backport if needed
* xfail test known to fail on mac
* force posix paths on windows
* Add typing_extensions for python < 3.8
* Sort dependencies in pyproject.toml
* Support python 3.6 str-to-datetime conversion
* Workaround https://bugs.python.org/issue43095
* xfail test_path_filter on windows
* Upgrade mkdocs and other dependencies to fix https://github.com/pawamoy/mkdocstrings/issues/222
* Add missing reference docs.
* Add workaround for https://github.com/pawamoy/mkdocstrings/pull/209
* Docs.
* Remove validators module
* Add workaround for https://github.com/pawamoy/mkdocstrings/issues/225
* Restore docs autorefs as explained in https://github.com/pawamoy/mkdocstrings/issues/226#issuecomment-775413562.
* Workaround https://github.com/pawamoy/pytkdocs/issues/86
2021-02-09 18:22:47 +00:00
Jairo Llopis
cda93273c1
Enhanced user input (#260)
* use a new toolkit for user prompting: questionary (patched).
* multiline questions.
* conditional questions.
* new toolkit for ui tests: pexpect.
* fix lots of tests.
* fix windows builds with newer poetry-dynamic-versioning.
* linters and mypy are now tests, to have faster ci.
* update deprecated ci commands.
* removed dependencies from old times.
* Remove toml 0.5+ syntax (dotted keys)
* Use powershell where syntax is compatible
* Change skip to xfail
* xfail pexpect tests on windows. I'm tired of trying to make it work
* more docs
* possibly something more.
2020-10-12 08:56:46 +01:00
Jairo Llopis
b479cb9804 Make exclude extend if called from CLI/API
When adding the `exclude` option from CLI/API, it extends the definitions found in `copier.yml`.

When adding it in `copier.yml`, it replaces the defaults.

Fixes #215, which explains that it was very unexpected that excluding some extra things included a lot of other things by accident.
2020-09-18 10:55:09 +00:00
Jairo Llopis
a0d6173347 Skip irreverent test on Mac OSX
TODO Get some happy Mac hacker that fixes this for us.
2020-08-08 15:27:56 +00:00
Jairo Llopis
00791ccf7d Fix encoding error in Mac OS
Partially revert 97c75e44025c5ecf886cf67d428161a0c61e7f29.
2020-08-08 15:27:56 +00:00
Jairo Llopis
45c5f0d90b Fix failing tests
https://github.com/jpscaletti/siht disappeared, so these tests were failing now. Fixed by using own copier repo to test.
2020-07-21 08:26:35 +00:00
Jairo Llopis
823f3a1935 Remove dst fixture
This is redundant with pytest's native `tmp_path` fixture, so we use that one instead now.
2020-06-23 07:58:03 +00:00
Timothée Mazzucotelli
c4b38a1ec6 Add subdirectory option
Co-authored-by: Jairo Llopis <Yajo@users.noreply.github.com>
2020-05-20 19:41:10 +02:00
Ben Felder
51db236ad8
Adapt include tests 2020-02-26 13:49:54 +01:00
Ben Felder
2f09876dd6
Extend test_exclude_file 2020-02-26 13:46:26 +01:00
Ben Felder
97c75e4402
Fixed unicode issue with test_exclude_file 2020-02-26 13:44:43 +01:00
Jairo Llopis
6bf0cedd3a
Add migrations support
This commit fixes #119. Summary:

- Depend on packaging to get a good implementation of PEP 440.
- Document new behaviors.
- Add support for migrations.
- Checkout by default the most modern git tag available in the template.
- Reuse `run_tasks` to run migrations too.
- Use `git describe --tags --always` to obtain template commit, to get a version parseable by PEP 440.
- Update `test_updatediff` to with new behaviors.

@Tecnativa TT20357
2020-02-21 13:52:35 +00:00
Jairo Llopis
0a952b7680 Run pre-commit for the 1st time
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!
2019-12-10 11:47:30 +00:00