Skip to content

Commit

Permalink
Bug 1401309 - [mozlint] Remove vcs.py and use mozversioncontrol inste…
Browse files Browse the repository at this point in the history
…ad, r=gps

This also migrates the vcs.py test to mozversioncontrol and adds a new task for
it.

MozReview-Commit-ID: 9jTRkjNupVA
  • Loading branch information
ahal committed Sep 25, 2017
1 parent d69d810 commit 14ad42f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 139 deletions.
1 change: 1 addition & 0 deletions python/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PYTHON_UNITTEST_MANIFESTS += [
'mach/mach/test/python.ini',
'mozbuild/dumbmake/test/python.ini',
'mozlint/test/python.ini',
'mozversioncontrol/test/python.ini',
]

if CONFIG['MOZ_BUILD_APP']:
Expand Down
33 changes: 25 additions & 8 deletions python/mozlint/mozlint/roller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
from collections import defaultdict
from concurrent.futures import ProcessPoolExecutor
from multiprocessing import cpu_count
from subprocess import CalledProcessError

from mozversioncontrol import get_repository_object, MissingUpstreamRepo, InvalidRepoPath

from .errors import LintersNotConfigured
from .parser import Parser
from .types import supported_types
from .vcs import VCSHelper


def _run_linters(config, paths, **lintargs):
Expand Down Expand Up @@ -55,13 +57,16 @@ class LintRoller(object):
:param lintargs: Arguments to pass to the underlying linter(s).
"""

def __init__(self, root=None, **lintargs):
def __init__(self, root, **lintargs):
self.parse = Parser()
self.vcs = VCSHelper.create()
try:
self.vcs = get_repository_object(root)
except InvalidRepoPath:
self.vcs = None

self.linters = []
self.lintargs = lintargs
self.lintargs['root'] = root or self.vcs.root or os.getcwd()
self.lintargs['root'] = root

# linters that return non-zero
self.failed = None
Expand Down Expand Up @@ -98,11 +103,23 @@ def roll(self, paths=None, outgoing=None, workdir=None, num_procs=None):
if not self.linters:
raise LintersNotConfigured

if not self.vcs and (workdir or outgoing):
print("error: '{}' is not a known repository, can't use "
"--workdir or --outgoing".format(self.lintargs['root']))

# Calculate files from VCS
if workdir:
paths.update(self.vcs.by_workdir(workdir))
if outgoing:
paths.update(self.vcs.by_outgoing(outgoing))
try:
if workdir:
paths.update(self.vcs.get_changed_files('AM', mode=workdir))
if outgoing:
try:
paths.update(self.vcs.get_outgoing_files('AM', upstream=outgoing))
except MissingUpstreamRepo:
print("warning: could not find default push, specify a remote for --outgoing")
except CalledProcessError as e:
print("error running: {}".format(' '.join(e.cmd)))
if e.output:
print(e.output)

if not paths and (workdir or outgoing):
print("warning: no files linted")
Expand Down
113 changes: 0 additions & 113 deletions python/mozlint/mozlint/vcs.py

This file was deleted.

4 changes: 0 additions & 4 deletions python/mozlint/test/python.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ subsuite = mozlint, os == "linux"
[test_parser.py]
[test_roller.py]
[test_types.py]
[test_vcs.py]
# these tests run in the build images on non-linux, which have old
# versions of mercurial and git installed
skip-if = os != "linux"
4 changes: 4 additions & 0 deletions python/mozversioncontrol/test/python.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[DEFAULT]
subsuite=mozversioncontrol

[test_workdir_outgoing.py]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import mozunit
import pytest

from mozlint.vcs import VCSHelper, vcs_class
from mozversioncontrol import get_repository_object


setup = {
Expand Down Expand Up @@ -95,29 +95,28 @@ def assert_files(actual, expected):
assert set(map(os.path.basename, actual)) == set(expected)


def test_vcs_helper(repo):
vcs = VCSHelper.create()
assert vcs.__class__ == vcs_class[repo.vcs]
assert vcs.root == repo.strpath
def test_workdir_outgoing(repo):
vcs = get_repository_object(repo.strpath)
assert vcs.path == repo.strpath

remotepath = '../remoterepo' if repo.vcs == 'hg' else 'upstream/master'

next(repo.setup)

assert_files(vcs.by_workdir('all'), ['bar', 'baz'])
assert_files(vcs.get_changed_files('AM', 'all'), ['bar', 'baz'])
if repo.vcs == 'git':
assert_files(vcs.by_workdir('staged'), ['baz'])
assert_files(vcs.get_changed_files('AM', mode='staged'), ['baz'])
elif repo.vcs == 'hg':
assert_files(vcs.by_workdir('staged'), ['bar', 'baz'])
assert_files(vcs.by_outgoing(), [])
assert_files(vcs.by_outgoing(remotepath), [])
assert_files(vcs.get_changed_files('AM', 'staged'), ['bar', 'baz'])
assert_files(vcs.get_outgoing_files('AM'), [])
assert_files(vcs.get_outgoing_files('AM', remotepath), [])

next(repo.setup)

assert_files(vcs.by_workdir('all'), [])
assert_files(vcs.by_workdir('staged'), [])
assert_files(vcs.by_outgoing(), ['bar', 'baz'])
assert_files(vcs.by_outgoing(remotepath), ['bar', 'baz'])
assert_files(vcs.get_changed_files('AM', 'all'), [])
assert_files(vcs.get_changed_files('AM', 'staged'), [])
assert_files(vcs.get_outgoing_files('AM'), ['bar', 'baz'])
assert_files(vcs.get_outgoing_files('AM', remotepath), ['bar', 'baz'])


if __name__ == '__main__':
Expand Down
23 changes: 23 additions & 0 deletions taskcluster/ci/source-test/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ mozlint:
- 'python/mozlint/**'
- 'python/mach_commands.py'

mozversioncontrol:
description: python/mozversioncontrol unit tests
platform: linux64/opt
treeherder:
symbol: py(vcs)
kind: test
tier: 2
worker-type:
by-platform:
linux64.*: aws-provisioner-v1/gecko-t-linux-xlarge
worker:
by-platform:
linux64.*:
docker-image: {in-tree: "lint"}
max-run-time: 3600
run:
using: mach
mach: python-test --subsuite mozversioncontrol
when:
files-changed:
- 'python/mozversioncontrol/**'
- 'python/mach_commands.py'

reftest-harness:
description: layout/tools/reftest unittests
platform:
Expand Down

0 comments on commit 14ad42f

Please sign in to comment.