22 Commits

Author SHA1 Message Date
Sigurd Spieckermann
ba514b424f fix: parse CLI data using question's answer parser 2023-02-27 18:48:58 +01:00
bpoirriez
a060aaa7c4 Add test 2022-09-08 18:30:00 +01:00
Talley Lambert
6fcd7e02b8
feat: add validator field to Question (#719)
* docs: add note to docstring

* feat: print spawn logs on failure, and fix failure in test

The test was failing because it turns out that `tui` won't print letters that must not change, when running an interactive TUI.

I changed the error message for something that will force all letters to change. This way it works as expected.

Co-authored-by: Jairo Llopis <yajo.sk8@gmail.com>
2022-08-06 15:48:21 +00:00
Paul Moore
05c5f09034
feat: simplify the format of the question prompt (#689)
Closes https://github.com/copier-org/copier/issues/674
2022-06-04 11:02:37 +00:00
Paul Moore
c5d46100a6
tests: refactor the tests to only depend on the prompt format in one place (#682)
* refactor(tests): refactor the tests to only depend on the prompt format in one place

* Address review comments
2022-05-28 08:42:19 +00:00
Jairo Llopis
eb3bb5e67a fix: stop remembering answers nobody asked
Before this patch, an answers file could remember answers to questions that were not present in the questionary.

STR:

1. In one project, apply one template that has a `.copier-answers.yml` file.
2. Now apply another template that has a different default value in `_answers_file`.
3. The second answers file would contain answers to the 1st template too.

@moduon MT-616
2022-04-20 09:07:29 +01:00
Jairo Llopis
af0dbac4ab fix: correct default for skipped questions
A skipped question was not saved by Questionary, so I need to check if the answer is exactly like the question and, in that case, re-render it again.

Docs clarified to avoid false expectations on what should be the answer.

Fixes https://github.com/copier-org/copier/issues/529
2022-02-26 10:03:05 +00:00
Dennis Roche
a1fcccf906 test: Replace force=True with defaults=True, overwrite=True 2021-07-02 15:34:51 +01:00
Jairo Llopis
3b63b6057b fix: restore templated choice keys and types
Last commit removed some false positives in tests and revealed these regressions.

Some tests are modified to reveal reality.
2021-06-11 07:19:46 +01:00
Jairo Llopis
5411276c8b fix: wrong usage of expect_exact([...])
I was expecting that calls in this form matched all strings in sequence. It turns out that [the docs][1] clearly state that it only tries to match one of them.

Thus, fixing the tests to avoid false positives.

[1]: https://pexpect.readthedocs.io/en/stable/api/pexpect.html?highlight=expect_exact#pexpect.spawn.expect_exact
2021-06-11 07:19:46 +01:00
Jairo Llopis
20c151e9f4 fix!: only support explicit types for multi-type choice questions
- Inform about `null` value being converted to choice key.
- Warn about problems when using multiple types in choices.

Fixes https://github.com/copier-org/copier/issues/405.
2021-05-21 16:54:30 +01:00
Jairo Llopis
2547899546 fix: remember user answers while running interactively
This was the case when forced, but not when ran interactively. It was a regression from the v6 refactor.

Fixes https://github.com/copier-org/copier/issues/327.
2021-04-23 17:45:25 +01:00
Jairo Llopis
0500a617c0 test: make spawned processes debuggable
Implement the workaround from https://github.com/microsoft/debugpy/issues/596#issuecomment-824643237 to allow debugging pexpect subprocesses.
2021-04-23 17:45:25 +01:00
Jairo Llopis
1482de4972
wip 2021-03-05 17:33:11 +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
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
Jairo Llopis
f7aee2857d Remember answer procedence
- `ConfigData` objects now know where do answers come from.
- Their `.data` attribute is now a computed property that merges all those answer sources in priority order.
- To merge dicts, `ChainMap` is used extensively.
- `query_user_data` gets both `last_answer_data` and `forced_answers_data` instead of the single `answers_data` argument it got before.
- By knowing where does an answer come from, now Copier avoids asking something if the user already answered that from other source. For example, if you use `copier -d some_question=some_answer copy $src $dst`, then Copier will not ask you about `some_question` again, because you already answered that. 🎉
- All answer sources are deep-copied to avoid modifying mutable dicts and affecting further copier executions.
- A minimal amount of tests got updated as they were now supposed to fail with new behavior.
- Ignore flake8 `E501 line too long` errors. We use black, that's just unnecessarily annoying.

@Tecnativa TT23705
2020-06-18 09:24:58 +01:00
Jairo Llopis
184a1ca98d
Fix type castings in choices
When data came from `--data` flag, it was always a string.

If some data was expected to be of another type, it could make the template fail.

The type casting system must be applied also to user answers, so here's the patch, docs and tests.

@Tecnativa TT20357
2020-04-13 12:31:45 +01:00
Jairo Llopis
32f795f0b5
Make sure --data works
When using the `--data` CLI option, all incoming data are strings. This is the expected behavior because at this point we still don't know the expected types of all answers (we don't even know the questions).

Now the type casting is done smartly when strings come in any form.

There are 2 special cases handled here:

1. When the expected type is bool and the incoming data is string. Handled by YAML because strings like "false", "0" and "no" would evaluate to `True` otherwise.
2. When the expected type is JSON or YAML but the incoming data is not a string. This can only happen when data comes in from API calls (not CLI) or is loaded from default answers in `copier.yml`. In these cases, we don't need to do any type casting, because the input is already a scalar.

@Tecnativa TT20357
2020-02-28 12:17:22 +00:00
Ben Felder
2915d347d1
Update docstrings in test_complex_questions 2020-02-27 20:39:15 +01:00
Jairo Llopis
2241d8fcb9
Add advanced questions format
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
2020-01-13 10:49:59 +01:00