Commit 22d95912 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Avoid editable install for non-setuptools projects

Adds new options --editable/--non-editable for users to enable/disable
editable installs which are only supported by projects using
setuptools.

The option defaults to --editable if setup.py is found,
else --non-editable.
parent 76e79e46
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ Run pylint from pre-commit with project dependencies installed

import subprocess
import sys
from os.path import isfile

import click
from pylint import lint
@@ -31,14 +32,20 @@ __version__ = '0.3'
	If the score is below the given threshold a non-zero exit code will be returned
	""",
)
@click.option(
	'--editable/--non-editable',
	default=isfile('setup.py'),
	help="Use the editable install (develop) feature provided by setuptools",
)
@click.argument('files', nargs=-1)
def main(extras, fail_under, files):
def main(extras, fail_under, editable, files):
	"""Invoke Pylint on the given files after ensuring dependencies are up to date"""
	join = ','.join
	cmd = [
		'pip', 'install', '--upgrade', '--editable',
		f'.[{join(extras)}]' if extras else '.',
	]
	cmd = ['pip', 'install', '--upgrade']
	if editable:
		# If this looks like a setuptools project, we can install editable
		cmd.append('--editable')
	cmd.append(f'.[{join(extras)}]' if extras else '.')

	proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
	if proc.returncode: