Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Apakottur committed Aug 6, 2024
1 parent f87c723 commit e4980df
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.tmp
__pycache__
.venv
.venv
.cspellcache
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ repos:
- id: python-check-mock-methods
- id: python-no-log-warn
- id: python-use-type-annotations
- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
hooks:
- id: absolufy-imports
types: [file]
types_or: [python, pyi]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.6
hooks:
Expand All @@ -99,7 +93,7 @@ repos:
- flake8-picky-parentheses==0.5.5
- flake8-pyi==24.6.0
- pep8-naming==0.14.1
- pydoclint==0.5.4
- pydoclint==0.5.6
args: [--config, ./linters/.flake8]
types: [file]
types_or: [python, pyi]
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ inputs:
pr-body:
description: "The body of the pull request"
required: false
default: "Automated changes by [update-python-poetry-packages](https://github.com/Apakottur/action-poetry-package-update) GitHub action"
default:
"Automated changes by [update-python-poetry-packages](https://github.com/Apakottur/action-poetry-package-update)
GitHub action"
runs:
using: "composite"
steps:
Expand Down
10 changes: 10 additions & 0 deletions linters/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dictionaries": ["custom-words"],
"dictionaryDefinitions": [
{
"name": "custom-words",
"path": "./cspell/words.txt",
"addWords": true
}
]
}
29 changes: 29 additions & 0 deletions linters/cspell/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
mypy
pyproject
pytest
typer
tomlkit
shpyx
sqlalchemy
classmethod
isort
pydoclint
pydocstyle
elif
contextlib
taplo
shfmt
noqa
apakottur
numpy
venv
pycache
yossi
rozantsev
asyncpg
pythonpath
shellcheck
pydantic
ignorelist
docstrings
biomejs
48 changes: 26 additions & 22 deletions linters/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ignore = [
# Ignored - Conflicts with Ruff formatter #
###########################################
"COM812", # Trailing comma missing
"E501", # Line too long
"E501", # Line too long
"ISC001", # Implicitly concatenated strings on a single line
##############
# Pydocstyle #
Expand All @@ -58,34 +58,34 @@ ignore = [
###################################
# Other checks that we don't want #
###################################
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
"BLE001", # Do not catch blind exception: `Exception`
"C901", # Method is too complex
"EM101", # Exception must not use a string literal, assign to variable first
"EM102", # Exception must not use an f-string literal, assign to variable first
"ERA001", # Found commented-out code
"FIX002", # Line contains TODO
"ISC003", # Explicitly concatenated string should be implicitly concatenate
"N818", # Exception name should be named with an Error suffix
"PD011", # Use `.to_numpy()` instead of `.values`
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
"BLE001", # Do not catch blind exception: `Exception`
"C901", # Method is too complex
"EM101", # Exception must not use a string literal, assign to variable first
"EM102", # Exception must not use an f-string literal, assign to variable first
"ERA001", # Found commented-out code
"FIX002", # Line contains TODO
"ISC003", # Explicitly concatenated string should be implicitly concatenate
"N818", # Exception name should be named with an Error suffix
"PD011", # Use `.to_numpy()` instead of `.values`
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments to function call
"PLR0915", # Too many statements
"PLR1722", # Use `sys.exit()` instead of `exit`
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
"PLR5501", # Consider using `elif` instead of `else` then `if` to remove one indentation level
"PTH123", # `open()` should be replaced by `Path.open()`
"RET505", # Unnecessary `else` after `return` statement
"RET506", # Unnecessary `else` after `raise` statement
"SIM102", # Use a single `if` statement instead of nested `if` statements
"SIM103", # Return the condition directly
"SIM105", # Use `contextlib.suppress()` instead of try-except-pass
"TCH001", # Move application import into a type-checking block
"TCH002", # Move third-party import into a type-checking block
"TD002", # Missing author in TODO
"TD003", # Missing issue link on the line following this TODO
"TRY003", # Avoid specifying long messages outside the exception class
"PTH123", # `open()` should be replaced by `Path.open()`
"RET505", # Unnecessary `else` after `return` statement
"RET506", # Unnecessary `else` after `raise` statement
"SIM102", # Use a single `if` statement instead of nested `if` statements
"SIM103", # Return the condition directly
"SIM105", # Use `contextlib.suppress()` instead of try-except-pass
"TCH001", # Move application import into a type-checking block
"TCH002", # Move third-party import into a type-checking block
"TD002", # Missing author in TODO
"TD003", # Missing issue link on the line following this TODO
"TRY003", # Avoid specifying long messages outside the exception class
]

[lint.isort]
Expand All @@ -110,3 +110,7 @@ builtins-ignorelist = ["id"]
"tests/*" = [
"S101", # Use of `assert` detected
]

"src/*" = [
"T201", # `print` found
]
19 changes: 19 additions & 0 deletions linters/yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends: default

rules:
line-length:
max: 120

document-start:
present: false


comments:
require-starting-space: true
ignore-shebangs: true
min-spaces-from-content: 1


truthy:
allowed-values: ['true', 'false', 'on', 'off']
check-keys: true
9 changes: 2 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
import argparse

import updater
import typer


def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument(
"--paths", help="List of paths to run the updater in.", nargs="+", default=["."]
)
parser.add_argument("--paths", help="List of paths to run the updater in.", nargs="+", default=["."])

return parser.parse_args()

Expand Down
8 changes: 2 additions & 6 deletions src/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def _run_updater_in_path(path: str) -> None:

for details in current_poetry_section.values():
if "path" in details:
file_path_to_deps[file_path.resolve()].append(
(Path(root) / details["path"] / name).resolve()
)
file_path_to_deps[file_path.resolve()].append((Path(root) / details["path"] / name).resolve())

# Order the projects based on interdependencies, where dependencies go first.
def cmp(x: Path, y: Path) -> int:
Expand Down Expand Up @@ -113,9 +111,7 @@ def cmp(x: Path, y: Path) -> int:
if isinstance(package_details, str):
current_poetry_section[original_package_name] = new_version
else:
current_poetry_section[original_package_name]["version"] = (
new_version
)
current_poetry_section[original_package_name]["version"] = new_version

# Write the updated configuration file.
Path(file_path).write_text(parsed_contents.as_string())
Expand Down
84 changes: 48 additions & 36 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,123 +87,135 @@ def run_in_tmp_directory(_tmp_dir: str) -> None:

def test_poetry_deps() -> None:
"""A package under `dependencies` is out of date"""
_run_updater([
Project(
"""
_run_updater(
[
Project(
"""
[tool.poetry.dependencies]
python = "^3.10"
shpyx = "0.0.13"
""",
"""
"""
[tool.poetry.dependencies]
python = "^3.10"
shpyx = "0.0.25"
""",
)
])
)
]
)


