Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff format #224

Merged
merged 3 commits into from
Oct 3, 2024
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
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file contains hashes of commits git blame should ignore.
# Run `git config blame.ignoreRevsFile .git-blame-ignore-revs` to enable.
# Requires git 2.23+.

# 2024-10-03 Applied ruff format to all python code
98477463d23e270c276097edde9eb41a8f944ca2
9 changes: 9 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ on:
branches:
- main
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python-and-dependencies
with:
python-version: "3.11"
- run: poetry run ruff format --check

lint:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 0 additions & 1 deletion abis_mapping/base/loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Dynamically loads template mappers"""


# Standard
import importlib
import pathlib
Expand Down
11 changes: 5 additions & 6 deletions abis_mapping/base/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def generate_blank_template(cls) -> None:
# Get raw schema
fields: list[dict] = json.loads(schema_file.read_text())["fields"]
out_path = directory / f"{cls.metadata()['name']}.{cls.metadata()['file_type'].lower()}"
with out_path.open('w') as f:
with out_path.open("w") as f:
csv_writer = csv.DictWriter(f, [field["name"] for field in fields])
csv_writer.writeheader()

Expand Down Expand Up @@ -172,7 +172,7 @@ def add_extra_fields_json(
@classmethod
def extract_extra_fields(
cls,
row: frictionless.Row
row: frictionless.Row,
) -> dict[str, Any]:
"""Extracts extra values from a row not in template schema.

Expand All @@ -193,7 +193,7 @@ def extract_extra_fields(
def extra_fields_schema(
cls,
data: frictionless.Row | base_types.ReadableType,
full_schema: bool = False
full_schema: bool = False,
) -> frictionless.Schema:
"""Creates a schema with all extra fields found in data.

Expand Down Expand Up @@ -234,14 +234,13 @@ def extra_fields_schema(
# Find list of extra fieldnames
existing_fieldnames = existing_schema.field_names
if len(actual_fieldnames) > len(existing_fieldnames):
extra_fieldnames = actual_fieldnames[len(existing_fieldnames):]
extra_fieldnames = actual_fieldnames[len(existing_fieldnames) :]
else:
extra_fieldnames = []

# Construct list of extra Fields with type of string
extra_fields = [
frictionless.Field.from_descriptor({"name": fieldname, "type": "string"})
for fieldname in extra_fieldnames
frictionless.Field.from_descriptor({"name": fieldname, "type": "string"}) for fieldname in extra_fieldnames
]

if full_schema:
Expand Down
1 change: 0 additions & 1 deletion abis_mapping/base/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides Base Types for the Package"""


# Typing
from os import PathLike
from typing import IO, Union
Expand Down
3 changes: 1 addition & 2 deletions abis_mapping/plugins/chronological.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless date and time validation checks for the package"""


# Third-party
import frictionless
import frictionless.errors
Expand Down Expand Up @@ -44,5 +43,5 @@ def validate_row(self, row: frictionless.Row) -> Iterator[frictionless.Error]:
if not all(x <= y for x, y in zip(tstmps[:-1], tstmps[1:], strict=True)):
yield frictionless.errors.RowConstraintError.from_row(
row=row,
note=f"the following dates are not in chronological order: {self.field_names}; with values: {tstmps}"
note=f"the following dates are not in chronological order: {self.field_names}; with values: {tstmps}",
)
1 change: 0 additions & 1 deletion abis_mapping/plugins/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless coordinate validation checks for the package"""


# Third-Party
import frictionless
import frictionless.errors
Expand Down
3 changes: 1 addition & 2 deletions abis_mapping/plugins/default_lookup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless default lookup checks for the package."""


# Third-party
import attrs
import frictionless
Expand Down Expand Up @@ -49,5 +48,5 @@ def validate_row(self, row: frictionless.Row) -> Iterator[frictionless.Error]:
note=(
f"'{self.key_field}': '{row[self.key_field]}' has no default value "
f"for field '{self.value_field}' and no other value provided."
)
),
)
1 change: 0 additions & 1 deletion abis_mapping/plugins/empty.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless empty data checks for the package"""


# Third-Party
import frictionless
import frictionless.errors
Expand Down
17 changes: 4 additions & 13 deletions abis_mapping/plugins/list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides custom frictionless list plugin for the package"""


# Third-Party
import frictionless
import frictionless.fields
Expand Down Expand Up @@ -62,15 +61,9 @@ def value_reader(cell: Any) -> Optional[list[str]]:
return None

# Create StringField instance
string_field = frictionless.fields.StringField(
name="delegatedParser",
format=self.format
)
string_field = frictionless.fields.StringField(name="delegatedParser", format=self.format)
# Split, Strip, Filter and Delegate Cell Parsing to the String Type
cell = [
string_field.read_cell(c.strip())[0]
for c in cell.split(self.delimiter) if c
]
cell = [string_field.read_cell(c.strip())[0] for c in cell.split(self.delimiter) if c]

# Check for Cell Parsing Failures
if not all(cell):
Expand All @@ -85,6 +78,7 @@ def value_reader(cell: Any) -> Optional[list[str]]:

def create_value_writer(self) -> frictionless.schema.types.IValueWriter:
"""Creates value writer callable."""

def value_writer(cell: list[str]) -> str:
"""Convert cell (write direction).

Expand All @@ -101,10 +95,7 @@ def value_writer(cell: list[str]) -> str:
)

