Skip to content
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
7 changes: 7 additions & 0 deletions .pre-commit-config.ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.5
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.5
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-yaml
args: [ --allow-multiple-documents ]
- id: check-json
- id: check-toml
- id: check-merge-conflict
- id: mixed-line-ending
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.18.2'
hooks:
- id: mypy
args: [--strict, --ignore-missing-imports, --check-untyped-defs]
additional_dependencies:
- types-click
- types-PyYAML
- types-requests
13 changes: 4 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ help:
@echo " install - Install the package and dependencies"
@echo " install-dev - Install the package and dev dependencies"
@echo " test - Run tests"
@echo " format - Format code with black"
@echo " format - Format code with ruff"
@echo " lint - Run linting checks"
@echo " security - Run security checks with bandit"
@echo " docs - Build the documentation"
Expand Down Expand Up @@ -59,24 +59,19 @@ test-trace: install-test
$(POETRY) run pytest -k "not kms" -vvv --log-cli-level=DEBUG

format: install-dev
$(POETRY) run black --extend-exclude test-data/gardenlinux .
$(POETRY) run -c .pre-commit-config.ruff.yaml --all-files

lint: install-dev
@echo
@echo "------------------------------------------------------------------------------------------------------------------------"
@echo "--// BLACK //-----------------------------------------------------------------------------------------------------------"
@echo "------------------------------------------------------------------------------------------------------------------------"
$(POETRY) run black --diff --extend-exclude test-data/gardenlinux .
@echo
@echo "------------------------------------------------------------------------------------------------------------------------"
@echo "--// ISORT //-----------------------------------------------------------------------------------------------------------"
@echo "------------------------------------------------------------------------------------------------------------------------"
$(POETRY) run isort --check-only .
@echo
@echo "------------------------------------------------------------------------------------------------------------------------"
@echo "--// PYRIGHT //---------------------------------------------------------------------------------------------------------"
@echo "--// PRE-COMMIT //------------------------------------------------------------------------------------------------------"
@echo "------------------------------------------------------------------------------------------------------------------------"
$(POETRY) run pyright
$(POETRY) run pre-commit run --all-files

security: install-dev
@if [ "$(CI)" = "true" ]; then \
Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

10 changes: 5 additions & 5 deletions hack/print_feature_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

search_and_print_directories() {
local pattern="$1"
local base_pattern="${pattern%%.*}"
local base_pattern="${pattern%%.*}"

while IFS= read -r file; do
dir=$(dirname "$file" | sed 's|^\./||')

suffix="${file##*/}"
suffix="${suffix#"$base_pattern"}"
suffix="${suffix#"$base_pattern"}"

echo "('$dir', '$suffix'),"
done < <(find . -type f -name "$pattern" | sort -u)
}
Expand Down
717 changes: 348 additions & 369 deletions poetry.lock

Large diffs are not rendered by default.

32 changes: 9 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@ packages = [{ include = "gardenlinux", from = "src" }]
[tool.poetry.dependencies]
python = ">=3.13, <3.14"
apt-repo = "^0.5"
boto3 = "^1.40.57"
click = "^8.2.1"
cryptography = "^46.0.1"
boto3 = "^1.42.10"
click = "^8.3.1"
cryptography = "^46.0.3"
jsonschema = "^4.25.1"
networkx = "^3.5"
networkx = "^3.6"
oras = "^0.2.38"
pygit2 = "^1.19.0"
pygments = "^2.19.2"
PyYAML = "^6.0.2"
gitpython = "^3.1.45"

[tool.poetry.group.dev.dependencies]
bandit = "^1.8.6"
black = "^25.1.0"
moto = "^5.1.12"
python-dotenv = "^1.1.1"
pytest = "^9.0.0"
bandit = "^1.9.2"
moto = "^5.1.16"
pre-commit = "^4.5.0"
python-dotenv = "^1.2.1"
pytest = "^9.0.2"
pytest-cov = "^7.0.0"
isort = "^7.0.0"
requests-mock = "^1.12.1"
pyright = "^1.1.403"

