Skip to content

Commit

Permalink
Add very minimal linting (#894)
Browse files Browse the repository at this point in the history
* Add some linting.

* Fix some lints.

---------

Co-authored-by: Itamar Turner-Trauring <itamar@pythonspeed.com>
  • Loading branch information
itamarst and pythonspeed committed Jan 18, 2024
1 parent 8d781c2 commit c36286f
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 253 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ jobs:
- name: install tox
run: pip install tox
- name: run tests
run: tox --verbose -e pep8
run: |
tox --verbose -e pep8
tox --verbose -e lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dist/
doc/changelog.rst
venv*
website-build/
.ruff_cache/

# auto-generated by hatch
eventlet/_version.py
2 changes: 0 additions & 2 deletions eventlet/backdoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import errno
import socket
import sys
import errno
import traceback

import eventlet
from eventlet import hubs
Expand Down
229 changes: 0 additions & 229 deletions eventlet/greenio/py2.py

This file was deleted.

2 changes: 1 addition & 1 deletion eventlet/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def monkey_patch(**on):
raise TypeError("monkey_patch() got an unexpected "
"keyword argument %r" % k)
if default_on is None:
default_on = not (True in on.values())
default_on = True not in on.values()
for modname in accepted_args:
if modname == 'MySQLdb':
# MySQLdb is only on when explicitly patched for the moment
Expand Down
5 changes: 3 additions & 2 deletions eventlet/zipkin/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ def build_span(name, trace_id, span_id, parent_id,

@staticmethod
def build_annotation(value, endpoint=None):
if isinstance(value, unicode):
if isinstance(value, str):
value = value.encode('utf-8')
assert isinstance(value, bytes)
return ttypes.Annotation(time.time() * 1000 * 1000,
str(value), endpoint)
value, endpoint)

@staticmethod
def build_binary_annotation(key, value, endpoint=None):
Expand Down
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,25 @@ version.source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "eventlet/_version.py"

[tool.ruff]
# Might eventually want to add evenetlet/green/, but it's a pain...
exclude = ["eventlet/green/", "eventlet/zipkin/_thrift", "tests/mock.py", "doc/"]
line-length = 123

[tool.ruff.lint]
# Too many to fix as first pass, but should perhaps go back and fix these:
ignore = [
# Ambiguous variable name
"E741",
# Local variable assigned but unused
"F841",
# Imported but unused
"F401",
# Bare except:
"E722",
# Module-level import not at top of file
"E402",
# Using a lambda expression with a name instead of just def
"E731",
]
2 changes: 1 addition & 1 deletion tests/greenio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_connect_timeout(self):
expect_socket_timeout(gs.connect, ('192.0.2.1', 80))
except OSError as e:
# unreachable is also a valid outcome
if not get_errno(e) in (errno.EHOSTUNREACH, errno.ENETUNREACH):
if get_errno(e) not in (errno.EHOSTUNREACH, errno.ENETUNREACH):
raise

def test_accept_timeout(self):
Expand Down
5 changes: 0 additions & 5 deletions tests/greenpool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
import tests


def passthru(a):
eventlet.sleep(0.01)
return a


def passthru2(a, b):
eventlet.sleep(0.01)
return a, b
Expand Down
4 changes: 0 additions & 4 deletions tests/isolated/patcher_builtin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
if __name__ == '__main__':
from tests.mock import patch

import sys
import eventlet
from eventlet import hubs
with patch.object(hubs, 'notify_opened') as mock_func:
eventlet.monkey_patch(builtins=True)
with open(__file__) as f:
mock_func.assert_called_with(f.fileno())
if sys.version_info.major == 2:
with file(__file__, 'r') as f:
mock_func.assert_called_with(f.fileno())
print('pass')
2 changes: 1 addition & 1 deletion tests/parse_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ def main(db):
sys.argv.append(latest_db)
for db in sys.argv[1:]:
main(db)
execfile('generate_report.py')
exec(open('generate_report.py').read())
2 changes: 0 additions & 2 deletions tests/ssl_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import contextlib
import random
import socket
import sys
import warnings

Expand Down
14 changes: 9 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# The flake8 and pep8 sections just contain configuration for corresponding tools.
# Checkers are not run implicitly.
[flake8]
exclude = *.egg*,.env,.git,.hg,.tox,_*,build*,dist*,venv*,mock.py,eventlet/green/http/*
ignore = E261,E402,E731,W503
max-line-length = 123

[pycodestyle]
count = 1
exclude = *.egg*,.env,.git,.hg,.tox,_*,build*,dist*,venv*,mock.py,eventlet/green/http/*
Expand Down Expand Up @@ -49,6 +44,15 @@ usedevelop = False
commands =
pycodestyle benchmarks/ eventlet/ tests/

[testenv:lint]
basepython = python3
setenv =
{[testenv]setenv}
deps =
ruff==0.1.13
commands =
ruff eventlet/ tests/

[testenv]
passenv =
CI
Expand Down

0 comments on commit c36286f

Please sign in to comment.