From 6886c8f4e686cf2fd23ddf415560bbedd5249ff1 Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:19:40 -0400 Subject: [PATCH] chore: Update ruff lint configuration --- extension_explorer/extract.py | 4 +-- extension_explorer/util.py | 47 +++++++++++------------------------ pyproject.toml | 18 +++++++++++++- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/extension_explorer/extract.py b/extension_explorer/extract.py index d720a4958..b1e6eb0c1 100644 --- a/extension_explorer/extract.py +++ b/extension_explorer/extract.py @@ -2,9 +2,7 @@ def extract_tag(fileobj, keywords, comment_tags, options): - """ - Yields the title values in the YAML file. - """ + """Yield the title values in the YAML file.""" data = safe_load(fileobj) for prefix, tags in data.items(): for i, tag in enumerate(tags): diff --git a/extension_explorer/util.py b/extension_explorer/util.py index 372759d3b..21e298c99 100644 --- a/extension_explorer/util.py +++ b/extension_explorer/util.py @@ -1,6 +1,4 @@ -""" -Module to keep ``views.py`` simple and high-level. -""" +"""Module to keep ``views.py`` simple and high-level.""" import contextlib import json import os @@ -29,9 +27,7 @@ def markdown(md): - """ - Renders Markdown text as HTML. - """ + """Render Markdown text as HTML.""" parser = MarkdownIt('default') env = {} @@ -49,7 +45,9 @@ def markdown(md): def get_extension_explorer_data_filename(): """ - Returns the data file's path. Set it with the ``EXTENSION_EXPLORER_DATA_FILENAME`` environment variable (default: + Return the data file's path. + + Set it with the ``EXTENSION_EXPLORER_DATA_FILENAME`` environment variable (default: ``extension_explorer/data/extensions.json``). """ if os.getenv('EXTENSION_EXPLORER_DATA_FILENAME'): @@ -59,9 +57,7 @@ def get_extension_explorer_data_filename(): @lru_cache def get_extensions(filename=None): - """ - Returns the data file's parsed contents. - """ + """Return the data file's parsed contents.""" if not filename: filename = get_extension_explorer_data_filename() with open(filename) as f: @@ -69,9 +65,7 @@ def get_extensions(filename=None): def set_tags(extensions): - """ - Adds tags and publishers to extensions, and returns profile, topic and publisher tags. - """ + """Add tags and publishers to extensions, and return profile, topic and publisher tags.""" with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'tags.yaml')) as f: data = safe_load(f) @@ -106,9 +100,7 @@ def set_tags(extensions): def get_present_and_historical_versions(extension): - """ - Returns the present and historical versions, with release dates, in reverse chronological order. - """ + """Return the present and historical versions, with release dates, in reverse chronological order.""" latest_version = extension['latest_version'] versions = extension['versions'] @@ -125,9 +117,7 @@ def get_present_and_historical_versions(extension): def identify_headings(html): - """ - Adds `id` attributes to headings in the HTML, skipping any changelog sub-headings. Returns HTML and headings. - """ + """Add `id` attributes to headings in the HTML, skipping any changelog sub-headings. Return HTML and headings.""" root = lxml.html.fromstring(html) headings = [] @@ -160,9 +150,7 @@ def identify_headings(html): def highlight_json(html): - """ - Highlights JSON code blocks. Returns the HTML, and the CSS for highlighting. - """ + """Highlight JSON code blocks. Return the HTML, and the CSS for highlighting.""" root = lxml.html.fromstring(html) for code_block in root.find_class('language-json'): @@ -177,7 +165,7 @@ def highlight_json(html): def get_codelist_tables(extension_version, lang): """ - Returns a list of tables, one per codelist. Each item is a list of the codelist's name, basename, documentation URL + Return a list of tables, one per codelist. Each item is a list of the codelist's name, basename, documentation URL (if patched), translated fieldnames, and and translated rows. Each row is a dictionary with up to three keys: "code", "title" and "content". The "content" value is a dictionary with "description" and "attributes" keys. The "description" value is the Description column value rendered from Markdown. The "attributes" value is a dictionary @@ -241,7 +229,7 @@ def get_codelist_tables(extension_version, lang): def get_removed_fields(extension_version, lang): """ - Returns a dictionary of deprecation status and field tables. Each table is a list of fields. Each field is a + Return a dictionary of deprecation status and field tables. Each table is a list of fields. Each field is a dictionary with "definition_path", "path" and "url" (if available) keys. All values are translated. """ tables = defaultdict(list) @@ -266,7 +254,7 @@ def get_removed_fields(extension_version, lang): def get_schema_tables(extension_version, lang): """ - Returns a dictionary of definition names and field tables. Each table is a list of fields. Each field is a + Return a dictionary of definition names and field tables. Each table is a list of fields. Each field is a dictionary with "definition_path", "path", "schema", "multilingual", "title", "description", "types" and "source" (if available) keys. All values are translated. @@ -308,10 +296,7 @@ def get_schema_tables(extension_version, lang): def _get_types(value, sources, extension_version, lang, n=1, field=None): - """ - Returns the types of the field, linking to definitions and iterating into arrays. - """ - + """Return the types of the field, linking to definitions and iterating into arrays.""" if '$ref' in value: name = value['$ref'][14:] # remove '#/definitions/' url = sources[name]['url'] if name in sources else f'#{name.lower()}' # local definition @@ -422,9 +407,7 @@ def _codelist_url(basename, extension_version, lang): @lru_cache def _ocds_codelist_names(): - """ - Returns the names of the codelists in the OCDS release schema. - """ + """Return the names of the codelists in the OCDS release schema.""" return _ocds_codelist_names_recursive(_ocds_release_schema('en')) diff --git a/pyproject.toml b/pyproject.toml index cb59b690e..1f8161028 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,23 @@ line-length = 119 target-version = "py310" [tool.ruff.lint] -select = ["E", "C4", "F", "I", "W"] +select = ["ALL"] +ignore = [ + "ANN", "C901", "COM812", "D203", "D212", "D415", "EM", "ISC001", "PERF203", "PLR091", "Q000", + "D1", "D205", + "PTH", + "FIX002", # todo +] + +[tool.ruff.lint.flake8-unused-arguments] +ignore-variadic-names = true + +[tool.ruff.lint.per-file-ignores] +"tests/*" = [ + "ARG001", "D", "FBT003", "INP001", "PLR2004", "S", "TRY003", +] +"*/extract.py" = ["ARG001"] # babel +"*/views.py" = ["ARG001"] # flask [[tool.babel.mappings]] method = "python"