Skip to content
Draft
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
6 changes: 6 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
fetch-depth: 0
# Number of commits to fetch. 0 indicates all history for all branches and tags.

#----------------------------------------------
# install uv and uvx
#----------------------------------------------
- name: Install uv and uvx
uses: astral-sh/setup-uv@v8.1.0

#----------------------------------------------
# poetry is not in the default image
#----------------------------------------------
Expand Down
31 changes: 16 additions & 15 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sphinxcontrib-mermaid = ">=1.0.0"
optional = true
[tool.poetry.group.test.dependencies]
coverage = ">=6.4.3,<8.0.0"
pytest = "^7.1.2"
pytest = ">=7.1.2,<10.0.0"
pytest-github-actions-annotate-failures = ">=0.1.7,<0.3.0"
pytest-json-report = "^1.5.0"
pytest-metadata = ">=2.0.2,<4.0.0"
Expand Down
14 changes: 12 additions & 2 deletions src/stubber/commands/build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from stubber.commands.cli import stubber_cli
from stubber.publish.defaults import GENERIC_U
from stubber.publish.enums import PackageType
from stubber.publish.publish import build_multiple
from stubber.utils.config import CONFIG

Expand Down Expand Up @@ -55,14 +56,22 @@
default=False,
help="build package even if no changes detected",
)
@click.option(
"--package-type",
"package_type",
type=click.Choice([t.value for t in PackageType], case_sensitive=False),
default=CONFIG.package_type.value,
show_default=True,
help="Package build tool to use (poetry or hatch)",
)
def cli_build(
family: str,
versions: Union[str, List[str]],
ports: Union[str, List[str]],
boards: Union[str, List[str]],
clean: bool,
force: bool,
# stub_type: str,
package_type: str,
):
"""
Commandline interface to publish stubs.
Expand All @@ -76,7 +85,7 @@ def cli_build(
if len(versions) > 1:
raise NotImplementedError("Multiple versions are not supported yet\n See https://github.com/Josverl/micropython-stubber/issues/487")

log.info(f"Build {family} {versions} {ports} {boards}")
log.info(f"Build {family} {versions} {ports} {boards} using {package_type}")

results = build_multiple(
family=family,
Expand All @@ -86,6 +95,7 @@ def cli_build(
production=True, # use production database during build
force=force,
clean=clean,
package_type=PackageType(package_type),
)
# log the number of results with no error
log.info(f"Built {len([r for r in results if not r['error']])} stub packages")
Expand Down
1 change: 1 addition & 0 deletions src/stubber/commands/config_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ def cli_config():
log.info(f"CONFIG.all_versions {CONFIG.all_versions}")
log.info(f"CONFIG.stable_version {CONFIG.stable_version}")
log.info(f"CONFIG.preview_version {CONFIG.preview_version}")
log.info(f"CONFIG.package_type {CONFIG.package_type}")
13 changes: 12 additions & 1 deletion src/stubber/commands/publish_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from stubber.commands.cli import stubber_cli
from stubber.publish.defaults import GENERIC_U
from stubber.publish.enums import PackageType
from stubber.publish.publish import publish_multiple
from stubber.utils.config import CONFIG

Expand Down Expand Up @@ -80,6 +81,14 @@
default=False,
help="clean folders after processing and publishing",
)
@click.option(
"--package-type",
"package_type",
type=click.Choice([t.value for t in PackageType], case_sensitive=False),
default=CONFIG.package_type.value,
show_default=True,
help="Package build tool to use (poetry or hatch)",
)
def cli_publish(
family: str,
versions: Union[str, List[str]],
Expand All @@ -90,6 +99,7 @@ def cli_publish(
force: bool = False,
dry_run: bool = False,
clean: bool = False,
package_type: str = CONFIG.package_type.value,
):
"""
Commandline interface to publish stubs.
Expand All @@ -103,7 +113,7 @@ def cli_publish(
raise NotImplementedError("Multiple versions are not supported yet\n See https://github.com/Josverl/micropython-stubber/issues/487")

destination = "pypi" if production else "test-pypi"
log.info(f"Publish {family} {versions} {ports} {boards} to {destination}")
log.info(f"Publish {family} {versions} {ports} {boards} to {destination} using {package_type}")

results = publish_multiple(
family=family,
Expand All @@ -115,6 +125,7 @@ def cli_publish(
force=force,
dry_run=dry_run,
clean=clean,
package_type=PackageType(package_type),
)
console = Console()

Expand Down
20 changes: 19 additions & 1 deletion src/stubber/publish/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,26 @@ def get_database(db_path: Path, production: bool = False) -> sqlite3.Connection:
conn = create_database(db_path)

conn.row_factory = sqlite3.Row # return rows as dicts
_migrate_add_package_type(conn)
return conn


def _migrate_add_package_type(conn: sqlite3.Connection) -> None:
"""
Add the ``package_type`` column to the packages table if it does not exist yet.

This is a forward migration for databases created before the column was introduced.
Existing rows will default to ``'poetry'``, which preserves backward-compatible
behaviour for all packages built before multi-backend support was added.
"""
cursor = conn.cursor()
cursor.execute("PRAGMA table_info(packages)")
columns = {row[1] for row in cursor.fetchall()}
if "package_type" not in columns:
cursor.execute("ALTER TABLE packages ADD COLUMN package_type TEXT DEFAULT 'poetry'")
conn.commit()


def create_database(db_path: Path) -> sqlite3.Connection:
"""
Create a new database at the given path.
Expand All @@ -51,7 +68,8 @@ def create_database(db_path: Path) -> sqlite3.Connection:
stub_hash TEXT,
port TEXT DEFAULT "",
board TEXT DEFAULT "",
variant TEXT DEFAULT ""
variant TEXT DEFAULT "",
package_type TEXT DEFAULT "poetry"
)
"""
conn.execute(SCHEMA)
Expand Down
16 changes: 16 additions & 0 deletions src/stubber/publish/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
from enum import Enum


class PackageType(str, Enum):
"""The type of build tool used to package the stubs."""

POETRY = "poetry"
"Use Poetry as the build tool (default, backward-compatible)"

HATCH = "hatch"
"Use Hatchling as the build tool (modern PEP 517 build backend)"

def __str__(self):
return self.value

def __repr__(self):
return self.value


class StubSource(str, Enum):
# NOTE: The literal values are persisted (e.g., databases/manifests). "MCU stubs" must remain unchanged.
FIRMWARE = "MCU stubs"
Expand Down
10 changes: 7 additions & 3 deletions src/stubber/publish/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from mpflash.logger import log
from mpflash.versions import clean_version

from stubber.publish.defaults import DEFAULT, GENERIC, GENERIC_L, default_board
from stubber.publish.enums import StubSource
from stubber.publish.defaults import GENERIC, GENERIC_L, default_board
from stubber.publish.enums import PackageType, StubSource
from stubber.publish.stubpackage import StubPackage, StubSources
from stubber.utils.config import CONFIG

Expand All @@ -38,6 +38,7 @@ def get_package(
port: str,
board: str = GENERIC_L,
family: str = "micropython",
package_type: Union[PackageType, str] = CONFIG.package_type,
) -> StubPackage:
"""Get the package from the database or create a new one if it does not exist."""
pkg_name = package_name(port=port, board=board, family=family)
Expand All @@ -55,6 +56,7 @@ def get_package(
board=board,
version=version,
json_data=package_info,
package_type=package_type,
)
# @Josverl: Check or update stub_sources if len < 3
EXPECTED_STUBS = 3
Expand All @@ -74,6 +76,7 @@ def get_package(
port=port,
board=board,
family=family,
package_type=package_type,
)


Expand Down Expand Up @@ -118,6 +121,7 @@ def create_package(
port: str,
board: str = "",
family: str = "micropython",
package_type: Union[PackageType, str] = CONFIG.package_type,
# pkg_type: str = COMBO_STUBS,
) -> StubPackage: # sourcery skip: merge-duplicate-blocks, remove-redundant-if
"""
Expand All @@ -130,7 +134,7 @@ def create_package(

assert port != "", "port must be specified for combo stubs"
stub_sources = combo_sources(family, port, board, ver_flat)
return StubPackage(pkg_name, port=port, board=board, version=mpy_version, stub_sources=stub_sources)
return StubPackage(pkg_name, port=port, board=board, version=mpy_version, stub_sources=stub_sources, package_type=package_type)


def combo_sources(family: str, port: str, board: str, ver_flat: str) -> StubSources:
Expand Down
9 changes: 6 additions & 3 deletions src/stubber/publish/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from stubber.publish.candidates import board_candidates, filter_list
from stubber.publish.database import get_database
from stubber.publish.defaults import DEFAULT_L, GENERIC_L, GENERIC_U
from stubber.publish.defaults import GENERIC_U
from stubber.publish.enums import PackageType
from stubber.publish.package import get_package
from stubber.utils.config import CONFIG

Expand All @@ -24,6 +25,7 @@ def build_multiple(
production: bool = False,
clean: bool = False,
force: bool = False,
package_type: Union[PackageType, str] = CONFIG.package_type,
) -> List[Dict[str, Any]]: # sourcery skip: default-mutable-arg
"""
Build a bunch of stub packages
Expand All @@ -42,7 +44,7 @@ def build_multiple(
log.info(f"checking {len(worklist)} possible board candidates")

for todo in worklist:
if package := get_package(db_conn, **todo):
if package := get_package(db_conn, **todo, package_type=package_type):
package.build_distribution(force=force, production=production)
results.append(package.status)
else:
Expand All @@ -60,6 +62,7 @@ def publish_multiple(
build: bool = False,
force: bool = False,
dry_run: bool = False,
package_type: Union[PackageType, str] = CONFIG.package_type,
) -> List[Dict[str, Any]]: # sourcery skip: default-mutable-arg
"""
Publish a bunch of stub packages
Expand All @@ -78,7 +81,7 @@ def publish_multiple(
return results

for todo in worklist:
if package := get_package(db_conn, **todo):
if package := get_package(db_conn, **todo, package_type=package_type):
package.publish_distribution_ifchanged(
db_conn=db_conn,
clean=clean,
Expand Down
Loading
Loading