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
47 changes: 21 additions & 26 deletions fusesoc/librarymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,36 @@
import os

from fusesoc.provider.provider import get_provider
from pydantic import model_validator
from pydantic.dataclasses import dataclass
from typing_extensions import Self

logger = logging.getLogger(__name__)


@dataclass(config={"validate_assignment": True})
class Library:
def __init__(
self,
name,
location,
sync_type=None,
sync_uri=None,
sync_version=None,
auto_sync=True,
):
if sync_type and not sync_type in ["local", "git"]:
name: str
location: str
sync_type: str | None = None
sync_uri: str | None = None
sync_version: str | None = None
auto_sync: bool = True

@model_validator(mode="after")
def check_instances(self) -> Self:
if self.sync_type and not self.sync_type in ["local", "git"]:
raise ValueError(
"Library {} ({}) Invalid sync-type '{}'".format(
name, location, sync_type
)
f"Library {self.name} ({self.location}) "
f"Invalid sync-type '{self.sync_type}'"
)

if sync_type in ["git"]:
if not sync_uri:
if self.sync_type in ["git"]:
if not self.sync_uri:
raise ValueError(
"Library {} ({}) sync-uri must be set when using sync_type 'git'".format(
name, location
)
f"Library {self.name} ({self.location}) "
"sync-uri must be set when using sync_type 'git'"
)

self.name = name
self.location = location
self.sync_type = sync_type or "local"
self.sync_uri = sync_uri
self.sync_version = sync_version
self.auto_sync = auto_sync
return self

def update(self, force=False):
def l(s):
Expand Down
5 changes: 4 additions & 1 deletion fusesoc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from yaml import SafeDumper as YamlDumper
from yaml import SafeLoader as YamlLoader

from pydantic import validate_call

from fusesoc.capi2.inheritance import Inheritance

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -62,7 +64,8 @@ def cygpath(win_path):
import os


def unique_dirs(file_list):
@validate_call
def unique_dirs(file_list: list[str]) -> list[str]:
return list({os.path.dirname(f) for f in file_list})


Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ dependencies = [
"edalize>=0.4.1",
"pyparsing>=2.3.1",
"pyyaml>=6.0",
"pydantic>=2.10.6",
"simplesat>=0.9.1",
"fastjsonschema",
"jsonschema2md",
"argcomplete",
]
requires-python = ">=3.6, <4"
requires-python = ">=3.10, <4"

[project.urls]
Homepage = "https://fusesoc.net"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_edalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_generators():
tests_dir = Path(__file__).parent
cores_dir = tests_dir / "capi2_cores" / "misc" / "generate"

lib = Library("edalizer", cores_dir)
lib = Library("edalizer", str(cores_dir))

cm = CoreManager(Config())
cm.add_library(lib, [])
Expand Down