Skip to content

Commit

Permalink
Add config parameter for kpm_build location
Browse files Browse the repository at this point in the history
Signed-off-by: bbrzyski <[email protected]>
  • Loading branch information
bbrzyski authored and koblonczek committed Dec 10, 2024
1 parent 3ccfa11 commit 7ac377b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added "IP Cores", "Externals", and "Constants" layers to the GUI which you can hide/show from the settings
- Nox session for downloading and packaging FuseSoc libraries
- Support Python 3.13 and dropped support for Python 3.8
- Added to config option for choosing a location where KPM server should be built
- All in one command `topwrap gui` for building, starting the KPM server and connecting the client to it.

### Changed

- All YAML files internal to Topwrap (examples, tests, built-in repo) now only use the `.yaml` extension
- Default location for built KPM server from `./build/` to `$XDG_CACHE_HOME/topwrap/kpm_build`

### Fixed

Expand Down
31 changes: 13 additions & 18 deletions topwrap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import concurrent.futures
import json
import logging
import os
import subprocess
import sys
import threading
Expand All @@ -15,6 +14,14 @@

import click

from topwrap.config import (
DEFAULT_BACKEND_ADDR,
DEFAULT_BACKEND_PORT,
DEFAULT_FRONTEND_DIR,
DEFAULT_SERVER_ADDR,
DEFAULT_SERVER_PORT,
DEFAULT_WORKSPACE_DIR,
)
from topwrap.design_to_kpm_dataflow_parser import kpm_dataflow_from_design_descr
from topwrap.kpm_common import RPCparams
from topwrap.yamls_to_kpm_spec_parser import ipcore_yamls_to_kpm_spec
Expand Down Expand Up @@ -179,18 +186,6 @@ def parse_main(
logging.info(f"VHDL Module '{vhdl_mod.module_name}'" f"saved in file '{yaml_path}'")


DEFAULT_SERVER_BASE_DIR = (
Path(os.environ.get("XDG_CACHE_HOME", "~/.local/cache")).expanduser() / "topwrap/kpm_build"
)
DEFAULT_WORKSPACE_DIR = DEFAULT_SERVER_BASE_DIR / "workspace"
DEFAULT_BACKEND_DIR = DEFAULT_SERVER_BASE_DIR / "backend"
DEFAULT_FRONTEND_DIR = DEFAULT_SERVER_BASE_DIR / "frontend"
DEFAULT_SERVER_ADDR = "127.0.0.1"
DEFAULT_SERVER_PORT = 9000
DEFAULT_BACKEND_ADDR = "127.0.0.1"
DEFAULT_BACKEND_PORT = 5000


class KPM:
@staticmethod
def build_server(**params_dict: Any):
Expand Down Expand Up @@ -286,13 +281,13 @@ def kpm_client_main(
@click.option(
"--workspace-directory",
type=click_opt_rw_dir,
default=DEFAULT_WORKSPACE_DIR,
default=Path(config.kpm_build_location) / DEFAULT_WORKSPACE_DIR,
help="Directory where the frontend sources should be stored",
)
@click.option(
"--output-directory",
type=click_opt_rw_dir,
default=DEFAULT_FRONTEND_DIR,
default=Path(config.kpm_build_location) / DEFAULT_FRONTEND_DIR,
help="Directory where the built frontend should be stored",
)
@click.pass_context
Expand All @@ -304,7 +299,7 @@ def kpm_build_server_ctx(ctx: click.Context, **_):
@click.option(
"--frontend-directory",
type=click_r_dir,
default=DEFAULT_FRONTEND_DIR,
default=Path(config.kpm_build_location) / DEFAULT_FRONTEND_DIR,
help="Location of the built frontend",
)
@click.option(
Expand Down Expand Up @@ -359,13 +354,13 @@ def kpm_run_server_ctx(ctx: click.Context, **_):
@click.option(
"--frontend-directory",
type=click_opt_rw_dir,
default=DEFAULT_FRONTEND_DIR,
default=Path(config.kpm_build_location) / DEFAULT_FRONTEND_DIR,
help="Location of the built frontend",
)
@click.option(
"--workspace-directory",
type=click_opt_rw_dir,
default=DEFAULT_WORKSPACE_DIR,
default=Path(config.kpm_build_location) / DEFAULT_WORKSPACE_DIR,
help="Directory where the frontend sources should be stored",
)
@click.option("--log-level", default="INFO", help="Log level")
Expand Down
19 changes: 17 additions & 2 deletions topwrap/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import logging
from os import PathLike
import os
from pathlib import Path
from typing import List, Optional

Expand All @@ -15,6 +15,17 @@

logger = logging.getLogger(__name__)

DEFAULT_SERVER_BASE_DIR = (
Path(os.environ.get("XDG_CACHE_HOME", "~/.local/cache")).expanduser() / "topwrap/kpm_build"
)
DEFAULT_WORKSPACE_DIR = "workspace"
DEFAULT_BACKEND_DIR = "backend"
DEFAULT_FRONTEND_DIR = "frontend"
DEFAULT_SERVER_ADDR = "127.0.0.1"
DEFAULT_SERVER_PORT = 9000
DEFAULT_BACKEND_ADDR = "127.0.0.1"
DEFAULT_BACKEND_PORT = 5000


class InvalidConfigError(Exception):
"""Raised when the provided configuration is incorrect"""
Expand All @@ -34,11 +45,15 @@ class Config(MarshmallowDataclassExtensions):

force_interface_compliance: Optional[bool] = ext_field(False)
repositories: Optional[List[RepositoryEntry]] = ext_field(list)
kpm_build_location: str = ext_field(str(DEFAULT_SERVER_BASE_DIR))

def update(self, config: "Config"):
if config.force_interface_compliance is not None:
self.force_interface_compliance = config.force_interface_compliance

if config.kpm_build_location is not None:
self.kpm_build_location = config.kpm_build_location

if config.repositories is not None:
if self.repositories is None:
self.repositories = config.repositories
Expand Down Expand Up @@ -87,7 +102,7 @@ class ConfigManager:

_interfaces_dir = Path("interfaces")

def __init__(self, search_paths: Optional[List[PathLike]] = None):
def __init__(self, search_paths: Optional[List[str]] = None):
if search_paths is None:
search_paths = self.DEFAULT_SEARCH_PATHS

Expand Down

0 comments on commit 7ac377b

Please sign in to comment.