99"""
1010Functionality to represent and operate on a HDL code project
1111"""
12- from typing import Optional
12+ from typing import Optional , Union
1313from pathlib import Path
1414import logging
1515from collections import OrderedDict
@@ -83,7 +83,7 @@ def add_builtin_library(self, logical_name):
8383 def add_library (
8484 self ,
8585 logical_name ,
86- directory ,
86+ directory : Union [ str , Path ] ,
8787 vhdl_standard : VHDLStandard = VHDL .STD_2008 ,
8888 is_external = False ,
8989 ):
@@ -93,19 +93,18 @@ def add_library(
9393 """
9494 self ._validate_new_library_name (logical_name )
9595
96+ dpath = Path (directory )
97+ dstr = str (directory )
98+
9699 if is_external :
97- if not exists (directory ):
98- raise ValueError ("External library %r does not exist" % directory )
100+ if not dpath . exists ():
101+ raise ValueError ("External library %r does not exist" % dstr )
99102
100- if not isdir (directory ):
101- raise ValueError (
102- "External library must be a directory. Got %r" % directory
103- )
103+ if not dpath .is_dir ():
104+ raise ValueError ("External library must be a directory. Got %r" % dstr )
104105
105- library = Library (
106- logical_name , directory , vhdl_standard , is_external = is_external
107- )
108- LOGGER .debug ("Adding library %s with path %s" , logical_name , directory )
106+ library = Library (logical_name , dstr , vhdl_standard , is_external = is_external )
107+ LOGGER .debug ("Adding library %s with path %s" , logical_name , dstr )
109108
110109 self ._libraries [logical_name ] = library
111110 self ._lower_library_names_dict [logical_name .lower ()] = library .name
0 commit comments