Skip to content

Commit

Permalink
chore: Update ruff lint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 16, 2024
1 parent 7df4a57 commit 6886c8f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
4 changes: 1 addition & 3 deletions extension_explorer/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
47 changes: 15 additions & 32 deletions extension_explorer/util.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -29,9 +27,7 @@


def markdown(md):
"""
Renders Markdown text as HTML.
"""
"""Render Markdown text as HTML."""
parser = MarkdownIt('default')
env = {}

Expand All @@ -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'):
Expand All @@ -59,19 +57,15 @@ 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:
return json.load(f)


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)

Expand Down Expand Up @@ -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']

Expand All @@ -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 = []
Expand Down Expand Up @@ -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'):
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))


Expand Down
18 changes: 17 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6886c8f

Please sign in to comment.