tests/test-check-module-imports.t
author Gregory Szorc <gregory.szorc@gmail.com>
Thu, 10 Nov 2016 22:15:58 -0800
changeset 30435 b86a448a2965
parent 29305 814076f4ace3
child 31442 d3a56bb268ee
permissions -rw-r--r--
zstd: vendor python-zstandard 0.5.0 As the commit message for the previous changeset says, we wish for zstd to be a 1st class citizen in Mercurial. To make that happen, we need to enable Python to talk to the zstd C API. And that requires bindings. This commit vendors a copy of existing Python bindings. Why do we need to vendor? As the commit message of the previous commit says, relying on systems in the wild to have the bindings or zstd present is a losing proposition. By distributing the zstd and bindings with Mercurial, we significantly increase our chances that zstd will work. Since zstd will deliver a better end-user experience by achieving better performance, this benefits our users. Another reason is that the Python bindings still aren't stable and the API is somewhat fluid. While Mercurial could be coded to target multiple versions of the Python bindings, it is safer to bundle an explicit, known working version. The added Python bindings are mostly a fully-featured interface to the zstd C API. They allow one-shot operations, streaming, reading and writing from objects implements the file object protocol, dictionary compression, control over low-level compression parameters, and more. The Python bindings work on Python 2.6, 2.7, and 3.3+ and have been tested on Linux and Windows. There are CFFI bindings, but they are lacking compared to the C extension. Upstream work will be needed before we can support zstd with PyPy. But it will be possible. The files added in this commit come from Git commit e637c1b214d5f869cf8116c550dcae23ec13b677 from https://github.com/indygreg/python-zstandard and are added without modifications. Some files from the upstream repository have been omitted, namely files related to continuous integration. In the spirit of full disclosure, I'm the maintainer of the "python-zstandard" project and have authored 100% of the code added in this commit. Unfortunately, the Python bindings have not been formally code reviewed by anyone. While I've tested much of the code thoroughly (I even have tests that fuzz APIs), there's a good chance there are bugs, memory leaks, not well thought out APIs, etc. If someone wants to review the code and send feedback to the GitHub project, it would be greatly appreciated. Despite my involvement with both projects, my opinions of code style differ from Mercurial's. The code in this commit introduces numerous code style violations in Mercurial's linters. So, the code is excluded from most lints. However, some violations I agree with. These have been added to the known violations ignore list for now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23894
f388ceae2250 test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents: 22947
diff changeset
     1
#require test-repo
f388ceae2250 test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents: 22947
diff changeset
     2
29219
3c9066ed557c tests: silence test-repo obsolete warning
timeless <timeless@mozdev.org>
parents: 29212
diff changeset
     3
  $ . "$TESTDIR/helpers-testrepo.sh"
20039
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     4
  $ import_checker="$TESTDIR"/../contrib/import-checker.py
23894
f388ceae2250 test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents: 22947
diff changeset
     5
20039
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     6
Run the doctests from the import checker, and make sure
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     7
it's working correctly.
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     8
  $ TERM=dumb
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     9
  $ export TERM
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    10
  $ python -m doctest $import_checker
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    11
25703
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    12
Run additional tests for the import checker
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    13
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    14
  $ mkdir testpackage
29206
0ec8501af800 import-checker: fix test to make a real package
Yuya Nishihara <yuya@tcha.org>
parents: 28923
diff changeset
    15
  $ touch testpackage/__init__.py
25703
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    16
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    17
  $ cat > testpackage/multiple.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    18
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    19
  > import os, sys
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    20
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    21
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    22
  $ cat > testpackage/unsorted.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    23
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    24
  > import sys
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    25
  > import os
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    26
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    27
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    28
  $ cat > testpackage/stdafterlocal.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    29
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    30
  > from . import unsorted
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    31
  > import os
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    32
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    33
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    34
  $ cat > testpackage/requirerelative.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    35
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    36
  > import testpackage.unsorted
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    37
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    38
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    39
  $ cat > testpackage/importalias.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    40
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    41
  > import ui
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    42
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    43
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    44
  $ cat > testpackage/relativestdlib.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    45
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    46
  > from .. import os
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    47
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    48
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    49
  $ cat > testpackage/symbolimport.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    50
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    51
  > from .unsorted import foo
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    52
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    53
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    54
  $ cat > testpackage/latesymbolimport.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    55
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    56
  > from . import unsorted
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    57
  > from mercurial.node import hex
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    58
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    59
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    60
  $ cat > testpackage/multiplegroups.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    61
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    62
  > from . import unsorted
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    63
  > from . import more
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    64
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    65
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    66
  $ mkdir testpackage/subpackage
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    67
  $ cat > testpackage/subpackage/levelpriority.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    68
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    69
  > from . import foo
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    70
  > from .. import parent
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    71
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
    72
