Skip to content

Commit

Permalink
chore: Run ruff check .
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 15, 2024
1 parent 2a97473 commit de7067e
Show file tree
Hide file tree
Showing 32 changed files with 163 additions and 163 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
python-version: [3.8, 3.9, '3.10', '3.11', '3.12', pypy-3.10]
python-version: [3.9, '3.10', '3.11', '3.12', pypy-3.10]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
19 changes: 18 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
Changelog
=========

1.1.14 (Unreleased)
-------------------

Changed
~~~~~~~

- Some arguments must be keyword arguments:

- :meth:`ocdskit.mapping_sheet.mapping_sheet`
- :meth:`ocdskit.schema.add_validation_properties`
- :meth:`ocdskit.util.iterencode`
- :meth:`ocdskit.util.json_dump`
- :meth:`ocdskit.util.json_dumps`

- Drop support for Python 3.8.

1.1.13 (2024-05-08)
-------------------

Expand Down Expand Up @@ -45,6 +61,7 @@ Added
~~~~~

- :meth:`ocdskit.util.is_linked_release` accepts a ``maximum_properties`` argument (default 3).
- Drop support for Python 3.7.

1.1.8 (2023-06-26)
------------------
Expand Down Expand Up @@ -91,7 +108,7 @@ New CLI options:
Changed
~~~~~~~

- Drop support for Python 3.6 (end-of-life 2021-12-23).
- Drop support for Python 3.6.

Fixed
~~~~~
Expand Down
5 changes: 1 addition & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import os
import sys

