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

Integrate with Starbase #422

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6fe4c5b
chore(linter): use starbase
syu-w Nov 28, 2023
42670ba
chore(deps): sync dev deps with starbase
syu-w Nov 28, 2023
ab04163
chore(tests): update tox.ini with starbase
syu-w Nov 28, 2023
c20d6d5
chore(linter): update to 3.10 style
syu-w Nov 28, 2023
518aa7e
chore(linter): misc auto fix
syu-w Nov 28, 2023
bbb3493
chore(linter): use tuple for pytest.mark.parametrize
syu-w Nov 28, 2023
9fc89bc
chore(linter): create list without concatenate
syu-w Nov 28, 2023
d9ef893
chore(linter): misc fix
syu-w Nov 28, 2023
d1a6efb
chore(linter): fix some annotations
syu-w Nov 28, 2023
d4b888a
chore(linter): temporarily turn off unfixed rules
syu-w Nov 29, 2023
39303dc
feat(project): migrate to pyproject.toml
syu-w Nov 29, 2023
7dd8598
feat(ci): use tox.ini for ci
syu-w Nov 29, 2023
f7ce055
test: allow venv sh shebang
syu-w Nov 30, 2023
cecd533
docs: use starbase readthedocs
syu-w Nov 30, 2023
aaca617
test(docs): delete docs build spread test
syu-w Dec 1, 2023
d48cb9a
chore(linter): fix mypy annotation errors
syu-w Dec 1, 2023
3144a2b
chore(linter): fix pyright annotation errors
syu-w Dec 1, 2023
7d2cd8e
chore(linter): fix docs linter errors
syu-w Dec 1, 2023
a3c4eac
chore(linter): fix yaml linter errors
syu-w Dec 1, 2023
b17987a
Merge branch 'main' into CRAFT-2249-starbase
syu-w Dec 4, 2023
49990bc
chore(ci): sync pre commit config with pyproject
syu-w Dec 4, 2023
33e8ca3
chore(linter): move run_user typing to the top
syu-w Dec 4, 2023
af5594d
chore(linter): fix _create_app return type
syu-w Dec 4, 2023
5ad6554
chore: update the snapcraft workaround comment
syu-w Dec 4, 2023
83ffa4f
chore(linter): increase line length for README
syu-w Dec 4, 2023
aaf57c0
fix: use values for get services
syu-w Dec 4, 2023
bf6a312
test: disable tests that will not work in tox
syu-w Dec 4, 2023
c8c2259
test(spread): add an spread test for shebang
syu-w Dec 5, 2023
d12616a
docs: update the how-to build docs to use tox
syu-w Dec 5, 2023
20a0ab9
chore(ci): fix naming
syu-w Dec 5, 2023
a1fd0ef
chore(deps): use requirements.txt with pyproject.toml
syu-w Dec 5, 2023
a3417f8
chore(snap): use setup.py
syu-w Dec 5, 2023
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
4 changes: 2 additions & 2 deletions rockcraft/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def run() -> int:

app = _create_app()

return app.run()
return app.run() # type: ignore[no-any-return]


def _create_app(): # noqa: ANN202
def _create_app(): # type: ignore[no-untyped-def] # noqa: ANN202
# pylint: disable=import-outside-toplevel
# Import these here so that the script that generates the docs for the
# commands doesn't need to know *too much* of the application.
Expand Down
19 changes: 13 additions & 6 deletions rockcraft/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import yaml
from craft_application.models import BuildInfo
from craft_application.models import Project as BaseProject
from craft_archives import repo
from craft_archives import repo # type: ignore[import-untyped]
from craft_providers import bases
from pydantic_yaml import YamlModelMixin

Expand All @@ -50,8 +50,10 @@
class Platform(pydantic.BaseModel):
"""Rockcraft project platform definition."""

build_on: pydantic.conlist(str, unique_items=True, min_items=1) | None
build_for: pydantic.conlist(str, unique_items=True, min_items=1) | None
build_on: pydantic.conlist(str, unique_items=True, min_items=1) | None # type: ignore[valid-type]
build_for: pydantic.conlist( # type: ignore[valid-type]
str, unique_items=True, min_items=1
) | None

class Config: # pylint: disable=too-few-public-methods
"""Pydantic model configuration."""
Expand Down Expand Up @@ -188,7 +190,7 @@ def _validate_license(cls, rock_license: str) -> str:
raise ProjectValidationError(
f"License {rock_license} not valid. It must be valid and in SPDX format."
)
return lic.id
return str(lic.id)

