1313
1414import pipcl
1515
16+
1617class WindowsVS :
1718 r'''
1819 Windows only. Finds locations of Visual Studio command-line tools. Assumes
@@ -33,7 +34,16 @@ class WindowsVS:
3334
3435 `.csc` is C# compiler; will be None if not found.
3536 '''
36- def __init__ ( self , year = None , grade = None , version = None , cpu = None , verbose = False ):
37+ def __init__ (
38+ self ,
39+ * ,
40+ year = None ,
41+ grade = None ,
42+ version = None ,
43+ cpu = None ,
44+ directory = None ,
45+ verbose = False ,
46+ ):
3747 '''
3848 Args:
3949 year:
@@ -52,7 +62,15 @@ def __init__( self, year=None, grade=None, version=None, cpu=None, verbose=False
5262 variable WDEV_VS_VERSION if set.
5363 cpu:
5464 None or a `WindowsCpu` instance.
65+ directory:
66+ Ignore year, grade, version and cpu and use this directory
67+ directly.
68+ verbose:
69+ .
70+
5571 '''
72+ if year is not None :
73+ year = str (year ) # Allow specification as a number.
5674 def default (value , name ):
5775 if value is None :
5876 name2 = f'WDEV_VS_{ name .upper ()} '
@@ -68,16 +86,17 @@ def default(value, name):
6886 if not cpu :
6987 cpu = WindowsCpu ()
7088
71- # Find `directory`.
72- #
73- pattern = f'C:\\ Program Files*\\ Microsoft Visual Studio\\ { year if year else "2*" } \\ { grade if grade else "*" } '
74- directories = glob .glob ( pattern )
75- if verbose :
76- _log ( f'Matches for: { pattern = } ' )
77- _log ( f'{ directories = } ' )
78- assert directories , f'No match found for: { pattern } '
79- directories .sort ()
80- directory = directories [- 1 ]
89+ if not directory :
90+ # Find `directory`.
91+ #
92+ pattern = _vs_pattern (year , grade )
93+ directories = glob .glob ( pattern )
94+ if verbose :
95+ _log ( f'Matches for: { pattern = } ' )
96+ _log ( f'{ directories = } ' )
97+ assert directories , f'No match found for { pattern = } .'
98+ directories .sort ()
99+ directory = directories [- 1 ]
81100
82101 # Find `devenv`.
83102 #
@@ -167,7 +186,7 @@ def default(value, name):
167186 self .year = year
168187 self .cpu = cpu
169188 except Exception as e :
170- raise Exception ( f'Unable to find Visual Studio' ) from e
189+ raise Exception ( f'Unable to find Visual Studio { year = } { grade = } { version = } { cpu = } { directory = } ' ) from e
171190
172191 def description_ml ( self , indent = '' ):
173192 '''
@@ -189,7 +208,40 @@ def description_ml( self, indent=''):
189208 return textwrap .indent ( ret , indent )
190209
191210 def __repr__ ( self ):
192- return ' ' .join ( self ._description ())
211+ items = list ()
212+ for name in (
213+ 'year' ,
214+ 'grade' ,
215+ 'version' ,
216+ 'directory' ,
217+ 'vcvars' ,
218+ 'cl' ,
219+ 'link' ,
220+ 'csc' ,
221+ 'msbuild' ,
222+ 'devenv' ,
223+ 'cpu' ,
224+ ):
225+ items .append (f'{ name } ={ getattr (self , name )!r} ' )
226+ return ' ' .join (items )
227+
228+
229+ def _vs_pattern (year = None , grade = None ):
230+ return f'C:\\ Program Files*\\ Microsoft Visual Studio\\ { year if year else "2*" } \\ { grade if grade else "*" } '
231+
232+
233+ def windows_vs_multiple (year = None , grade = None , verbose = 0 ):
234+ '''
235+ Returns list of WindowsVS instances.
236+ '''
237+ ret = list ()
238+ directories = glob .glob (_vs_pattern (year , grade ))
239+ for directory in directories :
240+ vs = WindowsVS (directory = directory )
241+ if verbose :
242+ _log (vs .description_ml ())
243+ ret .append (vs )
244+ return ret
193245
194246
195247class WindowsCpu :
0 commit comments