Commit Graph

56 Commits

Author SHA1 Message Date
Jun Wu
e62af0bff4 test-check-code: do not use xargs
We have too many files, and passing them via arguments could cause strange
errors on some platforms [1]. Since check-code.py can now take "-" and read
file names from stdin, use it instead of xargs to avoid the argv size limit.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-April/096346.html
2017-04-06 22:10:46 -07:00
Philippe Pepiot
e5957f96bd perf: add historical portability for util.timer
util.timer has been introduced in ae5d60bb and used in perf.py since 22fbca1d.
For historical portability, forcibly define util.timer in perf.py
2017-04-06 14:41:42 +02:00
Martin von Zweigbergk
6b2860bef0 check-code: fix "covert" typo 2017-04-03 11:30:51 -07:00
Jun Wu
e6e0b871f1 test-check-code: prevent files being added to the root directory
Adding new files in the root directory is probably a mistake, and is usually
discouraged [1]. The test catches it to avoid mistakes like [2].

Modify the test if files need to be added in the root.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-July/086442.html
[2]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/095836.html
2017-03-29 12:14:20 -07:00
Jun Wu
6ac1cb4157 unionrepo: avoid unnecessary node -> rev conversion 2017-03-29 16:28:51 -07:00
Jun Wu
9c45c07c8b bundlerepo: avoid unnecessary node -> rev conversion 2017-03-29 16:28:00 -07:00
Jun Wu
7f99b86dbd revlog: avoid unnecessary node -> rev conversion 2017-03-29 16:23:04 -07:00
Jun Wu
5dda7e9e48 check-code: detect r.revision(r.node(rev))
revlog.revision takes either node or rev, but taking a rev is more
efficient, because converting rev to node is just a seek and read.
That's cheaper than converting node to rev, which may require O(n) walk in
revlog index for the first times, and then triggering building the radix
tree index. Even with the radix tree built, rev -> node is still faster than
node -> rev because the radix tree requires more jumps in memory.

So r.revision(r.node(rev)) should be changed to r.revision(rev). This patch
adds a check-code rule to detect that.
2017-03-29 16:46:57 -07:00
Yuya Nishihara
af7f25fdb3 encoding: add converter between native str and byte string
This kind of encoding conversion is unavoidable on Python 3.
2017-03-13 09:12:56 -07:00
Yuya Nishihara
dcade16cf7 encoding: factor out unicode variants of from/tolocal()
Unfortunately, these functions will be commonly used on Python 3.
2017-03-13 09:11:08 -07:00
FUJIWARA Katsunori
9d450170ba py3: add "b" prefix to string literals related to module policy
String literals without explicit prefix in __init__.py and policy.py
are treated as unicode object on Python3, because these modules are
loaded before setup of our specific code transformation (the later
module is imported at the beginning of __init__.py).

BTW, "modulepolicy" in __init__.py is initialized by "policy.policy".

This causes issues below;

  - checking "policy" value in other modules causes unintentional result

    For example, "b'py' not in (u'c', u'py')" returns True
    unintentionally on Python3.

  - writing "policy" out fails at conversion from unicode to bytes

    db1ebf457295 fixed this issue for default code path, but "policy"
    can be overridden by HGMODULEPOLICY environment variable (it should
    be rare case for developer using Python3, though).

This patch does:

  - add "b" prefix to all string literals, which are related to module
    policy, in modules above.

  - check existence of HGMODULEPOLICY, and overwrite "policy" only if
    it exists

    For simplicity, this patch omits checking "supports_bytes_environ",
    switching os.environ/os.environb, and so on (Yuya agreed this in
    personal talking)
2017-03-13 04:06:36 +09:00
Augie Fackler
067ebafd12 merge with stable 2017-01-04 14:52:59 -05:00
Augie Fackler
6a644ad048 httpclient: update to 54868ef054d2 of httpplus
As of that revision, httpplus fully supports Python 3, including
mimicing all the subtle behavior changes around headers in Python 3's
http.client.
2016-06-27 11:53:50 -04:00
timeless
0c82fc02cd tests: silence test-repo obsolete warning
refactoring test-check-commit.t HGRCPATH bits as helpers-testrepo.sh
2016-05-11 04:49:27 +00:00
Pulkit Goyal
ff574e7b93 py3: use pycompat.getcwd instead of os.getcwd 2016-12-22 01:54:17 +05:30
Pulkit Goyal
589ad4d6b7 py3: use python 3 compatible variables in hgext/fsmontor/__init__.py
Earlier this was left thinking that its part of pywatchman package.
This patch replaces variables os.sep, sys.platform and os.envrion with their
py3 compatible ones.
2016-12-21 23:40:38 +05:30
Pulkit Goyal
2207f24f07 py3: add warnings in check-code related to py3
We have our own bytes versions of things like, getopt.getopt, os.sep, os.name,
sys.executable, os.environ and few more for python 3 portability. Its better
to come up with warnings if someone breaks the things which we have fixed.

