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

pre-commit + dev tools #214

Closed
wants to merge 10 commits into from
Closed
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
17 changes: 3 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,10 @@ jobs:
run: |
pip install -U pip
pip install '.[dev]'
- name: Mypy
run: |
mypy --show-error-context --show-error-codes
- name: Test [wrapper]
if: ${{ always() }}
run: |
python -m unittest test/test_wrapper.py -v
- uses: pre-commit/[email protected]
- name: Test [all]
run: |
python -m unittest -v |& tee log.txt
grep '^FAIL:' log.txt > fails.txt
# if all failures is not raised in `test.test_wrapper`:
if [ "$(grep 'test.test_wrapper' fails.txt | wc -l)" -ne "$(wc -l < fails.txt)" ]; then
pytest |& tee log.txt
if tail -1 log.txt | grep -q ' failed'; then
exit 1
else
echo 'All of the above failures are maybe false errors.'
echo 'See: https://github.com/RDFLib/sparqlwrapper/issues/192'
fi
78 changes: 78 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
exclude: |
(?x)^(
\.git/.*|
__pycache__/.*|
docs/.*|
build/.*|
dist/.*|
test/.*
)$

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-check-blanket-noqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
exclude: |
(?x)^(
\.git/.*|
__pycache__/.*|
docs/.*|
build/.*|
dist/.*
)$


- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
exclude: |
(?x)^(
\.git/.*|
__pycache__/.*|
docs/.*|
build/.*|
dist/.*
)$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.940
hooks:
- id: mypy
args: ['--no-warn-unused-ignores']
additional_dependencies: ['rdflib', 'types-setuptools', 'pandas-stubs']
exclude: |
(?x)^(
\.git/.*|
test/.*|
__pycache__/.*|
docs/.*|
test/.*|
build/.*|
scripts/.*|
dist/.*
)$
3 changes: 1 addition & 2 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SPARQL Python Wrapper is released under the W3C� SOFTWARE NOTICE AND LICENSE.
SPARQL Python Wrapper is released under the W3C� SOFTWARE NOTICE AND LICENSE.

This work (and included software, documentation such as READMEs, or other related items) is being provided by the copyright holders under the following license. By obtaining, using and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions.

Expand All @@ -15,4 +15,3 @@ COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQ
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders.

See also http://www.w3.org/Consortium/Legal/copyright-software for further details

