Skip to content

Commit

Permalink
build(lint): switch over to ruff; add taplo
Browse files Browse the repository at this point in the history
Ruff is faster, better integrated, easier to configure... Cool!

Taplo also helps with toml maintenance.
  • Loading branch information
yajo committed Jan 15, 2024
1 parent 53aab1f commit ab6805e
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ insert_final_newline = true
# For isort
profile = black

[*.{code-snippets,code-workspace,json,lock,nix,tf,yaml,yml}{,.jinja}]
[*.{code-snippets,code-workspace,json,lock,nix,toml,tf,yaml,yml}{,.jinja}]
indent_size = 2
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
- run: copier --version

# Run nix checks
- run: nix flake check -L --accept-flake-config
- run: nix flake check -L --accept-flake-config --impure

publish:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"esbenp.prettier-vscode",
"ms-python.black-formatter",
"ms-python.python",
"editorconfig.editorconfig",
"bpruitt-goddard.mermaid-markdown-syntax-highlighting"
Expand Down
18 changes: 7 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
"editor.formatOnSave": true,
"python.testing.pytestEnabled": true,
"markdown.extension.toc.updateOnSave": false,
"python.formatting.provider": "none",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"[python]": {
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
},
"[markdown]": {
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"python.autoComplete.extraPaths": ["__pypackages__/3.9/lib"],
"python.analysis.extraPaths": ["__pypackages__/3.9/lib"],
"python.pythonPath": ".venv/bin/python"
}
}
6 changes: 2 additions & 4 deletions copier/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Command line entrypoint. This module declares the Copier CLI applications.
"""Command line entrypoint. This module declares the Copier CLI applications.
Basically, there are 3 different commands you can run:
Expand Down Expand Up @@ -197,8 +196,7 @@ def data_file_switch(self, path: cli.ExistingFile) -> None:
self.data.update(updates_without_cli_overrides)

def _worker(self, src_path: OptStr = None, dst_path: str = ".", **kwargs) -> Worker:
"""
Run Copier's internal API using CLI switches.
"""Run Copier's internal API using CLI switches.
Arguments:
src_path: The source path of the template to generate the project from.
Expand Down
2 changes: 1 addition & 1 deletion copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def _render_folder(self, src_abspath: Path) -> None:
"""Recursively render a folder.
Args:
src_path:
src_abspath:
Folder to be rendered. It must be an absolute path within
the template.
"""
Expand Down
13 changes: 10 additions & 3 deletions copier/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,17 @@ def _re_octal_replace(match: re.Match) -> str:


def normalize_git_path(path: str) -> str:
# A filename like âñ will be reported by Git
# as "\\303\\242\\303\\261" (octal notation).
# This can be disabled with `git config core.quotepath off`.
r"""Convert weird characters returned by Git to normal UTF-8 path strings.
A filename like âñ will be reported by Git as "\\303\\242\\303\\261" (octal notation).
This can be disabled with `git config core.quotepath off`.
Args:
path: The Git path to normalize.
Returns:
str: The normalized Git path.
"""
# Remove surrounding quotes
if path[0] == path[-1] == '"':
path = path[1:-1]
Expand Down
3 changes: 2 additions & 1 deletion copier/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@


def get_git(context_dir: OptStrOrPath = None) -> LocalCommand:
"""Gets `git` command, or fails if it's not available"""
"""Gets `git` command, or fails if it's not available."""
command = local["git"]
if context_dir:
command = command["-C", context_dir]
return command


def get_git_version() -> Version:
"""Get the installed git version."""
git = get_git()

return Version(re.findall(r"\d+\.\d+\.\d+", git("version"))[0])
Expand Down
52 changes: 26 additions & 26 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
];
};
inputs = {
devenv.url = "github:cachix/devenv/v0.5";
devenv.url = "github:cachix/devenv/latest";
flake-compat = {
url = github:edolstra/flake-compat;
flake = false;
Expand Down Expand Up @@ -91,25 +91,22 @@

# IDE integration tools
alejandra
black
commitizen
isort
mypy
nodePackages.prettier
ruff
taplo
];
difftastic.enable = true;
pre-commit.hooks = {
alejandra.enable = true;
black.enable = true;
commitizen.enable = true;
editorconfig-checker.enable = true;
editorconfig-checker.excludes = [
"\.md$"
"\.noeof\."
"\.bundle$"
];
flake8.enable = true;
isort.enable = true;
prettier.enable = true;
prettier.excludes = [
# Those files have wrong syntax and would fail
Expand All @@ -118,6 +115,8 @@
# HACK https://github.com/prettier/prettier/issues/9430
"^tests/demo"
];
ruff.enable = true;
taplo.enable = true;
};
}
];
Expand Down
44 changes: 22 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ version = "0.0.0"
description = "A library for rendering project templates."
license = "MIT"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
authors = ["Ben Felder <[email protected]>"]
homepage = "https://github.com/copier-org/copier"
Expand Down Expand Up @@ -109,28 +109,28 @@ enable = true
style = "pep440"
vcs = "git"

[tool.black]
target-version = ["py38"]
[tool.ruff.lint]
extend-select = ["B", "D", "E", "F", "I", "UP"]
extend-ignore = ['B028', "B904", "D105", "D107", "E501"]

[tool.isort]
profile = "black"
combine_as_imports = true
known_first_party = ["copier"]
[tool.ruff.lint.per-file-ignores]
"tests/**" = ["D"]

[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ["copier"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.mypy]
ignore_missing_imports = true
plugins = ["pydantic.mypy"]
warn_no_return = false

[tool.pydocstyle]
match_dir = "^copier"
add_ignore = ["D105", "D107"]

[tool.pytest.ini_options]
addopts = "-n auto -ra"
markers = [
"impure: needs network or is not 100% reproducible"
]
markers = ["impure: needs network or is not 100% reproducible"]

[tool.commitizen]
annotated_tag = true
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_invalid_config_data(
) -> None:
template = Template(conf_path)
with pytest.raises(InvalidConfigFileError):
template.config_data
template.config_data # noqa: B018
if check_err:
_, err = capsys.readouterr()
assert check_err(err)
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_config_data_empty() -> None:
def test_multiple_config_file_error() -> None:
template = Template("tests/demo_multi_config")
with pytest.raises(MultipleConfigFilesError):
template.config_data
template.config_data # noqa: B018


# ConfigData
Expand Down

0 comments on commit ab6805e

Please sign in to comment.