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

Setup linting and formatting using ruff #62

Merged
merged 14 commits into from
Oct 7, 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
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

8 changes: 2 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ jobs:
${{ runner.os }}-pip-
- name: Install Hatch
uses: pypa/hatch@a3c83ab3d481fbc2dc91dd0088628817488dd1d5
- name: Install application and deps
run: |
python -m pip install --upgrade pip
pip install .
- name: Linting
run: |
pip install flake8
flake8 .
pip install ruff
ruff check
- name: Run tests
run: |
hatch run test:pytest
34 changes: 24 additions & 10 deletions bin/validate-raythena-job.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#!/usr/bin/env python
from __future__ import print_function

from array import array
import argparse
import json
import os.path as path

from array import array
import ROOT


def get_event_numbers(filename):
f = ROOT.TFile.Open(filename)
tree = f.Get("POOLCollectionTree")
event_number = array('Q', [0])
event_number = array("Q", [0])
n_entries = tree.GetEntries()
tree.SetBranchAddress('EventNumber', event_number)
tree.SetBranchAddress("EventNumber", event_number)
event_numbers = list()
for n in range(n_entries):
tree.GetEntry(n)
Expand All @@ -23,10 +21,10 @@ def get_event_numbers(filename):


def validate_job(job_dir, job_state_file):
with open(job_state_file, 'r') as f:
with open(job_state_file) as f:
job_state = json.load(f)
merged_input_files = job_state["merged"]
merged_output_files = set([list(x.keys())[0] for x in merged_input_files.values()])
merged_output_files = set([next(iter(x.keys())) for x in merged_input_files.values()])
event_numbers = set()
for output_file in merged_output_files:
output_file_abs = path.join(job_dir, "final", output_file)
Expand All @@ -37,14 +35,30 @@ def validate_job(job_dir, job_state_file):
current_event_numbers = get_event_numbers(output_file_abs)
unique_current_event_numbers = set(current_event_numbers)
if len(unique_current_event_numbers) != len(current_event_numbers):
print("Duplicate events in file " + output_file + "(" + str(len(current_event_numbers) - len(unique_current_event_numbers)) + "): ")
print(
"Duplicate events in file "
+ output_file
+ "("
+ str(len(current_event_numbers) - len(unique_current_event_numbers))
+ "): "
)
exit(1)
print(str(len(current_event_numbers)) + " events in file " + output_file)
if not unique_current_event_numbers.isdisjoint(event_numbers):
print("Found duplicate events in file " + output_file + ": " + str(unique_current_event_numbers & event_numbers))
print(
"Found duplicate events in file "
+ output_file
+ ": "
+ str(unique_current_event_numbers & event_numbers)
)
exit(1)
event_numbers |= unique_current_event_numbers
print("No duplicate found. # events merged: " + str(len(event_numbers)) + ", # of files: " + str(len(merged_output_files)))
print(
"No duplicate found. # events merged: "
+ str(len(event_numbers))
+ ", # of files: "
+ str(len(merged_output_files))
)


def main():
Expand Down
21 changes: 12 additions & 9 deletions example/standalone_ray_test_hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import argparse
import os
import platform
import time
from pprint import pprint
import ray
import time


def build_nodes_resource_list(redis_ip: str):
nodes = ray.nodes()
resource_list = list()
for node in nodes:
naddr = node['NodeManagerAddress']
naddr = node["NodeManagerAddress"]
if naddr == redis_ip:
continue
else:
Expand All @@ -27,7 +27,7 @@ def build_nodes_resource_list(redis_ip: str):


@ray.remote
class actor():
class actor:
def __init__(self) -> None:
self.pid = os.getpid()
self.hostname = platform.node()
Expand All @@ -42,8 +42,11 @@ def ping(self):

def main(redis_ip: str, redis_port: str, redis_password: str):
redis_address = f"{redis_ip}:{redis_port}"
ray.init(ignore_reinit_error=True,
address="%s" % redis_address, _redis_password="%s" % redis_password)
ray.init(
ignore_reinit_error=True,
address=f"{redis_address}",
_redis_password=f"{redis_password}",
)

# show the ray cluster
print(f"Ray Cluster resources : {ray.cluster_resources()}")
Expand Down Expand Up @@ -73,10 +76,10 @@ def main(redis_ip: str, redis_port: str, redis_password: str):


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Wait on ray head node or workers to connect')
parser.add_argument('--redis-ip', default="%s" % (os.environ["RAYTHENA_RAY_HEAD_IP"]))
parser.add_argument('--redis-port', default="%s" % (os.environ["RAYTHENA_RAY_REDIS_PORT"]))
parser.add_argument('--redis-password', default=os.environ["RAYTHENA_RAY_REDIS_PASSWORD"])
parser = argparse.ArgumentParser(description="Wait on ray head node or workers to connect")
parser.add_argument("--redis-ip", default="{}".format(os.environ["RAYTHENA_RAY_HEAD_IP"]))
parser.add_argument("--redis-port", default="{}".format(os.environ["RAYTHENA_RAY_REDIS_PORT"]))
parser.add_argument("--redis-password", default=os.environ["RAYTHENA_RAY_REDIS_PASSWORD"])
args = parser.parse_args()
print(f"args : {args}")
main(args.redis_ip, args.redis_port, args.redis_password)
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ dependencies = [

[tool.ruff]

line-length = 80
line-length = 120
indent-width = 4

target-version = "py39"

[tool.ruff.lint]

select = [
Expand All @@ -62,5 +64,10 @@ select = [
# flake8-simplify
"SIM",
# isort
"I"
"I",
# Ruff
"RUF",
]

[tool.ruff.lint.isort]
no-lines-before = ["third-party", "first-party", "standard-library"]
1 change: 1 addition & 0 deletions src/raythena/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
try:
from . import _version

__version__ = _version.__version__
except: # noqa: E722
__version__ = "0.0.0"
Loading
Loading