2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ include *.md
exclude Makefile
include test/*.py
include scripts/*.py
include requirements.txt
include requirements.development.txt
include LICENSE.txt
include ChangeLog.txt
graft docs/build/html
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ clean:
$(MAKE) -C ${DOCDIR} clean
rm -rf build
find . -name "*.pyc" -delete

14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ You can install SPARQLWrapper from GitHub::
You can install SPARQLWrapper from Debian::

$ sudo apt-get install python-sparqlwrapper

.. note::

Be aware that there could be a gap between the latest version of SPARQLWrapper
and the version available as Debian package.

Also, the source code of the package can be downloaded
Also, the source code of the package can be downloaded
in ``.zip`` and ``.tar.gz`` formats from `GitHub SPARQLWrapper releases <https://github.com/RDFLib/sparqlwrapper/releases>`_.
Documentation is included in the distribution.

Expand Down Expand Up @@ -125,9 +125,9 @@ This query gets a boolean response from DBPedia's SPARQL endpoint:

sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
ASK WHERE {
ASK WHERE {
<http://dbpedia.org/resource/Asturias> rdfs:label "Asturias"@es
}
}
""")
sparql.setReturnFormat(XML)
results = sparql.query().convert()
Expand Down Expand Up @@ -307,7 +307,7 @@ Return formats

The expected return formats differs per query type (``SELECT``, ``ASK``, ``CONSTRUCT``, ``DESCRIBE``...).

.. note:: From the `SPARQL specification <https://www.w3.org/TR/sparql11-protocol/#query-success>`_,
.. note:: From the `SPARQL specification <https://www.w3.org/TR/sparql11-protocol/#query-success>`_,
*The response body of a successful query operation with a 2XX response is either:*

* ``SELECT`` and ``ASK``: a SPARQL Results Document in XML, JSON, or CSV/TSV format.
Expand Down Expand Up @@ -430,12 +430,12 @@ in the return value). This features becomes particularly useful when the ``OPTIO
GET or POST
^^^^^^^^^^^

By default, all SPARQL services are invoked using HTTP **GET** verb. However,
By default, all SPARQL services are invoked using HTTP **GET** verb. However,
**POST** might be useful if the size of the query
extends a reasonable size; this can be set in the query instance.

Note that some combinations may not work yet with all SPARQL processors
(e.g., there are implementations where **POST + JSON return** does not work).
(e.g., there are implementations where **POST + JSON return** does not work).
Hopefully, this problem will eventually disappear.


Expand Down
5 changes: 2 additions & 3 deletions SPARQLWrapper/KeyCaseInsensitiveDict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
A simple implementation of a key case-insensitive dictionary.
..
Expand All @@ -18,12 +16,13 @@

_V = TypeVar("_V")


class KeyCaseInsensitiveDict(Dict[str, _V]):
"""
A simple implementation of a key case-insensitive dictionary
"""

def __init__(self, d: Mapping[str, _V]={}) -> None:
def __init__(self, d: Mapping[str, _V] = {}) -> None:
"""
:param dict d: The source dictionary.
"""
Expand Down
8 changes: 3 additions & 5 deletions SPARQLWrapper/SPARQLExceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
SPARQL Wrapper exceptions

Expand Down Expand Up @@ -35,15 +33,15 @@ def __init__(self, response: Optional[bytes] = None):
:param string response: The server response
"""
if response:
formatted_msg = "%s: %s. \n\nResponse:\n%r" % (
formatted_msg = "{}: {}. \n\nResponse:\n{!r}".format(
self.__class__.__name__,
self.msg,
response,
)
else:
formatted_msg = "%s: %s." % (self.__class__.__name__, self.msg)
formatted_msg = f"{self.__class__.__name__}: {self.msg}."

super(SPARQLWrapperException, self).__init__(formatted_msg)
super().__init__(formatted_msg)


class EndPointInternalError(SPARQLWrapperException):
Expand Down
28 changes: 12 additions & 16 deletions SPARQLWrapper/SmartWrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""

..
Expand Down Expand Up @@ -28,7 +26,7 @@
######################################################################################


class Value(object):
class Value:
"""
Class encapsulating a single binding for a variable.

Expand Down Expand Up @@ -68,23 +66,23 @@ def __init__(self, variable: str, binding: Dict[str, str]) -> None:
self.datatype = None
try:
self.lang = binding["xml:lang"]
except:
except Exception:
# no lang is set
pass
try:
self.datatype = binding["datatype"]
except:
except Exception:
pass

def __repr__(self) -> str:
cls = self.__class__.__name__
return "%s(%s:%r)" % (cls, self.type, self.value)
return f"{cls}({self.type}:{self.value!r})"


######################################################################################


class Bindings(object):
class Bindings:
"""
Class encapsulating one query result, based on the JSON return format. It decodes the
return values to make it a bit more usable for a standard usage. The class consumes the
Expand Down Expand Up @@ -121,7 +119,7 @@ def __init__(self, retval: QueryResult):
self.variables: Optional[List[str]] = None
try:
self.variables = self.fullResult["head"]["vars"]
except:
except Exception:
pass

self.bindings: List[Dict[str, Value]] = []
Expand All @@ -136,13 +134,13 @@ def __init__(self, retval: QueryResult):
# there is a real binding for this key
newBind[key] = Value(key, b[key])
self.bindings.append(newBind)
except:
except Exception:
pass

self.askResult = False
try:
self.askResult = self.fullResult["boolean"]
except:
except Exception:
pass

def getValues(self, key: str) -> Optional[List[Value]]:
Expand All @@ -156,7 +154,7 @@ def getValues(self, key: str) -> Optional[List[Value]]:
"""
try:
return [b[key] for b in self[key]]
except:
except Exception:
return []

def __contains__(self, key: Union[str, List[str], Tuple[str]]) -> bool:
Expand Down Expand Up @@ -310,9 +308,7 @@ def __init__(self, baseURI: str, defaultGraph: Optional[str] = None):
:param defaultGraph: URI for the default graph. Default is ``None``, can be set via an explicit call, too.
:type defaultGraph: string
"""
super(SPARQLWrapper2, self).__init__(
baseURI, returnFormat=JSON, defaultGraph=defaultGraph
)
super().__init__(baseURI, returnFormat=JSON, defaultGraph=defaultGraph)

def setReturnFormat(self, format: Optional[str]) -> None:
"""
Expand Down Expand Up @@ -343,7 +339,7 @@ def query(self) -> Union[Bindings, QueryResult]: # type: ignore[override]
:return: query result
:rtype: :class:`Bindings` instance
"""
res = super(SPARQLWrapper2, self).query()
res = super().query()

if self.queryType == SELECT:
return Bindings(res)
Expand All @@ -363,4 +359,4 @@ def queryAndConvert( # type: ignore[override]
if self.queryType == SELECT:
return self.query()
else:
return super(SPARQLWrapper2, self).queryAndConvert()
return super().queryAndConvert()
Loading