Commit Graph

30 Commits

Author SHA1 Message Date
Gregory Szorc
97fa6a9809 ui: use absolute_import
And we have no more ambiguous mixed imports \o/
2015-08-08 18:25:41 -07:00
Gregory Szorc
1e68b1d684 templater: use absolute_import 2015-08-08 18:23:53 -07:00
Gregory Szorc
754028767d revset: use absolute_import 2015-08-08 18:36:58 -07:00
Gregory Szorc
bf31c39d5d fileset: use absolute_import 2015-08-08 18:34:37 -07:00
Gregory Szorc
177174bac6 dispatch: use absolute_import
A mixed, ambiguous import has been removed!
2015-08-08 14:42:48 -07:00
Gregory Szorc
788d5ef232 commands: break import cycle
This was the easiest link in the chain to break as there was only
one use of commandserver in commands.py. Other files had multiple
users.
2015-08-08 14:30:39 -07:00
Gregory Szorc
a935029795 cmdutil: break import cycle
This was the easiest place to break the chain, as there were only
2 uses of the imported module in the file.
2015-08-08 00:47:19 -07:00
FUJIWARA Katsunori
4bae7bb820 import-checker.py: exit with code 0 if no error is detected
Before this patch, `import-checker.py` exits with non-0 code, if no
error is detected. This is unusual as Unix command.

This change may be a one of preparations for issue4677, because this
can avoid extra explanation about unusual exit code of
`import-checker.py` for third party tool developers.
2015-07-03 06:56:03 +09:00
Gregory Szorc
5fe42b2975 import-checker: establish modern import convention
We introduce a new convention for declaring imports and enforce it via
the import checker script.

The new convention is only active when absolute imports are used, which is
currently nowhere. Keying off "from __future__ import absolute_import" to
engage the new import convention seems like the easiest solution. It is
also beneficial for Mercurial to use this mode because it means less work
and ambiguity for the importer and potentially better performance due to
fewer stat() system calls because the importer won't look for modules in
relative paths unless explicitly asked.

Once all files are converted to use absolute import, we can refactor
this code to again only have a single import convention and we can
require use of absolute import in the style checker.

