base: added method for converting Library/Cell to corresponding path

Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
This commit is contained in:
Grzegorz Latosinski 2020-12-02 15:43:16 +01:00
parent 69c025e4b5
commit dbba89f549
1 changed files with 44 additions and 2 deletions

View File

@ -157,7 +157,6 @@ def parse_pathname(pathname):
return lib, filename
def parse_filename(pathname) -> Tuple[LibraryOrCell, Optional[str], Optional[str]]:
"""Extract library and module name from filename.
@ -258,6 +257,50 @@ def parse_filename(pathname) -> Tuple[LibraryOrCell, Optional[str], Optional[str
return (library, extra, extension)
def convert_to_path(libraryorcell: LibraryOrCell, libdir : str):
"""Create path to the library or cell from the objects
Parameters
----------
libraryorcell : Library or Cell
Library or Cell information
libdir : str
Path to the root directory of the Skywater PDK libraries
Returns
-------
str : Path to the library (or cell) directory
See Also
--------
skywater_pdk.base.parse_pathname
skywater_pdk.base.Cell
skywater_pdk.base.Library
Examples
--------
>>> lib = parse_pathname('libraries/sky130_fd_pr/v0.0.1')[0]
>>> convert_to_path(lib, 'libraries')
'libraries/sky130_fd_pr/v0.0.1'
>>> cell = parse_pathname('libraries/sky130_fd_pr/v0.20.1/cells/cap_mim_m3/sky130_fd_pr__cap_mim_m3_1.model.spice')[0]
>>> convert_to_path(cell, 'libraries')
'libraries/sky130_fd_pr/v0.20.1/cells/cap_mim_m3'
"""
assert type(libraryorcell) is Library or type(libraryorcell) is Cell
libdir = Path(libdir)
if type(libraryorcell) is Library:
version = (f'v{libraryorcell.version.fullname}'
if libraryorcell.version else 'latest')
return str(libdir / libraryorcell.fullname / version)
if type(libraryorcell) is Cell:
library = libraryorcell.library
version = (f'v{library.version.fullname}'
if library.version else 'latest')
libname = library.fullname
return str(libdir / libname / version / 'cells' / libraryorcell.name)
SEPERATOR = "__"
@comparable_to_none
@ -621,7 +664,6 @@ class Cell:
return cls(**kw)
if __name__ == "__main__":
import doctest
doctest.testmod()