Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
language: python

python:
- 3.5
- 3.8

- '3.8'
env:
- TOXENV=django22
- TOXENV=quality
- TOXENV=docs

- TOXENV=django22
- TOXENV=django30
- TOXENV=django31
cache:
- pip

Expand All @@ -35,7 +34,7 @@ deploy:
distributions: sdist bdist_wheel
on:
tags: true
python: 3.5
condition: '$TOXENV = quality'
python: 3.8
condition: $TOXENV = quality
password:
secure: Q+rwwfNHu5nHSowWdT2K0pDr7pwccsFlTHvwXMUaSK7D7tXRYju9fHWGA3zVHJzYxD8V2UvSYapAdQldkwws5jcspZsDK8wyGS8W66lQ/W/5SnEo/u4+G4OAcSJAb7WIv1K9qI15xqQ+o25sh3kZa+8DSX9Aot+jLkm1vuxv8Togj8MGmdxhBnajlonfaTuK6asAkqvKbJqStcMgv10Vy3Yq2vqYLAqgS4aVpruLLb7F+BA0gY/FGgZNXTtFH/X6EX8L7IZIocp3eQylFq9yeQlGS9nIkTagYbBZcmN0khgJoqRksfuTDsleEsJ8kEKnOo56HjuNByljN/Fh5jpQDb7j2IqocwwarKGz7rDdEH28KN/r/GgUIDquuMLxNvqGTjpLeTjAYlHM1GRbOYlqgCMbWpl7/lcawHkSvkYW47gHl6YqmtI4KX/Nm+/SAWZvxjG0sDY5vUtqmLzH7L6FmAMn0C46H5o+MJ9ChdjRnRDU7BJFrXhKerKOwT1jdk7Dj99Uf39mSkLVsE3RC7+8xDCbBY3+qxmD0XsD6uX4CFfmOQrJEoeDlLbTIkQg8vFetEBedRaBrVbBztnWG9wgAWQYA0oxo+s/67BOTd/UkQrReNTwTaMIwuTaibDEl0OEa7jBtkBAbUKJWg+6Ih0HT0J67dULrswPoZ1V8UHVMsQ=
46 changes: 23 additions & 23 deletions code_annotations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from code_annotations.helpers import VerboseEcho


class AnnotationConfig(object):
class AnnotationConfig:
"""
Configuration shared among all Code Annotations commands.
"""
Expand Down Expand Up @@ -51,10 +51,10 @@ def __init__(self, config_file_path, report_path_override=None, verbosity=1, sou
self.echo.set_verbosity(verbosity)

self.report_path = report_path_override if report_path_override else raw_config['report_path']
self.echo("Configured for report path: {}".format(self.report_path))
self.echo(f"Configured for report path: {self.report_path}")

self.source_path = source_path_override if source_path_override else raw_config['source_path']
self.echo("Configured for source path: {}".format(self.source_path))
self.echo(f"Configured for source path: {self.source_path}")

self._configure_coverage(raw_config.get('coverage_target', None))
self.report_template_dir = raw_config.get('report_template_dir')
Expand Down Expand Up @@ -125,7 +125,7 @@ def _is_annotation_token(self, token_or_group):

def _add_annotation_token(self, token):
if token in self.annotation_tokens:
raise ConfigurationException('{} is configured more than once, tokens must be unique.'.format(token))
raise ConfigurationException(f'{token} is configured more than once, tokens must be unique.')
self.annotation_tokens.append(token)

def _configure_coverage(self, coverage_target):
Expand All @@ -141,14 +141,14 @@ def _configure_coverage(self, coverage_target):
if coverage_target:
try:
self.coverage_target = float(coverage_target)
except (TypeError, ValueError):
except (TypeError, ValueError) as error:
raise ConfigurationException(
'Coverage target must be a number between 0 and 100 not "{}".'.format(coverage_target)
)
f'Coverage target must be a number between 0 and 100 not "{coverage_target}".'
) from error

if self.coverage_target < 0.0 or self.coverage_target > 100.0:
raise ConfigurationException(
'Invalid coverage target. {} is not between 0 and 100.'.format(self.coverage_target)
f'Invalid coverage target. {self.coverage_target} is not between 0 and 100.'
)
else:
self.coverage_target = None
Expand All @@ -167,7 +167,7 @@ def _configure_group(self, group_name, group):
self.groups[group_name] = []

if not group or len(group) == 1:
raise ConfigurationException('Group "{}" must have more than one annotation.'.format(group_name))
raise ConfigurationException(f'Group "{group_name}" must have more than one annotation.')

for annotation in group:
for annotation_token in annotation:
Expand All @@ -179,7 +179,7 @@ def _configure_group(self, group_name, group):

