Skip to content

Commit

Permalink
fix: update buildspec and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
esynr3z committed Oct 24, 2024
1 parent 477c946 commit 164ca10
Show file tree
Hide file tree
Showing 13 changed files with 670 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ __pycache__
build
dist
*.egg-info
corsair/_version.py
.coverage
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ repos:
pass_filenames: false
files: ^(.*/)?(poetry\.lock|pyproject\.toml)$

- id: poetry-install
name: poetry-install
description: Run poetry install to install dependencies from the lock file
entry: poetry install
language: python
- id: pytest
name: Pytest smoke testing
description: Run pytest to execute all smoke tests
entry: poetry run pytest -m "smoke"
language: system
pass_filenames: false
stages: [post-checkout, post-merge]
stages: [pre-commit]
always_run: true
15 changes: 13 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import sys
"""Configuration for pytest."""

from __future__ import annotations

collect_ignore = ['setup.py', 'docs']
from typing import TYPE_CHECKING

if TYPE_CHECKING:
import pytest

collect_ignore = ["docs"]


def pytest_configure(config: pytest.Config) -> None:
"""Perform initial configuration."""
config.addinivalue_line("markers", "smoke: mark test as smoke to run before commiting code")
12 changes: 7 additions & 5 deletions corsair/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# Disable any rich formated output if user wish (disables color as well)
if os.getenv("TERM") in ("dumb", "unknown"):
# Values above are from rich package documentation, but for typer we need to apply them manually
typer.core.rich = None
typer.core.rich = None # pyright: ignore [reportAttributeAccessIssue]
app.pretty_exceptions_enable = False

# Enable verbose output for debugging if user wish
Expand All @@ -49,11 +49,13 @@
@app.command()
def build(
spec: Annotated[
Path,
Path | None,
typer.Argument(
help="Path to a build specification file.",
show_default=False,
help="Optional path to a build specification file. "
"By default, 'crsbuild.toml' or '*.csrbuild.toml' are expected.",
),
] = Path("corsair.toml"),
] = Path("csrbuild.toml"),
targets: Annotated[
list[str] | None,
typer.Option(
Expand Down Expand Up @@ -100,7 +102,7 @@ def schemas(outdir: Annotated[Path, typer.Argument(help="Path for output files."
"""Dump JSON schemas for all possible user input files."""
logger.debug("cmd schemas args: %s", locals())
with utils.chdir(outdir):
buildspec_schema = outdir / "corsair.buildspec.json"
buildspec_schema = outdir / "csrbuild.schema.json"
logger.info("Dump schema for the build specification: %s", buildspec_schema)
input.buildspec.BuildSpecification.to_json_schema_file(buildspec_schema)

Expand Down
6 changes: 3 additions & 3 deletions corsair/input/buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
if TYPE_CHECKING:
from pathlib import Path

from .config import GlobalConfig
from .target import AnyTarget

from pydantic import BaseModel, Field

from .config import GlobalConfig
from .target import AnyTarget

if sys.version_info >= (3, 11):
import tomllib as tomlib
else:
Expand Down
9 changes: 3 additions & 6 deletions corsair/input/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pathlib import Path
from pathlib import Path

from pydantic import (
BaseModel,
Expand Down Expand Up @@ -50,10 +47,10 @@ class ForceNameCase(str, Enum):
class GlobalConfig(BaseModel):
"""Global configuration parameters of the Corsair build specification."""

regmap: Path
regmap: Path = Path("csrmap.yaml")
"""Path to a register map to be processed."""

regmap_parser: str | None = Field(pattern=r"^.*\.py::\w+$", examples=["foo.py::FooParser"])
regmap_parser: str | None = Field(default=None, pattern=r"^.+\.py::\w+$", examples=["foo.py::FooParser"])
"""Select register map parser class explicitly.
Parser is selected automatically based on file extension if value is not provided.
Expand Down
119 changes: 112 additions & 7 deletions poetry.lock

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

Loading

0 comments on commit 164ca10

Please sign in to comment.