From ed38efe905fdf948a7c602145da7de4dd0b5e73e Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:34:03 +0200 Subject: [PATCH 01/12] ci - Add initial config for pre-commit hook --- .pre-commit-config.yaml | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b270cd0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,78 @@ +# SPDX-FileCopyrightText: none +# SPDX-License-Identifier: CC0-1.0 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + # Forbid files which have a UTF-8 byte-order marker + - id: check-byte-order-marker + # Require literal syntax when initializing empty or zero Python builtin types + - id: check-builtin-literals + # Check for files that would conflict in case-insensitive filesystems + - id: check-case-conflict + # Ensures that (non-binary) executables have a shebang + - id: check-executables-have-shebangs + # Check for files that contain merge conflict strings + - id: check-merge-conflict + # Checks for symlinks which do not point to anything + - id: check-symlinks + # This hook checks yaml files for parseable syntax + - id: check-yaml + files: .drone.yml + # Drone CI config allows and requires multiple documents + args: [--allow-multiple-documents] + - id: check-yaml + exclude: .drone.yml + # Detects the presence of private keys + - id: detect-private-key + # Ensures that a file is either empty, or ends with one newline + - id: end-of-file-fixer + # Replaces or checks mixed line ending + - id: mixed-line-ending + # This hook trims trailing whitespace + - id: trailing-whitespace + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.6.0 + hooks: + # Enforce that `noqa` annotations always occur with specific codes + - id: python-check-blanket-noqa + # Prevent common mistakes of `assert mck.not_called()`, `assert mck.called_once_with(...)` and `mck.assert_called` + - id: python-check-mock-methods + # A quick check for the `eval()` built-in function + - id: python-no-eval + # A quick check for the deprecated `.warn()` method of python loggers + - id: python-no-log-warn + # ToDo: Fix code + # # Enforce that python3.6+ type annotations are used instead of type comments + # - id: python-use-type-annotations + # Detect common mistake of using single backticks when writing rst + - id: rst-backticks + # Detect mistake of inline code touching normal text in rst + - id: rst-inline-touching-normal + # Forbid files which have a UTF-8 Unicode replacement character + - id: text-unicode-replacement-char + + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.2 + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear + - flake8-implicit-str-concat + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.782 + hooks: + - id: mypy + args: [--no-strict-optional, --ignore-missing-imports, --allow-untyped-global] + exclude: ^(docs/) + + # Check for missing licensing and copyright information. + # The REUSE helper tool assists with achieving and confirming REUSE compliance. + # See: https://reuse.software/ + - repo: https://github.com/fsfe/reuse-tool + rev: v0.11.1 + hooks: + - id: reuse From 06462633d08ff7044cd333d9eed31d41baf8520a Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:34:32 +0200 Subject: [PATCH 02/12] * - Fix white spaces --- .coveragerc | 2 +- LICENSE | 1 - docs/source/changelog.rst | 2 +- docs/source/contributing.rst | 2 +- examples/get_ways.py | 2 +- overpy/__init__.py | 2 +- tests/test_json.py | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.coveragerc b/.coveragerc index 7ac65cb..da6884c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,2 @@ [run] -source = overpy \ No newline at end of file +source = overpy diff --git a/LICENSE b/LICENSE index 8a66c64..413d750 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 6f90edd..09929fe 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -1 +1 @@ -.. include:: ../../CHANGELOG.rst \ No newline at end of file +.. include:: ../../CHANGELOG.rst diff --git a/docs/source/contributing.rst b/docs/source/contributing.rst index 8cb3146..ac7b6bc 100644 --- a/docs/source/contributing.rst +++ b/docs/source/contributing.rst @@ -1 +1 @@ -.. include:: ../../CONTRIBUTING.rst \ No newline at end of file +.. include:: ../../CONTRIBUTING.rst diff --git a/examples/get_ways.py b/examples/get_ways.py index b352409..365d6bd 100755 --- a/examples/get_ways.py +++ b/examples/get_ways.py @@ -15,4 +15,4 @@ print(" Highway: %s" % way.tags.get("highway", "n/a")) print(" Nodes:") for node in way.nodes: - print(f" Lat: {node.lat:f}, Lon: {node.lon:f}") \ No newline at end of file + print(f" Lat: {node.lat:f}, Lon: {node.lon:f}") diff --git a/overpy/__init__.py b/overpy/__init__.py index a041e04..cedfc89 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -347,7 +347,7 @@ def from_json(cls, data, api=None): def from_xml(cls, data, api=None, parser=None): """ Create a new instance and load data from xml data or object. - + .. note:: If parser is set to None, the functions tries to find the best parse. By default the SAX parser is chosen if a string is provided as data. diff --git a/tests/test_json.py b/tests/test_json.py index 1d362cb..686e7f4 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -115,4 +115,4 @@ def test_remark_runtime_remark(self): def test_remark_unknown(self): api = overpy.Overpass() with pytest.raises(overpy.exception.OverpassUnknownError): - api.parse_json(read_file("json/remark-unknown-01.json")) \ No newline at end of file + api.parse_json(read_file("json/remark-unknown-01.json")) From 2db0c3db7efd7a84e66c2877fe4493029f3d1e6d Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:37:32 +0200 Subject: [PATCH 03/12] git - Update gitignore --- .gitignore | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 233 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b592f96..06be097 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,234 @@ -__pycache__ -*.pyc -*.pyo -*.swp -/build/ -/dist/ -/docs/build/ -/.idea/ +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ *.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Vim template +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + From da272b73b8168fead2b9a7805a7cd3f3ec12a244 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:50:35 +0200 Subject: [PATCH 04/12] ci - Add flake8 config --- .flake8 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..363978b --- /dev/null +++ b/.flake8 @@ -0,0 +1,8 @@ +# SPDX-FileCopyrightText: none +# SPDX-License-Identifier: CC0-1.0 + +[flake8] +max-line-length = 120 +extend-exclude = + venv/ + docs/source/conf.py From 1bc2e9b607097888b8dc2651ffd4a1f07e4af87a Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:51:02 +0200 Subject: [PATCH 05/12] git - Exclude some files from pre-commit hook --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b270cd0..f89c0d6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,10 +28,13 @@ repos: - id: detect-private-key # Ensures that a file is either empty, or ends with one newline - id: end-of-file-fixer + exclude: ^tests/(json|response|xml)/ # Replaces or checks mixed line ending - id: mixed-line-ending + exclude: ^tests/(json|response|xml)/ # This hook trims trailing whitespace - id: trailing-whitespace + exclude: ^tests/(json|response|xml)/ - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.6.0 @@ -76,3 +79,4 @@ repos: rev: v0.11.1 hooks: - id: reuse + exclude: ^tests/(json|response|xml)/ From da3c00a15ffb7444b1d5087b356c6a4cc8ba6727 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:51:26 +0200 Subject: [PATCH 06/12] git - Fix gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 06be097..255357a 100644 --- a/.gitignore +++ b/.gitignore @@ -231,4 +231,3 @@ Sessionx.vim tags # Persistent undo [._]*.un~ - From 578adced7c88014a48fafa2cc37ecb33cb199346 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:52:29 +0200 Subject: [PATCH 07/12] git - Disable FSFE REUSE check We have to fix some other issues before we fix this --- .pre-commit-config.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f89c0d6..cc424ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -72,11 +72,11 @@ repos: args: [--no-strict-optional, --ignore-missing-imports, --allow-untyped-global] exclude: ^(docs/) - # Check for missing licensing and copyright information. - # The REUSE helper tool assists with achieving and confirming REUSE compliance. - # See: https://reuse.software/ - - repo: https://github.com/fsfe/reuse-tool - rev: v0.11.1 - hooks: - - id: reuse - exclude: ^tests/(json|response|xml)/ +# # Check for missing licensing and copyright information. +# # The REUSE helper tool assists with achieving and confirming REUSE compliance. +# # See: https://reuse.software/ +# - repo: https://github.com/fsfe/reuse-tool +# rev: v0.11.1 +# hooks: +# - id: reuse +# exclude: ^tests/(json|response|xml)/ From b4ae3d5a9e739e250775beb6401d791b95511cc2 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:54:40 +0200 Subject: [PATCH 08/12] test - Remove unused imports --- tests/__init__.py | 4 ++-- tests/base_class.py | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index d59ab53..52f1119 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -3,8 +3,8 @@ from pathlib import Path from threading import Lock -from socketserver import BaseRequestHandler, TCPServer, ThreadingMixIn -from http.server import BaseHTTPRequestHandler, HTTPServer +from socketserver import BaseRequestHandler, TCPServer +from http.server import HTTPServer TCPServer.allow_reuse_address = True diff --git a/tests/base_class.py b/tests/base_class.py index be89a1a..208cbcd 100644 --- a/tests/base_class.py +++ b/tests/base_class.py @@ -1,13 +1,10 @@ from decimal import Decimal from datetime import datetime -import os import pytest import overpy -from tests import read_file - class BaseTestAreas: @staticmethod From 57d3e5b877d58d952c5dcbd37ac416b08ad61ae4 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 22:56:44 +0200 Subject: [PATCH 09/12] src - Fix setup.py and remove unused imports --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index b74ee3c..2b5a7c2 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -import os -import sys from pathlib import Path from setuptools import setup, find_packages @@ -40,7 +38,7 @@ packages=find_packages(exclude=["*.tests", "*.tests.*", "tests"]), include_package_data=True, package_data={ - #"": ["README"], + # "": ["README"], }, setup_requires=["pytest-runner"], tests_require=["pytest"], From 4443cb7c8153ec7998b2c825560ae2ba5cfc7189 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 23:06:10 +0200 Subject: [PATCH 10/12] src - Fix import and source --- overpy/__init__.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/overpy/__init__.py b/overpy/__init__.py index cedfc89..92565af 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -9,7 +9,8 @@ import time from overpy import exception -from overpy.__about__ import ( +# Ignore flake8 F401 warning for unused vars +from overpy.__about__ import ( # noqa: F401 __author__, __copyright__, __email__, __license__, __summary__, __title__, __uri__, __version__ ) @@ -52,7 +53,13 @@ class Overpass: default_retry_timeout = 1.0 default_url = "http://overpass-api.de/api/interpreter" - def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX, max_retry_count=None, retry_timeout=None): + def __init__( + self, + read_chunk_size=None, + url=None, + xml_parser=XML_PARSER_SAX, + max_retry_count=None, + retry_timeout=None): """ :param read_chunk_size: Max size of each chunk read from the server response :type read_chunk_size: Integer @@ -142,10 +149,10 @@ def query(self, query): if content_type == "application/osm3s+xml": return self.parse_xml(response) - e = exception.OverpassUnknownContentType(content_type) + current_exception = exception.OverpassUnknownContentType(content_type) if not do_retry: - raise e - retry_exceptions.append(e) + raise current_exception + retry_exceptions.append(current_exception) continue if f.code == 400: @@ -158,33 +165,33 @@ def query(self, query): tmp = repr(tmp) msgs.append(tmp) - e = exception.OverpassBadRequest( + current_exception = exception.OverpassBadRequest( query, msgs=msgs ) if not do_retry: - raise e - retry_exceptions.append(e) + raise current_exception + retry_exceptions.append(current_exception) continue if f.code == 429: - e = exception.OverpassTooManyRequests + current_exception = exception.OverpassTooManyRequests if not do_retry: - raise e - retry_exceptions.append(e) + raise current_exception + retry_exceptions.append(current_exception) continue if f.code == 504: - e = exception.OverpassGatewayTimeout + current_exception = exception.OverpassGatewayTimeout if not do_retry: - raise e - retry_exceptions.append(e) + raise current_exception + retry_exceptions.append(current_exception) continue - e = exception.OverpassUnknownHTTPStatusCode(f.code) + current_exception = exception.OverpassUnknownHTTPStatusCode(f.code) if not do_retry: - raise e - retry_exceptions.append(e) + raise current_exception + retry_exceptions.append(current_exception) continue raise exception.MaxRetriesReached(retry_count=retry_num, exceptions=retry_exceptions) From 6e40b0471cd25a8a5d33e51a87bd73b0a6088033 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 23:06:26 +0200 Subject: [PATCH 11/12] test - Fix imports --- tests/test_json.py | 2 +- tests/test_request.py | 3 ++- tests/test_result.py | 4 +++- tests/test_result_way.py | 3 ++- tests/test_xml.py | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_json.py b/tests/test_json.py index 686e7f4..9a96d0e 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -2,8 +2,8 @@ import overpy +from tests import read_file from tests.base_class import BaseTestAreas, BaseTestNodes, BaseTestRelation, BaseTestWay -from tests.base_class import read_file class TestAreas(BaseTestAreas): diff --git a/tests/test_request.py b/tests/test_request.py index 16a7937..a545035 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -1,8 +1,9 @@ +from http.server import BaseHTTPRequestHandler + import pytest import overpy -from tests import BaseHTTPRequestHandler from tests import read_file, new_server_thread, stop_server_thread diff --git a/tests/test_result.py b/tests/test_result.py index 4c57d87..217a6f0 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -1,9 +1,11 @@ +from http.server import BaseHTTPRequestHandler + import pytest import overpy +from tests import read_file, new_server_thread, stop_server_thread from tests.base_class import BaseTestWay -from tests import read_file, new_server_thread, stop_server_thread, BaseHTTPRequestHandler class HandleResponseJSON02(BaseHTTPRequestHandler): diff --git a/tests/test_result_way.py b/tests/test_result_way.py index 36625e2..6289b4b 100644 --- a/tests/test_result_way.py +++ b/tests/test_result_way.py @@ -1,8 +1,9 @@ +from http.server import BaseHTTPRequestHandler + import pytest import overpy -from tests import BaseHTTPRequestHandler from tests import read_file, new_server_thread, stop_server_thread diff --git a/tests/test_xml.py b/tests/test_xml.py index 7c3c9db..8a00b76 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -2,8 +2,8 @@ import overpy +from tests import read_file from tests.base_class import BaseTestAreas, BaseTestNodes, BaseTestRelation, BaseTestWay -from tests.base_class import read_file class TestAreas(BaseTestAreas): From ba8adea7ee4c914ee6e240f9f7d17c49eac9d4bd Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 14 Apr 2021 23:07:57 +0200 Subject: [PATCH 12/12] ci - Add pre-commit action --- .github/workflows/pre-commit.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..7233479 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [master] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.0