# Otherwise it should be a text type, if not then error out
elif not self._is_annotation_token(annotation_value):
raise ConfigurationException('{} is an unknown annotation type.'.format(annotation))
raise ConfigurationException(f'{annotation} is an unknown annotation type.')

self.groups[group_name].append(annotation_token)
self._add_annotation_token(annotation_token)
Expand Down Expand Up @@ -219,15 +219,15 @@ def _configure_annotations(self, raw_config):

elif not self._is_annotation_token(annotation): # pragma: no cover
raise TypeError(
'{} is an unknown type, must be strings or lists.'.format(annotation_token_or_group_name)
f'{annotation_token_or_group_name} is an unknown type, must be strings or lists.'
)
else:
self._add_annotation_token(annotation_token_or_group_name)
self.annotation_regexes.append(re.escape(annotation_token_or_group_name))

self.echo.echo_v("Groups configured: {}".format(self.groups))
self.echo.echo_v("Choices configured: {}".format(self.choices))
self.echo.echo_v("Annotation tokens configured: {}".format(self.annotation_tokens))
self.echo.echo_v(f"Groups configured: {self.groups}")
self.echo.echo_v(f"Choices configured: {self.choices}")
self.echo.echo_v(f"Annotation tokens configured: {self.annotation_tokens}")

def _plugin_load_failed_handler(self, *args, **kwargs):
"""
Expand Down Expand Up @@ -281,7 +281,7 @@ def _configure_extensions(self):
))


class BaseSearch(object, metaclass=ABCMeta):
class BaseSearch(metaclass=ABCMeta):
"""
Base class for searchers.
"""
Expand Down Expand Up @@ -365,7 +365,7 @@ def _check_results_choices(self, annotation):
)
)
elif choice in found_valid_choices:
self._add_annotation_error(annotation, '"{}" is already present in this annotation.'.format(choice))
self._add_annotation_error(annotation, f'"{choice}" is already present in this annotation.')
else:
found_valid_choices.append(choice)
else:
Expand Down Expand Up @@ -446,7 +446,7 @@ def check_results(self, all_results):
elif token in found_group_members:
self._add_annotation_error(
annotation,
'"{}" is already in the group that starts with "{}"'.format(token, current_group)
f'"{token}" is already in the group that starts with "{current_group}"'
)
current_group = None
found_group_members = []
Expand All @@ -465,7 +465,7 @@ def check_results(self, all_results):
# If we get here there is a problem with check_results' group_children not matching up with
# our config's groups. That puts us in an unknown state, so we should quit.
raise Exception(
'group_children is out of sync with config.groups. {} is not in a group!'.format(token)
f'group_children is out of sync with config.groups. {token} is not in a group!'
)

found_group_members = [token]
Expand All @@ -480,7 +480,7 @@ def check_results(self, all_results):
found_group_members = []

if current_group:
self.errors.append('File("{}") finished with an incomplete group {}!'.format(filename, current_group))
self.errors.append(f'File("{filename}") finished with an incomplete group {current_group}!')

return not self.errors

Expand Down Expand Up @@ -531,15 +531,15 @@ def _format_results_for_report(self, all_results):
current_group_id = 0

for filename in all_results:
self.echo.echo_vv("report_format: formatting {}".format(filename))
self.echo.echo_vv(f"report_format: formatting {filename}")
formatted_results[filename] = []
current_group = None

found_group_members = []

for annotation in all_results[filename]:
token = annotation['annotation_token']
self.echo.echo_vvv("report_format: formatting annotation token {}".format(token))
self.echo.echo_vvv(f"report_format: formatting annotation token {token}")

if current_group:
if token not in self.config.groups[current_group]:
Expand Down Expand Up @@ -572,7 +572,7 @@ def _format_results_for_report(self, all_results):
current_group_id, current_group, token, annotation['line_number'])
)
else:
self.echo.echo_vv('Adding single token {}.'.format(token))
self.echo.echo_vv(f'Adding single token {token}.')
formatted_results[filename].append(annotation)

# If we have all members, this group is done
Expand Down Expand Up @@ -603,7 +603,7 @@ def report(self, all_results, report_prefix=''):

formatted_results = self._format_results_for_report(all_results)

self.echo("Generating report to {}".format(report_filename))
self.echo(f"Generating report to {report_filename}")

try:
os.makedirs(self.config.report_path)
Expand Down
8 changes: 4 additions & 4 deletions code_annotations/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ def static_find_annotations(config_file, source_path, report_path, verbosity, li
if report:
click.echo("Writing report...")
report_filename = searcher.report(all_results)
click.echo("Report written to {}.".format(report_filename))
click.echo(f"Report written to {report_filename}.")

elapsed = datetime.datetime.now() - start_time
annotation_count = 0

for filename in all_results:
annotation_count += len(all_results[filename])

click.echo("Search found {} annotations in {}.".format(annotation_count, elapsed))
click.echo(f"Search found {annotation_count} annotations in {elapsed}.")

except Exception as exc: # pylint: disable=broad-except
click.echo(traceback.print_exc())
Expand Down Expand Up @@ -203,15 +203,15 @@ def generate_docs(
'rendered_report_source_link_prefix'
):
if not getattr(config, key):
raise ConfigurationException("No {key} key in {config_file}".format(key=key, config_file=config_file))
raise ConfigurationException(f"No {key} key in {config_file}")

config.echo("Rendering the following reports: \n{}".format("\n".join([r.name for r in report_files])))

renderer = ReportRenderer(config, report_files)
renderer.render()

elapsed = datetime.datetime.now() - start_time
click.echo("Report rendered in {} seconds.".format(elapsed.total_seconds()))
click.echo(f"Report rendered in {elapsed.total_seconds()} seconds.")
except Exception as exc: # pylint: disable=broad-except
click.echo(traceback.print_exc())
fail(str(exc))
2 changes: 1 addition & 1 deletion code_annotations/contrib/sphinx/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ def quote_value(value):
except ValueError:
pass
if isinstance(value, str):
return '"{}"'.format(value)
return f'"{value}"'
return str(value)
3 changes: 1 addition & 2 deletions code_annotations/contrib/sphinx/extensions/featuretoggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os

import pkg_resources

from docutils import nodes
from sphinx.util.docutils import SphinxDirective

Expand Down Expand Up @@ -76,7 +75,7 @@ def iter_nodes(self):
toggle_default_value = toggle.get(".. toggle_default:", "Not defined")
toggle_default_node = nodes.literal(text=quote_value(toggle_default_value))
toggle_section = nodes.section(
"", ids=["featuretoggle-{}".format(toggle_name)]
"", ids=[f"featuretoggle-{toggle_name}"]
)
toggle_section += nodes.title(text=toggle_name)
toggle_section += nodes.paragraph("", "Default: ", toggle_default_node)
Expand Down
3 changes: 1 addition & 2 deletions code_annotations/contrib/sphinx/extensions/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os

import pkg_resources

from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.util.docutils import SphinxDirective
Expand Down Expand Up @@ -85,7 +84,7 @@ def iter_nodes(self):
setting_default_node = nodes.literal(
text=quote_value(setting_default_value)
)
setting_section = nodes.section("", ids=["setting-{}".format(setting_name)])
setting_section = nodes.section("", ids=[f"setting-{setting_name}"])
setting_section += nodes.title(text=setting_name)
setting_section += nodes.paragraph("", "Default: ", setting_default_node)
setting_section += nodes.paragraph(
Expand Down
11 changes: 5 additions & 6 deletions code_annotations/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from code_annotations.helpers import clean_abs_path, clean_annotation, get_annotation_regex


class AnnotationExtension(object, metaclass=ABCMeta):
class AnnotationExtension(metaclass=ABCMeta):
"""
Abstract base class that annotation extensions will inherit from.
"""
Expand Down Expand Up @@ -72,12 +72,11 @@ def __init__(self, config, echo):
config: The configuration dict
echo: VerboseEcho object for logging
"""
super(SimpleRegexAnnotationExtension, self).__init__(config, echo)
super().__init__(config, echo)

