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
Comment on lines +12 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This contemporary commentary isn't needed. Looks more like PRs comments than code ones.
  • Needs to point at everything (as before) before merging, at least for the check part.
  • I assume checks can't be too bad, since it was passing flake8 before. If it is, maybe tune/comment the config temporarily until more involved changes can be addressed?

Copy link
Collaborator

@mielvds mielvds Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with these points. I guess Anatoly added this commentary for our reviewing convenience, but it should go before merging. Let's also add the other files as well (after rebase!) and discuss the formatting as a whole.

For the last point though: could we turn this around and see how involved the changes actually are? It might be unnecessary to do this incrementally, which will save us some time.


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this, it's correctly handled in #224.

Copy link
Collaborator

@mielvds mielvds Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rebase this on master (#224 has been merged)?


# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume a reformat with this would be a massive style only change. Might be good to leave at flake8 settings until it's desired (if ever) to reformat everything as one single pass.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anatoly-scherbakov This is a good point. Opposed to what I wrote earlier, I suggest we put this line in comments (with a TODO note to switch when ready) and set it to 79 for now.


# 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