Skip to content

Commit

Permalink
[formatting] run isort black and flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
adfaure committed Dec 6, 2024
1 parent 8ccb3f2 commit 1e15c87
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 30 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
# Docs
sphinx
sphinx-rtd-theme
flake8
];
in
pkgs.mkShell {
Expand Down
1 change: 0 additions & 1 deletion oar/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
def get_token_data(
credentials: Annotated[str, Depends(oauth2_scheme)], config=Depends(get_config)
) -> Optional[dict]:

token = credentials.credentials

# FIXME: HAndlre er
Expand Down
10 changes: 6 additions & 4 deletions oar/api/routers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from oar.cli.oarhold import oarhold
from oar.cli.oarresume import oarresume
from oar.lib.configuration import Configuration
from oar.lib.job_handling import convert_status_code
from oar.lib.models import Job
from oar.lib.submission import JobParameters, Submission, check_reservation
from oar.lib.job_handling import convert_status_code

from ..auth import need_authentication
from ..dependencies import get_config, get_db
Expand Down Expand Up @@ -53,11 +53,13 @@ def attach_nodes(job, jobs_resources):
job["nodes"].append(node)
network_addresses.append(node["network_address"])


def attach_exit_status(job):
if 'exit_code' in job and job["exit_code"] is not None:
job["exit_status_code"] = convert_status_code(job["exit_code"])
if "exit_code" in job and job["exit_code"] is not None:
job["exit_status_code"] = convert_status_code(job["exit_code"])
else:
job["exit_status_code"] = None
job["exit_status_code"] = None


@router.get("")
@router.get("/")
Expand Down
1 change: 0 additions & 1 deletion oar/api/routers/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def proxy(
db: Session = Depends(get_db),
config: Configuration = Depends(get_config),
):

if "OARDIR" not in os.environ:
os.environ["OARDIR"] = "/usr/local/lib/oar"

Expand Down
1 change: 0 additions & 1 deletion oar/cli/oarnodesetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ def cli(
last_property_value,
version,
):

ctx = click.get_current_context()
if ctx.obj:
(session, config) = ctx.obj
Expand Down
5 changes: 3 additions & 2 deletions oar/cli/oarstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ def cli(
yaml,
version,
):

ctx = click.get_current_context()
if ctx.obj:
session = ctx.obj
Expand Down Expand Up @@ -649,7 +648,9 @@ def cli(

for job in jobs:
job.cpuset_name = get_job_cpuset_name(session, job.id, job=job)
job.exit_status_code = str(get_job_exit_status_code(session, job.id, job=job))
job.exit_status_code = str(
get_job_exit_status_code(session, job.id, job=job)
)

print_jobs(session, True, jobs, format, show_resources, full)

Expand Down
1 change: 0 additions & 1 deletion oar/kao/quotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def next_rules(self, t_epoch):
return (rules_id, remaining_duration)

def show(self, t=None, begin=None, end=None, check=True, json=False):

t_epoch = None
if t:
try:
Expand Down
4 changes: 3 additions & 1 deletion oar/lib/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ def check_accounting_update(session: Session, window_size: int):
nb_resources,
)

session.query(Job).filter(Job.accounted == "NO").update({Job.accounted: "YES"}, synchronize_session=False)
session.query(Job).filter(Job.accounted == "NO").update(
{Job.accounted: "YES"}, synchronize_session=False
)

session.commit()

Expand Down
22 changes: 18 additions & 4 deletions oar/lib/basequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# from . import db
from .exceptions import DoesNotExist
from .models import (
EventLog,
AssignedResource,
EventLog,
GanttJobsPredictionsVisu,
GanttJobsResourcesVisu,
Job,
Expand Down Expand Up @@ -268,7 +268,14 @@ def get_jobs_events(self, jobs):
"""Returns the list of events associated to the job passed
in parameter."""
db = self.session
columns = (EventLog.id, EventLog.date, EventLog.description, EventLog.type, EventLog.to_check, EventLog.job_id)
columns = (
EventLog.id,
EventLog.date,
EventLog.description,
EventLog.type,
EventLog.to_check,
EventLog.job_id,
)
query = (
db.query(Job.id, EventLog)
.options(Load(EventLog).load_only(*columns))
Expand All @@ -285,11 +292,18 @@ def get_one_job_events(self, job):
"""Returns the list of events associated to the job passed
in parameter."""
db = self.session
columns = (EventLog.id, EventLog.date, EventLog.description, EventLog.type, EventLog.to_check, EventLog.job_id)
columns = (
EventLog.id,
EventLog.date,
EventLog.description,
EventLog.type,
EventLog.to_check,
EventLog.job_id,
)
query = (
db.query(EventLog)
.options(Load(EventLog).load_only(*columns))
.filter_by(job_id = job.id)
.filter_by(job_id=job.id)
)
return query

Expand Down
1 change: 0 additions & 1 deletion oar/lib/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ def apply_admission_rules(
if ("ADMISSION_RULES_IN_FILES" in config) and (
config["ADMISSION_RULES_IN_FILES"] == "yes"
):

if rule:
regex = rule
else:
Expand Down
1 change: 0 additions & 1 deletion oar/lib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def create_almighty_socket(server_hostname: str, server_port: str): # pragma: n
def notify_almighty(
cmd: str, job_id: Optional[int] = None, args: Optional[List[str]] = None
) -> bool: # pragma: no cover

if not almighty_socket:
create_almighty_socket(
config["SERVER_HOSTNAME"], config["APPENDICE_SERVER_PORT"]
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/check-formatting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ set -e

echo "-- Check imports"
isort --version
isort . --check-only --diff
isort oar tests --check-only --diff

echo "-- Check code formatting"
black --version
black . --check --diff
black oar tests --check --diff

echo "-- Static code check"
flake8 --version
Expand Down
1 change: 0 additions & 1 deletion tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def assign_node_list(nodes): # TODO TOREPLACE


def write_banned_file(config):

now = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")

banned_file = f"""
Expand Down
1 change: 0 additions & 1 deletion tests/api/test_api_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_invalid_token(client):
[("bob", 200), ("globally_revoked_token", 401), ("old_token", 401)],
)
def test_token_revocation(client, user_tokens, user, status_code):

res = client.get(
"/check_token",
headers={"Authorization": f"Bearer {user_tokens[user]}"},
Expand Down
1 change: 0 additions & 1 deletion tests/cli/test_oarqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def minimal_db_initialization(request, setup_config):
scoped = scoped_session(session_factory)

with ephemeral_session(scoped, engine, bind=engine) as session:

Queue.create(session, name="default", scheduler_policy="kao", state="unkown")
yield session

Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def backup_and_restore_environ_function(request):
"""
old_environ = dict(os.environ)
try:

yield

finally:
Expand All @@ -106,7 +105,6 @@ def backup_and_restore_environ_module(request):
"""
old_environ = dict(os.environ)
try:

yield

finally:
Expand Down
1 change: 0 additions & 1 deletion tests/kao/test_db_all_in_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ def test_db_all_in_one_sleep_node_1(
def test_db_all_in_one_wakeup_node_energy_saving_internal_1(
monkeypatch, minimal_db_initialization, setup_config, active_energy_saving
):

config = active_energy_saving

config["ENERGY_SAVING_INTERNAL"] = "yes"
Expand Down
1 change: 0 additions & 1 deletion tests/kao/test_db_all_in_one_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def minimal_db_initialization(request, setup_config):
scoped = scoped_session(session_factory)

with ephemeral_session(scoped, engine, bind=engine) as session:

Queue.create(
session,
name="default",
Expand Down
1 change: 0 additions & 1 deletion tests/kao/test_db_suspend_resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def minimal_db_initialization(request, setup_config):
scoped = scoped_session(session_factory)

with ephemeral_session(scoped, engine, bind=engine) as session:

Queue.create(
session,
name="default",
Expand Down
1 change: 0 additions & 1 deletion tests/kao/test_temporal_quotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def period_weekstart():


def test_calendar_periodical_fromJson(oar_conf):

calendar = Calendar(rules_example_full, oar_conf)
print()
calendar.show()
Expand Down
8 changes: 7 additions & 1 deletion tests/modules/test_bipbip_commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ def test_bipbip_commander_OAREXEC(setup):
# exitcode = bipbip_commander.bipbip_leon_executors[10].exitcode
print("helloe", fake_popen)
assert bipbip_commander.bipbip_leon_commands_to_run == []
assert ["/usr/local/lib/oar/oar-bipbip", "10", "2", "N", "34",] == fake_popen[
assert [
"/usr/local/lib/oar/oar-bipbip",
"10",
"2",
"N",
"34",
] == fake_popen[
"cmd"
].split(" ")

Expand Down
1 change: 0 additions & 1 deletion tests/modules/test_node_change_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ def test_node_change_state_resource_dead_assigned(


def assign_resources_with_range(session, job_id, from_, to_):

moldable = (
session.query(MoldableJobDescription)
.filter(MoldableJobDescription.job_id == job_id)
Expand Down

0 comments on commit 1e15c87

Please sign in to comment.