Commit e5022212 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Provide nicer output when optional deps are missing

parent 21bbee26
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ Shields.io badge building module
import io
from urllib import parse

from . import errors


SHIELD_IO_ENDPOINT = 'https://img.shields.io/badge/{subject}-{status}-{colour}.svg'

@@ -29,9 +31,7 @@ def make_badge(subject: str, status: str, colour: str, out_file: io.IOBase) -> N
	try:
		import requests
	except ImportError as exc:
		raise ImportError(
			"Optional dependencies not installed: please install pylint_reporter[badges]"
		) from exc
		raise errors.OptionalImportError('badges') from exc
	url = SHIELD_IO_ENDPOINT.format(
		subject=parse.quote(subject),
		status=parse.quote(status),
+40 −0
Original line number Diff line number Diff line
#
#   Copyright 2019 Dominik Sekotill <dom.sekotill@kodo.org.uk>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

"""
Package exception classes
"""


class OptionalImportError(ImportError):
	"""
	ImportError for optional dependencies

	Only one argument should be supplied: the name of the 'extras' package that would need to 
	be installed to pull in the required dependencies.
	"""

	@property
	def extras_name(self):
		"""The first constructor argument, which should be an 'extras' name"""
		# pylint: disable=unsubscriptable-object
		return self.args[0]

	def __str__(self):
		return (
			"Optional dependencies not installed: please install "
			"pylint-reporter[{self.extras_name}]"
			.format(self=self)
		)
+6 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import argparse
import json
import sys

from . import badge, reporter
from . import badge, errors, reporter


def main(argv=None):
@@ -78,7 +78,11 @@ def main(argv=None):
	)

	args = parser.parse_args(argv or sys.argv[1:])

	try:
		args.cmd(args)
	except errors.OptionalImportError as exc:
		parser.exit(3, str(exc) + '\n')


def cmd_score(args) -> int: