Skip to content

Commit

Permalink
Merge pull request #3582 from lonvia/switch-to-flake
Browse files Browse the repository at this point in the history
Switch from pylint to flake8 for linting
  • Loading branch information
lonvia authored Nov 11, 2024
2 parents 5ec0732 + d77aa7d commit ae8694a
Show file tree
Hide file tree
Showing 121 changed files with 672 additions and 1,140 deletions.
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 100
max-doc-length = 100
extend-ignore =
# something == None constructs are needed for SQLAlchemy
E711
per-file-ignores =
__init__.py: F401
6 changes: 3 additions & 3 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ jobs:
- name: Install Python webservers
run: pip3 install falcon starlette asgi_lifespan

- name: Install latest pylint
run: pip3 install -U pylint
- name: Install latest flake8
run: pip3 install -U flake8
if: matrix.flavour == 'ubuntu-22'

- name: Python linting
run: python3 -m pylint src
run: python3 -m flake8 src
working-directory: Nominatim
if: matrix.flavour == 'ubuntu-22'

Expand Down
22 changes: 0 additions & 22 deletions .pylintrc

This file was deleted.

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ are in process of consolidating the style. The following rules apply:
* leave out space between a function name and bracket
but add one between control statement(if, while, etc.) and bracket

The coding style is enforced with pylint. It can be tested with:
The coding style is enforced with flake8. It can be tested with:

```
pylint3 --extension-pkg-whitelist=osmium nominatim
make lint
```

## Testing
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pytest:
pytest test/python

lint:
pylint src
flake8 src

bdd:
cd test/bdd; behave -DREMOVE_TEMPLATE=1
Expand Down
5 changes: 2 additions & 3 deletions docs/develop/Development-Environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The Nominatim test suite consists of behavioural tests (using behave) and
unit tests (using pytest). It has the following additional requirements:

* [behave test framework](https://behave.readthedocs.io) >= 1.2.6
* [Pylint](https://pylint.org/) (CI always runs the latest version from pip)
* [flake8](https://flake8.pycqa.org/en/stable/) (CI always runs the latest version from pip)
* [mypy](http://mypy-lang.org/) (plus typing information for external libs)
* [Python Typing Extensions](https://github.com/python/typing_extensions) (for Python < 3.9)
* [pytest](https://pytest.org)
Expand All @@ -55,7 +55,6 @@ the vendored version of osm2pgsql, you need to set the PATH accordingly.
### Installing prerequisites on Ubuntu/Debian

The Python tools should always be run with the most recent version.
In particular, pylint tends to have a lot of breaking changes between versions.
The easiest way, to handle these Python dependencies is to run your
development from within a virtual environment.

Expand All @@ -70,7 +69,7 @@ virtualenv ~/nominatim-dev-venv
~/nominatim-dev-venv/bin/pip install\
psutil psycopg[binary] PyICU SQLAlchemy \
python-dotenv jinja2 pyYAML datrie behave \
mkdocs mkdocstrings mkdocs-gen-files pytest pytest-asyncio pylint \
mkdocs mkdocstrings mkdocs-gen-files pytest pytest-asyncio flake8 \
types-jinja2 types-markupsafe types-psutil types-psycopg2 \
types-pygments types-pyyaml types-requests types-ujson \
types-urllib3 typing-extensions unicorn falcon starlette \
Expand Down
3 changes: 0 additions & 3 deletions src/nominatim_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import from this file, not from the source files directly.
"""

# See also https://github.com/PyCQA/pylint/issues/6006
# pylint: disable=useless-import-alias

from .errors import (UsageError as UsageError)
from .config import (Configuration as Configuration)

Expand Down
2 changes: 1 addition & 1 deletion src/nominatim_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
# This file is just a placeholder to make the config module available
# during development. It will be replaced by nominatim_db/config.py on
# installation.
# pylint: skip-file
# flake8: noqa
from nominatim_db.config import *
15 changes: 4 additions & 11 deletions src/nominatim_api/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

T = TypeVar('T')


class SearchConnection:
""" An extended SQLAlchemy connection class, that also contains
the table definitions. The underlying asynchronous SQLAlchemy
Expand All @@ -32,37 +33,32 @@ def __init__(self, conn: AsyncConnection,
tables: SearchTables,
properties: Dict[str, Any]) -> None:
self.connection = conn
self.t = tables # pylint: disable=invalid-name
self.t = tables
self._property_cache = properties
self._classtables: Optional[Set[str]] = None
self.query_timeout: Optional[int] = None


def set_query_timeout(self, timeout: Optional[int]) -> None:
""" Set the timeout after which a query over this connection
is cancelled.
"""
self.query_timeout = timeout


async def scalar(self, sql: sa.sql.base.Executable,
params: Union[Mapping[str, Any], None] = None
) -> Any:
params: Union[Mapping[str, Any], None] = None) -> Any:
""" Execute a 'scalar()' query on the connection.
"""
log().sql(self.connection, sql, params)
return await asyncio.wait_for(self.connection.scalar(sql, params), self.query_timeout)


async def execute(self, sql: 'sa.Executable',
params: Union[Mapping[str, Any], Sequence[Mapping[str, Any]], None] = None
) -> 'sa.Result[Any]':
) -> 'sa.Result[Any]':
""" Execute a 'execute()' query on the connection.
"""
log().sql(self.connection, sql, params)
return await asyncio.wait_for(self.connection.execute(sql, params), self.query_timeout)


async def get_property(self, name: str, cached: bool = True) -> str:
""" Get a property from Nominatim's property table.
Expand All @@ -89,7 +85,6 @@ async def get_property(self, name: str, cached: bool = True) -> str:

return cast(str, value)


async def get_db_property(self, name: str) -> Any:
""" Get a setting from the database. At the moment, only
'server_version', the version of the database software, can
Expand All @@ -102,7 +97,6 @@ async def get_db_property(self, name: str) -> Any:

return self._property_cache['DB:server_version']


async def get_cached_value(self, group: str, name: str,
factory: Callable[[], Awaitable[T]]) -> T:
""" Access the cache for this Nominatim instance.
Expand All @@ -125,7 +119,6 @@ async def get_cached_value(self, group: str, name: str,

return value


async def get_class_table(self, cls: str, typ: str) -> Optional[SaFromClause]:
""" Lookup up if there is a classtype table for the given category
and return a SQLAlchemy table for it, if it exists.
Expand Down
Loading

0 comments on commit ae8694a

Please sign in to comment.