Coverage for tsfpga/ip_core_file.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-21 20:51 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project, a project platform for modern FPGA development. 

5# https://tsfpga.com 

6# https://github.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9from pathlib import Path 

10from typing import Any 

11 

12 

13class IpCoreFile: 

14 """ 

15 Class for handling an IP core file. 

16 """ 

17 

18 def __init__( 

19 self, 

20 path: Path, 

21 **variables: Any, # noqa: ANN401 

22 ) -> None: 

23 """ 

24 Arguments: 

25 path: Path to the TCL script that creates the IP. 

26 Should typically end in .tcl. 

27 variables: These name/value variable pairs will be set in TCL before 

28 the IP core ``.tcl`` file is sourced. This makes it possible to parameterize the IP 

29 core creation. 

30 

31 .. note:: 

32 This is a "kwargs" style argument. You can pass any number of named arguments. 

33 """ 

34 self.path = path 

35 self.variables = variables 

36 

37 @property 

38 def name(self) -> str: 

39 """ 

40 A shorthand name for this IP core. 

41 """ 

42 file_name_no_suffix = self.path.stem 

43 if " " in file_name_no_suffix: 

44 raise ValueError(f"File name may not contain spaces: {self.path}") 

45 return file_name_no_suffix 

46 

47 def __str__(self) -> str: 

48 return f"{self.__class__.__name__}:{self.path}:{self.variables}"