Skip to content

Commit

Permalink
formatted by ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
duguyue100 committed Mar 16, 2024
1 parent af69780 commit 0552338
Show file tree
Hide file tree
Showing 39 changed files with 951 additions and 672 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.2
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ "--fix"]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
1 change: 1 addition & 0 deletions pyaer/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""About page."""

__all__ = ["__version__", "__author__", "__author_email__", "__url__"]

__version__ = "0.2.7a0"
Expand Down
2 changes: 2 additions & 0 deletions pyaer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

from __future__ import absolute_import
from __future__ import print_function

Expand All @@ -12,6 +13,7 @@
from pyaer.__about__ import __author__ # noqa
from pyaer.__about__ import __version__ # noqa


FILE_PATH = os.path.realpath(__file__)
CURR_PATH = os.path.dirname(os.path.realpath(__file__))
PKG_PATH = os.path.dirname(CURR_PATH)
Expand Down
8 changes: 4 additions & 4 deletions pyaer/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Author: Yuhuang Hu
Email : yuhuang.hu@ini.uzh.ch
"""

import json
import signal
import subprocess
Expand All @@ -25,6 +26,7 @@
import numpy as np
import zmq


try:
import zarr
except Exception:
Expand Down Expand Up @@ -181,7 +183,6 @@ def __init__(
name : str
the name of the publisher
"""

self.__dict__.update(kwargs)

self.url = url
Expand Down Expand Up @@ -271,7 +272,7 @@ def __init__(
port=5100,
master_topic="",
name="",
**kwargs
**kwargs,
):
"""AERPublisher.
Expand Down Expand Up @@ -605,7 +606,7 @@ def __init__(
sub_port=5099,
sub_topic="",
sub_name="",
**kwargs
**kwargs,
):
"""Publisher-Subscriber.
Expand Down Expand Up @@ -760,7 +761,6 @@ def get_keys(self):

def get_frame(self, device_name, group_name):
"""Get frame events at this packet."""

try:
frame_events = self.aer_file[device_name][group_name]["frame_events"][()]

Expand Down
5 changes: 2 additions & 3 deletions pyaer/davis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import numpy as np

from pyaer import libcaer
Expand Down Expand Up @@ -855,7 +856,6 @@ def get_bias(self):
bias_obj: `dict`<br/>
dictionary that contains DAVIS current bias settings.
"""

bias_obj = {}
# output sources
bias_obj["aps_enabled"] = self.get_config(
Expand Down Expand Up @@ -1310,7 +1310,6 @@ def get_event_container(self):
Instead of returning different variables, return an event container.
"""

data = self.get_event()

if data is None:
Expand Down Expand Up @@ -1447,7 +1446,7 @@ def get_event(self, mode="events"):
num_imu_event,
)
else:
return None,0,None,0,None,0,None,0
return None, 0, None, 0, None, 0, None, 0


class DAVISFX2(DAVIS):
Expand Down
1 change: 1 addition & 0 deletions pyaer/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import abc

from pyaer import libcaer
Expand Down
1 change: 1 addition & 0 deletions pyaer/dvs128.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import numpy as np

from pyaer import libcaer
Expand Down
1 change: 1 addition & 0 deletions pyaer/dvxplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import numpy as np

from pyaer import libcaer
Expand Down
7 changes: 4 additions & 3 deletions pyaer/dynapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import time

import numpy as np
Expand Down Expand Up @@ -186,7 +187,7 @@ def set_bias_from_json(
1: [0, 1, 2, 3],
2: [0, 1, 2, 3],
3: [0, 1, 2, 3],
}
}
```
"""
bias_obj = utils.load_dynapse_bias(file_path, verbose)
Expand Down Expand Up @@ -369,7 +370,7 @@ def set_bias(
1: [0, 1, 2, 3],
2: [0, 1, 2, 3],
3: [0, 1, 2, 3],
}
}
```
# Returns
Expand Down Expand Up @@ -408,7 +409,7 @@ def set_bias(
assert isinstance(scope, dict)

# Set biases for some activity
for (chip_id, core_ids) in scope.items():
for chip_id, core_ids in scope.items():
self.set_activity_bias(
bias_obj, self.chip_config[chip_id], core_ids=core_ids
)
Expand Down
1 change: 1 addition & 0 deletions pyaer/edvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import numpy as np

from pyaer import libcaer
Expand Down
1 change: 1 addition & 0 deletions pyaer/evk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import numpy as np

from pyaer import libcaer
Expand Down
1 change: 1 addition & 0 deletions pyaer/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

from typing import Any
from typing import Dict

Expand Down
2 changes: 2 additions & 0 deletions pyaer/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import logging
from logging import Logger
from typing import Optional
from typing import TextIO


# Remaps logging levels for easy access.
NOTSET = logging.NOTSET
DEBUG = logging.DEBUG
Expand Down
3 changes: 2 additions & 1 deletion pyaer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""

import importlib.util as imutil
import json
import os
Expand All @@ -16,6 +17,7 @@
from pyaer import libcaer
from pyaer import log


logger = log.get_logger("utils", pyaer.LOG_LEVEL)


Expand All @@ -42,7 +44,6 @@ def import_custom_module(custom_file, custom_class):

def parse_type(custom_str):
"""Parse custom string to its corresponding type."""

# check integer
try:
return int(custom_str)
Expand Down
77 changes: 77 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
line-length = 88

exclude = [
".git/",
"__pycache__/",
"build/",
"dist/",
"venv*/",
"docs/",
"docs/*",
"res/",
"res/*",
]

[lint]

extend-select = [
# Enable the isort rules.
"I",
# Enable all `pydocstyle` rules, limiting to those that adhere to the
# Google convention via `convention = "google"`, below.
"D",
# Doc line length.
"W505"
]

ignore = [
"E203",
"E501",
# On top of the Google convention, disable `D417`, which requires
# documentation for every function parameter.
"D417",
# Missing docstring in public module
"D100",
# Missing docstring in public class
"D101",
# Missing docstring in public method
"D102",
# Missing docstring in public function
"D103",
# Missing docstring in public package
"D104",
# Missing docstring in magic method
"D105",
# Missing docstring in `__init__`
"D107",
# 1 blank line required between summary line and description.
# This is needed because sometimes our summaries span multiple lines.
"D205",
# Multi-line docstring closing quotes should be on a separate line
# This is a result of summary lines spanning more than one line.
"D209",
# Multi-line docstring summary should start at the first line.
"D212",
# Use `r"""` if any backslashes in a docstring.
"D301",
# Doc line too long
# This is needed because we have ~400 errors otherwise.
"W505",
]


[lint.isort]
order-by-type = false
case-sensitive = false
split-on-trailing-comma = true
force-single-line = true
lines-after-imports = 2

[lint.pydocstyle]
convention = "google"

[lint.pycodestyle]
max-doc-length = 88

[format]
docstring-code-format = true
49 changes: 28 additions & 21 deletions scripts/aer_comm/aer_hub
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,61 @@ Author: Yuhuang Hu
Email : yuhuang.hu@ini.uzh.ch
"""

from __future__ import print_function, absolute_import
from __future__ import absolute_import
from __future__ import print_function

import json
import argparse
import json

from pyaer.comm import AERHub


parser = argparse.ArgumentParser("AER Hub")

parser.add_argument("--url", type=str,
default="tcp://127.0.0.1",
help="AERHub URL")
parser.add_argument("--url", type=str, default="tcp://127.0.0.1", help="AERHub URL")

# Note that the publisher port and subscriber port are
# hub_sub_port and hub_pub_port respectively.
# This reversed order is intentional.
# User doesn't need to know.
parser.add_argument("--publisher_port", type=int,
default=5100,
help="the port that connects all publishers")
parser.add_argument("--subscriber_port", type=int,
default=5099,
help="the port that connects all subscribers")
parser.add_argument(
"--publisher_port",
type=int,
default=5100,
help="the port that connects all publishers",
)
parser.add_argument(
"--subscriber_port",
type=int,
default=5099,
help="the port that connects all subscribers",
)

parser.add_argument("--aer_hub_name", type=str,
default="PyAER Message Hub")
parser.add_argument("--aer_hub_name", type=str, default="PyAER Message Hub")

args = parser.parse_args()

# print all options
print("="*50)
print("=" * 50)
print(json.dumps(args.__dict__, indent=4, sort_keys=True))
print("="*50)
print("=" * 50)


aer_hub = AERHub(url=args.url,
hub_pub_port=args.subscriber_port,
hub_sub_port=args.publisher_port,
aer_hub_name=args.aer_hub_name)
aer_hub = AERHub(
url=args.url,
hub_pub_port=args.subscriber_port,
hub_sub_port=args.publisher_port,
aer_hub_name=args.aer_hub_name,
)

aer_hub.logger.info("="*50)
aer_hub.logger.info("=" * 50)
aer_hub.logger.info("Tools")
aer_hub.logger.info("aer_hub: launch a central message relay hub")
aer_hub.logger.info("aer_lstopic: display all published topics")
aer_hub.logger.info("aer_publisher: add a custom publisher")
aer_hub.logger.info("aer_subscriber: add a custom subscriber")
aer_hub.logger.info("aer_saver: add an AER Saver")
aer_hub.logger.info("="*50)
aer_hub.logger.info("=" * 50)

# run the hub
aer_hub.run()
Loading

0 comments on commit 0552338

Please sign in to comment.