The rules for the new convention are documented in the docstring of the
added function. Tests have been added to test-module-imports.t. Some
tests are sensitive to newlines and source column position, which makes
docstring testing difficult and/or impossible.
2015-06-28 12:46:34 -07:00
Pierre-Yves David
5f05d2698e progress: move the singleton logic to the ui module
The use of a singleton for all of progress handling is debatable (because
config may vary). However this is how the extension has been doing it so far.
We move that code into the ui module because this is where is should belong when
progress is moved into core.
2015-06-07 17:26:34 -07:00
Gregory Szorc
2d896585ec test-module-imports: drop check for Python >= 2.6
Support for Python 2.4 and 2.5 has been dropped. This check is no
longer necessary.
2015-05-25 11:06:49 -07:00
FUJIWARA Katsunori
22ede7817f tests: check import cycles in hgext/**.py, too
It is important to realize existing cycles in hgext/**.py.
2015-05-18 02:53:08 +09:00
FUJIWARA Katsunori
8a7efd627d import-checker: make imported_modules yield absolute dotted_name_of_path
This patch makes `imported_modules()` always yield absolute
`dotted_name_of_path()`-ed name by strict detection with
`fromlocal()`.

This change improves circular detection in some points:

  - locally defined modules, of which name collides against one of
    standard library, can be examined correctly

    For example, circular import related to `commands` is overlooked
    before this patch.

  - names not useful for circular detection are ignored

    Names below are also yielded before this patch:

      - module names of standard library (= not locally defined one)
      - non-module names (e.g. `node.nullid` of `from node import nullid`)

    These redundant names decrease performance of circular detection.

    For example, with files at 13dc86d189c9, average loops per file in
    `checkmod()` is reduced from 165 to 109.

  - `__init__` can be handled correctly in `checkmod()`

    For example, current implementation has problems below:

      - `from xxx import yyy` doesn't recognize `xxx.__init__` as imported

      - `xxx.__init__` imported via `import xxx` is treated as `xxx`,
        and circular detection is aborted, because `key` of such
        module name is not `xxx` but `xxx.__init__`

  - it is easy to enhance for `from . import xxx` style or so (in the
    future)

    Module name detection in `imported_modules()` can use information
    in `ast.ImportFrom` fully.

It is assumed that all locally defined modules are correctly specified
to `import-checker.py` at once.

Strictly speaking, when `from foo.bar.baz import module1` imports
`foo.bar.baz.module1` module, current `imported_modules()` yields only
`foo.bar.baz.__init__`, even though also `foo.__init__` and
`foo.bar.__init__` should be yielded to detect circular import
exactly.

But this limitation is reasonable one for improvement in this patch,
because current `__init__` files in Mercurial seems to be implemented
carefully.
2015-05-18 02:52:55 +09:00
FUJIWARA Katsunori
0f658fb502 import-checker: add xargs like mode
Before this patch, "import-check.py" is invoked via "xargs" in
"test-module-imports.t", but it doesn't ensure that
"import-checker.py" is certainly invoked with all mercurial specific
files at once.

"xargs" may invoke specified command multiple times with part of
arguments given from stdin: according to "xargs(1)" man page, this
dividing arguments is system-dependent.

This patch adds "xargs" like mode to "import-checker.py".

This can ensure that "import-checker.py" is certainly invoked with all
mercurial specific files at once in "test-module-imports.t". This is
assumed by subsequent patches.
2015-05-14 01:49:10 +09:00
Matt Harbison
65f90257b1 crecord: fix mixed imports warning 2015-04-09 23:47:07 -04:00
Gregory Szorc
7498d10d47 revset: don't import discovery at module level
discovery.py imports a lot of the world. Pierre-Yves told me to move it
to a function-level import to avoid an import cycle in a future patch.
2015-04-14 12:54:16 -04:00
Matt Mackall
407d8470d0 import-checker: fix rotatecycle
It was duplicating the last element sometimes.
2015-03-27 18:50:39 -05:00
Matt Harbison
430072a9cc crecord: conditionalize the imports that are not available on Windows
'fcntl', 'termios' and 'wcurses' are not available on the default Windows python
installation, and importing them caused widespread carnage in the test suite.
There were 29 different changed test files (on top of unrelated errors), mostly
in the form of an ImportError.

The failures weren't related to actual crecord use, and followed the import
chain:

    'localrepo' -> 'subrepo' -> 'cmdutil' -> 'crecord' -> 'fcntl'
2015-03-20 23:32:00 -04:00
Matt Mackall
c031f45352 test-module-imports: use test-repo requirement 2015-01-16 16:25:30 -08:00
Augie Fackler
a5ddb1dcfe tests: use $PYTHON instead of hardcoding python
This makes running the testsuite with pypy possible.
2014-10-15 15:35:59 -04:00
Durham Goode
f8aca20bcb template: add revset() template function
Adds a template function that executes a revset and returns the list of
revisions as the result. It has the signature 'revset(query [, args...])'. The
args are optional and are applied to the query string using the standard
python string.format(args) pattern. This allows things like:
'{revset("parents({0})", rev)}' to produce the parents of each individual
commit in the log output.  If no args are specified, the revset result is
cached for the duration of the templater; so it's better to not use args if
performance is a concern.

By itself, revset() can be used to print commit parents, print the common
ancestor of a commit with the main branch, etc.

It can be used with the ifcontains() function to do things like
'{ifcontains(rev, revset('.'), label(...), ...)}' to color the working copy
parent, to color certain branches, to color draft commits, etc.
2014-02-11 21:04:12 -08:00
Augie Fackler
859551f9b1 repoview: use repo.revs() instead of a private revset method
Breaks an import cycle.
2014-02-04 17:13:45 -05:00
Augie Fackler
edc98c0164 match: use ctx.getfileset() instead of fileset.getfileset()
Resolves an import cycle involving match and merge.
2014-02-04 14:54:42 -05:00
Simon Heimberg
d4711ad797 tests: test-module-imports.t works on windows (with backslash path sep)
Transform the backslashes to slashes on windows, because they are eaten up by
the shell. (Similar as done in test-check-pyflakes.t.)

This test will not produce a traceback on windows anymore. But the test still
fails because the detected mixed imports differ.
2014-01-28 00:33:52 +01:00
Augie Fackler
8bfe6ea1ed itersubrepos: move to scmutil to break a direct import cycle 2014-02-03 18:36:00 -05:00
Mads Kiilerich
446ad18e32 import-checker: show stdlib and relative imports separately
Make the output more useful for debugging problems.
2014-02-05 01:43:51 +01:00
Chris Jerdonek
2f40a478a8 import-checker: backout dbcb4de20d06 (issue4129)
This patch backs out dbcb4de20d06, which caused test-module-imports.t to
be skipped when the test was run using virtualenv.  Since the test now
passes when using virtualenv, the skip is no longer necessary.
2013-12-22 21:27:00 -08:00
Augie Fackler
e5f635905e test-module-imports: try and detect virtualenv breakage (issue4129)
virtualenvs (among other things) break the stdlib module detection in
the import checker, and I don't see a good way to work around that for
now.
2013-12-14 11:58:26 -05:00
Augie Fackler
b707be4041 test-module-imports: skip on Python < 2.6, since ast is new in 2.6 2013-11-17 18:13:55 -05:00
Augie Fackler
96de448db2 test-module-imports.t: new test to use the import cycle detector 2013-11-17 13:38:35 -05:00