Skip to content

Commit c9cc644

Browse files
chore: 🪟🫂Windows friendly tooling (#2587)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 31549a4 commit c9cc644

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ repos:
4040

4141
- id: custom-checks
4242
name: custom repo checks
43-
entry: poetry run python scripts/run_checks.py
43+
entry: python scripts/run_checks.py
4444
files: ^cognite/.*.(py|pyi)$
4545
language: system
4646
pass_filenames: true
4747
require_serial: true # avoid possible race conditions
4848

4949
- id: sync-client-codegen
5050
name: run sync codegen on changed files
51-
entry: poetry run python scripts/sync_client_codegen/main.py run --files
51+
entry: python scripts/sync_client_codegen/main.py run --files
5252
files: ^cognite/.*.(py|pyi)$
5353
language: system
5454
pass_filenames: true

scripts/sync_client_codegen/codegen_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def is_md5_hash(s: str) -> bool:
6464

6565

6666
def read_hash_from_file(path: Path) -> tuple[bool, str]:
67-
with path.open("r") as f:
67+
with path.open("r", encoding="utf-8") as f:
6868
f.readline()
6969
f.readline()
7070
maybe_hash = f.readline().strip()
@@ -260,7 +260,7 @@ def ensure_parent_dir(file: Path) -> None:
260260

261261
@cache
262262
def get_source_code(file: Path) -> str:
263-
return file.read_text()
263+
return file.read_text(encoding="utf-8")
264264

265265

266266
def filter_base_apis_and_sort_alphabetically(dct: dict[str, str]) -> list[tuple[str, str]]:

scripts/sync_client_codegen/create_sync_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
verify_cognite_client_is_up_to_date,
4242
)
4343

44-
SYNC_API_TEMPLATE = Path("scripts/sync_client_codegen/sync_api_template.txt").read_text()
44+
SYNC_API_TEMPLATE = Path("scripts/sync_client_codegen/sync_api_template.txt").read_text(encoding="utf-8")
4545

4646

4747
def _generate_code_for_single_sync_api(
@@ -258,7 +258,7 @@ def _compare_normalized_files_and_maybe_update_hash_only(files_to_update: set[Si
258258
for f in files_to_update:
259259
f.temp_filepath = tmp_dir / f.filepath
260260
ensure_parent_dir(f.temp_filepath)
261-
f.temp_filepath.write_text(f.get_new_source)
261+
f.temp_filepath.write_text(f.get_new_source, encoding="utf-8")
262262

263263
# Before compare, we need to run ruff (large overhead, so we do it once for all files):
264264
run_ruff([f.temp_filepath for f in files_to_update], verbose=False)
@@ -295,7 +295,7 @@ def _compare_normalized_files_and_maybe_update_hash_only(files_to_update: set[Si
295295
# Note: DO NOT use normalized_src here, the reason we do all of this is precisely to preserve
296296
# e.g. type-ignore comments that would otherwise be lost on regeneration.
297297
current_source = get_source_code(write_file)
298-
write_file.write_text(current_source.replace(existing_hash, f.get_new_hash))
298+
write_file.write_text(current_source.replace(existing_hash, f.get_new_hash), encoding="utf-8")
299299

300300

301301
def _report_after_verification(
@@ -335,7 +335,7 @@ def _report_after_verification(
335335
def _write_updated_sync_api_files(files_to_update: set[SingleAPIFile]) -> None:
336336
for f in files_to_update:
337337
ensure_parent_dir(f.filepath)
338-
f.filepath.write_text(f.get_new_source)
338+
f.filepath.write_text(f.get_new_source, encoding="utf-8")
339339
if f.class_name:
340340
print(f"- Generated/updated sync API code for {f.class_name} from '{f.read_filepath}' ✅")
341341
else:
@@ -391,7 +391,7 @@ def _run_files(
391391

392392
if client_has_changed:
393393
to_be_linted.append(SYNC_CLIENT_PATH)
394-
SYNC_CLIENT_PATH.write_text(new_client_source_code)
394+
SYNC_CLIENT_PATH.write_text(new_client_source_code, encoding="utf-8")
395395
print(f"- Regenerated (sync) CogniteClient: '{SYNC_CLIENT_PATH}' ✅")
396396
elif args.verbose:
397397
print(f"- Skipped (sync) CogniteClient, is up to date: '{SYNC_CLIENT_PATH}' ⏭️")

scripts/sync_client_codegen/create_sync_client.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from tempfile import NamedTemporaryFile
2+
from tempfile import TemporaryDirectory
33

44
from scripts.sync_client_codegen.codegen_utils import (
55
filter_base_apis_and_sort_alphabetically,
@@ -14,7 +14,7 @@
1414
SYNC_CLIENT_PATH,
1515
)
1616

17-
COGNITE_CLIENT_TEMPLATE = Path("scripts/sync_client_codegen/sync_client_template.txt").read_text()
17+
COGNITE_CLIENT_TEMPLATE = Path("scripts/sync_client_codegen/sync_client_template.txt").read_text(encoding="utf-8")
1818

1919

2020
def create_sync_cognite_client(
@@ -39,10 +39,9 @@ def create_sync_cognite_client(
3939

4040

4141
def verify_cognite_client_is_up_to_date(new_source: str) -> bool:
42-
with NamedTemporaryFile(mode="w+", suffix=".py") as f:
43-
f.write(new_source)
44-
f.flush() # Ensure content is written before ruff reads it
45-
path = Path(f.name)
42+
with TemporaryDirectory() as tmp_dir:
43+
path = Path(tmp_dir) / "sync_client.py"
44+
path.write_text(new_source, encoding="utf-8")
4645
run_ruff_direct(path)
4746
new_file_ast = get_canonical_source(path)
4847

0 commit comments

Comments
 (0)