Skip to content

Commit

Permalink
feat: basic craftcraft app
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Jan 4, 2024
1 parent 8a8ed38 commit 0072119
Show file tree
Hide file tree
Showing 18 changed files with 801 additions and 29 deletions.
14 changes: 3 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,15 @@ repos:
- id: check-vcs-permalinks
- id: fix-byte-order-marker
- id: mixed-line-ending
- repo: https://github.com/charliermarsh/ruff-pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
# renovate: datasource=pypi;depName=ruff
rev: "v0.1.11"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
# renovate: datasource=pypi;depName=black
rev: "23.12.1"
hooks:
- id: black
args: [--fix]
- id: ruff-format
- repo: https://github.com/adrienverge/yamllint.git
# renovate: datasource=pypi;depName=yamllint
rev: "v1.33.0"
hooks:
- id: yamllint
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
hooks:
- id: mypy
42 changes: 42 additions & 0 deletions craftcraft/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is part of craftcraft.
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Craftcraft: Verify your sources."""

from craft_parts.features import Features

from . import models
from .application import Craftcraft

try:
# This only gets created at wheel-creation time, so we're ignoring all of
# it for type checking purposes.
from ._version import ( # type: ignore[import]
__version__,
)
except ImportError: # pragma: no cover
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("craftcraft")
except PackageNotFoundError:
__version__ = "dev"

Features(
enable_overlay=False,
enable_partitions=True,
)

__all__ = ["__version__", "models", "Craftcraft"]
21 changes: 21 additions & 0 deletions craftcraft/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is part of craftcraft
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Entrypoint to use if running with python -m craftcraft."""
import sys

from craftcraft.cli import main

sys.exit(main())
69 changes: 69 additions & 0 deletions craftcraft/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This file is part of craftcraft.
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Main application class for craftcraft."""
import copy
from typing import Any

import craft_parts
from craft_application import Application, AppMetadata, util

from craftcraft import models

APP_METADATA = AppMetadata(
name="craftcraft",
summary="Craft a craft application with craft-application",
ProjectClass=models.Project,
)


class Craftcraft(Application):
"""Craftcraft application definition."""

def configure(self, global_args: dict[str, Any]) -> None:
"""Configure the application using global command-line arguments."""

def _configure_services(self, platform: str | None, build_for: str | None) -> None:
if build_for is None:
build_for = util.get_host_architecture()

self.services.set_kwargs(
"package",
platform=platform,
build_for=build_for,
)
super()._configure_services(platform, build_for)

def _extra_yaml_transform(self, yaml_data: dict[str, Any]) -> dict[str, Any]:
"""Transform the YAML file before parsing it as a project."""
yaml_data = copy.deepcopy(yaml_data)

# Put your transforms here.
yaml_data.update({})

return yaml_data

def _project_vars(self, yaml_data: dict[str, Any]) -> dict[str, str]:
"""Populate any variables to be used in the project info."""
project_vars = super()._project_vars(yaml_data)

# Update the dictionary here.
project_vars.update({})

return project_vars

def _set_global_environment(self, info: craft_parts.ProjectInfo) -> None:
"""Populate the global environment to use when running the parts lifecycle."""
super()._set_global_environment(info)
31 changes: 31 additions & 0 deletions craftcraft/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is part of craftcraft.
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Command-line interface entrypoint."""

from craftcraft import Craftcraft, application, services


def main() -> int:
"""Start up and run Craftcraft."""
factory = services.ServiceFactory(
app=application.APP_METADATA,
LifecycleClass=services.Lifecycle,
PackageClass=services.Package,
)

app = Craftcraft(app=application.APP_METADATA, services=factory)

return app.run()
27 changes: 27 additions & 0 deletions craftcraft/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is part of craftcraft.
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Global constants to use in craftcraft."""

# Bases supported by this application.
SUPPORTED_BASES = [
"ubuntu@22.04",
]

# Bases that , as well as the version in which they were deprecated.
DEPRECATED_BASES: dict[str, str] = {
# Map the base name to the version in which it was deprecated.
"ubuntu@20.04": "0.0",
}
22 changes: 22 additions & 0 deletions craftcraft/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is part of craftcraft.
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Data models for Craftcraft."""

from .metadata import Metadata
from .project import Project
from .util import Base

__all__ = ["Metadata", "Project"]
31 changes: 31 additions & 0 deletions craftcraft/models/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is part of craftcraft.
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""metadata.yaml description for craftcraft output."""

from craft_application.models import BaseMetadata

from craftcraft.models.util import Base


class Metadata(BaseMetadata):
"""Structure to hold output metadata."""

name: str
summary: str
description: str
version: str
license: str
base: Base
Loading

0 comments on commit 0072119

Please sign in to comment.