Skip to content

Commit 8066d6a

Browse files
committed
Fix lint issues across praktika
1 parent fe2518b commit 8066d6a

39 files changed

Lines changed: 478 additions & 146 deletions

ci/tests/example_2/some_job_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from praktika.settings import Settings
33
from praktika.utils import Shell, Utils
44

5-
# cache-bust: 2026-06-23
5+
# cache-bust: 2026-07-13
66

77
if __name__ == "__main__":
88
# 1. do some work

ci/tests/test_runner.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,84 @@ def test_non_docker_job_does_not_mutate_parent_pythonpath(self):
269269
finally:
270270
os.environ.pop("PYTHONPATH", None)
271271

272+
def test_docker_job_mounts_installed_package_dir(self):
273+
Path(_TEST_TEMP_DIR).mkdir(parents=True, exist_ok=True)
274+
275+
import sys
276+
import types
277+
from unittest import mock
278+
279+
with mock.patch.dict(sys.modules, {"requests": types.ModuleType("requests")}):
280+
from praktika import runner
281+
282+
captured = {}
283+
284+
class DummyTeePopen:
285+
def __init__(self, command, **kwargs):
286+
captured["command"] = command
287+
self.timeout_exceeded = False
288+
289+
def __enter__(self):
290+
return self
291+
292+
def __exit__(self, exc_type, exc_val, exc_tb):
293+
return False
294+
295+
def wait(self):
296+
return 0
297+
298+
def get_latest_log(self, max_lines=20):
299+
return ""
300+
301+
staged_package_dir = Path(runner._staged_praktika_package_dir())
302+
staged_praktika_package = staged_package_dir / "praktika"
303+
job = SimpleNamespace(
304+
name="docker-job",
305+
run_in_docker="example/image:latest",
306+
timeout=1,
307+
timeout_shell_cleanup=None,
308+
enable_gh_auth=False,
309+
command="echo ok",
310+
)
311+
workflow = SimpleNamespace(name="workflow")
312+
313+
with mock.patch.object(runner, "TeePopen", DummyTeePopen), mock.patch.object(
314+
runner.Shell, "check", lambda *args, **kwargs: False
315+
), mock.patch.object(
316+
runner.Shell, "run", lambda *args, **kwargs: None
317+
), mock.patch.object(
318+
runner.Result,
319+
"from_fs",
320+
staticmethod(
321+
lambda *args, **kwargs: SimpleNamespace(
322+
is_completed=lambda: True,
323+
is_running=lambda: False,
324+
is_error=lambda: False,
325+
dump=lambda: None,
326+
)
327+
),
328+
), mock.patch.object(
329+
runner._Environment,
330+
"get",
331+
staticmethod(
332+
lambda: SimpleNamespace(
333+
WORKFLOW_CONFIG=None,
334+
dump=lambda: None,
335+
)
336+
),
337+
):
338+
rc = runner.Runner()._run(workflow=workflow, job=job, no_docker=False)
339+
340+
self.assertEqual(rc, 0)
341+
self.assertTrue(staged_package_dir.is_dir())
342+
self.assertTrue(staged_praktika_package.is_dir())
343+
self.assertIn(
344+
f"--volume {staged_package_dir}:{staged_package_dir}",
345+
captured["command"],
346+
)
347+
self.assertIn(f"-e PYTHONPATH={staged_package_dir}", captured["command"])
348+
self.assertNotIn("PYTHONPATH=.", captured["command"])
349+
272350
def test_exit_code_result_synthesizes_fail_on_nonzero_exit(self):
273351
"""enable_exit_code_result=True + script that exits non-zero
274352
without dumping a Result -> synthesized FAIL Result with the

ci/workflows/praktika_pr_advanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ci.settings.settings import RunnerLabels
99
from praktika.settings import Settings
1010

11-
_HEAD_PRAKTIKA_VERSION = "0.1.8"
11+
_HEAD_PRAKTIKA_VERSION = "0.1.9"
1212

1313
artifact = Artifact.Config(name="greet", type=Artifact.Type.S3, path="./artifact.txt")
1414

praktika/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def main(argv=None):
359359
for workflow in workflows:
360360
print(
361361
f"Workflow [{workflow.name}] has jobs:\n"
362-
" \"" + f'"\n "'.join([job.name for job in workflow.jobs]) + '"'
362+
' "' + '"\n "'.join([job.name for job in workflow.jobs]) + '"'
363363
)
364364
Utils.exit_with_error("Job name is required to run a job.")
365365

praktika/_environment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def from_env(cls) -> "_Environment":
165165
if LINKED_PR_NUMBER
166166
else ""
167167
)
168-
except:
168+
except Exception:
169169
LINKED_PR_NUMBER = 0
170170
CHANGE_URL = ""
171171

@@ -356,7 +356,7 @@ def get(cls):
356356
env = cls.from_workflow_data()
357357
env.dump()
358358
return env
359-
except FileNotFoundError as e:
359+
except FileNotFoundError:
360360
# For workflows without Config job
361361
print(
362362
f"NOTE: Workflow context file [{Settings.WORKFLOW_STATUS_FILE}] does not exist - read context from GH event"
@@ -428,7 +428,7 @@ def get_s3_prefix_static(cls, pr_number, branch, sha, workflow_name="", latest=F
428428
prefix = f"REFs/{branch}"
429429
assert sha or latest
430430
if latest:
431-
prefix += f"/latest"
431+
prefix += "/latest"
432432
elif sha:
433433
prefix += f"/{sha}"
434434
if cls._should_include_workflow_name_in_s3_prefix(workflow_name):

praktika/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def push_success_record(
5353
)
5454
assert (
5555
Settings.CACHE_S3_PATH
56-
), f"Setting CACHE_S3_PATH must be defined with enabled CI Cache"
56+
), "Setting CACHE_S3_PATH must be defined with enabled CI Cache"
5757
record_path = f"{Settings.CACHE_S3_PATH}/v{Settings.CACHE_VERSION}/{Utils.normalize_string(job_name)}/{job_digest}/{type_}"
5858
record_file = Path(Settings.TEMP_DIR) / type_
5959
record.dump(record_file)
@@ -69,7 +69,7 @@ def fetch_success(self, job_name, job_digest):
6969
type_ = Cache.CacheRecord.Type.SUCCESS
7070
assert (
7171
Settings.CACHE_S3_PATH
72-
), f"Setting CACHE_S3_PATH must be defined with enabled CI Cache"
72+
), "Setting CACHE_S3_PATH must be defined with enabled CI Cache"
7373
record_path = f"{Settings.CACHE_S3_PATH}/v{Settings.CACHE_VERSION}/{Utils.normalize_string(job_name)}/{job_digest}/{type_}"
7474
record_file_local_dir = (
7575
f"{Settings.CACHE_LOCAL_PATH}/{Utils.normalize_string(job_name)}/"

praktika/cidb.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import copy
22
import dataclasses
33
import json
4-
import os
54
import time
65
import urllib
76
from typing import List, Optional
@@ -15,9 +14,10 @@
1514
if not Info().is_local_run:
1615
raise ex
1716
else:
18-
print(
19-
f"WARNING: 'requests' module is not installed: {ex}. CIDB will not work - ok for local runs only."
20-
)
17+
print(
18+
"WARNING: 'requests' module is not installed: "
19+
f"{ex}. CIDB will not work - ok for local runs only."
20+
)
2121

2222
from .result import Result
2323
from .settings import Settings
@@ -429,7 +429,7 @@ def check(self):
429429
# Create a session object
430430
params = {
431431
"database": Settings.CI_DB_DB_NAME,
432-
"query": f"SELECT 1",
432+
"query": "SELECT 1",
433433
}
434434
error = ""
435435
for retry in range(2):

praktika/gh.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def get_changed_files(cls, strict=False) -> List[str]:
7979
raise RuntimeError(
8080
f"Failed to extract repository name from remote URL [{repo_url}]"
8181
)
82-
sha = Shell.get_output(f"git rev-parse HEAD", strict=True)
82+
sha = Shell.get_output("git rev-parse HEAD", strict=True)
8383

8484
assert repo_name
8585
print(repo_name)
@@ -797,7 +797,7 @@ def post_updateable_comment(
797797
else:
798798
if not only_update:
799799
cmd = f"gh pr comment {pr} --body-file {temp_file_path}"
800-
print(f"Create new comment")
800+
print("Create new comment")
801801
res = cls.do_command_with_retries(cmd)
802802
else:
803803
print(
@@ -856,7 +856,7 @@ def get_pr_title_body_labels(cls, pr=None, repo=None):
856856
pr_data = json.loads(output)
857857
title = pr_data["title"]
858858
body = pr_data["body"]
859-
labels = [l["name"] for l in pr_data["labels"]]
859+
labels = [label["name"] for label in pr_data["labels"]]
860860
except Exception:
861861
print("ERROR: Failed to get PR data")
862862
traceback.print_exc()
@@ -1115,7 +1115,7 @@ class ResultSummaryForGH:
11151115
sha: str = ""
11161116
start_time: Optional[float] = None
11171117
duration: Optional[float] = None
1118-
failed_results: List["ResultSummaryForGH"] = dataclasses.field(
1118+
failed_results: List["GH.ResultSummaryForGH"] = dataclasses.field(
11191119
default_factory=list
11201120
)
11211121
info: str = ""

praktika/infrastructure/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
"DedicatedHost",
1919
"EC2Instance",
2020
"IAMInstanceProfile",
21+
"IAMRole",
2122
"ImageBuilder",
2223
"Lambda",
2324
"LaunchTemplate",
2425
"Components",
26+
"ReportPage",
27+
"SecretParameter",
2528
"SQSQueue",
29+
"Storage",
30+
"VPC",
2631
]

praktika/infrastructure/autoscaling_group.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from ._utils import aws_client
2-
import json
3-
from dataclasses import asdict, dataclass, field
2+
from dataclasses import dataclass, field
43
from typing import Any, Dict, List, Optional
54

65

@@ -56,8 +55,6 @@ def fetch(self):
5655
Raises:
5756
Exception: If ASG does not exist or AWS API call fails
5857
"""
59-
import boto3
60-
6158
asg_client = aws_client("autoscaling", self.region, self.name)
6259

6360
resp = asg_client.describe_auto_scaling_groups(
@@ -125,8 +122,6 @@ def _resolve_subnet_ids(self) -> List[str]:
125122
f"subnet_ids must be specified (non-empty) for ASG '{self.name}' or provide vpc_id/vpc_name for subnet discovery"
126123
)
127124

128-
import boto3
129-
130125
ec2 = aws_client("ec2", self.region, self.name)
131126

132127
vpc_id = self.vpc_id
@@ -242,7 +237,6 @@ def deploy(self):
242237
- This component intentionally does not try to manage every ASG attribute.
243238
- It focuses on core runner-like ASG needs: subnets, LT, capacity, target groups, tags.
244239
"""
245-
import boto3
246240
from botocore.config import Config
247241

248242
self.ext.pop("deferred_missing_launch_template", None)
@@ -392,7 +386,6 @@ def restart(self):
392386
return self
393387

394388
def delete(self):
395-
import boto3
396389
client = aws_client("autoscaling", self.region, self.name)
397390
try:
398391
client.delete_auto_scaling_group(

0 commit comments

Comments
 (0)