After this patch, check-code will warn us to use our bytes version.
These checks run on mercurial/ and hgext/ and pycompat.py is excluded.
2016-12-21 22:42:31 +05:30
David Soria Parra
66598c8ac2 tests: exclude bundled pywatchman from check-code test
pywatchman is imported from upstream and therefore fails to pass
linting. We have added 'no-check-code' manually to every file in the
past. This is cumbersome and modifies upstream sources.
2016-12-20 20:28:41 -08:00
Gregory Szorc
d5c4807106 debugcommands: sort command order
The diff is a bit large but it is straight code moving without any
logical modifications.
2016-11-25 09:59:39 -08:00
Gregory Szorc
7ab5315d89 tests: add test that @commands in debugcommands.py are sorted
I felt like inline Python in test-check-code.t was the most
appropriate place for this, as other linters in contrib/ seem to
be source file agnostic.

The test currently fails.
2016-11-25 09:55:05 -08:00
Gregory Szorc
2005375cdc 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.
2016-11-10 22:15:58 -08:00
Gregory Szorc
e735a48987 statprof: vendor statprof.py
Vendored from https://bitbucket.org/facebook/hg-experimental
changeset 73f9db47ae5a1a9fa29a98dfe92d557ad51234c3 without
modification.

This introduces a number of code style violations. The file
already has the magic words to skip test-check-code.t. I'll
make additional changes to clean up the test-check-py3-compat.t
warnings and to change some behavior in the code that isn't
suitable for general use.

test-check-commit.t also complains about numerous things. But
there's nothing we can do if we're importing as-is.
2016-11-01 18:54:03 -07:00
Augie Fackler
b569044317 fsmonitor: flag msc_stdint as no-check-code
I'd rather not modify code that we're vendoring, so I'm just marking
it this way.
2016-03-14 21:15:59 -04:00
Martijn Pieters
64a4b2e8cf fsmonitor: dependencies for new experimental extension
In preparation for the filesystem monitor extension, include the pywatchman
library. The fbmonitor extension relies on this library to communicate with
the Watchman service. The library is BSD licensed and is taken from
https://github.com/facebook/watchman/tree/master/python.

This package has not been updated to mercurial code standards.
2016-03-02 16:25:12 +00:00
timeless
a2c7933e41 zeroconf: replace has_key with in 2016-03-01 10:22:10 +00:00
Pierre-Yves David
7cae660c88 tests: move the '-hg' postfix for all style tests
We had them on 'test-check-code-hg.t' to avoid collision with the test checking
'check-code' itself. Now that this one have been rename, we can safely remove
this suffix for all of them. This get them in line with 'check-pyflakes.t'.
2015-12-05 22:49:39 -08:00
Pierre-Yves David
22f4eed389 test: rename 'check-code' own test to 'test-contrib-check-code.t'
This test (making sure the 'check-code' script run as intended) have been
confused with the test making that the mercurial code base comply with our
coding still by multiple generations of contributors.

We are moving it out of the way so that all tests starting with
'test-check' are now doing compliance testing.
2015-12-05 22:47:26 -08:00
Pierre-Yves David
4a231c9668 check-code: entirely drop the 'non-py24.py' file from the test
There are no Python 2.4 related errors remaining.
2015-05-18 16:30:24 -05:00
Pierre-Yves David
624cc99b09 check-code: drop the 'format' built-in
I'm not clear what it is doing, but one who knows what it is about can now make
use of it.
2015-05-18 16:11:44 -05:00
Pierre-Yves David
2d3ab51ced check-code: drop the yield inside try/finally ban
This is now possible with Python 2.6.
2015-05-18 12:56:59 -05:00
Augie Fackler
82d20c6721 check-code: un-ban __builtins__.all now that we're on 2.6 2015-05-16 14:34:04 -04:00
Augie Fackler
8135f8f3bf check-code: un-ban any() now that we're on 2.6 2015-05-16 14:31:03 -04:00
Pierre-Yves David
5c28bef986 check-code: lift the ban on 'next()'
'next' is supported by Python2.6 the new lowest version supported by Mercurial.
2015-05-17 17:47:42 -07:00
Pierre-Yves David
b126ceafed check-code: fix the error message about 'class foo():'
Using 'classs foo():' result in old style object instead of new style object. We
do not want old style object so this check is unrelated to 2.4.
2015-05-17 17:40:26 -07:00
Matt Mackall
d4d62e93d0 check-code: drop try/except/finally check 2015-05-15 09:54:35 -05:00
Mads Kiilerich
523c87c1fe spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
Steven Brown
b97c015cd5 check-code: check for consistent usage of the websub filter in hgweb templates
The check-code tool now expects the "desc" keyword to be followed by the
"websub" filter, with the following exceptions:
a) It has no filters at all, e.g. a changeset description in the raw style
   templates or the repository description in the summary page.