[tool.poetry.group.docs.dependencies]
sphinx-rtd-theme = "^3.0.2"
Expand All @@ -54,19 +53,6 @@ line_length = 120
known_first_party = ["gardenlinux"]
skip = ["test-data", ".venv", "**/__pycache", ".pytest-cache", "hack"]

[tool.pyright]
typeCheckingMode = "strict"
venvPath = "."
venv = ".venv"
exclude = [
"test-data",
"docs",
"hack",
".venv",
".pytest-cache",
"**/__pycache",
]

[tool.bandit]
skips = ["B101", "B404"] # allow asserts, subprocesses
exclude_dirs = ["tests"]
Expand Down
27 changes: 0 additions & 27 deletions pyrightconfig.json

This file was deleted.

6 changes: 3 additions & 3 deletions src/gardenlinux/apt/debsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Debsrc:
Apache License, Version 2.0
"""

def __init__(self, deb_source, deb_version):
def __init__(self, deb_source: str, deb_version: str):
"""
Constructor __init__(Debsrc)

Expand All @@ -31,8 +31,8 @@ def __init__(self, deb_source, deb_version):
:since: 0.7.0
"""

self.deb_source: str = deb_source
self.deb_version: str = deb_version
self.deb_source = deb_source
self.deb_version = deb_version

def __repr__(self) -> str:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/gardenlinux/apt/package_repo_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from apt_repo import APTRepository


class GardenLinuxRepo(APTRepository):
class GardenLinuxRepo(APTRepository): # type: ignore[misc]
"""
Class to reflect APT based GardenLinux repositories.

Expand Down
7 changes: 2 additions & 5 deletions src/gardenlinux/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@

GL_BUG_REPORT_URL = "https://github.com/gardenlinux/gardenlinux/issues"
GL_COMMIT_SPECIAL_VALUES = ("local",)
GL_DEB_REPO_BASE_URL = "https://packages.gardenlinux.io/gardenlinux"
GL_DISTRIBUTION_NAME = "Garden Linux"
GL_HOME_URL = "https://gardenlinux.io"
GL_RELEASE_ID = "gardenlinux"
Expand All @@ -161,12 +162,8 @@

S3_DOWNLOADS_DIR = Path(os.path.dirname(__file__)) / ".." / "s3_downloads"

GL_DEB_REPO_BASE_URL = "https://packages.gardenlinux.io/gardenlinux"
GLVD_BASE_URL = (
"https://security.gardenlinux.org/v1"
)

GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME = "gardenlinux-github-releases"
GLVD_BASE_URL = "https://security.gardenlinux.org/v1"

# https://github.com/gardenlinux/gardenlinux/issues/3044
# Empty string is the 'legacy' variant with traditional root fs and still needed/supported
Expand Down
10 changes: 5 additions & 5 deletions src/gardenlinux/features/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ def main() -> None:
else:
print_output_from_cname(args.type, cname)
elif args.type == "commit_id":
print(commit_id_or_hash[:8])
print(commit_id_or_hash[:8]) # type: ignore[index]
elif args.type == "container_tag":
print(re.sub("\\W+", "-", f"{version}-{commit_id_or_hash[:8]}"))
print(re.sub("\\W+", "-", f"{version}-{commit_id_or_hash[:8]}")) # type: ignore[index]
elif args.type == "version":
print(version)
elif args.type == "version_and_commit_id":
print(f"{version}-{commit_id_or_hash[:8]}")
print(f"{version}-{commit_id_or_hash[:8]}") # type: ignore[index]


def get_version_and_commit_id_from_files(gardenlinux_root: str) -> tuple[str, str]:
Expand Down Expand Up @@ -235,7 +235,7 @@ def print_output_from_features_parser(
cname_instance: CName,
parser: Parser,
flavor: str,
ignores_list: set,
ignores_list: Set[str],
) -> None:
"""
Prints output to stdout based on the given features parser and parameters.
Expand All @@ -248,7 +248,7 @@ def print_output_from_features_parser(
:since: 1.0.0
"""