26964
5abba2c92da3 import-checker: allow import of child modules from package root
Yuya Nishihara <yuya@tcha.org>
parents: 26956
diff changeset
    73
  $ touch testpackage/subpackage/foo.py
5abba2c92da3 import-checker: allow import of child modules from package root
Yuya Nishihara <yuya@tcha.org>
parents: 26956
diff changeset
    74
  $ cat > testpackage/subpackage/__init__.py << EOF
5abba2c92da3 import-checker: allow import of child modules from package root
Yuya Nishihara <yuya@tcha.org>
parents: 26956
diff changeset
    75
  > from __future__ import absolute_import
5abba2c92da3 import-checker: allow import of child modules from package root
Yuya Nishihara <yuya@tcha.org>
parents: 26956
diff changeset
    76
  > from . import levelpriority  # should not cause cycle
5abba2c92da3 import-checker: allow import of child modules from package root
Yuya Nishihara <yuya@tcha.org>
parents: 26956
diff changeset
    77
  > EOF
5abba2c92da3 import-checker: allow import of child modules from package root
Yuya Nishihara <yuya@tcha.org>
parents: 26956
diff changeset
    78
26965
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    79
  $ cat > testpackage/subpackage/localimport.py << EOF
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    80
  > from __future__ import absolute_import
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    81
  > from . import foo
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    82
  > def bar():
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    83
  >     # should not cause "higher-level import should come first"
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    84
  >     from .. import unsorted
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    85
  >     # but other errors should be detected
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    86
  >     from .. import more
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    87
  >     import testpackage.subpackage.levelpriority
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    88
  > EOF
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
    89
27272
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    90
  $ cat > testpackage/importmodulefromsub.py << EOF
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    91
  > from __future__ import absolute_import
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    92
  > from .subpackage import foo  # not a "direct symbol import"
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    93
  > EOF
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    94
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    95
  $ cat > testpackage/importsymbolfromsub.py << EOF
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    96
  > from __future__ import absolute_import
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    97
  > from .subpackage import foo, nonmodule
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    98
  > EOF
69308357ecd1 import-checker: allow absolute imports of sub modules from local packages
Yuya Nishihara <yuya@tcha.org>
parents: 26965
diff changeset
    99