b) It is followed by the "firstline" filter, e.g. the first line of the
   changeset description is displayed as a summary or title.
2014-05-17 17:11:06 +08:00
FUJIWARA Katsunori
0ba1f1ddab check-code: detect "% inside _()" when there are leading whitespaces
Before this patch, "contrib/check-code.py" can't detect "% inside _()"
correctly, when there are leading whitespaces before the format
string, like below:

    _(
      "format string %s" % v)

This patch adds regexp pattern "[ \t\n]*" before the pattern matching
against the format string.

"[\s\n]" can't be used in this purpose, because "\s" is automatically
replaced with "[ \t]" by "_preparepats()" and "\s" in "[]" causes
nested "[]" unexpectedly.
2014-04-16 03:05:00 +09:00
Augie Fackler
ad0fddea79 check-code: disallow use of dict(key=value) construction
{} literals are faster and more consistent across Python 2 and 3.

Whitelisted the one use of dict() that is using a generator expresion.
2014-03-12 13:31:27 -04:00
Simon Heimberg
a4feb953c7 check-code: prepend warning prefix only once, but for each warning
The code adding the prefix is now run once per pattern. It was run once per
file (after the change 17484f4c54fb).
Demonstrate that it is working now by extending the test. Raise two different
warnings, one of them twice.
2013-11-09 10:21:20 +01:00
Simon Heimberg
81c6ecacd6 check-code: check comment for '.. note::' without two newlines
Because string entries are replaced before matching, we must search for
the transformed pattern. But it seems to be quite unique and does not return
false matches. If it will, they can be listed as 3rd arg in pypats.
2013-11-05 09:00:31 +01:00
Augie Fackler
ac76c4f1a9 check-code: add a check for the next() builtin, which was new in 2.6 2013-07-25 10:44:51 -04:00
Simon Heimberg
7ea18de5fd check-code: do not abort on an unreadable file, only report this 2013-07-22 10:04:45 +02:00
Simon Heimberg
83278fd7d4 check-code: automatically preppend "warning: " to all warning messages
Some warnings had "warning: " at the beginning of their message. Now this
is done consistent for all messages.
Especially in test-check-code-hg.t it is an advantage to see warnings at once
because only exceptions to them are tolerated. It is (almost) as obvious as
before a6180647ea.

The prefix will not remain when a warning is changed to a failure. A change
like a91387a37f will not be necessary anymore.
2013-07-16 01:29:14 +02:00
Simon Heimberg
0e27bb618e check-code: do not prepend "warning" to a failure message
The prefix has not been removed when this check changed from a warning to a
failure.
2013-03-09 22:14:46 +01:00
Augie Fackler
6f81622e24 check-code: disallow defunct <> operator
Added a test for that and one other python3 check in
test-check-code.t.
2013-01-01 13:05:22 -06:00
Augie Fackler
a52590ca42 check-code: disallow two-argument form of raise
Using this old form makes any attempt to port to Python 3 harder, and
the new syntax is supported in 2.4 already.
2013-01-01 12:58:21 -06:00
Thomas Arendsen Hein
23c6bfee41 check-code: catch yield inside try/finally (with tests)
This is not allowed in Python 2.4.
2012-09-19 12:29:12 +02:00
Mads Kiilerich
5e3dc3e383 avoid using abbreviations that look like spelling errors 2012-08-27 23:14:27 +02:00
Mads Kiilerich
ef0024b865 check-code: add --nolineno option for hiding line numbers
This makes the output more stable when it is used as a whitelist.
2011-11-11 01:25:47 +01:00