Bug 1460402 - Update the flake8 support to use the pip class r=ahal

MozReview-Commit-ID: 9BWa0cnWJdS

--HG--
extra : rebase_source : a4574227e2f165fa9b2529fb0e36f24f26ee5cfd
This commit is contained in:
Sylvestre Ledru 2018-05-09 21:55:21 +02:00
Родитель 9773d1f2f1
Коммит 91cdb3d557
2 изменённых файлов: 4 добавлений и 56 удалений

Просмотреть файл

@ -5,13 +5,13 @@
import json import json
import os import os
import signal import signal
import subprocess
from collections import defaultdict from collections import defaultdict
import which import which
from mozprocess import ProcessHandlerMixin from mozprocess import ProcessHandlerMixin
from mozlint import result from mozlint import result
from mozlint.util import pip
from mozlint.pathutils import get_ancestors_by_name from mozlint.pathutils import get_ancestors_by_name
@ -105,32 +105,6 @@ def get_flake8_binary():
return None return None
def _run_pip(*args):
"""
Helper function that runs pip with subprocess
"""
try:
subprocess.check_output(['pip'] + list(args),
stderr=subprocess.STDOUT)
return True
except subprocess.CalledProcessError as e:
print(e.output)
return False
def reinstall_flake8():
"""
Try to install flake8 at the target version, returns True on success
otherwise prints the otuput of the pip command and returns False
"""
if _run_pip('install', '-U',
'--require-hashes', '-r',
FLAKE8_REQUIREMENTS_PATH):
return True
return False
def run_process(config, cmd): def run_process(config, cmd):
proc = Flake8Process(config, cmd) proc = Flake8Process(config, cmd)
proc.run() proc.run()
@ -142,7 +116,7 @@ def run_process(config, cmd):
def lint(paths, config, **lintargs): def lint(paths, config, **lintargs):
if not reinstall_flake8(): if not pip.reinstall_program(FLAKE8_REQUIREMENTS_PATH):
print(FLAKE8_INSTALL_ERROR) print(FLAKE8_INSTALL_ERROR)
return 1 return 1

Просмотреть файл

@ -6,13 +6,13 @@ import json
import os import os
import platform import platform
import signal import signal
import subprocess
import sys import sys
from collections import defaultdict from collections import defaultdict
from mozprocess import ProcessHandlerMixin from mozprocess import ProcessHandlerMixin
from mozlint import result from mozlint import result
from mozlint.util import pip
from mozlint.pathutils import get_ancestors_by_name from mozlint.pathutils import get_ancestors_by_name
@ -98,32 +98,6 @@ class Flake8Process(ProcessHandlerMixin):
signal.signal(signal.SIGINT, orig) signal.signal(signal.SIGINT, orig)
def _run_pip(*args):
"""
Helper function that runs pip with subprocess
"""
try:
subprocess.check_output([os.path.join(bindir, 'pip')] + list(args),
stderr=subprocess.STDOUT)
return True
except subprocess.CalledProcessError as e:
print(e.output)
return False
def reinstall_flake8():
"""
Try to install flake8 at the target version, returns True on success
otherwise prints the otuput of the pip command and returns False
"""
if _run_pip('install', '-U',
'--require-hashes', '-r',
FLAKE8_REQUIREMENTS_PATH):
return True
return False
def run_process(config, cmd): def run_process(config, cmd):
proc = Flake8Process(config, cmd) proc = Flake8Process(config, cmd)
proc.run() proc.run()
@ -135,7 +109,7 @@ def run_process(config, cmd):
def setup(root): def setup(root):
if not reinstall_flake8(): if not pip.reinstall_program(FLAKE8_REQUIREMENTS_PATH):
print(FLAKE8_INSTALL_ERROR) print(FLAKE8_INSTALL_ERROR)
return 1 return 1