Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add ruff rules, fix all CI #3

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/lock/aarch64-apple-darwin/.requirements_dev.in.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5bb70432f4c0ad95df62595bdcfdce40f288df99f6a2712fddcb8603b91cc5c7 requirements_dev.in
d60f7e1bbc797733bbb995197ff47b52a1806cdbdc9468bd54f7edd90d95d4f8 requirements_dev.in
4 changes: 2 additions & 2 deletions deps/lock/aarch64-apple-darwin/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/aarch64-apple-darwin/requirements_dev.txt --python-platform aarch64-apple-darwin --python-version 3.9
# uv pip compile requirements_dev.in -o /Users/kiyoon/project/python-import.nvim/deps/lock/aarch64-apple-darwin/requirements_dev.txt --python-platform aarch64-apple-darwin --python-version 3.9
click==8.1.7
# via typer
coverage==7.5.3
Expand All @@ -26,7 +26,7 @@ pytest-cov==5.0.0
# via -r requirements_dev.in
rich==13.7.1
# via typer
ruff==0.4.7
ruff==0.6.7
# via -r requirements_dev.in
shellingham==1.5.4
# via typer
Expand Down
2 changes: 1 addition & 1 deletion deps/lock/x86_64-apple-darwin/.requirements_dev.in.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5bb70432f4c0ad95df62595bdcfdce40f288df99f6a2712fddcb8603b91cc5c7 requirements_dev.in
d60f7e1bbc797733bbb995197ff47b52a1806cdbdc9468bd54f7edd90d95d4f8 requirements_dev.in
4 changes: 2 additions & 2 deletions deps/lock/x86_64-apple-darwin/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-apple-darwin/requirements_dev.txt --python-platform x86_64-apple-darwin --python-version 3.9
# uv pip compile requirements_dev.in -o /Users/kiyoon/project/python-import.nvim/deps/lock/x86_64-apple-darwin/requirements_dev.txt --python-platform x86_64-apple-darwin --python-version 3.9
click==8.1.7
# via typer
coverage==7.5.3
Expand All @@ -26,7 +26,7 @@ pytest-cov==5.0.0
# via -r requirements_dev.in
rich==13.7.1
# via typer
ruff==0.4.7
ruff==0.6.7
# via -r requirements_dev.in
shellingham==1.5.4
# via typer
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5bb70432f4c0ad95df62595bdcfdce40f288df99f6a2712fddcb8603b91cc5c7 requirements_dev.in
d60f7e1bbc797733bbb995197ff47b52a1806cdbdc9468bd54f7edd90d95d4f8 requirements_dev.in
4 changes: 2 additions & 2 deletions deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt --python-platform x86_64-manylinux_2_28 --python-version 3.9
# uv pip compile requirements_dev.in -o /Users/kiyoon/project/python-import.nvim/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt --python-platform x86_64-manylinux_2_28 --python-version 3.9
click==8.1.7
# via typer
coverage==7.5.3
Expand All @@ -26,7 +26,7 @@ pytest-cov==5.0.0
# via -r requirements_dev.in
rich==13.7.1
# via typer
ruff==0.4.7
ruff==0.6.7
# via -r requirements_dev.in
shellingham==1.5.4
# via typer
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5bb70432f4c0ad95df62595bdcfdce40f288df99f6a2712fddcb8603b91cc5c7 requirements_dev.in
d60f7e1bbc797733bbb995197ff47b52a1806cdbdc9468bd54f7edd90d95d4f8 requirements_dev.in
4 changes: 2 additions & 2 deletions deps/lock/x86_64-pc-windows-msvc/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-pc-windows-msvc/requirements_dev.txt --python-platform x86_64-pc-windows-msvc --python-version 3.9
# uv pip compile requirements_dev.in -o /Users/kiyoon/project/python-import.nvim/deps/lock/x86_64-pc-windows-msvc/requirements_dev.txt --python-platform x86_64-pc-windows-msvc --python-version 3.9
click==8.1.7
# via typer
colorama==0.4.6
Expand Down Expand Up @@ -30,7 +30,7 @@ pytest-cov==5.0.0
# via -r requirements_dev.in
rich==13.7.1
# via typer
ruff==0.4.7
ruff==0.6.7
# via -r requirements_dev.in
shellingham==1.5.4
# via typer
Expand Down
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ log_cli_level = "INFO"

[tool.ruff]
src = ["src"] # for ruff isort
namespace-packages = ["tools", "scripts"] # for INP rule, suppress on these directories
extend-exclude = [
"src/python_import/_version.py", # CHANGE
"tests/sample_projects/project1/*",
Expand All @@ -77,6 +78,7 @@ select = [
"RET503", # return
"PTH", # path
"NPY", # numpy
"PD", # pandas
"PYI", # type stubs for pyright/pylance
"PT", # pytest
"PIE", #
Expand All @@ -86,6 +88,21 @@ select = [
"DTZ", # datetime
"YTT",
"ASYNC",
"FBT", # boolean trap
"A", # Shadowing python builtins
"EXE", # executable (shebang)
"FA", # future annotations
"ISC", # Implicit string concatenation
"ICN", # Import convention
"INP", # Implicit namespace package (no __init__.py)
"Q", # Quotes
"RSE", # raise
"SLOT", # __slots__
"PL", # Pylint
"TRY", # try
"FAST", # FastAPI
"AIR", # airflow
"DOC", # docstring

# Not important
"T10", # debug statements
Expand All @@ -101,12 +118,14 @@ ignore = [
"D212", # Multi-line docstring summary should start at the first line
"D417", # require documentation for every function parameter.
"D401", # require an imperative mood for all docstrings.
"DOC201", # missing Return field in docstring
"PTH123", # Path.open should be used instead of built-in open
"PT006", # Pytest parameterize style
"N812", # Lowercase `functional` imported as non-lowercase `F` (import torch.nn.functional as F)
"NPY002", # legacy numpy random
"UP017", # datetime.timezone.utc -> datetime.UTC
"SIM108", # use ternary operator instead of if-else
"TRY003", # long message in except
]

[tool.ruff.lint.pydocstyle]
Expand All @@ -132,6 +151,11 @@ required-imports = [
# NOTE: Ruff code TID is currently disabled, so this settings doesn't do anything.
banned-module-level-imports = ["torch", "tensorflow"]

[tool.ruff.lint.pylint]
max-args = 10
max-bool-expr = 10
max-statements = 100

[tool.pyright]
include = ["src"]

Expand Down
6 changes: 4 additions & 2 deletions src/python_import/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
)


def version_callback(value: bool):
def version_callback(*, value: bool):
if value:
print(f"python-import v{python_import.__version__}")
raise typer.Exit()
raise typer.Exit


@app.callback()
def common(
ctx: typer.Context,
*,
version: bool = typer.Option(
None, "-v", "--version", callback=version_callback, help="Show version"
),
Expand Down Expand Up @@ -79,6 +80,7 @@ def count(
],
cwd=project_root,
capture_output=True,
check=False,
)
# print(rg_outputs)

Expand Down
2 changes: 2 additions & 0 deletions src/python_import/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def relative_import_to_absolute_import(
project_root: str | PathLike,
python_file_path: str | PathLike,
from_import_name: str,
*,
check_dir_exists: bool = True,
):
"""
Expand Down Expand Up @@ -275,6 +276,7 @@ def get_all_imports_in_file_as_absolute_with_word(
],
cwd=project_root,
capture_output=True,
check=False,
)
# print(rg_outputs)

Expand Down
Empty file added tests/__init__.py
Empty file.