# Join and Delegate Cell Serialization to the String Type
return self.delimiter.join(
string_field.write_cell(c)[0]
for c in cell
)
return self.delimiter.join(string_field.write_cell(c)[0] for c in cell)

# Return writer callable
return value_writer
Expand Down
1 change: 0 additions & 1 deletion abis_mapping/plugins/logical_or.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless logical OR checks for the package"""


# Third-Party
import frictionless
import frictionless.errors
Expand Down
1 change: 0 additions & 1 deletion abis_mapping/plugins/mutual_exclusion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless mutual exclusion checks for the package"""


# Third-Party
import frictionless
import frictionless.errors
Expand Down
1 change: 0 additions & 1 deletion abis_mapping/plugins/mutual_inclusion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless mutual inclusion checks for the package"""


# Third-Party
import frictionless
import frictionless.errors
Expand Down
12 changes: 2 additions & 10 deletions abis_mapping/plugins/sites_geometry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless geometry sites' data template checks for the package."""


# Third-party
import frictionless
import frictionless.errors
Expand Down Expand Up @@ -38,11 +37,7 @@ def validate_row(self, row: frictionless.Row) -> Iterator[frictionless.Error]:
site_id = row["siteID"] in self.occurrence_site_ids

# Perform check
if (
(lat and long and datum) or
(wkt and datum) or
site_id
):
if (lat and long and datum) or (wkt and datum) or site_id:
return

# Create error note
Expand All @@ -58,7 +53,4 @@ def validate_row(self, row: frictionless.Row) -> Iterator[frictionless.Error]:
note += "incorrect combination of geometry fields provided."

# Yield error
yield frictionless.errors.RowConstraintError.from_row(
row=row,
note=note
)
yield frictionless.errors.RowConstraintError.from_row(row=row, note=note)
1 change: 0 additions & 1 deletion abis_mapping/plugins/tabular.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides extra frictionless tabular checks for the package"""


# Third-Party
import frictionless
import frictionless.errors
Expand Down
4 changes: 2 additions & 2 deletions abis_mapping/plugins/timestamp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides custom frictionless timestamp plugin for the package"""


# Third-Party
import attrs
import frictionless
Expand Down Expand Up @@ -49,7 +48,7 @@ class TimestampField(frictionless.Field):
"required",
"minimum",
"maximum",
"enum"
"enum",
]

def create_value_reader(self) -> frictionless.schema.types.IValueReader:
Expand Down Expand Up @@ -87,6 +86,7 @@ def value_reader(cell: Any) -> temporal.Timestamp | None:

def create_value_writer(self) -> frictionless.schema.types.IValueWriter:
"""Creates value writer callable."""

def value_writer(cell: temporal.Timestamp) -> str:
"""Convert cell (write direction)

Expand Down
2 changes: 1 addition & 1 deletion abis_mapping/plugins/wkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WKTPlugin(frictionless.Plugin):

def select_field_class(
self,
type: Optional[str] = None # noqa: A002
type: Optional[str] = None, # noqa: A002
) -> Optional[Type[frictionless.Field]]:
"""Return the custom field class for the plugin.

Expand Down
7 changes: 4 additions & 3 deletions abis_mapping/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

class Settings(pydantic_settings.BaseSettings):
"""Model for defining default project-wide settings."""

# Default precision for rounding WKT coordinates when serializing.
DEFAULT_WKT_ROUNDING_PRECISION: int = 8

# Default CRS to transform all input geometry to.
DEFAULT_TARGET_CRS: str = 'GDA2020'
DEFAULT_TARGET_CRS: str = "GDA2020"

# Base url for the instructions site
INSTRUCTIONS_BASE_URL: str = 'https://gaiaresources.github.io/abis-mapping/'
INSTRUCTIONS_BASE_URL: str = "https://gaiaresources.github.io/abis-mapping/"

# The version of the documents to be selected
INSTRUCTIONS_VERSION: str = 'dev'
INSTRUCTIONS_VERSION: str = "dev"

# Version parts
MAJOR_VERSION: int = int(importlib.metadata.version("abis-mapping").split(".", 1)[0])
Expand Down
Loading