diff --git a/flake.nix b/flake.nix index 63238ed6..da425a7e 100644 --- a/flake.nix +++ b/flake.nix @@ -91,6 +91,7 @@ # Dev dependencies isort + flake8 ]; in pkgs.mkShell { diff --git a/oar/api/auth.py b/oar/api/auth.py index 7822ae82..818b2190 100644 --- a/oar/api/auth.py +++ b/oar/api/auth.py @@ -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 diff --git a/oar/api/routers/job.py b/oar/api/routers/job.py index 501212c1..e1c1429f 100644 --- a/oar/api/routers/job.py +++ b/oar/api/routers/job.py @@ -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 @@ -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("/") diff --git a/oar/api/routers/proxy.py b/oar/api/routers/proxy.py index 4bb19d97..06f9d58d 100644 --- a/oar/api/routers/proxy.py +++ b/oar/api/routers/proxy.py @@ -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" diff --git a/oar/cli/oarnodesetting.py b/oar/cli/oarnodesetting.py index bd29ee1a..819fc310 100644 --- a/oar/cli/oarnodesetting.py +++ b/oar/cli/oarnodesetting.py @@ -399,7 +399,6 @@ def cli( last_property_value, version, ): - ctx = click.get_current_context() if ctx.obj: (session, config) = ctx.obj diff --git a/oar/cli/oarstat.py b/oar/cli/oarstat.py index 682fda1c..72f23dc5 100644 --- a/oar/cli/oarstat.py +++ b/oar/cli/oarstat.py @@ -581,7 +581,6 @@ def cli( yaml, version, ): - ctx = click.get_current_context() if ctx.obj: session = ctx.obj @@ -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) diff --git a/oar/kao/quotas.py b/oar/kao/quotas.py index 55d3afed..59ed50e6 100644 --- a/oar/kao/quotas.py +++ b/oar/kao/quotas.py @@ -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: diff --git a/oar/lib/accounting.py b/oar/lib/accounting.py index c6ed26f5..931df3fc 100644 --- a/oar/lib/accounting.py +++ b/oar/lib/accounting.py @@ -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() diff --git a/oar/lib/basequery.py b/oar/lib/basequery.py index 2ad7729c..2bab67e8 100644 --- a/oar/lib/basequery.py +++ b/oar/lib/basequery.py @@ -7,8 +7,8 @@ # from . import db from .exceptions import DoesNotExist from .models import ( - EventLog, AssignedResource, + EventLog, GanttJobsPredictionsVisu, GanttJobsResourcesVisu, Job, @@ -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)) @@ -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 diff --git a/oar/lib/submission.py b/oar/lib/submission.py index be21ea82..6b846335 100644 --- a/oar/lib/submission.py +++ b/oar/lib/submission.py @@ -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: diff --git a/oar/lib/tools.py b/oar/lib/tools.py index ee9a53d3..b139dec0 100644 --- a/oar/lib/tools.py +++ b/oar/lib/tools.py @@ -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"] diff --git a/scripts/ci/check-formatting.sh b/scripts/ci/check-formatting.sh index 3ee29972..3486d857 100755 --- a/scripts/ci/check-formatting.sh +++ b/scripts/ci/check-formatting.sh @@ -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 diff --git a/tests/api/conftest.py b/tests/api/conftest.py index ede1681c..9f5b0637 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -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""" diff --git a/tests/api/test_api_tokens.py b/tests/api/test_api_tokens.py index b0655c4a..30dc5182 100644 --- a/tests/api/test_api_tokens.py +++ b/tests/api/test_api_tokens.py @@ -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]}"}, diff --git a/tests/cli/test_oarqueue.py b/tests/cli/test_oarqueue.py index 2d833604..bfbcf59d 100644 --- a/tests/cli/test_oarqueue.py +++ b/tests/cli/test_oarqueue.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index acbbd1bd..3037fca9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -91,7 +91,6 @@ def backup_and_restore_environ_function(request): """ old_environ = dict(os.environ) try: - yield finally: @@ -106,7 +105,6 @@ def backup_and_restore_environ_module(request): """ old_environ = dict(os.environ) try: - yield finally: diff --git a/tests/kao/test_db_all_in_one.py b/tests/kao/test_db_all_in_one.py index 7f1083eb..22c46c44 100644 --- a/tests/kao/test_db_all_in_one.py +++ b/tests/kao/test_db_all_in_one.py @@ -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" diff --git a/tests/kao/test_db_all_in_one_others.py b/tests/kao/test_db_all_in_one_others.py index 7a36c8cd..0e0a5183 100644 --- a/tests/kao/test_db_all_in_one_others.py +++ b/tests/kao/test_db_all_in_one_others.py @@ -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", diff --git a/tests/kao/test_db_suspend_resume.py b/tests/kao/test_db_suspend_resume.py index 5aff04c1..434057a1 100644 --- a/tests/kao/test_db_suspend_resume.py +++ b/tests/kao/test_db_suspend_resume.py @@ -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", diff --git a/tests/kao/test_temporal_quotas.py b/tests/kao/test_temporal_quotas.py index a29eff82..35102b54 100644 --- a/tests/kao/test_temporal_quotas.py +++ b/tests/kao/test_temporal_quotas.py @@ -142,7 +142,6 @@ def period_weekstart(): def test_calendar_periodical_fromJson(oar_conf): - calendar = Calendar(rules_example_full, oar_conf) print() calendar.show() diff --git a/tests/modules/test_bipbip_commander.py b/tests/modules/test_bipbip_commander.py index c0d2103f..c7d61850 100644 --- a/tests/modules/test_bipbip_commander.py +++ b/tests/modules/test_bipbip_commander.py @@ -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(" ") diff --git a/tests/modules/test_node_change_state.py b/tests/modules/test_node_change_state.py index 82061f40..47ee3de3 100644 --- a/tests/modules/test_node_change_state.py +++ b/tests/modules/test_node_change_state.py @@ -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)