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

switch to ruff for lint/format #1969

Merged
merged 10 commits into from
Apr 2, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# flake8 no longer used,
# ruff config in pyproject.toml
[flake8]
exclude = .git,dist,docs,zmq/eventloop/minitornado,buildutils/templates
ignore = E,W
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ _deps
/Makefile
_src
licenses
.virtual_documents
54 changes: 18 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
language: python
pass_filenames: false
additional_dependencies:
- black
- ruff
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17 # Use the ref you want to point at
hooks:
Expand All @@ -24,19 +24,24 @@ repos:
- mdformat-myst
exclude: LICENSE.md

- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args:
- --in-place
exclude: zmq/tests/test_imports.py
# autoformat and lint Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
hooks:
- id: ruff
types_or:
- python
- jupyter
- pyi
args: ["--fix", "--show-fixes"]
- id: ruff-format
types_or:
- python
- jupyter
- pyi
# don't format zmq/constants.py twice
exclude: zmq/constants.py

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
exclude: ^buildutils/templates/
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
Expand All @@ -49,29 +54,6 @@ repos:
args: [zmq]
additional_dependencies:
- types-paramiko
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args:
- --py36-plus
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
# don't run black twice on constants.py
exclude: zmq/constants.py
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down
14 changes: 2 additions & 12 deletions RELICENSE/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,5 @@ def sort_key(email_commits):
commits[0].authored_datetime.year,
)
else:
msg = "{commits} commits ({start}-{end})".format(
commits=len(commits),
start=commits[-1].authored_datetime.year,
end=commits[0].authored_datetime.year,
)
print(
"- [ ] {name} {email}: {msg}".format(
name=email_names[email],
email=email,
msg=msg,
)
)
msg = f"{len(commits)} commits ({commits[-1].authored_datetime.year}-{commits[0].authored_datetime.year})"
print(f"- [ ] {email_names[email]} {email}: {msg}")
6 changes: 3 additions & 3 deletions buildutils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
root = pjoin(buildutils, os.path.pardir)

sys.path.insert(0, pjoin(root, 'zmq'))
import constants
import constants # noqa: E402

all_names = []
for name in constants.__all__:
Expand All @@ -49,7 +49,7 @@ def cython_enums():
lines = []
for name in all_names:
if no_prefix(name):
lines.append('enum: ZMQ_{0} "{0}"'.format(name))
lines.append(f'enum: ZMQ_{name} "{name}"')
else:
lines.append(f'enum: ZMQ_{name}')

Expand Down Expand Up @@ -112,7 +112,7 @@ def generate_file(fname, ns_func, dest_dir="."):
with open(dest, 'w') as f:
f.write(out)
if fname.endswith(".py"):
run([sys.executable, "-m", "black", dest])
run(["ruff", "format", dest])


def render_constants():
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
sys.path.append(str(repo_root))

# set target libzmq version
from buildutils.bundle import bundled_version
from buildutils.bundle import bundled_version # noqa

# remove repo root from sys.path
sys.path = sys.path[:-1]
Expand Down
6 changes: 1 addition & 5 deletions examples/asyncio/helloworld_pubsub_dealerrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ async def lang_changer_router(self) -> None:
)

self.hello_world.change_language()
print(
"Changed language! New language is: {}\n".format(
self.hello_world.lang
)
)
print(f"Changed language! New language is: {self.hello_world.lang}\n")

except Exception as e:
print("Error with sub world")
Expand Down
1 change: 0 additions & 1 deletion examples/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This example is placed in the Public Domain
# It may also be used under the Creative Commons CC-0 License, (C) PyZMQ Developers


import time
from threading import Thread