def additional_filter_func(node):
def additional_filter_func(node: str) -> bool:
return node not in ignores_list

if output_type == "features":
Expand Down
38 changes: 21 additions & 17 deletions src/gardenlinux/features/cname.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from configparser import UNNAMED_SECTION, ConfigParser
from os import PathLike, environ
from pathlib import Path
from typing import Optional
from typing import List, Optional

from ..constants import (
ARCHS,
Expand All @@ -34,7 +34,13 @@ class CName(object):
Apache License, Version 2.0
"""

def __init__(self, cname, arch=None, commit_hash=None, version=None):
def __init__(
self,
cname: str,
arch: Optional[str] = None,
commit_hash: Optional[str] = None,
version: Optional[str] = None,
):
"""
Constructor __init__(CName)

Expand All @@ -49,17 +55,15 @@ def __init__(self, cname, arch=None, commit_hash=None, version=None):
self._arch = None
self._commit_hash = None
self._commit_id = None
self._feature_elements_cached = None
self._feature_flags_cached = None
self._feature_platforms_cached = None
self._feature_set_cached = None
self._platform_variant_cached = None

self._feature_elements_cached: Optional[List[str]] = None
self._feature_flags_cached: Optional[List[str]] = None
self._feature_platform_cached: Optional[str] = None
self._feature_set_cached: Optional[str] = None
self._platform_variant_cached: Optional[str] = None
self._flag_multiple_platforms = bool(
environ.get("GL_ALLOW_FRANKENSTEIN", False)
)

self._flavor = None
self._flavor = ""
self._version = None

commit_id_or_hash = None
Expand Down Expand Up @@ -151,7 +155,7 @@ def commit_hash(self) -> str:
return self._commit_hash

@commit_hash.setter
def commit_hash(self, commit_hash) -> None:
def commit_hash(self, commit_hash: str) -> None:
"""
Sets the commit hash

Expand All @@ -178,7 +182,7 @@ def commit_id(self) -> Optional[str]:
return self._commit_id

@property
def flavor(self) -> str | None:
def flavor(self) -> str:
"""
Returns the flavor for the cname parsed.

Expand Down Expand Up @@ -386,7 +390,7 @@ def version_epoch(self) -> Optional[int]:

return epoch

def load_from_release_file(self, release_file: PathLike | str) -> None:
def load_from_release_file(self, release_file: PathLike[str] | str) -> None:
"""
Loads and parses a release metadata file.

Expand All @@ -398,7 +402,7 @@ def load_from_release_file(self, release_file: PathLike | str) -> None:
if not isinstance(release_file, PathLike):
release_file = Path(release_file)

if not release_file.exists():
if not release_file.exists(): # type: ignore[attr-defined]
raise RuntimeError(
f"Release metadata file given is invalid: {release_file}"
)
Expand Down Expand Up @@ -480,7 +484,7 @@ def load_from_release_file(self, release_file: PathLike | str) -> None:
).strip("\"'")

def save_to_release_file(
self, release_file: PathLike | str, overwrite: Optional[bool] = False
self, release_file: PathLike[str] | str, overwrite: Optional[bool] = False
) -> None:
"""
Saves the release metadata file.
Expand All @@ -493,10 +497,10 @@ def save_to_release_file(
if not isinstance(release_file, PathLike):
release_file = Path(release_file)

if not overwrite and release_file.exists():
if not overwrite and release_file.exists(): # type: ignore[attr-defined]
raise RuntimeError(
f"Refused to overwrite existing release metadata file: {release_file}"
)

with release_file.open("w") as fp:
with release_file.open("w") as fp: # type: ignore[attr-defined]
fp.write(self.release_metadata_string)
2 changes: 1 addition & 1 deletion src/gardenlinux/features/cname_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .parser import Parser


def main():
def main() -> None:
"""
gl-cname main()

Expand Down
2 changes: 1 addition & 1 deletion src/gardenlinux/features/metadata_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]


def main():
def main() -> None:
"""
gl-metadata main()

Expand Down
Loading
Loading