base: moved libdir parameter as field in the Library
Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
This commit is contained in:
parent
dbba89f549
commit
2770251073
|
@ -518,6 +518,7 @@ class Library:
|
||||||
type: LibraryType = dj_pass_cfg()
|
type: LibraryType = dj_pass_cfg()
|
||||||
name: str = ''
|
name: str = ''
|
||||||
version: Optional[LibraryVersion] = None
|
version: Optional[LibraryVersion] = None
|
||||||
|
rootdir: str = ''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fullname(self):
|
def fullname(self):
|
||||||
|
@ -530,7 +531,7 @@ class Library:
|
||||||
return "_".join(output)
|
return "_".join(output)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, s):
|
def parse(cls, s, libroot=''):
|
||||||
if SEPERATOR in s:
|
if SEPERATOR in s:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Found separator '__' in library name: {!r}".format(s))
|
"Found separator '__' in library name: {!r}".format(s))
|
||||||
|
@ -546,10 +547,11 @@ class Library:
|
||||||
kw['type'] = LibraryType.parse(bits.pop(0))
|
kw['type'] = LibraryType.parse(bits.pop(0))
|
||||||
if bits:
|
if bits:
|
||||||
kw['name'] = bits.pop(0)
|
kw['name'] = bits.pop(0)
|
||||||
|
kw['rootdir'] = libroot
|
||||||
return cls(**kw)
|
return cls(**kw)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_libraries(cls, libroot : str) -> Iterator['Library']:
|
def get_libraries(cls, libroot : str = '') -> Iterator['Library']:
|
||||||
"""
|
"""
|
||||||
Lists libraries present in the libroot directory.
|
Lists libraries present in the libroot directory.
|
||||||
|
|
||||||
|
@ -563,55 +565,46 @@ class Library:
|
||||||
Library : next library object
|
Library : next library object
|
||||||
"""
|
"""
|
||||||
libroot = Path(libroot)
|
libroot = Path(libroot)
|
||||||
|
assert libroot.is_dir()
|
||||||
for libdir in libroot.iterdir():
|
for libdir in libroot.iterdir():
|
||||||
if libdir.is_dir():
|
if libdir.is_dir():
|
||||||
yield cls.parse(libdir.name)
|
yield cls.parse(libdir.name, libroot)
|
||||||
|
|
||||||
def get_versions(self, libroot : str) -> Iterator['LibraryVersion']:
|
def get_versions(self) -> Iterator['LibraryVersion']:
|
||||||
"""
|
"""
|
||||||
Lists versions of the library.
|
Lists versions of the library.
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
libroot : str
|
|
||||||
Path to the Skywater PDK libraries.
|
|
||||||
|
|
||||||
Yields
|
Yields
|
||||||
------
|
------
|
||||||
LibraryVersion : next version of the library
|
LibraryVersion : next version of the library
|
||||||
"""
|
"""
|
||||||
libdir = Path(libroot) / self.fullname
|
libdir = Path(self.rootdir) / self.fullname
|
||||||
for version in libdir.iterdir():
|
for version in libdir.iterdir():
|
||||||
if version.is_dir() and version.name != 'latest':
|
if version.is_dir() and version.name != 'latest':
|
||||||
yield LibraryVersion.parse(version.name)
|
yield LibraryVersion.parse(version.name)
|
||||||
|
|
||||||
def get_cells(self, libroot) -> Iterator['Cell']:
|
def get_cells(self) -> Iterator['Cell']:
|
||||||
"""
|
"""
|
||||||
Lists cells for the library.
|
Lists cells for the library.
|
||||||
|
|
||||||
If the version of the library is not specified, the cells for the
|
If the version of the library is not specified, the cells for the
|
||||||
'latest' version are listed.
|
'latest' version are listed.
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
libroot : str
|
|
||||||
Path to the Skywater PDK libraries.
|
|
||||||
|
|
||||||
Yields
|
Yields
|
||||||
------
|
------
|
||||||
Cell : next cell in the library
|
Cell : next cell in the library
|
||||||
"""
|
"""
|
||||||
libdir = Path(libroot) / self.fullname
|
libdir = Path(self.rootdir) / self.fullname
|
||||||
version = 'latest'
|
version = 'latest'
|
||||||
if self.version:
|
if self.version:
|
||||||
version = f'v{self.version.fullname}'
|
version = f'v{self.version.fullname}'
|
||||||
libdir = libdir / version / 'cells'
|
libdir = libdir / version / 'cells'
|
||||||
assert libdir.is_dir()
|
if libdir.is_dir():
|
||||||
for cell in libdir.iterdir():
|
for cell in libdir.iterdir():
|
||||||
if cell.is_dir():
|
if cell.is_dir():
|
||||||
cell = Cell.parse(cell.name)
|
cell = Cell.parse(cell.name)
|
||||||
cell.library = self
|
cell.library = self
|
||||||
yield cell
|
yield cell
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
|
@ -663,6 +656,23 @@ class Cell:
|
||||||
kw['name'] = s
|
kw['name'] = s
|
||||||
return cls(**kw)
|
return cls(**kw)
|
||||||
|
|
||||||
|
def get_matching_files(self, pattern) -> Iterator[str]:
|
||||||
|
"""
|
||||||
|
Yields files for a matching pattern for a given cell if present.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
pattern : str
|
||||||
|
The file pattern to look for
|
||||||
|
|
||||||
|
Yields
|
||||||
|
------
|
||||||
|
str : path to files for a given cell
|
||||||
|
"""
|
||||||
|
celldir = Path(convert_to_path(self, self.library.rootdir))
|
||||||
|
for filename in celldir.glob(pattern):
|
||||||
|
yield str(filename)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
Loading…
Reference in New Issue