@pydantic.validator("title", always=True)
@classmethod
Expand Down Expand Up @@ -337,7 +339,12 @@ def _validate_entrypoint_service(
"a valid Pebble service."
)

command = values.get("services")[entrypoint_service].command
services = values.get("services")
syu-w marked this conversation as resolved.
Show resolved Hide resolved
if services:
command = services[entrypoint_service].command
else:
raise ProjectValidationError("The project does not define any services.")

command_sh_args = shlex.split(command)
# optional arg is surrounded by brackets, so check that they exist in the
# right order
Expand Down Expand Up @@ -432,7 +439,7 @@ def unmarshal(cls, data: dict[str, Any]) -> "Project":

def generate_metadata(
self, generation_time: str, base_digest: bytes
) -> tuple[dict, dict]:
) -> tuple[dict[str, Any], dict[str, Any]]:
"""Generate the ROCK's metadata (both the OCI annotation and internal metadata.

:param generation_time: the UTC time at the time of calling this method
Expand Down
9 changes: 5 additions & 4 deletions rockcraft/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,14 @@ def add_user(
emit.progress(f"Adding user {username}:{uid} with group {username}:{uid}")
self.add_layer(tag, Path(tmpfs))

def stat(self) -> dict[Any, Any]:
def stat(self) -> dict[str, Any]:
"""Obtain the image statistics, as reported by "umoci stat --json"."""
image_path = self.path / self.image_name
output = _process_run(
output: bytes = _process_run(
["umoci", "stat", "--json", "--image", str(image_path)]
).stdout
return json.loads(output)
result: dict[str, Any] = json.loads(output)
return result

@staticmethod
def digest(source_image: str) -> bytes:
Expand Down Expand Up @@ -598,7 +599,7 @@ def _inject_architecture_variant(image_path: Path, variant: str) -> None:
tl_index_path.write_bytes(json.dumps(tl_index).encode("utf-8"))


def _process_run(command: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
def _process_run(command: list[str], **kwargs: Any) -> subprocess.CompletedProcess[Any]:
"""Run a command and handle its output."""
if not Path(command[0]).is_absolute():
command[0] = get_snap_command_path(command[0])
Expand Down
2 changes: 1 addition & 1 deletion rockcraft/plugins/python_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PythonPlugin(python_plugin.PythonPlugin):
@override
def _should_remove_symlinks(self) -> bool:
"""Overridden because for ubuntu bases we must always remove the symlinks."""
return self._part_info.base != "bare"
return bool(self._part_info.base != "bare")
syu-w marked this conversation as resolved.
Show resolved Hide resolved

@override
def _get_system_python_interpreter(self) -> str | None:
Expand Down
10 changes: 6 additions & 4 deletions rockcraft/services/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
from typing import Any, cast

from craft_application import LifecycleService
from craft_archives import repo
from craft_archives import repo # type: ignore[import-untyped]
from craft_cli import emit
from craft_parts import Features, LifecycleManager, Step, callbacks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ir seems that this can imported only if TYPE_CHECKING?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got:

rockcraft/services/lifecycle.py:35:29: TCH004 Move import `craft_parts.LifecycleManager` out of type-checking block. Import is used for more than type hinting.

from craft_parts.errors import CallbackRegistrationError
from craft_parts.infos import ProjectInfo
from craft_parts.infos import ProjectInfo, StepInfo
from overrides import override

from rockcraft import layers
Expand Down Expand Up @@ -111,10 +111,12 @@ def _install_overlay_repositories(overlay_dir: Path, project_info: ProjectInfo)
)


def _post_prime_callback(step_info) -> bool:
def _post_prime_callback(step_info: StepInfo) -> bool:
prime_dir = step_info.prime_dir
files = step_info.state.files
base_layer_dir = step_info.rootfs_dir
files: set[str]

files = step_info.state.files if step_info.state else set()

layers.prune_prime_files(prime_dir, files, base_layer_dir)
return True
3 changes: 2 additions & 1 deletion rockcraft/usernames.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

"""List of allowed shared usernames/UIDs (analogously to SnapD)."""


import pydantic


Expand All @@ -38,7 +39,7 @@ def _validate_run_user(cls, username: str) -> str:

return username

def get_dict(self) -> dict:
def get_dict(self) -> dict[str, dict[str, int]]:
"""Cast the object into a dict using the username as the key."""
return {self.username: {"uid": self.uid}}

Expand Down