sapling/contrib/utils.py
Jun Wu 584656dff3 codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).

Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.

Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.

An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.

As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.

Reviewed By: wez, phillco, simpkins, pkaush, singhsrb

Differential Revision: D8173629

fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-25 22:17:29 -07:00

60 lines
2.0 KiB
Python

from __future__ import absolute_import
import multiprocessing
import os
import subprocess
reporoot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def getrunner():
"""return the path of run-tests.py. best-effort"""
runner = "run-tests.py"
# Try MERCURIALRUNTEST
candidate = os.environ.get("MERCURIALRUNTEST")
if candidate and os.access(candidate, os.X_OK):
return candidate
# Search in PATH
for d in os.environ.get("PATH").split(os.path.pathsep):
candidate = os.path.abspath(os.path.join(d, runner))
if os.access(candidate, os.X_OK):
return candidate
# Search some common places for run-tests.py, as a nice default
# if we cannot find it otherwise.
for prefix in [os.path.dirname(reporoot), os.path.expanduser("~")]:
for hgrepo in ["hg", "hg-crew", "hg-committed"]:
path = os.path.abspath(os.path.join(prefix, hgrepo, "tests", runner))
if os.access(path, os.X_OK):
return path
return runner
def reporequires():
"""return a list of string, which are the requirements of the hg repo"""
requirespath = os.path.join(reporoot, ".hg", "requires")
if os.path.exists(requirespath):
return [s.rstrip() for s in open(requirespath, "r")]
return []
def spawnruntests(args, **kwds):
cpucount = multiprocessing.cpu_count()
cmd = [getrunner(), "-j%d" % cpucount]
# Include the repository root in PYTHONPATH so the unit tests will find
# the extensions from the local repository, rather than the versions
# already installed on the system.
env = os.environ.copy()
if "PYTHONPATH" in env:
existing_pypath = [env["PYTHONPATH"]]
else:
existing_pypath = []
env["PYTHONPATH"] = os.path.pathsep.join([reporoot] + existing_pypath)
# Spawn the run-tests.py process.
cmd += args
cwd = os.path.join(reporoot, "tests")
proc = subprocess.Popen(cmd, cwd=cwd, env=env, **kwds)
return proc