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

Add isort #1689

Merged
merged 10 commits into from
Feb 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
test_harness+="./with-fuseki.sh"
fi
black --config black.toml --check --diff ./rdflib || true
isort --check-only --diff . || true
flake8 --exit-zero rdflib
mypy --show-error-context --show-error-codes
"${test_harness[@]}" pytest -ra --cov
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ ci:
autofix_prs: false

repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
# This is here to defer file selection to isort which will do it based on
# black config.
pass_filenames: false
require_serial: true
args: ["."]
- repo: local
hooks:
# using a local hook for black because of an issue that arises when using
Expand Down
6 changes: 3 additions & 3 deletions examples/film.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
"""
import datetime
import os
import sys
import re
import sys
import time

try:
import imdb
except ImportError:
imdb = None

from rdflib import BNode, ConjunctiveGraph, URIRef, Literal, Namespace
from rdflib.namespace import FOAF, DC, RDF
from rdflib import BNode, ConjunctiveGraph, Literal, Namespace, URIRef
from rdflib.namespace import DC, FOAF, RDF

storefn = os.path.expanduser("~/movies.n3")
# storefn = '/home/simon/codes/film.dev/movies.n3'
Expand Down
6 changes: 2 additions & 4 deletions rdflib/extras/describer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@
"""

from contextlib import contextmanager

from rdflib.graph import Graph
from rdflib.namespace import RDF
from rdflib.term import BNode
from rdflib.term import Identifier
from rdflib.term import Literal
from rdflib.term import URIRef
from rdflib.term import BNode, Identifier, Literal, URIRef


class Describer(object):
Expand Down
10 changes: 4 additions & 6 deletions rdflib/extras/infixowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@
"""

import itertools
import logging

from rdflib import BNode, Literal, Namespace, RDF, RDFS, URIRef, Variable
from rdflib.graph import Graph
from rdflib import RDF, RDFS, BNode, Literal, Namespace, URIRef, Variable
from rdflib.collection import Collection
from rdflib.namespace import OWL, XSD
from rdflib.namespace import NamespaceManager
from rdflib.graph import Graph
from rdflib.namespace import OWL, XSD, NamespaceManager
from rdflib.term import Identifier
from rdflib.util import first

import logging

logger = logging.getLogger(__name__)


Expand Down
18 changes: 8 additions & 10 deletions rdflib/plugins/parsers/notation3.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,30 @@
Copyright 2010, Gunnar A. Grimnes

"""
import sys
import codecs
import os
import re
import codecs
from typing import IO, TYPE_CHECKING, Any, Callable, Dict, Optional, TypeVar, Union
import sys

# importing typing for `typing.List` because `List`` is used for something else
import typing

from decimal import Decimal

from typing import IO, TYPE_CHECKING, Any, Callable, Dict, Optional, TypeVar, Union
from uuid import uuid4

from rdflib.compat import long_type
from rdflib.exceptions import ParserError
from rdflib.graph import ConjunctiveGraph, Graph, QuotedGraph
from rdflib.term import (
_XSD_PFX,
BNode,
Identifier,
Literal,
Node,
URIRef,
BNode,
Literal,
Variable,
_XSD_PFX,
_unique_id,
)
from rdflib.graph import QuotedGraph, ConjunctiveGraph, Graph
from rdflib.compat import long_type

__all__ = [
"BadSyntax",
Expand Down
13 changes: 6 additions & 7 deletions rdflib/plugins/parsers/ntriples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
Author: Sean B. Palmer, inamidst.com
"""

import re
import codecs
import re
from io import BytesIO, StringIO, TextIOBase
from typing import IO, TYPE_CHECKING, Optional, Pattern, TextIO, Union

from rdflib.term import Node, URIRef as URI
from rdflib.term import BNode as bNode
from rdflib.term import Literal
from rdflib.compat import decodeUnicodeEscape, _string_escape_map
from rdflib.compat import _string_escape_map, decodeUnicodeEscape
from rdflib.exceptions import ParserError as ParseError
from rdflib.parser import InputSource, Parser

from io import StringIO, TextIOBase, BytesIO
from rdflib.term import BNode as bNode
from rdflib.term import Literal, Node
from rdflib.term import URIRef as URI

if TYPE_CHECKING:
from rdflib.graph import Graph
Expand Down
6 changes: 2 additions & 4 deletions rdflib/tools/rdfpipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
resulting graph to a chosen format.
"""

import logging
import sys
from optparse import OptionParser
import logging

import rdflib
from rdflib import plugin
from rdflib.store import Store
from rdflib.graph import ConjunctiveGraph
from rdflib.parser import Parser
from rdflib.serializer import Serializer

from rdflib.store import Store
from rdflib.util import guess_format


DEFAULT_INPUT_FORMAT = "xml"
DEFAULT_OUTPUT_FORMAT = "n3"

Expand Down
1 change: 1 addition & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ myst-parser
pytest
pytest-cov
pytest-subtests
isort
sphinx
sphinxcontrib-apidoc
sphinxcontrib-kroki
Expand Down
28 changes: 28 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ exclude = (?x)(
^.*test/plugins/.*/setup.py$
)

[isort]
profile = black
py_version = 37
line_length = 88
supported_extensions =
pyw
pyi
skip =
.eggs # exclude a few common directories in the
.git # root of the project
.hg
.mypy_cache
.pytest_cache
.tox
.venv
.github
_build
htmlcov
benchmarks
examples # No need to Black examples
test # Tests are a mess, don't black them
test_reports
rdflib.egg-info
buck-out
build
dist
venv

[tool:pytest]
addopts =
--doctest-modules
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python

import codecs
import os
import re
import codecs
from setuptools import setup, find_packages

from setuptools import find_packages, setup

kwargs = {}
kwargs["install_requires"] = [
Expand Down
3 changes: 2 additions & 1 deletion test/test_issue200.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python

import os
import rdflib
import unittest

import pytest

import rdflib

if os.name == "nt":
pytestmark = pytest.mark.skip(
Expand Down
7 changes: 3 additions & 4 deletions test/test_serializer_trix.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python

import unittest

from rdflib.graph import ConjunctiveGraph
from rdflib.term import URIRef, Literal
from rdflib.graph import Graph
from io import BytesIO

from rdflib.graph import ConjunctiveGraph, Graph
from rdflib.term import Literal, URIRef


class TestTrixSerialize(unittest.TestCase):
def setUp(self):
Expand Down
5 changes: 2 additions & 3 deletions test/test_trix_parse.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python
import os

from rdflib.graph import ConjunctiveGraph
import unittest

from test import TEST_DIR

from rdflib.graph import ConjunctiveGraph


class TestTrixParse(unittest.TestCase):
def setUp(self):
Expand Down