Skip to content
Open
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
5 changes: 1 addition & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-test.txt
- name: Lint
# FIXME
continue-on-error: true
run: |
flake8 lib/pyld tests --count --show-source --statistics
run: make lint
test:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@ test:
pytest

upgrade-submodules:
git submodule update --remote --init --recursive
git submodule update --remote --init --recursive

# At this stage, we are limiting our formatting efforts to one file. We need to ensure that:
# * our formatting rules are sane,
# * we are not introducing conflicts with currently open PRs,
# * and the PR introducing `ruff` is not too large.
RUFF_TARGET = lib/pyld/context_resolver.py

lint:
ruff check $(RUFF_TARGET)

fmt:
ruff check --fix $(RUFF_TARGET)
ruff format $(RUFF_TARGET)
10 changes: 6 additions & 4 deletions lib/pyld/context_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"""

from frozendict import frozendict

from c14n.Canonicalize import canonicalize
from pyld import jsonld, iri_resolver
from pyld import iri_resolver, jsonld

from .resolved_context import ResolvedContext

MAX_CONTEXT_URLS = 10
Expand Down Expand Up @@ -42,7 +44,7 @@ def resolve(self, active_ctx, context, base, cycles=None):
cycles = set()

# process `@context`
if (isinstance(context, dict) or isinstance(context, frozendict)) and '@context' in context:
if isinstance(context, (dict, frozendict)) and '@context' in context:
context = context['@context']

# context is one or more contexts
Expand Down Expand Up @@ -154,7 +156,7 @@ def _fetch_context(self, active_ctx, url, cycles):
'provided for a remote context.',
'jsonld.InvalidUrl',
{'url': url, 'cause': cause},
code='loading remote context failed')
code='loading remote context failed') from cause

# ensure ctx is an object
if not isinstance(context, dict) and not isinstance(context, frozendict):
Expand Down Expand Up @@ -201,7 +203,7 @@ def _resolve_context_urls(self, context, base):
for num, element in enumerate(ctx):
if isinstance(element, str):
ctx[num] = iri_resolver.resolve(element, base)
elif isinstance(element, dict) or isinstance(element, frozendict):
elif isinstance(element, (dict, frozendict)):
self. _resolve_context_urls({'@context': element}, base)
return

Expand Down
57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[tool.ruff]
# Target Python version
target-version = "py310"

# Line length (matching rdflib's flake8 config)
line-length = 88

# Include and exclude patterns
include = ["*.py"]
exclude = [
".git",
"__pycache__",
".venv",
"venv",
"build",
"dist",
"*.egg-info",
]

[tool.ruff.lint]
# Enable common rule sets
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort (import sorting)
"N", # pep8-naming
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
]

# Ignore specific rules if needed
ignore = [
"E501", # line too long (handled by formatter, matches rdflib's flake8)
"F821", # undefined name (matches rdflib's flake8 W806 ignore)
"Q000", # quote style (preserved by formatter)
"Q001", # quote style (preserved by formatter)
"Q002", # quote style (preserved by formatter)
"Q003", # quote style (preserved by formatter)
]

[tool.ruff.format]
# Preserve existing quote styles (don't enforce single or double quotes)
quote-style = "preserve"
# Indent with spaces
indent-style = "space"
# Use 4 spaces for indentation
skip-magic-trailing-comma = false
# Line ending style
line-ending = "auto"

[tool.ruff.lint.isort]
# Import sorting configuration
known-first-party = ["pyld", "c14n"]

4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flake8
pytest
ruff
pytest