Remove black in lint.sh and format.sh (#1676)

This commit is contained in:
Koudai Aono
2023-11-10 03:57:47 +09:00
committed by GitHub
parent cbbe26da46
commit 8ca47052e8
12 changed files with 49 additions and 52 deletions

View File

@@ -1,14 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
files: "^datamodel_code_generator|^tests"
exclude: "^tests/data"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.4'
rev: 'v0.1.5'
hooks:
- id: ruff
files: "^datamodel_code_generator|^tests"
exclude: "^tests/data"
args: [--fix, --exit-non-zero-on-fix]
args: [ --fix ]
- id: ruff-format
files: "^datamodel_code_generator|^tests"
exclude: "^tests/data"

View File

@@ -186,9 +186,7 @@ class Config(BaseModel):
def validate_each_item(each_item: Any) -> Tuple[str, str]:
if isinstance(each_item, str): # pragma: no cover
try:
field_name, field_value = each_item.split(
':', maxsplit=1
) # type: str, str
field_name, field_value = each_item.split(':', maxsplit=1) # type: str, str
return field_name, field_value.lstrip()
except ValueError:
raise Error(f'Invalid http header: {each_item!r}')
@@ -342,8 +340,8 @@ def main(args: Optional[Sequence[str]] = None) -> Exit:
if not is_supported_in_black(config.target_python_version): # pragma: no cover
print(
f"Installed black doesn't support Python version {config.target_python_version.value}.\n" # type: ignore
f"You have to install a newer black.\n"
f"Installed black version: {black.__version__}",
f'You have to install a newer black.\n'
f'Installed black version: {black.__version__}',
file=sys.stderr,
)
return Exit.ERROR

View File

@@ -421,7 +421,7 @@ openapi_options.add_argument(
# ======================================================================================
general_options.add_argument(
'--debug',
help="show debug message (require \"debug\". `$ pip install 'datamodel-code-generator[debug]'`)",
help='show debug message (require "debug". `$ pip install \'datamodel-code-generator[debug]\'`)',
action='store_true',
default=None,
)

View File

@@ -30,11 +30,22 @@ class PythonVersion(Enum):
@cached_property
def _is_py_310_or_later(self) -> bool: # pragma: no cover
return self.value not in {self.PY_36.value, self.PY_37.value, self.PY_38.value, self.PY_39.value} # type: ignore
return self.value not in {
self.PY_36.value,
self.PY_37.value,
self.PY_38.value,
self.PY_39.value,
} # type: ignore
@cached_property
def _is_py_311_or_later(self) -> bool: # pragma: no cover
return self.value not in {self.PY_36.value, self.PY_37.value, self.PY_38.value, self.PY_39.value, self.PY_310.value} # type: ignore
return self.value not in {
self.PY_36.value,
self.PY_37.value,
self.PY_38.value,
self.PY_39.value,
self.PY_310.value,
} # type: ignore
@property
def has_literal_type(self) -> bool:

View File

@@ -42,6 +42,6 @@ __all__ = [
'CustomRootType',
'DataClass',
'dump_resolve_reference_action',
'DataTypeManager'
'DataTypeManager',
# 'VALIDATOR_TEMPLATE',
]

View File

@@ -124,7 +124,7 @@ byes_kwargs: Set[str] = {'minLength', 'maxLength'}
escape_characters = str.maketrans(
{
"'": r"\'",
"'": r'\'',
'\b': r'\b',
'\f': r'\f',
'\n': r'\n',

View File

@@ -26,7 +26,7 @@ from datamodel_code_generator.types import NOT_REQUIRED_PREFIX
escape_characters = str.maketrans(
{
'\\': r'\\',
"'": r"\'",
"'": r'\'',
'\b': r'\b',
'\f': r'\f',
'\n': r'\n',

View File

@@ -58,7 +58,7 @@ def get_special_path(keyword: str, path: List[str]) -> List[str]:
escape_characters = str.maketrans(
{
'\\': r'\\',
"'": r"\'",
"'": r'\'',
'\b': r'\b',
'\f': r'\f',
'\n': r'\n',
@@ -457,9 +457,9 @@ class Parser(ABC):
self.source: Union[str, Path, List[Path], ParseResult] = source
self.custom_template_dir = custom_template_dir
self.extra_template_data: DefaultDict[
str, Any
] = extra_template_data or defaultdict(dict)
self.extra_template_data: DefaultDict[str, Any] = (
extra_template_data or defaultdict(dict)
)
if allow_population_by_field_name:
self.extra_template_data[ALL_MODEL]['allow_population_by_field_name'] = True
@@ -1073,9 +1073,10 @@ class Parser(ABC):
model_class_name_baseclasses: Dict[DataModel, Tuple[str, Set[str]]] = {}
for model in models:
class_name = model.class_name
model_class_name_baseclasses[model] = class_name, {
b.type_hint for b in model.base_classes if b.reference
} - {class_name}
model_class_name_baseclasses[model] = (
class_name,
{b.type_hint for b in model.base_classes if b.reference} - {class_name},
)
changed: bool = True
while changed:
@@ -1172,9 +1173,7 @@ class Parser(ABC):
module_to_import: Dict[Tuple[str, ...], Imports] = {}
previous_module = () # type: Tuple[str, ...]
for module, models in (
(k, [*v]) for k, v in grouped_models
): # type: Tuple[str, ...], List[DataModel]
for module, models in ((k, [*v]) for k, v in grouped_models): # type: Tuple[str, ...], List[DataModel]
for model in models:
model_to_module_models[model] = module, models
self.__delete_duplicate_models(models)

View File

@@ -566,9 +566,9 @@ class OpenAPIParser(JsonSchemaParser):
)
except ImportError: # pragma: no cover
warn(
"Warning: Validation was skipped for OpenAPI. `prance` or `openapi-spec-validator` are not "
"installed.\n"
"To use --validation option after datamodel-code-generator 0.24.0, Please run `$pip install "
'Warning: Validation was skipped for OpenAPI. `prance` or `openapi-spec-validator` are not '
'installed.\n'
'To use --validation option after datamodel-code-generator 0.24.0, Please run `$pip install '
"'datamodel-code-generator[validation]'`.\n"
)

View File

@@ -93,24 +93,14 @@ line-length = 88
extend-select = ['Q', 'RUF100', 'C4', 'UP', 'I']
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'}
target-version = 'py37'
ignore = ['E501', 'UP006', 'UP007']
ignore = ['E501', 'UP006', 'UP007', 'Q000', 'Q003' ]
extend-exclude = ['tests/data']
[tool.black]
line-length = 88
skip-string-normalization = true
# language=RegExp
exclude = '(tests/data|\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|.*\/models\.py.*|.*\/models\/.*)'
target-version = ['py37']
[tool.ruff.isort]
#multi-line-output = 3
#include-trailing-comma = true
#force-grid-wrap = 0
#use-parentheses = true
#line-length = 88
#skip = "tests/data"
[tool.ruff.format]
quote-style = "single"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
[tool.mypy]
plugins = "pydantic.mypy"

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -e
black datamodel_code_generator tests
ruff --fix datamodel_code_generator tests
ruff check --fix datamodel_code_generator tests
ruff format datamodel_code_generator tests

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
black --check datamodel_code_generator tests
ruff datamodel_code_generator tests
ruff check datamodel_code_generator tests
ruff format --check datamodel_code_generator tests
mypy datamodel_code_generator