-
Notifications
You must be signed in to change notification settings - Fork 136
Try out ruff
#227
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
base: master
Are you sure you want to change the base?
Try out ruff
#227
Changes from all commits
60260e0
d042697
ae7911e
82c9138
a8dd36f
b7690f5
b24b7b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this, it's correctly handled in #224.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
|
@@ -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 | ||
|
|
||
|
|
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| flake8 | ||
| pytest | ||
| ruff | ||
| pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.