25703
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   100
  $ cat > testpackage/sortedentries.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   101
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   102
  > from . import (
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   103
  >     foo,
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   104
  >     bar,
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   105
  > )
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   106
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   107
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   108
  $ cat > testpackage/importfromalias.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   109
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   110
  > from . import ui
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   111
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   112
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   113
  $ cat > testpackage/importfromrelative.py << EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   114
  > from __future__ import absolute_import
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   115
  > from testpackage.unsorted import foo
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   116
  > EOF
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   117
29208
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   118
  $ mkdir testpackage2
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   119
  $ touch testpackage2/__init__.py
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   120
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   121
  $ cat > testpackage2/latesymbolimport.py << EOF
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   122
  > from __future__ import absolute_import
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   123
  > from testpackage import unsorted
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   124
  > from mercurial.node import hex
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   125
  > EOF
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   126
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   127
  $ python "$import_checker" testpackage*/*.py testpackage/subpackage/*.py
26956
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   128
  testpackage/importalias.py:2: ui module must be "as" aliased to uimod
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   129
  testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   130
  testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted
27273
5d5b98346fc2 import-checker: tell which symbol causes "direct symbol import"
Yuya Nishihara <yuya@tcha.org>
parents: 27272
diff changeset
   131
  testpackage/importfromrelative.py:2: direct symbol import foo from testpackage.unsorted
5d5b98346fc2 import-checker: tell which symbol causes "direct symbol import"
Yuya Nishihara <yuya@tcha.org>
parents: 27272
diff changeset
   132
  testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage
26956
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   133
  testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   134
  testpackage/multiple.py:2: multiple imported names: os, sys
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   135
  testpackage/multiplegroups.py:3: multiple "from . import" statements
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   136
  testpackage/relativestdlib.py:2: relative import of stdlib module
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   137
  testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   138
  testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo
28330
f3fb24e36d61 import-checker: report local with stdlib late warning
timeless <timeless@mozdev.org>
parents: 28275
diff changeset
   139
  testpackage/stdafterlocal.py:3: stdlib import "os" follows local import: testpackage
26956
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   140
  testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage
26965
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
   141
  testpackage/subpackage/localimport.py:7: multiple "from .. import" statements
1fa66d3ad28d import-checker: reset context to verify convention in function scope
Yuya Nishihara <yuya@tcha.org>
parents: 26964
diff changeset
   142
  testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority
27273
5d5b98346fc2 import-checker: tell which symbol causes "direct symbol import"
Yuya Nishihara <yuya@tcha.org>
parents: 27272
diff changeset
   143
  testpackage/symbolimport.py:2: direct symbol import foo from testpackage.unsorted
26956
4b56214ebb7a import-checker: include lineno in warning message
Yuya Nishihara <yuya@tcha.org>
parents: 25989
diff changeset
   144
  testpackage/unsorted.py:3: imports not lexically sorted: os < sys
29208
cba8bc11ed10 import-checker: extend check of symbol-import order to all local modules
Yuya Nishihara <yuya@tcha.org>
parents: 29206
diff changeset
   145
  testpackage2/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node
25731
cd1daab5d036 import-checker.py: exit with code 0 if no error is detected
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25703
diff changeset
   146
  [1]
25703
1a6a117d0b95 import-checker: establish modern import convention
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25498
diff changeset
   147
20039
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   148
  $ cd "$TESTDIR"/..
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   149
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   150
There are a handful of cases here that require renaming a module so it
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   151
doesn't overlap with a stdlib module name. There are also some cycles
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   152
here that we should still endeavor to fix, and some cycles will be
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   153
hidden by deduplication algorithm in the cycle detector, so fixing
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   154
these may expose other cycles.
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
   155
28844
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   156
Known-bad files are excluded by -X as some of them would produce unstable
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   157
outputs, which should be fixed later.
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   158
29234
393aef802535 tests: enable import checker for all python files (including no .py files)
Yuya Nishihara <yuya@tcha.org>
parents: 29219
diff changeset
   159
  $ hg locate 'set:**.py or grep(r"^#!.*?python")' \
28923
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   160
  > 'tests/**.t' \
29212
8005e0e0eb33 tests: enable import checker for all **.py files
Yuya Nishihara <yuya@tcha.org>
parents: 29208
diff changeset
   161
  > -X contrib/debugshell.py \
30435
b86a448a2965 zstd: vendor python-zstandard 0.5.0
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29305
diff changeset
   162
  > -X contrib/python-zstandard/ \
29212
8005e0e0eb33 tests: enable import checker for all **.py files
Yuya Nishihara <yuya@tcha.org>
parents: 29208
diff changeset
   163
  > -X contrib/win32/hgwebdir_wsgi.py \
8005e0e0eb33 tests: enable import checker for all **.py files
Yuya Nishihara <yuya@tcha.org>
parents: 29208
diff changeset
   164
  > -X doc/gendoc.py \
8005e0e0eb33 tests: enable import checker for all **.py files
Yuya Nishihara <yuya@tcha.org>
parents: 29208
diff changeset
   165
  > -X doc/hgmanpage.py \
29234
393aef802535 tests: enable import checker for all python files (including no .py files)
Yuya Nishihara <yuya@tcha.org>
parents: 29219
diff changeset
   166
  > -X i18n/posplit \
28844
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   167
  > -X tests/test-hgweb-auth.py \
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   168
  > -X tests/hypothesishelpers.py \
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   169
  > -X tests/test-ctxmanager.py \
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   170
  > -X tests/test-lock.py \
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   171
  > -X tests/test-verify-repo-operations.py \
28923
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   172
  > -X tests/test-hook.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   173
  > -X tests/test-import.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   174
  > -X tests/test-check-module-imports.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   175
  > -X tests/test-commit-interactive.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   176
  > -X tests/test-contrib-check-code.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   177
  > -X tests/test-extension.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   178
  > -X tests/test-hghave.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   179
  > -X tests/test-hgweb-no-path-info.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   180
  > -X tests/test-hgweb-no-request-uri.t \
531dea16f4f7 tests: run import-checker with tests .t files
timeless <timeless@mozdev.org>
parents: 28844
diff changeset
   181
  > -X tests/test-hgweb-non-interactive.t \
28844
99a2bdad0fda tests: enable import checker for tests/**.py files
Yuya Nishihara <yuya@tcha.org>
parents: 28330
diff changeset
   182
  > | sed 's-\\-/-g' | python "$import_checker" -