##// END OF EJS Templates
tests: use pyflakes module instead of pyflakes executable...
Manuel Jacob -
r44951:e397c6d7 default
parent child Browse files
Show More
@@ -1,1051 +1,1051 b''
1 1 from __future__ import absolute_import, print_function
2 2
3 3 import distutils.version
4 4 import os
5 5 import re
6 6 import socket
7 7 import stat
8 8 import subprocess
9 9 import sys
10 10 import tempfile
11 11
12 12 tempprefix = 'hg-hghave-'
13 13
14 14 checks = {
15 15 "true": (lambda: True, "yak shaving"),
16 16 "false": (lambda: False, "nail clipper"),
17 17 }
18 18
19 19 try:
20 20 import msvcrt
21 21
22 22 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
23 23 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
24 24 except ImportError:
25 25 pass
26 26
27 27 stdout = getattr(sys.stdout, 'buffer', sys.stdout)
28 28 stderr = getattr(sys.stderr, 'buffer', sys.stderr)
29 29
30 30 if sys.version_info[0] >= 3:
31 31
32 32 def _sys2bytes(p):
33 33 if p is None:
34 34 return p
35 35 return p.encode('utf-8')
36 36
37 37 def _bytes2sys(p):
38 38 if p is None:
39 39 return p
40 40 return p.decode('utf-8')
41 41
42 42
43 43 else:
44 44
45 45 def _sys2bytes(p):
46 46 return p
47 47
48 48 _bytes2sys = _sys2bytes
49 49
50 50
51 51 def check(name, desc):
52 52 """Registers a check function for a feature."""
53 53
54 54 def decorator(func):
55 55 checks[name] = (func, desc)
56 56 return func
57 57
58 58 return decorator
59 59
60 60
61 61 def checkvers(name, desc, vers):
62 62 """Registers a check function for each of a series of versions.
63 63
64 64 vers can be a list or an iterator.
65 65
66 66 Produces a series of feature checks that have the form <name><vers> without
67 67 any punctuation (even if there's punctuation in 'vers'; i.e. this produces
68 68 'py38', not 'py3.8' or 'py-38')."""
69 69
70 70 def decorator(func):
71 71 def funcv(v):
72 72 def f():
73 73 return func(v)
74 74
75 75 return f
76 76
77 77 for v in vers:
78 78 v = str(v)
79 79 f = funcv(v)
80 80 checks['%s%s' % (name, v.replace('.', ''))] = (f, desc % v)
81 81 return func
82 82
83 83 return decorator
84 84
85 85
86 86 def checkfeatures(features):
87 87 result = {
88 88 'error': [],
89 89 'missing': [],
90 90 'skipped': [],
91 91 }
92 92
93 93 for feature in features:
94 94 negate = feature.startswith('no-')
95 95 if negate:
96 96 feature = feature[3:]
97 97
98 98 if feature not in checks:
99 99 result['missing'].append(feature)
100 100 continue
101 101
102 102 check, desc = checks[feature]
103 103 try:
104 104 available = check()
105 105 except Exception:
106 106 result['error'].append('hghave check failed: %s' % feature)
107 107 continue
108 108
109 109 if not negate and not available:
110 110 result['skipped'].append('missing feature: %s' % desc)
111 111 elif negate and available:
112 112 result['skipped'].append('system supports %s' % desc)
113 113
114 114 return result
115 115
116 116
117 117 def require(features):
118 118 """Require that features are available, exiting if not."""
119 119 result = checkfeatures(features)
120 120
121 121 for missing in result['missing']:
122 122 stderr.write(
123 123 ('skipped: unknown feature: %s\n' % missing).encode('utf-8')
124 124 )
125 125 for msg in result['skipped']:
126 126 stderr.write(('skipped: %s\n' % msg).encode('utf-8'))
127 127 for msg in result['error']:
128 128 stderr.write(('%s\n' % msg).encode('utf-8'))
129 129
130 130 if result['missing']:
131 131 sys.exit(2)
132 132
133 133 if result['skipped'] or result['error']:
134 134 sys.exit(1)
135 135
136 136
137 137 def matchoutput(cmd, regexp, ignorestatus=False):
138 138 """Return the match object if cmd executes successfully and its output
139 139 is matched by the supplied regular expression.
140 140 """
141 141 r = re.compile(regexp)
142 142 p = subprocess.Popen(
143 143 cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
144 144 )
145 145 s = p.communicate()[0]
146 146 ret = p.returncode
147 147 return (ignorestatus or not ret) and r.search(s)
148 148
149 149
150 150 @check("baz", "GNU Arch baz client")
151 151 def has_baz():
152 152 return matchoutput('baz --version 2>&1', br'baz Bazaar version')
153 153
154 154
155 155 @check("bzr", "Canonical's Bazaar client")
156 156 def has_bzr():
157 157 try:
158 158 import bzrlib
159 159 import bzrlib.bzrdir
160 160 import bzrlib.errors
161 161 import bzrlib.revision
162 162 import bzrlib.revisionspec
163 163
164 164 bzrlib.revisionspec.RevisionSpec
165 165 return bzrlib.__doc__ is not None
166 166 except (AttributeError, ImportError):
167 167 return False
168 168
169 169
170 170 @checkvers("bzr", "Canonical's Bazaar client >= %s", (1.14,))
171 171 def has_bzr_range(v):
172 172 major, minor = v.split('rc')[0].split('.')[0:2]
173 173 try:
174 174 import bzrlib
175 175
176 176 return bzrlib.__doc__ is not None and bzrlib.version_info[:2] >= (
177 177 int(major),
178 178 int(minor),
179 179 )
180 180 except ImportError:
181 181 return False
182 182
183 183
184 184 @check("chg", "running with chg")
185 185 def has_chg():
186 186 return 'CHGHG' in os.environ
187 187
188 188
189 189 @check("cvs", "cvs client/server")
190 190 def has_cvs():
191 191 re = br'Concurrent Versions System.*?server'
192 192 return matchoutput('cvs --version 2>&1', re) and not has_msys()
193 193
194 194
195 195 @check("cvs112", "cvs client/server 1.12.* (not cvsnt)")
196 196 def has_cvs112():
197 197 re = br'Concurrent Versions System \(CVS\) 1.12.*?server'
198 198 return matchoutput('cvs --version 2>&1', re) and not has_msys()
199 199
200 200
201 201 @check("cvsnt", "cvsnt client/server")
202 202 def has_cvsnt():
203 203 re = br'Concurrent Versions System \(CVSNT\) (\d+).(\d+).*\(client/server\)'
204 204 return matchoutput('cvsnt --version 2>&1', re)
205 205
206 206
207 207 @check("darcs", "darcs client")
208 208 def has_darcs():
209 209 return matchoutput('darcs --version', br'\b2\.([2-9]|\d{2})', True)
210 210
211 211
212 212 @check("mtn", "monotone client (>= 1.0)")
213 213 def has_mtn():
214 214 return matchoutput('mtn --version', br'monotone', True) and not matchoutput(
215 215 'mtn --version', br'monotone 0\.', True
216 216 )
217 217
218 218
219 219 @check("eol-in-paths", "end-of-lines in paths")
220 220 def has_eol_in_paths():
221 221 try:
222 222 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
223 223 os.close(fd)
224 224 os.remove(path)
225 225 return True
226 226 except (IOError, OSError):
227 227 return False
228 228
229 229
230 230 @check("execbit", "executable bit")
231 231 def has_executablebit():
232 232 try:
233 233 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
234 234 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
235 235 try:
236 236 os.close(fh)
237 237 m = os.stat(fn).st_mode & 0o777
238 238 new_file_has_exec = m & EXECFLAGS
239 239 os.chmod(fn, m ^ EXECFLAGS)
240 240 exec_flags_cannot_flip = (os.stat(fn).st_mode & 0o777) == m
241 241 finally:
242 242 os.unlink(fn)
243 243 except (IOError, OSError):
244 244 # we don't care, the user probably won't be able to commit anyway
245 245 return False
246 246 return not (new_file_has_exec or exec_flags_cannot_flip)
247 247
248 248
249 249 @check("icasefs", "case insensitive file system")
250 250 def has_icasefs():
251 251 # Stolen from mercurial.util
252 252 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
253 253 os.close(fd)
254 254 try:
255 255 s1 = os.stat(path)
256 256 d, b = os.path.split(path)
257 257 p2 = os.path.join(d, b.upper())
258 258 if path == p2:
259 259 p2 = os.path.join(d, b.lower())
260 260 try:
261 261 s2 = os.stat(p2)
262 262 return s2 == s1
263 263 except OSError:
264 264 return False
265 265 finally:
266 266 os.remove(path)
267 267
268 268
269 269 @check("fifo", "named pipes")
270 270 def has_fifo():
271 271 if getattr(os, "mkfifo", None) is None:
272 272 return False
273 273 name = tempfile.mktemp(dir='.', prefix=tempprefix)
274 274 try:
275 275 os.mkfifo(name)
276 276 os.unlink(name)
277 277 return True
278 278 except OSError:
279 279 return False
280 280
281 281
282 282 @check("killdaemons", 'killdaemons.py support')
283 283 def has_killdaemons():
284 284 return True
285 285
286 286
287 287 @check("cacheable", "cacheable filesystem")
288 288 def has_cacheable_fs():
289 289 from mercurial import util
290 290
291 291 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
292 292 os.close(fd)
293 293 try:
294 294 return util.cachestat(path).cacheable()
295 295 finally:
296 296 os.remove(path)
297 297
298 298
299 299 @check("lsprof", "python lsprof module")
300 300 def has_lsprof():
301 301 try:
302 302 import _lsprof
303 303
304 304 _lsprof.Profiler # silence unused import warning
305 305 return True
306 306 except ImportError:
307 307 return False
308 308
309 309
310 310 def _gethgversion():
311 311 m = matchoutput('hg --version --quiet 2>&1', br'(\d+)\.(\d+)')
312 312 if not m:
313 313 return (0, 0)
314 314 return (int(m.group(1)), int(m.group(2)))
315 315
316 316
317 317 _hgversion = None
318 318
319 319
320 320 def gethgversion():
321 321 global _hgversion
322 322 if _hgversion is None:
323 323 _hgversion = _gethgversion()
324 324 return _hgversion
325 325
326 326
327 327 @checkvers(
328 328 "hg", "Mercurial >= %s", list([(1.0 * x) / 10 for x in range(9, 99)])
329 329 )
330 330 def has_hg_range(v):
331 331 major, minor = v.split('.')[0:2]
332 332 return gethgversion() >= (int(major), int(minor))
333 333
334 334
335 335 @check("hg08", "Mercurial >= 0.8")
336 336 def has_hg08():
337 337 if checks["hg09"][0]():
338 338 return True
339 339 return matchoutput('hg help annotate 2>&1', '--date')
340 340
341 341
342 342 @check("hg07", "Mercurial >= 0.7")
343 343 def has_hg07():
344 344 if checks["hg08"][0]():
345 345 return True
346 346 return matchoutput('hg --version --quiet 2>&1', 'Mercurial Distributed SCM')
347 347
348 348
349 349 @check("hg06", "Mercurial >= 0.6")
350 350 def has_hg06():
351 351 if checks["hg07"][0]():
352 352 return True
353 353 return matchoutput('hg --version --quiet 2>&1', 'Mercurial version')
354 354
355 355
356 356 @check("gettext", "GNU Gettext (msgfmt)")
357 357 def has_gettext():
358 358 return matchoutput('msgfmt --version', br'GNU gettext-tools')
359 359
360 360
361 361 @check("git", "git command line client")
362 362 def has_git():
363 363 return matchoutput('git --version 2>&1', br'^git version')
364 364
365 365
366 366 def getgitversion():
367 367 m = matchoutput('git --version 2>&1', br'git version (\d+)\.(\d+)')
368 368 if not m:
369 369 return (0, 0)
370 370 return (int(m.group(1)), int(m.group(2)))
371 371
372 372
373 373 # https://github.com/git-lfs/lfs-test-server
374 374 @check("lfs-test-server", "git-lfs test server")
375 375 def has_lfsserver():
376 376 exe = 'lfs-test-server'
377 377 if has_windows():
378 378 exe = 'lfs-test-server.exe'
379 379 return any(
380 380 os.access(os.path.join(path, exe), os.X_OK)
381 381 for path in os.environ["PATH"].split(os.pathsep)
382 382 )
383 383
384 384
385 385 @checkvers("git", "git client (with ext::sh support) version >= %s", (1.9,))
386 386 def has_git_range(v):
387 387 major, minor = v.split('.')[0:2]
388 388 return getgitversion() >= (int(major), int(minor))
389 389
390 390
391 391 @check("docutils", "Docutils text processing library")
392 392 def has_docutils():
393 393 try:
394 394 import docutils.core
395 395
396 396 docutils.core.publish_cmdline # silence unused import
397 397 return True
398 398 except ImportError:
399 399 return False
400 400
401 401
402 402 def getsvnversion():
403 403 m = matchoutput('svn --version --quiet 2>&1', br'^(\d+)\.(\d+)')
404 404 if not m:
405 405 return (0, 0)
406 406 return (int(m.group(1)), int(m.group(2)))
407 407
408 408
409 409 @checkvers("svn", "subversion client and admin tools >= %s", (1.3, 1.5))
410 410 def has_svn_range(v):
411 411 major, minor = v.split('.')[0:2]
412 412 return getsvnversion() >= (int(major), int(minor))
413 413
414 414
415 415 @check("svn", "subversion client and admin tools")
416 416 def has_svn():
417 417 return matchoutput('svn --version 2>&1', br'^svn, version') and matchoutput(
418 418 'svnadmin --version 2>&1', br'^svnadmin, version'
419 419 )
420 420
421 421
422 422 @check("svn-bindings", "subversion python bindings")
423 423 def has_svn_bindings():
424 424 try:
425 425 import svn.core
426 426
427 427 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
428 428 if version < (1, 4):
429 429 return False
430 430 return True
431 431 except ImportError:
432 432 return False
433 433
434 434
435 435 @check("p4", "Perforce server and client")
436 436 def has_p4():
437 437 return matchoutput('p4 -V', br'Rev\. P4/') and matchoutput(
438 438 'p4d -V', br'Rev\. P4D/'
439 439 )
440 440
441 441
442 442 @check("symlink", "symbolic links")
443 443 def has_symlink():
444 444 # mercurial.windows.checklink() is a hard 'no' at the moment
445 445 if os.name == 'nt' or getattr(os, "symlink", None) is None:
446 446 return False
447 447 name = tempfile.mktemp(dir='.', prefix=tempprefix)
448 448 try:
449 449 os.symlink(".", name)
450 450 os.unlink(name)
451 451 return True
452 452 except (OSError, AttributeError):
453 453 return False
454 454
455 455
456 456 @check("hardlink", "hardlinks")
457 457 def has_hardlink():
458 458 from mercurial import util
459 459
460 460 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
461 461 os.close(fh)
462 462 name = tempfile.mktemp(dir='.', prefix=tempprefix)
463 463 try:
464 464 util.oslink(_sys2bytes(fn), _sys2bytes(name))
465 465 os.unlink(name)
466 466 return True
467 467 except OSError:
468 468 return False
469 469 finally:
470 470 os.unlink(fn)
471 471
472 472
473 473 @check("hardlink-whitelisted", "hardlinks on whitelisted filesystems")
474 474 def has_hardlink_whitelisted():
475 475 from mercurial import util
476 476
477 477 try:
478 478 fstype = util.getfstype(b'.')
479 479 except OSError:
480 480 return False
481 481 return fstype in util._hardlinkfswhitelist
482 482
483 483
484 484 @check("rmcwd", "can remove current working directory")
485 485 def has_rmcwd():
486 486 ocwd = os.getcwd()
487 487 temp = tempfile.mkdtemp(dir='.', prefix=tempprefix)
488 488 try:
489 489 os.chdir(temp)
490 490 # On Linux, 'rmdir .' isn't allowed, but the other names are okay.
491 491 # On Solaris and Windows, the cwd can't be removed by any names.
492 492 os.rmdir(os.getcwd())
493 493 return True
494 494 except OSError:
495 495 return False
496 496 finally:
497 497 os.chdir(ocwd)
498 498 # clean up temp dir on platforms where cwd can't be removed
499 499 try:
500 500 os.rmdir(temp)
501 501 except OSError:
502 502 pass
503 503
504 504
505 505 @check("tla", "GNU Arch tla client")
506 506 def has_tla():
507 507 return matchoutput('tla --version 2>&1', br'The GNU Arch Revision')
508 508
509 509
510 510 @check("gpg", "gpg client")
511 511 def has_gpg():
512 512 return matchoutput('gpg --version 2>&1', br'GnuPG')
513 513
514 514
515 515 @check("gpg2", "gpg client v2")
516 516 def has_gpg2():
517 517 return matchoutput('gpg --version 2>&1', br'GnuPG[^0-9]+2\.')
518 518
519 519
520 520 @check("gpg21", "gpg client v2.1+")
521 521 def has_gpg21():
522 522 return matchoutput('gpg --version 2>&1', br'GnuPG[^0-9]+2\.(?!0)')
523 523
524 524
525 525 @check("unix-permissions", "unix-style permissions")
526 526 def has_unix_permissions():
527 527 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
528 528 try:
529 529 fname = os.path.join(d, 'foo')
530 530 for umask in (0o77, 0o07, 0o22):
531 531 os.umask(umask)
532 532 f = open(fname, 'w')
533 533 f.close()
534 534 mode = os.stat(fname).st_mode
535 535 os.unlink(fname)
536 536 if mode & 0o777 != ~umask & 0o666:
537 537 return False
538 538 return True
539 539 finally:
540 540 os.rmdir(d)
541 541
542 542
543 543 @check("unix-socket", "AF_UNIX socket family")
544 544 def has_unix_socket():
545 545 return getattr(socket, 'AF_UNIX', None) is not None
546 546
547 547
548 548 @check("root", "root permissions")
549 549 def has_root():
550 550 return getattr(os, 'geteuid', None) and os.geteuid() == 0
551 551
552 552
553 553 @check("pyflakes", "Pyflakes python linter")
554 554 def has_pyflakes():
555 555 return matchoutput(
556 "sh -c \"echo 'import re' 2>&1 | pyflakes\"",
556 "sh -c \"echo 'import re' 2>&1 | $PYTHON -m pyflakes\"",
557 557 br"<stdin>:1: 're' imported but unused",
558 558 True,
559 559 )
560 560
561 561
562 562 @check("pylint", "Pylint python linter")
563 563 def has_pylint():
564 564 return matchoutput("pylint --help", br"Usage: pylint", True)
565 565
566 566
567 567 @check("clang-format", "clang-format C code formatter")
568 568 def has_clang_format():
569 569 m = matchoutput('clang-format --version', br'clang-format version (\d)')
570 570 # style changed somewhere between 4.x and 6.x
571 571 return m and int(m.group(1)) >= 6
572 572
573 573
574 574 @check("jshint", "JSHint static code analysis tool")
575 575 def has_jshint():
576 576 return matchoutput("jshint --version 2>&1", br"jshint v")
577 577
578 578
579 579 @check("pygments", "Pygments source highlighting library")
580 580 def has_pygments():
581 581 try:
582 582 import pygments
583 583
584 584 pygments.highlight # silence unused import warning
585 585 return True
586 586 except ImportError:
587 587 return False
588 588
589 589
590 590 @check("pygments25", "Pygments version >= 2.5")
591 591 def pygments25():
592 592 try:
593 593 import pygments
594 594
595 595 v = pygments.__version__
596 596 except ImportError:
597 597 return False
598 598
599 599 parts = v.split(".")
600 600 major = int(parts[0])
601 601 minor = int(parts[1])
602 602
603 603 return (major, minor) >= (2, 5)
604 604
605 605
606 606 @check("outer-repo", "outer repo")
607 607 def has_outer_repo():
608 608 # failing for other reasons than 'no repo' imply that there is a repo
609 609 return not matchoutput('hg root 2>&1', br'abort: no repository found', True)
610 610
611 611
612 612 @check("ssl", "ssl module available")
613 613 def has_ssl():
614 614 try:
615 615 import ssl
616 616
617 617 ssl.CERT_NONE
618 618 return True
619 619 except ImportError:
620 620 return False
621 621
622 622
623 623 @check("sslcontext", "python >= 2.7.9 ssl")
624 624 def has_sslcontext():
625 625 try:
626 626 import ssl
627 627
628 628 ssl.SSLContext
629 629 return True
630 630 except (ImportError, AttributeError):
631 631 return False
632 632
633 633
634 634 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
635 635 def has_defaultcacerts():
636 636 from mercurial import sslutil, ui as uimod
637 637
638 638 ui = uimod.ui.load()
639 639 return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts
640 640
641 641
642 642 @check("defaultcacertsloaded", "detected presence of loaded system CA certs")
643 643 def has_defaultcacertsloaded():
644 644 import ssl
645 645 from mercurial import sslutil, ui as uimod
646 646
647 647 if not has_defaultcacerts():
648 648 return False
649 649 if not has_sslcontext():
650 650 return False
651 651
652 652 ui = uimod.ui.load()
653 653 cafile = sslutil._defaultcacerts(ui)
654 654 ctx = ssl.create_default_context()
655 655 if cafile:
656 656 ctx.load_verify_locations(cafile=cafile)
657 657 else:
658 658 ctx.load_default_certs()
659 659
660 660 return len(ctx.get_ca_certs()) > 0
661 661
662 662
663 663 @check("tls1.2", "TLS 1.2 protocol support")
664 664 def has_tls1_2():
665 665 from mercurial import sslutil
666 666
667 667 return b'tls1.2' in sslutil.supportedprotocols
668 668
669 669
670 670 @check("windows", "Windows")
671 671 def has_windows():
672 672 return os.name == 'nt'
673 673
674 674
675 675 @check("system-sh", "system() uses sh")
676 676 def has_system_sh():
677 677 return os.name != 'nt'
678 678
679 679
680 680 @check("serve", "platform and python can manage 'hg serve -d'")
681 681 def has_serve():
682 682 return True
683 683
684 684
685 685 @check("test-repo", "running tests from repository")
686 686 def has_test_repo():
687 687 t = os.environ["TESTDIR"]
688 688 return os.path.isdir(os.path.join(t, "..", ".hg"))
689 689
690 690
691 691 @check("tic", "terminfo compiler and curses module")
692 692 def has_tic():
693 693 try:
694 694 import curses
695 695
696 696 curses.COLOR_BLUE
697 697 return matchoutput('test -x "`which tic`"', br'')
698 698 except (ImportError, AttributeError):
699 699 return False
700 700
701 701
702 702 @check("xz", "xz compression utility")
703 703 def has_xz():
704 704 # When Windows invokes a subprocess in shell mode, it uses `cmd.exe`, which
705 705 # only knows `where`, not `which`. So invoke MSYS shell explicitly.
706 706 return matchoutput("sh -c 'test -x \"`which xz`\"'", b'')
707 707
708 708
709 709 @check("msys", "Windows with MSYS")
710 710 def has_msys():
711 711 return os.getenv('MSYSTEM')
712 712
713 713
714 714 @check("aix", "AIX")
715 715 def has_aix():
716 716 return sys.platform.startswith("aix")
717 717
718 718
719 719 @check("osx", "OS X")
720 720 def has_osx():
721 721 return sys.platform == 'darwin'
722 722
723 723
724 724 @check("osxpackaging", "OS X packaging tools")
725 725 def has_osxpackaging():
726 726 try:
727 727 return (
728 728 matchoutput('pkgbuild', br'Usage: pkgbuild ', ignorestatus=1)
729 729 and matchoutput(
730 730 'productbuild', br'Usage: productbuild ', ignorestatus=1
731 731 )
732 732 and matchoutput('lsbom', br'Usage: lsbom', ignorestatus=1)
733 733 and matchoutput('xar --help', br'Usage: xar', ignorestatus=1)
734 734 )
735 735 except ImportError:
736 736 return False
737 737
738 738
739 739 @check('linuxormacos', 'Linux or MacOS')
740 740 def has_linuxormacos():
741 741 # This isn't a perfect test for MacOS. But it is sufficient for our needs.
742 742 return sys.platform.startswith(('linux', 'darwin'))
743 743
744 744
745 745 @check("docker", "docker support")
746 746 def has_docker():
747 747 pat = br'A self-sufficient runtime for'
748 748 if matchoutput('docker --help', pat):
749 749 if 'linux' not in sys.platform:
750 750 # TODO: in theory we should be able to test docker-based
751 751 # package creation on non-linux using boot2docker, but in
752 752 # practice that requires extra coordination to make sure
753 753 # $TESTTEMP is going to be visible at the same path to the
754 754 # boot2docker VM. If we figure out how to verify that, we
755 755 # can use the following instead of just saying False:
756 756 # return 'DOCKER_HOST' in os.environ
757 757 return False
758 758
759 759 return True
760 760 return False
761 761
762 762
763 763 @check("debhelper", "debian packaging tools")
764 764 def has_debhelper():
765 765 # Some versions of dpkg say `dpkg', some say 'dpkg' (` vs ' on the first
766 766 # quote), so just accept anything in that spot.
767 767 dpkg = matchoutput(
768 768 'dpkg --version', br"Debian .dpkg' package management program"
769 769 )
770 770 dh = matchoutput(
771 771 'dh --help', br'dh is a part of debhelper.', ignorestatus=True
772 772 )
773 773 dh_py2 = matchoutput(
774 774 'dh_python2 --help', br'other supported Python versions'
775 775 )
776 776 # debuild comes from the 'devscripts' package, though you might want
777 777 # the 'build-debs' package instead, which has a dependency on devscripts.
778 778 debuild = matchoutput(
779 779 'debuild --help', br'to run debian/rules with given parameter'
780 780 )
781 781 return dpkg and dh and dh_py2 and debuild
782 782
783 783
784 784 @check(
785 785 "debdeps", "debian build dependencies (run dpkg-checkbuilddeps in contrib/)"
786 786 )
787 787 def has_debdeps():
788 788 # just check exit status (ignoring output)
789 789 path = '%s/../contrib/packaging/debian/control' % os.environ['TESTDIR']
790 790 return matchoutput('dpkg-checkbuilddeps %s' % path, br'')
791 791
792 792
793 793 @check("demandimport", "demandimport enabled")
794 794 def has_demandimport():
795 795 # chg disables demandimport intentionally for performance wins.
796 796 return (not has_chg()) and os.environ.get('HGDEMANDIMPORT') != 'disable'
797 797
798 798
799 799 # Add "py27", "py35", ... as possible feature checks. Note that there's no
800 800 # punctuation here.
801 801 @checkvers("py", "Python >= %s", (2.7, 3.5, 3.6, 3.7, 3.8, 3.9))
802 802 def has_python_range(v):
803 803 major, minor = v.split('.')[0:2]
804 804 py_major, py_minor = sys.version_info.major, sys.version_info.minor
805 805
806 806 return (py_major, py_minor) >= (int(major), int(minor))
807 807
808 808
809 809 @check("py3", "running with Python 3.x")
810 810 def has_py3():
811 811 return 3 == sys.version_info[0]
812 812
813 813
814 814 @check("py3exe", "a Python 3.x interpreter is available")
815 815 def has_python3exe():
816 816 return matchoutput('python3 -V', br'^Python 3.(5|6|7|8|9)')
817 817
818 818
819 819 @check("pure", "running with pure Python code")
820 820 def has_pure():
821 821 return any(
822 822 [
823 823 os.environ.get("HGMODULEPOLICY") == "py",
824 824 os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure",
825 825 ]
826 826 )
827 827
828 828
829 829 @check("slow", "allow slow tests (use --allow-slow-tests)")
830 830 def has_slow():
831 831 return os.environ.get('HGTEST_SLOW') == 'slow'
832 832
833 833
834 834 @check("hypothesis", "Hypothesis automated test generation")
835 835 def has_hypothesis():
836 836 try:
837 837 import hypothesis
838 838
839 839 hypothesis.given
840 840 return True
841 841 except ImportError:
842 842 return False
843 843
844 844
845 845 @check("unziplinks", "unzip(1) understands and extracts symlinks")
846 846 def unzip_understands_symlinks():
847 847 return matchoutput('unzip --help', br'Info-ZIP')
848 848
849 849
850 850 @check("zstd", "zstd Python module available")
851 851 def has_zstd():
852 852 try:
853 853 import mercurial.zstd
854 854
855 855 mercurial.zstd.__version__
856 856 return True
857 857 except ImportError:
858 858 return False
859 859
860 860
861 861 @check("devfull", "/dev/full special file")
862 862 def has_dev_full():
863 863 return os.path.exists('/dev/full')
864 864
865 865
866 866 @check("ensurepip", "ensurepip module")
867 867 def has_ensurepip():
868 868 try:
869 869 import ensurepip
870 870
871 871 ensurepip.bootstrap
872 872 return True
873 873 except ImportError:
874 874 return False
875 875
876 876
877 877 @check("virtualenv", "Python virtualenv support")
878 878 def has_virtualenv():
879 879 try:
880 880 import virtualenv
881 881
882 882 virtualenv.ACTIVATE_SH
883 883 return True
884 884 except ImportError:
885 885 return False
886 886
887 887
888 888 @check("fsmonitor", "running tests with fsmonitor")
889 889 def has_fsmonitor():
890 890 return 'HGFSMONITOR_TESTS' in os.environ
891 891
892 892
893 893 @check("fuzzywuzzy", "Fuzzy string matching library")
894 894 def has_fuzzywuzzy():
895 895 try:
896 896 import fuzzywuzzy
897 897
898 898 fuzzywuzzy.__version__
899 899 return True
900 900 except ImportError:
901 901 return False
902 902
903 903
904 904 @check("clang-libfuzzer", "clang new enough to include libfuzzer")
905 905 def has_clang_libfuzzer():
906 906 mat = matchoutput('clang --version', br'clang version (\d)')
907 907 if mat:
908 908 # libfuzzer is new in clang 6
909 909 return int(mat.group(1)) > 5
910 910 return False
911 911
912 912
913 913 @check("clang-6.0", "clang 6.0 with version suffix (libfuzzer included)")
914 914 def has_clang60():
915 915 return matchoutput('clang-6.0 --version', br'clang version 6\.')
916 916
917 917
918 918 @check("xdiff", "xdiff algorithm")
919 919 def has_xdiff():
920 920 try:
921 921 from mercurial import policy
922 922
923 923 bdiff = policy.importmod('bdiff')
924 924 return bdiff.xdiffblocks(b'', b'') == [(0, 0, 0, 0)]
925 925 except (ImportError, AttributeError):
926 926 return False
927 927
928 928
929 929 @check('extraextensions', 'whether tests are running with extra extensions')
930 930 def has_extraextensions():
931 931 return 'HGTESTEXTRAEXTENSIONS' in os.environ
932 932
933 933
934 934 def getrepofeatures():
935 935 """Obtain set of repository features in use.
936 936
937 937 HGREPOFEATURES can be used to define or remove features. It contains
938 938 a space-delimited list of feature strings. Strings beginning with ``-``
939 939 mean to remove.
940 940 """
941 941 # Default list provided by core.
942 942 features = {
943 943 'bundlerepo',
944 944 'revlogstore',
945 945 'fncache',
946 946 }
947 947
948 948 # Features that imply other features.
949 949 implies = {
950 950 'simplestore': ['-revlogstore', '-bundlerepo', '-fncache'],
951 951 }
952 952
953 953 for override in os.environ.get('HGREPOFEATURES', '').split(' '):
954 954 if not override:
955 955 continue
956 956
957 957 if override.startswith('-'):
958 958 if override[1:] in features:
959 959 features.remove(override[1:])
960 960 else:
961 961 features.add(override)
962 962
963 963 for imply in implies.get(override, []):
964 964 if imply.startswith('-'):
965 965 if imply[1:] in features:
966 966 features.remove(imply[1:])
967 967 else:
968 968 features.add(imply)
969 969
970 970 return features
971 971
972 972
973 973 @check('reporevlogstore', 'repository using the default revlog store')
974 974 def has_reporevlogstore():
975 975 return 'revlogstore' in getrepofeatures()
976 976
977 977
978 978 @check('reposimplestore', 'repository using simple storage extension')
979 979 def has_reposimplestore():
980 980 return 'simplestore' in getrepofeatures()
981 981
982 982
983 983 @check('repobundlerepo', 'whether we can open bundle files as repos')
984 984 def has_repobundlerepo():
985 985 return 'bundlerepo' in getrepofeatures()
986 986
987 987
988 988 @check('repofncache', 'repository has an fncache')
989 989 def has_repofncache():
990 990 return 'fncache' in getrepofeatures()
991 991
992 992
993 993 @check('sqlite', 'sqlite3 module is available')
994 994 def has_sqlite():
995 995 try:
996 996 import sqlite3
997 997
998 998 version = sqlite3.sqlite_version_info
999 999 except ImportError:
1000 1000 return False
1001 1001
1002 1002 if version < (3, 8, 3):
1003 1003 # WITH clause not supported
1004 1004 return False
1005 1005
1006 1006 return matchoutput('sqlite3 -version', br'^3\.\d+')
1007 1007
1008 1008
1009 1009 @check('vcr', 'vcr http mocking library')
1010 1010 def has_vcr():
1011 1011 try:
1012 1012 import vcr
1013 1013
1014 1014 vcr.VCR
1015 1015 return True
1016 1016 except (ImportError, AttributeError):
1017 1017 pass
1018 1018 return False
1019 1019
1020 1020
1021 1021 @check('emacs', 'GNU Emacs')
1022 1022 def has_emacs():
1023 1023 # Our emacs lisp uses `with-eval-after-load` which is new in emacs
1024 1024 # 24.4, so we allow emacs 24.4, 24.5, and 25+ (24.5 was the last
1025 1025 # 24 release)
1026 1026 return matchoutput('emacs --version', b'GNU Emacs 2(4.4|4.5|5|6|7|8|9)')
1027 1027
1028 1028
1029 1029 @check('black', 'the black formatter for python')
1030 1030 def has_black():
1031 1031 blackcmd = 'black --version'
1032 1032 version_regex = b'black, version ([0-9a-b.]+)'
1033 1033 version = matchoutput(blackcmd, version_regex)
1034 1034 sv = distutils.version.StrictVersion
1035 1035 return version and sv(_bytes2sys(version.group(1))) >= sv('19.10b0')
1036 1036
1037 1037
1038 1038 @check('pytype', 'the pytype type checker')
1039 1039 def has_pytype():
1040 1040 pytypecmd = 'pytype --version'
1041 1041 version = matchoutput(pytypecmd, b'[0-9a-b.]+')
1042 1042 sv = distutils.version.StrictVersion
1043 1043 return version and sv(_bytes2sys(version.group(0))) >= sv('2019.10.17')
1044 1044
1045 1045
1046 1046 @check("rustfmt", "rustfmt tool")
1047 1047 def has_rustfmt():
1048 1048 # We use Nightly's rustfmt due to current unstable config options.
1049 1049 return matchoutput(
1050 1050 '`rustup which --toolchain nightly rustfmt` --version', b'rustfmt'
1051 1051 )
@@ -1,28 +1,28 b''
1 1 #require test-repo pyflakes hg10
2 2
3 3 $ . "$TESTDIR/helpers-testrepo.sh"
4 4
5 5 run pyflakes on all tracked files ending in .py or without a file ending
6 6 (skipping binary file random-seed)
7 7
8 8 $ cat > test.py <<EOF
9 9 > print(undefinedname)
10 10 > EOF
11 11 $ pyflakes test.py 2>/dev/null | "$TESTDIR/filterpyflakes.py"
12 12 test.py:1: undefined name 'undefinedname'
13 13
14 14 $ cd "`dirname "$TESTDIR"`"
15 15
16 16 $ testrepohg locate 'set:**.py or grep("^#!.*python")' \
17 17 > -X hgext/fsmonitor/pywatchman \
18 18 > -X mercurial/pycompat.py -X contrib/python-zstandard \
19 19 > -X mercurial/thirdparty/cbor \
20 20 > -X mercurial/thirdparty/concurrent \
21 21 > -X mercurial/thirdparty/zope \
22 22 > 2>/dev/null \
23 > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
23 > | xargs $PYTHON -m pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
24 24 contrib/perf.py:*: undefined name 'xrange' (glob) (?)
25 25 mercurial/hgweb/server.py:*: undefined name 'reload' (glob) (?)
26 26 mercurial/util.py:*: undefined name 'file' (glob) (?)
27 27 mercurial/encoding.py:*: undefined name 'localstr' (glob) (?)
28 28
General Comments 0
You need to be logged in to leave comments. Login now