if self.lang_comment_definition is None: # pragma: no cover
raise ValueError('Subclasses of SimpleRegexAnnotationExtension must define lang_comment_definition!')

# pylint: disable=not-a-mapping
self.comment_regex = re.compile(
self.comment_regex_fmt.format(**self.lang_comment_definition),
flags=re.VERBOSE
Expand All @@ -92,7 +91,7 @@ def __init__(self, config, echo):
# annotation.
self.query = get_annotation_regex(self.config.annotation_regexes)

self.ECHO.echo_v("{} extension regex query: {}".format(self.extension_name, self.query.pattern))
self.ECHO.echo_v(f"{self.extension_name} extension regex query: {self.query.pattern}")

def search(self, file_handle):
"""
Expand Down Expand Up @@ -124,13 +123,13 @@ def search(self, file_handle):
try:
annotation_token = inner_match.group('token')
annotation_data = inner_match.group('data')
except IndexError:
except IndexError as error:
# pragma: no cover
raise ValueError('{}::{}: Could not find "data" or "token" groups. Found: {}'.format(
fname,
line,
inner_match.groupdict()
))
)) from error
annotation_token, annotation_data = clean_annotation(annotation_token, annotation_data)
found_annotations.append({
'found_by': self.extension_name,
Expand Down
Loading