@@ -246,6 +246,51 @@ sub taptest
246
246
exit $status if $status ;
247
247
}
248
248
249
+ sub mangle_plpython3
250
+ {
251
+ my $tests = shift ;
252
+ mkdir " results" unless -d " results" ;
253
+ mkdir " sql/python3" ;
254
+ mkdir " results/python3" ;
255
+ mkdir " expected/python3" ;
256
+
257
+ foreach my $test (@$tests )
258
+ {
259
+ local $/ = undef ;
260
+ foreach my $dir (' sql' ,' expected' )
261
+ {
262
+ my $extension = ($dir eq ' sql' ? ' sql' : ' out' );
263
+
264
+ my @files = glob (" $dir /$test .$extension $dir /${test} _[0-9].$extension " );
265
+ foreach my $file (@files )
266
+ {
267
+ open (my $handle , " $file " ) || die " test file $file not found" ;
268
+ my $contents = <$handle >;
269
+ close ($handle );
270
+ map
271
+ {
272
+ s / except ([[:alpha:]][[:alpha:].]*), *([[:alpha:]][[:alpha:]]*):/ except $1 as $2 :/ g ;
273
+ s / <type 'exceptions\. ([[:alpha:]]*)'>/ <class '$1 '>/ g ;
274
+ s / <type 'long'>/ <class 'int'>/ g ;
275
+ s / ([0-9][0-9]*)L/ $1 / g ;
276
+ s / ([ [{])u"/ $1 "/ g ;
277
+ s / ([ [{])u'/ $1 '/ g ;
278
+ s / def next/ def __next__/ g ;
279
+ s / LANGUAGE plpython2?u/ LANGUAGE plpython3u/ g ;
280
+ s / EXTENSION ([^ ]*_)*plpython2?u/ EXTENSION $1plpython3u/ g ;
281
+ s / installing required extension "plpython2u"/ installing required extension "plpython3u"/ g ;
282
+ } $contents ;
283
+ my $base = basename $file ;
284
+ open ($handle , " >$dir /python3/$base " ) || die " opening python 3 file for $file " ;
285
+ print $handle $contents ;
286
+ close ($handle );
287
+ }
288
+ }
289
+ }
290
+ map { $_ =~ s ! ^! python3/! ; } @$tests ;
291
+ return @$tests ;
292
+ }
293
+
249
294
sub plcheck
250
295
{
251
296
chdir " $topdir /src/pl" ;
@@ -268,7 +313,8 @@ sub plcheck
268
313
}
269
314
if ($lang eq ' plpython' )
270
315
{
271
- next unless -d " $topdir /$Config /plpython2" ;
316
+ next unless -d " $topdir /$Config /plpython2" ||
317
+ -d " $topdir /$Config /plpython3" ;
272
318
$lang = ' plpythonu' ;
273
319
}
274
320
else
@@ -278,6 +324,8 @@ sub plcheck
278
324
my @lang_args = (" --load-extension=$lang " );
279
325
chdir $dir ;
280
326
my @tests = fetchTests();
327
+ @tests = mangle_plpython3(\@tests )
328
+ if $lang eq ' plpythonu' && -d " $topdir /$Config /plpython3" ;
281
329
if ($lang eq ' plperl' )
282
330
{
283
331
@@ -293,6 +341,10 @@ sub plcheck
293
341
push (@tests , ' plperl_plperlu' );
294
342
}
295
343
}
344
+ elsif ($lang eq ' plpythonu' && -d " $topdir /$Config /plpython3" )
345
+ {
346
+ @lang_args = ();
347
+ }
296
348
print
297
349
" ============================================================\n " ;
298
350
print " Checking $lang \n " ;
@@ -311,7 +363,6 @@ sub plcheck
311
363
312
364
sub subdircheck
313
365
{
314
- my $subdir = shift ;
315
366
my $module = shift ;
316
367
317
368
if ( !-d " $module /sql"
@@ -325,44 +376,35 @@ sub subdircheck
325
376
my @tests = fetchTests();
326
377
my @opts = fetchRegressOpts();
327
378
328
- # Add some options for transform modules, see their respective
329
- # Makefile for more details regarding Python-version specific
379
+ # Special processing for python transform modules, see their respective
380
+ # Makefiles for more details regarding Python-version specific
330
381
# dependencies.
331
- if ( $module eq " hstore_plpython"
332
- || $module eq " jsonb_plpython"
333
- || $module eq " ltree_plpython" )
382
+ if ( $module =~ / _plpython$ / )
334
383
{
335
384
die " Python not enabled in configuration"
336
385
if !defined ($config -> {python });
337
386
338
- # Attempt to get python version and location.
339
- # Assume python.exe in specified dir.
340
- my $pythonprog = " import sys;" . " print(str(sys.version_info[0]))" ;
341
- my $prefixcmd = $config -> {python } . " \\ python -c \" $pythonprog \" " ;
342
- my $pyver = ` $prefixcmd ` ;
343
- die " Could not query for python version!\n " if $? ;
344
- chomp ($pyver );
345
- if ($pyver eq " 2" )
387
+ @opts = grep { $_ !~ / plpythonu/ } @opts ;
388
+
389
+ if (-d " $topdir /$Config /plpython2" )
346
390
{
347
391
push @opts , " --load-extension=plpythonu" ;
348
392
push @opts , ' --load-extension=' . $module . ' u' ;
349
393
}
350
394
else
351
395
{
352
-
353
- # disable tests on python3 for now.
354
- chdir " .." ;
355
- return ;
396
+ # must be python 3
397
+ @tests = mangle_plpython3(\@tests );
356
398
}
357
399
}
358
400
359
-
360
401
print " ============================================================\n " ;
361
402
print " Checking $module \n " ;
362
403
my @args = (
363
404
" $topdir /$Config /pg_regress/pg_regress" ,
364
405
" --bindir=${topdir} /${Config} /psql" ,
365
406
" --dbname=contrib_regression" , @opts , @tests );
407
+ print join (' ' ,@args )," \n " ;
366
408
system (@args );
367
409
chdir " .." ;
368
410
}
@@ -373,19 +415,15 @@ sub contribcheck
373
415
my $mstat = 0;
374
416
foreach my $module (glob (" *" ))
375
417
{
376
-
377
418
# these configuration-based exclusions must match Install.pm
378
419
next if ($module eq " uuid-ossp" && !defined ($config -> {uuid }));
379
420
next if ($module eq " sslinfo" && !defined ($config -> {openssl }));
380
421
next if ($module eq " xml2" && !defined ($config -> {xml }));
381
- next if ($module eq " hstore_plperl" && !defined ($config -> {perl }));
382
- next if ($module eq " jsonb_plperl" && !defined ($config -> {perl }));
383
- next if ($module eq " hstore_plpython" && !defined ($config -> {python }));
384
- next if ($module eq " jsonb_plpython" && !defined ($config -> {python }));
385
- next if ($module eq " ltree_plpython" && !defined ($config -> {python }));
422
+ next if ($module =~ / _plperl$ / && !defined ($config -> {perl }));
423
+ next if ($module =~ / _plpython$ / && !defined ($config -> {python }));
386
424
next if ($module eq " sepgsql" );
387
425
388
- subdircheck(" $topdir /contrib " , $module );
426
+ subdircheck($module );
389
427
my $status = $? >> 8;
390
428
$mstat ||= $status ;
391
429
}
@@ -398,7 +436,7 @@ sub modulescheck
398
436
my $mstat = 0;
399
437
foreach my $module (glob (" *" ))
400
438
{
401
- subdircheck(" $topdir /src/test/modules " , $module );
439
+ subdircheck($module );
402
440
my $status = $? >> 8;
403
441
$mstat ||= $status ;
404
442
}
0 commit comments