Expand Down
4 changes: 2 additions & 2 deletions examples/eventloop/echostream.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""Adapted echo.py to put the send in the event loop using a ZMQStream.
"""
"""Adapted echo.py to put the send in the event loop using a ZMQStream."""

from typing import List

from tornado import ioloop
Expand Down
1 change: 0 additions & 1 deletion examples/pubsub/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# the file LICENSE.BSD, distributed as part of this software.
# -----------------------------------------------------------------------------


import sys
import time

Expand Down
4 changes: 1 addition & 3 deletions examples/security/asyncio-ironhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ async def run() -> None:
if __name__ == '__main__':
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError(
"Security is not supported in libzmq version < 4.0. libzmq version {}".format(
zmq.zmq_version()
)
f"Security is not supported in libzmq version < 4.0. libzmq version {zmq.zmq_version()}"
)

if '-v' in sys.argv:
Expand Down
4 changes: 1 addition & 3 deletions examples/security/generate_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def generate_certificates(base_dir: Union[str, os.PathLike]) -> None:
if __name__ == '__main__':
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError(
"Security is not supported in libzmq version < 4.0. libzmq version {}".format(
zmq.zmq_version()
)
f"Security is not supported in libzmq version < 4.0. libzmq version {zmq.zmq_version()}"
)

generate_certificates(os.path.dirname(__file__))
6 changes: 3 additions & 3 deletions examples/security/grasslands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
'''
No protection at all.

All connections are accepted, there is no authentication, and no privacy.
All connections are accepted, there is no authentication, and no privacy.

This is how ZeroMQ always worked until we built security into the wire
protocol in early 2013. Internally, it uses a security mechanism called
This is how ZeroMQ always worked until we built security into the wire
protocol in early 2013. Internally, it uses a security mechanism called
"NULL".

Author: Chris Laws
Expand Down
4 changes: 1 addition & 3 deletions examples/security/ioloop-ironhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ async def run() -> None:
if __name__ == '__main__':
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError(
"Security is not supported in libzmq version < 4.0. libzmq version {}".format(
zmq.zmq_version()
)
f"Security is not supported in libzmq version < 4.0. libzmq version {zmq.zmq_version()}"
)

if '-v' in sys.argv:
Expand Down
4 changes: 1 addition & 3 deletions examples/security/ironhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def run() -> None:
if __name__ == '__main__':
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError(
"Security is not supported in libzmq version < 4.0. libzmq version {}".format(
zmq.zmq_version()
)
f"Security is not supported in libzmq version < 4.0. libzmq version {zmq.zmq_version()}"
)

if '-v' in sys.argv:
Expand Down
4 changes: 1 addition & 3 deletions examples/security/stonehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ def run() -> None:
if __name__ == '__main__':
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError(
"Security is not supported in libzmq version < 4.0. libzmq version {}".format(
zmq.zmq_version()
)
f"Security is not supported in libzmq version < 4.0. libzmq version {zmq.zmq_version()}"
)

if '-v' in sys.argv:
Expand Down
4 changes: 1 addition & 3 deletions examples/security/strawhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def run() -> None:
if __name__ == '__main__':
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError(
"Security is not supported in libzmq version < 4.0. libzmq version {}".format(
zmq.zmq_version()
)
f"Security is not supported in libzmq version < 4.0. libzmq version {zmq.zmq_version()}"
)

if '-v' in sys.argv:
Expand Down
4 changes: 1 addition & 3 deletions examples/security/woodhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def run() -> None:
if __name__ == '__main__':
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError(
"Security is not supported in libzmq version < 4.0. libzmq version {}".format(
zmq.zmq_version()
)
f"Security is not supported in libzmq version < 4.0. libzmq version {zmq.zmq_version()}"
)

if '-v' in sys.argv:
Expand Down
8 changes: 4 additions & 4 deletions perf/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM python:3.6
RUN pip install pandas cython
RUN pip install -vv https://github.com/zeromq/pyzmq/archive/master.tar.gz --install-option=--zmq=bundled
FROM python:3.11
RUN pip install pandas
RUN pip install --pre pyzmq
RUN mkdir /data && mkdir /perf
ADD *.py /perf/

WORKDIR /data
ENTRYPOINT ["python", "/perf/collect.py"]
ENTRYPOINT ["python3", "/perf/collect.py"]
CMD ["thr"]
4 changes: 2 additions & 2 deletions perf/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
BASE_IMAGE=python:3.6
BASE_IMAGE=python:3.11
IMAGE=pyzmq-perf
VOLUME=pyzmq-perf

ifeq ($(DOCKER_MACHINE_NAME), "")
ifeq ("$(DOCKER_MACHINE_NAME)", "")
OUT_PATH=$(PWD)
FETCH=true
else
Expand Down
Loading
Loading