Skip to content

Commit

Permalink
Add lock feature (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Apakottur authored Sep 16, 2024
1 parent 19e04e1 commit d65027a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repos:
hooks:
- id: biome-check
args: [--config-path, ./linters]
additional_dependencies: ["@biomejs/biome@1.8.3"]
additional_dependencies: ["@biomejs/biome@1.9.0"]
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.13.1
hooks:
Expand Down Expand Up @@ -88,12 +88,12 @@ repos:
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==24.4.26
- flake8-bugbear==24.8.19
- flake8-comprehensions==3.15.0
- flake8-picky-parentheses==0.5.5
- flake8-pyi==24.6.0
- pep8-naming==0.14.1
- pydoclint==0.5.6
- pydoclint==0.5.7
args: [--config, ./linters/.flake8]
types: [file]
types_or: [python, pyi]
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,3 @@ git push -f origin v1.0.x v1
```

4. Create and publish a release from the new tag.

## TODO

1. Run `mypy` in CI
2. Add support for not updating specific packages
3. Add input argument to specify paths (with the default checking the whole repo)
34 changes: 17 additions & 17 deletions poetry.lock

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

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ authors = []

[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.28"
tomlkit = "0.13.0"
typer = "0.12.3"
shpyx = "0.0.29"
tomlkit = "0.13.2"
typer = "0.12.5"

[tool.poetry.dev-dependencies]
pytest = "8.3.2"
pytest = "8.3.3"
pytest-mock = "3.14.0"
11 changes: 11 additions & 0 deletions src/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,21 @@ def cmp(x: Path, y: Path) -> int:
for name, details in current_poetry_section.items()
if name.lower() == package_name.lower()
)

if isinstance(package_details, str):
written_version = package_details
else:
written_version = package_details["version"]

except (StopIteration, tomlkit.exceptions.NonExistentKey):
# Either the section is missing or the package is not in this section.
continue

# Skip packages that are locked via the '==' operator.
if written_version.startswith("=="):
print("Skipping locked package:", package_name)
continue

print(f"Updating {package_name}: {installed_version} -> {new_version}")

# Replace the old version of the package with the new one.
Expand Down
42 changes: 32 additions & 10 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_poetry_deps() -> None:
"""
[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
)
]
Expand All @@ -128,7 +128,7 @@ def test_poetry_dev_deps() -> None:
python = "~3.12"
[tool.poetry.dev-dependencies]
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
)
]
Expand All @@ -150,7 +150,7 @@ def test_poetry_dev_deps() -> None:
python = "~3.12"
[tool.poetry.group.dev.dependencies]
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
)
]
Expand All @@ -176,7 +176,7 @@ def test_multiline_deps() -> None:
sqlalchemy = { extras = [
"postgresql",
"postgresql_asyncpg"
], version = "2.0.32" }
], version = "2.0.34" }
""",
)
]
Expand All @@ -191,12 +191,12 @@ def test_no_changes() -> None:
"""
[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
"""
[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
)
]
Expand All @@ -216,7 +216,7 @@ def test_casing() -> None:
"""
[tool.poetry.dependencies]
python = "~3.12"
sHpYx = "0.0.28"
sHpYx = "0.0.29"
""",
)
]
Expand Down Expand Up @@ -281,7 +281,7 @@ def _os_walk(path: str, *args: Any, **kwargs: Any) -> list[tuple[str, list[str],
"""
[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
"inner_2",
),
Expand Down Expand Up @@ -321,7 +321,7 @@ def test_path_dependency_duplicates_dependency() -> None:
[tool.poetry.dependencies]
python = "~3.12"
inner = { path = "../inner", develop = true }
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
"outer",
),
Expand All @@ -334,9 +334,31 @@ def test_path_dependency_duplicates_dependency() -> None:
"""
[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.28"
shpyx = "0.0.29"
""",
"inner",
),
],
)


def test_locked_version() -> None:
"""Verify that packages with a '==' are ignored for updates"""
_run_updater(
[
Project(
"""
[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.13"
sqlalchemy = "==1.4.36" # Locked for some reason.
""",
"""
[tool.poetry.dependencies]
python = "~3.12"
shpyx = "0.0.29"
sqlalchemy = "==1.4.36" # Locked for some reason.
""",
)
]
)

0 comments on commit d65027a

Please sign in to comment.