Expand Down
9 changes: 3 additions & 6 deletions ocdskit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main(description='Open Contracting Data Standard CLI', modules=COMMAND_MODUL
try:
command = importlib.import_module(module).Command(subparsers)
except ImportError as e:
logger.error('exception "%s" prevented loading of %s module', e, module)
logger.error('exception "%s" prevented loading of %s module', e, module) # noqa: TRY400 # UX
else:
subcommands[command.name] = command

Expand Down Expand Up @@ -73,17 +73,14 @@ def main(description='Open Contracting Data Standard CLI', modules=COMMAND_MODUL
parser.print_help()


def _showwarning(message, category, filename, lineno, file=None, line=None):
def _showwarning(message, category, filename, lineno, file=None, line=None): # noqa: ARG001
if file is None:
file = sys.stderr
print(message, file=file)


def _raise_encoding_error(e, encoding):
if encoding and encoding.lower() == 'iso-8859-1':
suggestion = 'utf-8'
else:
suggestion = 'iso-8859-1'
suggestion = 'utf-8' if encoding and encoding.lower() == 'iso-8859-1' else 'iso-8859-1'
raise CommandError(f'encoding error: {e}\nTry `--encoding {suggestion}`?')


Expand Down
10 changes: 6 additions & 4 deletions ocdskit/combine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import Union

from ocdsextensionregistry import ProfileBuilder
from ocdsmerge import Merger
Expand Down Expand Up @@ -142,15 +143,16 @@ def combine_release_packages(packages, uri='', publisher=None, published_date=''
def merge(
data,
uri: str = '',
publisher: Union[dict, None] = None,
publisher: dict | None = None,
published_date: str = '',
version: str = DEFAULT_VERSION,
schema: Union[dict, None] = None,
schema: dict | None = None,
*,
return_versioned_release: bool = False,
return_package: bool = False,
use_linked_releases: bool = False,
streaming: bool = False,
force_version: Union[str, None] = None,
force_version: str | None = None,
ignore_version: bool = False,
convert_exceptions_to_warnings: bool = False,
):
Expand Down
8 changes: 4 additions & 4 deletions ocdskit/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def read(self, buf_size):


class BaseCommand(ABC):
kwargs = {}
kwargs = {} # noqa: RUF012

def __init__(self, subparsers):
"""
Expand All @@ -28,12 +28,12 @@ def __init__(self, subparsers):
self.add_arguments()
self.args = None

def add_base_arguments(self):
def add_base_arguments(self): # noqa: B027 # noop
"""
Adds default arguments to all commands.
"""

def add_arguments(self):
def add_arguments(self): # noqa: B027 # noop
"""
Adds arguments specific to this command.
"""
Expand Down Expand Up @@ -63,7 +63,7 @@ def items(self, **kwargs):
file = StandardInputReader(self.args.encoding)
yield from ijson.items(file, self.prefix(), multiple_values=True, **kwargs)

def print(self, data, streaming=False):
def print(self, data, *, streaming=False):
"""
Prints JSON data.
Expand Down
6 changes: 4 additions & 2 deletions ocdskit/commands/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

class Command(OCDSCommand):
name = 'compile'
help = 'reads release packages and individual releases from standard input, merges the releases by OCID, and ' \
'prints the compiled releases'
help = (
'reads release packages and individual releases from standard input, merges the releases by OCID, '
'and prints the compiled releases'
)

def add_arguments(self):
self.add_argument('--schema', help='the URL or path of the patched release schema to use')
Expand Down
2 changes: 1 addition & 1 deletion ocdskit/commands/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def indent(self, path):
json_dump(data, f, indent=self.args.indent, ensure_ascii=self.args.ascii)
f.write('\n')
except json.decoder.JSONDecodeError as e:
logger.error('%s is not valid JSON. (json.decoder.JSONDecodeError: %s)', path, e)
logger.error('%s is not valid JSON. (json.decoder.JSONDecodeError: %s)', path, e) # noqa: TRY400 # UX
2 changes: 1 addition & 1 deletion ocdskit/commands/mapping_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Command(BaseCommand):
name = 'mapping-sheet'
help = 'generates a spreadsheet with all field paths in a JSON Schema'
kwargs = {
kwargs = { # noqa: RUF012
'epilog': dedent(
"""
The --extension option must be declared after the file argument. It accepts multiple values, which can be
Expand Down
5 changes: 1 addition & 4 deletions ocdskit/commands/schema_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ def recurse(data):
recurse(item)
elif isinstance(data, dict):
if 'codelist' in data:
if 'openCodelist' in data:
open_codelist = data['openCodelist']
else:
open_codelist = 'enum' not in data
open_codelist = data.get('openCodelist', 'enum' not in data)
codelists[data['codelist']].add(open_codelist)

for key, value in data.items():
Expand Down
6 changes: 4 additions & 2 deletions ocdskit/commands/schema_strict.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

class Command(BaseCommand):
name = 'schema-strict'
help = 'adds "minItems" and "uniqueItems" if an array, "minProperties" if an object and "minLength" if a ' \
'string and "enum", "format" and "pattern" are not set'
help = (
'adds "minItems" and "uniqueItems" if an array, "minProperties" if an object and '
'"minLength" if a string and "enum", "format" and "pattern" are not set'
)

def add_arguments(self):
self.add_argument('file', help='the schema file')
Expand Down
10 changes: 2 additions & 8 deletions ocdskit/commands/set_closed_codelist_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ def handle(self):
self.collect_codelists(directory)
self.update_json_schema(directory)

codelists_not_seen = []
for codelist in self.codelists:
if codelist not in self.codelists_seen:
codelists_not_seen.append(codelist)
codelists_not_seen = [codelist for codelist in self.codelists if codelist not in self.codelists_seen]

if codelists_not_seen:
logger.error('unused codelists: %s', ' '.join(codelists_not_seen))
Expand All @@ -57,10 +54,7 @@ def collect_codelists(self, directory):
with open(os.path.join(root, name)) as f:
reader = csv.DictReader(f)
row = next(reader)
if 'Code' in row:
codes = [row['Code'] for row in itertools.chain([row], reader)]
else:
codes = []
codes = [row['Code'] for row in itertools.chain([row], reader)] if 'Code' in row else []

if codes:
if name.startswith('+'):
Expand Down
5 changes: 1 addition & 4 deletions ocdskit/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ def handle(self):
versions = self.args.versions

version_from, version_to = versions.split(':')
if version_from < version_to:
direction = 'up'
else:
direction = 'down'
direction = 'up' if version_from < version_to else 'down'

try:
upgrade_method = getattr(upgrade, f"upgrade_{versions.replace('.', '').replace(':', '_')}")
Expand Down
4 changes: 2 additions & 2 deletions ocdskit/mapping_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
INLINE_LINK_RE = re.compile(r'\[([^\]]+)\]\(([^)]+)\)')


def mapping_sheet(schema, order_by=None, infer_required=False, extension_field=None, inherit_extension=True,
def mapping_sheet(schema, *, order_by=None, infer_required=False, extension_field=None, inherit_extension=True,
include_codelist=False, include_deprecated=True, include_definitions=False, base_uri=None):
"""
Returns information about all field paths in a JSON Schema, as columns and rows.
Expand Down Expand Up @@ -112,7 +112,7 @@ def mapping_sheet(schema, order_by=None, infer_required=False, extension_field=N
try:
rows.sort(key=lambda row: row[order_by])
except KeyError as e:
raise MissingColumnError(f"the column '{order_by}' doesn't exist did you make a typo?") from e
raise MissingColumnError(f"the column '{order_by}' doesn't exist - did you make a typo?") from e

columns = ['section', 'path', 'title', 'description', 'type', 'range', 'values', 'links', 'deprecated',
'deprecationNotes']
Expand Down
21 changes: 14 additions & 7 deletions ocdskit/packager.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

import itertools
import os
import warnings
from abc import ABC, abstractmethod
from collections import defaultdict
from tempfile import NamedTemporaryFile
from typing import Union
from typing import TYPE_CHECKING

import ocdsmerge
from ocdsmerge.exceptions import InconsistentTypeError

from ocdskit.exceptions import InconsistentVersionError, MergeErrorWarning, MissingOcidKeyError
Expand All @@ -21,6 +22,9 @@
jsonlib,
)

if TYPE_CHECKING:
import ocdsmerge

try:
import sqlite3

Expand Down Expand Up @@ -54,7 +58,7 @@ class Packager:
same version of OCDS.
"""

def __init__(self, force_version: Union[str, None] = None):
def __init__(self, force_version: str | None = None):
"""
:param force_version: version to use instead of the version of the first release package or individual release
"""
Expand All @@ -72,7 +76,7 @@ def __enter__(self):
def __exit__(self, type_, value, traceback):
self.backend.close()

def add(self, data, ignore_version: bool = False):
def add(self, data, *, ignore_version: bool = False):
"""
Adds release packages and/or individual releases to be merged.
Expand Down Expand Up @@ -116,6 +120,7 @@ def add(self, data, ignore_version: bool = False):
def output_package(
self,
merger: ocdsmerge.merge.Merger,
*,
return_versioned_release: bool = False,
use_linked_releases: bool = False,
streaming: bool = False,
Expand All @@ -137,7 +142,7 @@ def output_package(
convert_exceptions_to_warnings=convert_exceptions_to_warnings,
)

# If a user wants to stream data but cant exhaust records right away, we can add an `autoclose=True` argument.
# If a user wants to stream data but can't exhaust records right away, we can add an `autoclose=True` argument.
# If set to `False`, `__exit__` will do nothing, and the user will need to call `packager.backend.close()`.
if not streaming:
records = list(records)
Expand All @@ -153,6 +158,7 @@ def output_package(
def output_records(
self,
merger: ocdsmerge.merge.Merger,
*,
return_versioned_release: bool = False,
use_linked_releases: bool = False,
convert_exceptions_to_warnings: bool = False,
Expand Down Expand Up @@ -204,6 +210,7 @@ def output_records(
def output_releases(
self,
merger: ocdsmerge.merge.Merger,
*,
return_versioned_release: bool = False,
convert_exceptions_to_warnings: bool = False,
):
Expand Down Expand Up @@ -263,12 +270,12 @@ def get_releases_by_ocid(self):
OCIDs are yielded in alphabetical order. The iterable is in any order.
"""

def flush(self):
def flush(self): # noqa: B027 # noop
"""
Flushes the internal buffer of releases. This may be a no-op on some backends.
"""

def close(self):
def close(self): # noqa: B027 # noop
"""
Tidies up any resources used by the backend. This may be a no-op on some backends.
"""
Expand Down
Loading

0 comments on commit de7067e

Please sign in to comment.