def test_poetry_dev_deps() -> None:
"""A package under `dev-dependencies` is out of date"""
# Old syntax.
_run_updater([
Project(
"""
_run_updater(
[
Project(
"""
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.dev-dependencies]
shpyx = "0.0.13"
""",
"""
"""
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.dev-dependencies]
shpyx = "0.0.25"
""",
)
])
)
]
)

# New syntax.
_run_updater([
Project(
"""
_run_updater(
[
Project(
"""
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.group.dev.dependencies]
shpyx = "0.0.13"
""",
"""
"""
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.group.dev.dependencies]
shpyx = "0.0.25"
""",
)
])
)
]
)


def test_multiline_deps() -> None:
"""A package with a multi-line configuration is out of date"""
_run_updater([
Project(
"""
_run_updater(
[
Project(
"""
[tool.poetry.dependencies]
python = "^3.10"
sqlalchemy = { extras = [
"postgresql",
"postgresql_asyncpg"
], version = "1.4.36" }
""",
"""
"""
[tool.poetry.dependencies]
python = "^3.10"
sqlalchemy = { extras = [
"postgresql",
"postgresql_asyncpg"
], version = "2.0.25" }
""",
)
])
)
]
)


def test_no_changes() -> None:
"""Everything is up to date"""
_run_updater([
Project(
"""
_run_updater(
[
Project(
"""
[tool.poetry.dependencies]
python = "^3.10"
shpyx = "0.0.25"
""",
"""
"""
[tool.poetry.dependencies]
python = "^3.10"
shpyx = "0.0.25"
""",
)
])
)
]
)


def test_casing() -> None:
"""Verify that lower/upper case in package names is preserved"""
_run_updater([
Project(
"""
_run_updater(
[
Project(
"""
[tool.poetry.dependencies]
python = "^3.10"
sHpYx = "0.0.13"
""",
"""
"""
[tool.poetry.dependencies]
python = "^3.10"
sHpYx = "0.0.25"
""",
)
])
)
]
)


def test_path_dependency_run_order(mocker: MockerFixture) -> None:
Expand Down

0 comments on commit e4980df

Please sign in to comment.