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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ format: install-dev

lint: install-dev
$(POETRY) run black --diff --extend-exclude test-data/gardenlinux .
$(POETRY) run isort --check-only .
$(POETRY) run pyright

security: install-dev
@if [ "$(CI)" = "true" ]; then \
Expand Down
272 changes: 168 additions & 104 deletions poetry.lock

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Contains tools to work with the features directory of gardenlinux
authors = ["Garden Linux Maintainers <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
packages = [{include = "gardenlinux", from="src"}]
packages = [{ include = "gardenlinux", from = "src" }]

[tool.poetry.dependencies]
python = "^3.13"
Expand All @@ -29,6 +29,7 @@ pytest = "^8.4.1"
pytest-cov = "^7.0.0"
isort = "^6.0.1"
requests-mock = "^1.12.1"
pyright = "^1.1.403"

[tool.poetry.group.docs.dependencies]
sphinx-rtd-theme = "^3.0.2"
Expand All @@ -44,13 +45,29 @@ gl-s3 = "gardenlinux.s3.__main__:main"
pythonpath = ["src"]
norecursedirs = "test-data"

[tool.isort]
profile = "black"
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"]

[tool.isort]
known_first_party = "gardenlinux"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
27 changes: 27 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Pyright is configured in 'strict' mode in pyproject.toml
// This file overrides some reports and tones them down to warnings, if they are not critical.
// It also turns some up to become warnings or errors.
"reportShadowedImports": "warning",
"reportImportCycles": "error",
"reportOptionalMemberAccess": "warning",
"reportOptionalSubscript": "warning",
"reportOptionalContextManager": "warning",
"reportOptionalCall": "warning",
"reportUnusedVariable": "warning",
"reportUnusedImport": "warning",
"reportUnusedFunction": "warning",
"reportUnusedCallResult": "none",
"reportUnusedClass": "warning",
"reportUnnecessaryCast": "warning",
"reportUnnecessaryComparison": "warning",
"reportUnnecessaryIsInstance": "warning",
"reportUnnecessaryContains": "warning",
// Becomes useful after introduction of type annotations
// "reportUnknownMemberType": "warning",
// "reportUnknownParameterType": "warning",
// "reportUnknownArgumentType": "warning",
// "reportUnknownVariableType": "warning",
"reportTypedDictNotRequiredAccess": "error",
"reportDeprecated": "warning",
}
3 changes: 2 additions & 1 deletion src/gardenlinux/apt/package_repo_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
APT repositories
"""

from apt_repo import APTRepository
from typing import Optional

from apt_repo import APTRepository


class GardenLinuxRepo(APTRepository):
"""
Expand Down
1 change: 0 additions & 1 deletion src/gardenlinux/features/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from .cname import CName
from .parser import Parser


