Skip to content

Commit

Permalink
Revert "Remove support for custom lexers temporarily"
Browse files Browse the repository at this point in the history
This reverts commit 598388a because it's no longer needed with questionary 1.7.0.
  • Loading branch information
Jairo Llopis authored and github-actions[bot] committed Oct 16, 2020
1 parent 3a63b16 commit 81e03a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
9 changes: 9 additions & 0 deletions copier/config/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from iteration_utilities import deepflatten
from jinja2 import UndefinedError
from jinja2.sandbox import SandboxedEnvironment
from prompt_toolkit.lexers import PygmentsLexer
from pydantic import BaseModel, Field, validator
from pygments.lexers.data import JsonLexer, YamlLexer
from questionary import prompt
from questionary.prompts.common import Choice
from yamlinclude import YamlIncludeConstructor
Expand Down Expand Up @@ -206,6 +208,7 @@ def get_placeholder(self) -> str:

def get_questionary_structure(self) -> AnyByStrDict:
"""Get the question in a format that the questionary lib understands."""
lexer = None
result = {
"default": self.get_default(for_rendering=True),
"filter": self.filter_answer,
Expand All @@ -231,6 +234,12 @@ def get_questionary_structure(self) -> AnyByStrDict:
if questionary_type == "input":
if self.secret:
questionary_type = "password"
elif self.type_name == "yaml":
lexer = PygmentsLexer(YamlLexer)
elif self.type_name == "json":
lexer = PygmentsLexer(JsonLexer)
if lexer:
result["lexer"] = lexer
result["multiline"] = self.get_multiline()
placeholder = self.get_placeholder()
if placeholder:
Expand Down
12 changes: 0 additions & 12 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import inspect
from pathlib import Path

import pexpect
import pytest
import yaml
from plumbum import local
from plumbum.cmd import git
from questionary.prompts.text import text

from .helpers import COPIER_PATH, Keyboard, build_file_tree

Expand Down Expand Up @@ -247,13 +245,3 @@ def test_multiline(tmp_path_factory, spawn, type_):
"question_4": ("answer 4"),
"question_5": ("answer 5"),
}


def questionary_supports_custom_lexer():
"""Check that questionary doesn't support custom lexers.
If this test fails, it means that https://github.com/tmbo/questionary/pull/70
was merged and then you should revert https://github.com/copier-org/copier/pull/289
to enable lexer support.
"""
assert "lexer" not in inspect.signature(text).parameters

0 comments on commit 81e03a5

Please sign in to comment.