57
57
APPENGINE_BLACKLIST = set ()
58
58
59
59
60
+ # Libraries that only work on Python 2.7
61
+ PY27_ONLY_LIBRARIES = ['mysql-python' ]
62
+
63
+
60
64
def list_files (folder , pattern ):
61
65
"""Lists all files below the given folder that match the pattern."""
62
66
for root , folders , files in os .walk (folder ):
@@ -145,7 +149,7 @@ def run_tests_in_sesssion(
145
149
146
150
It:
147
151
1. Install the common testing utilities.
148
- 2. Installs the test requirements for the current interpreter .
152
+ 2. Installs the test requirements.
149
153
3. Determines which pytest arguments to use. skip_flaky causes extra
150
154
arguments to be passed that will skip tests marked flaky.
151
155
4. If posargs are specified, it will use that as the list of samples to
@@ -159,7 +163,7 @@ def run_tests_in_sesssion(
159
163
"""
160
164
session .interpreter = interpreter
161
165
session .install (REPO_TOOLS_REQ )
162
- session .install ('-r' , 'requirements-{}- dev.txt' . format ( interpreter ) )
166
+ session .install ('-r' , 'requirements-dev.txt' )
163
167
164
168
if use_appengine :
165
169
setup_appengine (session )
@@ -184,11 +188,6 @@ def run_tests_in_sesssion(
184
188
print ('\n ' .join (sample_directories ))
185
189
186
190
for sample in sample_directories :
187
- # Install additional dependencies if they exist
188
- dirname = sample if os .path .isdir (sample ) else os .path .dirname (sample )
189
- for reqfile in list_files (dirname , 'requirements*.txt' ):
190
- session .install ('-r' , reqfile )
191
-
192
191
# Ignore lib and env directories
193
192
ignore_args = [
194
193
'--ignore' , os .path .join (sample , 'lib' ),
@@ -267,3 +266,38 @@ def session_reqcheck(session):
267
266
268
267
for reqfile in list_files ('.' , 'requirements*.txt' ):
269
268
session .run ('gcprepotools' , command , reqfile )
269
+
270
+
271
+ def session_reqrollup (session ):
272
+ """Rolls up all requirements files into requirements-dev.txt.
273
+
274
+ This does not test for uniqueness. pip itself will validate that.
275
+ """
276
+ requirements = set ()
277
+ requirements_files = list (list_files ('.' , 'requirements*.txt' ))
278
+ requirements_files .append ('./requirements-dev.in' )
279
+
280
+ for filename in requirements_files :
281
+ if filename == './requirements-dev.txt' :
282
+ continue
283
+
284
+ with open (filename , 'r' ) as f :
285
+ lines = f .readlines ()
286
+ requirements .update (lines )
287
+
288
+ def mark_if_necessary (requirement ):
289
+ """Adds environment markers to Python 2.7-only libraries."""
290
+ for library in PY27_ONLY_LIBRARIES :
291
+ if requirement .startswith (library ):
292
+ return '{}; python_version == \' 2.7\' \n ' .format (
293
+ requirement .strip ())
294
+ return requirement
295
+
296
+ requirements = [
297
+ mark_if_necessary (requirement ) for requirement in requirements ]
298
+
299
+ with open ('requirements-dev.txt' , 'w' ) as f :
300
+ f .write ('# This file is generated by nox -s reqrollup. Do not edit.\n ' )
301
+ for requirement in sorted (requirements , key = lambda s : s .lower ()):
302
+ if not requirement .startswith ('#' ):
303
+ f .write (requirement )
0 commit comments