_ARGS_TYPE_ALLOWED = [
"cname",
"cname_base",
Expand Down
3 changes: 1 addition & 2 deletions src/gardenlinux/features/cname.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
Canonical name (cname)
"""

from typing import Optional
import re
from typing import Optional

from ..constants import ARCHS

from .parser import Parser


Expand Down
9 changes: 4 additions & 5 deletions src/gardenlinux/features/cname_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
gl-cname main entrypoint
"""

from functools import reduce
from os.path import basename, dirname
import argparse
import logging
import re

from .cname import CName
from .parser import Parser
from functools import reduce
from os.path import basename, dirname

from .__main__ import (
get_cname_base,
get_minimal_feature_set,
get_version_and_commit_id_from_files,
sort_subset,
)
from .cname import CName
from .parser import Parser


def main():
Expand Down
8 changes: 4 additions & 4 deletions src/gardenlinux/features/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
Features parser based on networkx.Digraph
"""

from glob import glob
from typing import Callable, Optional
import logging
import networkx
import os
import re
import subprocess
from glob import glob
from typing import Callable, Optional

import networkx
import yaml

from ..constants import (
ARCHS,
BARE_FLAVOR_FEATURE_CONTENT,
BARE_FLAVOR_LIBC_FEATURE_CONTENT,
)

from ..logger import LoggerSetup


Expand Down
8 changes: 4 additions & 4 deletions src/gardenlinux/flavors/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
gl-flavors-parse main entrypoint
"""

from argparse import ArgumentParser
from pathlib import Path
from tempfile import TemporaryDirectory
import json
import os
import sys
from argparse import ArgumentParser
from pathlib import Path
from tempfile import TemporaryDirectory

from .parser import Parser
from ..constants import GL_REPOSITORY_URL
from ..git import Repository
from .parser import Parser


def _get_flavors_file_data(flavors_file):
Expand Down
3 changes: 2 additions & 1 deletion src/gardenlinux/flavors/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
Flavors parser
"""

from jsonschema import validate as jsonschema_validate
import fnmatch

import yaml
from jsonschema import validate as jsonschema_validate

from ..constants import GL_FLAVORS_SCHEMA
from ..logger import LoggerSetup
Expand Down
5 changes: 3 additions & 2 deletions src/gardenlinux/git/repository.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-

import sys
from os import PathLike
from pathlib import Path
import sys

from pygit2 import init_repository, Oid
from pygit2 import Oid
from pygit2 import Repository as _Repository
from pygit2 import init_repository

from ..constants import GL_REPOSITORY_URL
from ..logger import LoggerSetup
Expand Down
2 changes: 1 addition & 1 deletion src/gardenlinux/oci/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"""

import os
import click

import click
from pygments.lexer import default

from .container import Container
Expand Down
20 changes: 10 additions & 10 deletions src/gardenlinux/oci/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
"""

import json
import jsonschema
import logging
from base64 import b64encode
from configparser import ConfigParser, UNNAMED_SECTION
from collections.abc import Sequence
from configparser import UNNAMED_SECTION, ConfigParser
from hashlib import sha256
from oras.container import Container as OrasContainer
from oras.defaults import unknown_config_media_type as UNKNOWN_CONFIG_MEDIA_TYPE
from oras.provider import Registry
from oras.utils import make_targz, extract_targz
from os import fdopen, getenv, PathLike
from os import PathLike, fdopen, getenv
from pathlib import Path
from requests import Response
from tempfile import mkstemp
from typing import Optional
from urllib.parse import urlsplit

import jsonschema
from oras.container import Container as OrasContainer
from oras.defaults import unknown_config_media_type as UNKNOWN_CONFIG_MEDIA_TYPE
from oras.provider import Registry
from oras.utils import extract_targz, make_targz
from requests import Response

from ..constants import GL_MEDIA_TYPE_LOOKUP, OCI_IMAGE_INDEX_MEDIA_TYPE
from ..features.cname import CName
from ..logger import LoggerSetup

from .image_manifest import ImageManifest
from .index import Index
from .layer import Layer
from .image_manifest import ImageManifest
from .manifest import Manifest
from .schemas import index as IndexSchema

Expand Down
4 changes: 2 additions & 2 deletions src/gardenlinux/oci/image_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import json
from copy import deepcopy
from oras.oci import Layer
from os import PathLike
from pathlib import Path

from ..features import CName
from oras.oci import Layer

from ..features import CName
from .manifest import Manifest
from .platform import NewPlatform
from .schemas import EmptyManifestMetadata
Expand Down
5 changes: 3 additions & 2 deletions src/gardenlinux/oci/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from collections.abc import Mapping
from os import PathLike
from oras.defaults import annotation_title as ANNOTATION_TITLE
from oras.oci import Layer as _Layer
from pathlib import Path
from typing import Optional

from oras.defaults import annotation_title as ANNOTATION_TITLE
from oras.oci import Layer as _Layer

from ..constants import GL_MEDIA_TYPE_LOOKUP, GL_MEDIA_TYPES

_SUPPORTED_MAPPING_KEYS = ("annotations",)
Expand Down
1 change: 1 addition & 0 deletions src/gardenlinux/oci/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from copy import deepcopy
from hashlib import sha256

from oras.defaults import unknown_config_media_type as UNKNOWN_CONFIG_MEDIA_TYPE
from oras.oci import EmptyManifest

Expand Down
1 change: 0 additions & 1 deletion src/gardenlinux/s3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from .s3_artifacts import S3Artifacts


_ARGS_ACTION_ALLOWED = [
"download-artifacts-from-bucket",
"upload-artifacts-to-bucket",
Expand Down
7 changes: 4 additions & 3 deletions src/gardenlinux/s3/s3_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"""

import logging
import yaml
from configparser import ConfigParser, UNNAMED_SECTION
from configparser import UNNAMED_SECTION, ConfigParser
from datetime import datetime
from hashlib import file_digest
from os import PathLike, stat
Expand All @@ -16,9 +15,11 @@
from typing import Any, Optional
from urllib.parse import urlencode

from .bucket import Bucket
import yaml

from ..features.cname import CName
from ..logger import LoggerSetup
from .bucket import Bucket


class S3Artifacts(object):
Expand Down
3 changes: 2 additions & 1 deletion tests/apt/test_debsource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from gardenlinux.apt import DebsrcFile
import io

from gardenlinux.apt import DebsrcFile

test_data = """Package: vim
Source: vim (2:9.1.0496-1)
Version: 2:9.1.0496-1+b1
Expand Down
20 changes: 10 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
from datetime import datetime, timedelta
from tempfile import mkstemp
import json
import os
import shutil
import subprocess
import sys
import pytest
from datetime import datetime, timedelta
from tempfile import mkstemp

import pytest
from cryptography import x509
from cryptography.x509.oid import NameOID
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.x509.oid import NameOID
from dotenv import load_dotenv

from gardenlinux.features import Parser

from .constants import (
TEST_DATA_DIR,
GL_ROOT_DIR,
CERT_DIR,
GARDENLINUX_ROOT_DIR_EXAMPLE,
GL_ROOT_DIR,
TEST_ARCHITECTURES,
TEST_COMMIT,
TEST_VERSION,
TEST_PLATFORMS,
TEST_DATA_DIR,
TEST_FEATURE_SET,
TEST_FEATURE_STRINGS_SHORT,
TEST_ARCHITECTURES,
TEST_PLATFORMS,
TEST_VERSION,
)

from .helper import call_command, spawn_background_process


Expand Down
Loading
Loading