@@ -151,6 +151,23 @@ def __init__(
151
151
self .source = source or DATA_DIR
152
152
self .root = root .resolve ()
153
153
154
+ def find (self , identifier : str ) -> pathlib .Path :
155
+ """Convenience method for finding a data file."""
156
+ path = pathlib .Path (identifier )
157
+ if path .parent == pathlib .Path ("." ):
158
+ # No group provided but it's a distribution file, assume it's from packages/
159
+ if path .name .endswith ((".whl" , ".tar.gz" )):
160
+ group = "packages"
161
+ else :
162
+ raise ValueError ("must provide a data group prefix" )
163
+ else :
164
+ group = path .parent .name
165
+
166
+ resource = self .root / group / path .name
167
+ if not resource .exists ():
168
+ raise ValueError (f"data '{ identifier } ' does not exist!" )
169
+ return resource
170
+
154
171
@classmethod
155
172
def copy (cls , root : pathlib .Path ) -> TestData :
156
173
obj = cls (root )
@@ -725,13 +742,24 @@ def pip(
725
742
def pip_install_local (
726
743
self ,
727
744
* args : StrPath ,
745
+ find_links : StrPath | list [StrPath ] = "packages" ,
728
746
** kwargs : Any ,
729
747
) -> TestPipResult :
748
+ if not isinstance (find_links , list ):
749
+ find_links = [find_links ]
750
+ find_links_args : list [StrPath ] = []
751
+ for folder in find_links :
752
+ path = pathlib .Path (folder )
753
+ find_links_args .append ("--find-links" )
754
+ if path .parent == pathlib .Path ("." ):
755
+ find_links_args .append (pathlib .Path (DATA_DIR , folder ).as_uri ())
756
+ else :
757
+ find_links_args .append (path )
758
+
730
759
return self .pip (
731
760
"install" ,
732
761
"--no-index" ,
733
- "--find-links" ,
734
- pathlib .Path (DATA_DIR , "packages" ).as_uri (),
762
+ * find_links_args ,
735
763
* args ,
736
764
** kwargs ,
737
765
)
0 commit comments