Coverage for tsfpga/ip_core_file.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 20:52 +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 

9# Standard libraries 

10from pathlib import Path 

11from typing import Any 

12 

13 

14class IpCoreFile: 

15 """ 

16 Class for handling an IP core file. 

17 """ 

18 

19 def __init__(self, path: Path, **variables: Any) -> None: 

20 """ 

21 Arguments: 

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

23 Should typically end in .tcl. 

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

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

26 core creation. 

27 

28 .. note:: 

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

30 """ 

31 self.path = path 

32 self.variables = variables 

33 

34 @property 

35 def name(self) -> str: 

36 """ 

37 A shorthand name for this IP core. 

38 """ 

39 file_name_no_suffix = self.path.stem 

40 if " " in file_name_no_suffix: 

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

42 return file_name_no_suffix 

43 

44 def __str__(self) -> str: 

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