Skip to content

Commit 6e7c6f9

Browse files
committed
chore: refactor operations and update pre-commit policies
- Moved several operation modules to a new `_internal` directory to better separate implementation details from the public API. - Updated `pyproject.toml` to reflect changes in file paths and adjusted pre-commit policy limits for maximum file lines, directory entries, and snake binding words. - Revised documentation to point to the new internal module paths for tokenizer artifacts and dependency strategies. - Enhanced unit tests to accommodate the refactored module structure and ensure continued functionality.
1 parent 0fab71b commit 6e7c6f9

38 files changed

Lines changed: 2707 additions & 2585 deletions

docs/advanced/tokenizer-artifact.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ client:
4747

4848
## API
4949

50-
- `init_tokenizer_artifact_directory` and helpers: **Tokenizer artifact** in [API Reference](../reference/api.md) (`yt_framework.operations.tokenizer_artifact`).
50+
- `init_tokenizer_artifact_directory` and helpers: **Tokenizer artifact** in [API Reference](../reference/api.md) (`yt_framework.operations._internal.tokenizer_artifact`).
5151
- Exported on `yt_framework.operations` for advanced callers.
5252

5353
## See also

docs/operations/command-mode-map-reduce.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ If omitted, the uploader picks defaults (e.g. first existing among `reducer.py`,
6767

6868
## Removability
6969

70-
- Logic lives mainly in `yt_framework/operations/tar_command_wiring.py`, `yt_framework/job_command/`, and branches in `dependency_strategy.py` / `map_reduce.py`.
70+
- Logic lives mainly in `yt_framework/operations/_internal/tar_command_wiring.py`, `yt_framework/job_command/`, and branches in `_internal/dependency_strategy.py` / `map_reduce.py`.
7171
- Disable by omitting `tar_command_bootstrap` or setting it `false`.
7272

7373
## Dev client

docs/reference/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ YQL operations are implemented as methods on `BaseYTClient` and its subclasses (
149149
### Tokenizer artifact
150150

151151
```{eval-rst}
152-
.. automodule:: yt_framework.operations.tokenizer_artifact
152+
.. automodule:: yt_framework.operations._internal.tokenizer_artifact
153153
:members:
154154
:undoc-members:
155155
:show-inheritance:

pyproject.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,17 @@ ignore = [
9292
# Subprocess jobs run bash -c with pipeline-built commands (Bandit cannot verify).
9393
"yt_framework/yt/client_dev.py" = ["ARG002", "PLR0913"]
9494
# Complexity: remaining high-arity API surfaces are isolated to explicit modules.
95-
"yt_framework/operations/dependency_strategy.py" = ["PLR0913"]
95+
"yt_framework/operations/_internal/dependency_strategy.py" = ["PLR0913"]
9696
"yt_framework/operations/map_reduce.py" = ["PLR0913"]
9797
"yt_framework/operations/s3.py" = ["PLR0913"]
9898
"yt_framework/operations/upload.py" = ["PLR0913"]
9999
"yt_framework/yt/client_base.py" = ["PLR0913"]
100100
"yt_framework/yt/client_prod.py" = ["PLR0913"]
101+
# Split-out client bodies: same API arity and dev unused-arg rules as monolithic clients.
102+
"yt_framework/yt/_client_split/_client_dev_ops_mixin.py" = ["ARG002", "PLR0913"]
103+
"yt_framework/yt/_client_split/_client_dev_yql_mixin.py" = ["PLR0913"]
104+
"yt_framework/yt/_client_split/_client_prod_ops_mixin.py" = ["PLR0913"]
105+
"yt_framework/yt/_client_split/_client_prod_yql_mixin.py" = ["PLR0913"]
101106
"yt_framework/yt/_client_prod_runtime.py" = ["PLR0913", "ANN401", "TC003", "TC001"]
102107
"yt_framework/yt/_client_dev_runtime.py" = ["PLR0913", "ANN401", "TC003"]
103108
"yt_framework/yt/yql_builder.py" = ["PLR0913"]
@@ -200,17 +205,17 @@ line-ending = "auto"
200205

201206
[tool.yt_framework.pre_commit.max_file_lines]
202207
enabled = true
203-
limit = 1500
208+
limit = 800
204209
roots = ["yt_framework", "ytjobs"]
205210

206211
[tool.yt_framework.pre_commit.max_dir_entries]
207212
enabled = true
208-
limit = 15
213+
limit = 12
209214
roots = ["yt_framework", "ytjobs"]
210215

211216
[tool.yt_framework.pre_commit.max_snake_binding_words]
212217
enabled = true
213-
limit = 8
218+
limit = 6
214219
roots = ["yt_framework", "ytjobs"]
215220

216221
[tool.vulture]

tests/test_client_prod.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from yt_framework.yt._client_prod_runtime import (
1313
_apply_command_leg_format,
14-
_apply_max_row_weight_to_spec_builder,
15-
_apply_spec_options_and_split_run_operation_kwargs,
14+
_apply_max_row_weight_spec_builder,
15+
_apply_spec_options_split_run_kwargs,
1616
)
1717
from yt_framework.yt.client_base import OperationResources
1818
from yt_framework.yt.client_prod import YTProdClient
@@ -52,7 +52,7 @@ def title(self, value: str) -> "_FakeSpecBuilder":
5252

5353
def test_apply_spec_options_splits_run_operation_kwargs_from_builder_chain() -> None:
5454
b = _FakeSpecBuilder()
55-
b2, run_op = _apply_spec_options_and_split_run_operation_kwargs(
55+
b2, run_op = _apply_spec_options_split_run_kwargs(
5656
b,
5757
{"title": "my_job", "sync": True},
5858
)
@@ -64,7 +64,7 @@ def test_apply_spec_options_splits_run_operation_kwargs_from_builder_chain() ->
6464
def test_apply_spec_options_raises_value_error_on_unknown_operation_kwarg() -> None:
6565
b = _FakeSpecBuilder()
6666
with pytest.raises(ValueError, match="Unknown YT operation option 'bad_kw'"):
67-
_apply_spec_options_and_split_run_operation_kwargs(b, {"bad_kw": 1})
67+
_apply_spec_options_split_run_kwargs(b, {"bad_kw": 1})
6868

6969

7070
class _LegBuilderWithFormat:
@@ -134,7 +134,7 @@ def _prod_client_with_run_operation_id(
134134

135135
def _stub_split_run_operation_kwargs(monkeypatch: pytest.MonkeyPatch) -> None:
136136
monkeypatch.setattr(
137-
"yt_framework.yt._client_prod_runtime._apply_spec_options_and_split_run_operation_kwargs",
137+
"yt_framework.yt._client_prod_runtime._apply_spec_options_split_run_kwargs",
138138
lambda sb, kw: (sb, {}),
139139
)
140140

@@ -152,25 +152,23 @@ def test_apply_command_leg_format_skips_format_for_typed_job_leg() -> None:
152152
assert b.format_specs == []
153153

154154

155-
def test_apply_max_row_weight_to_spec_builder_writes_bytes_to_table_writer() -> None:
155+
def test_apply_max_row_weight_spec_builder_writes_bytes_to_table_writer() -> None:
156156
b = _BuilderWithTableWriter()
157-
out = _apply_max_row_weight_to_spec_builder(b, "128M")
157+
out = _apply_max_row_weight_spec_builder(b, "128M")
158158
assert out is b
159159
assert b.payload == {"max_row_weight": 134217728}
160160

161161

162-
def test_apply_max_row_weight_to_spec_builder_uses_job_io_fallback_with_bytes() -> None:
162+
def test_apply_max_row_weight_spec_builder_uses_job_io_fallback_with_bytes() -> None:
163163
b = _BuilderWithJobIo()
164-
out = _apply_max_row_weight_to_spec_builder(b, "64M")
164+
out = _apply_max_row_weight_spec_builder(b, "64M")
165165
assert out is b
166166
assert b.payload == {"table_writer": {"max_row_weight": 67108864}}
167167

168168

169-
def test_apply_max_row_weight_to_spec_builder_prefers_table_writer_over_job_io() -> (
170-
None
171-
):
169+
def test_apply_max_row_weight_spec_builder_prefers_table_writer_over_job_io() -> None:
172170
b = _BuilderWithTableWriterAndJobIo()
173-
out = _apply_max_row_weight_to_spec_builder(b, "64M")
171+
out = _apply_max_row_weight_spec_builder(b, "64M")
174172
assert out is b
175173
assert b.table_writer_payload == {"max_row_weight": 67108864}
176174
assert b.job_io_payload is None
@@ -286,7 +284,7 @@ def test_yt_prod_client_run_map_partitions_env_into_vault_and_wraps_string_comma
286284
"yt_framework.yt._client_prod_runtime.MapSpecBuilder", lambda: spec
287285
)
288286
monkeypatch.setattr(
289-
"yt_framework.yt._client_prod_runtime._apply_spec_options_and_split_run_operation_kwargs",
287+
"yt_framework.yt._client_prod_runtime._apply_spec_options_split_run_kwargs",
290288
lambda sb, kw: (sb, {}),
291289
)
292290

@@ -485,7 +483,7 @@ def _otp(paths: Any) -> Any:
485483
)
486484

487485
monkeypatch.setattr(
488-
"yt_framework.yt._client_prod_runtime._apply_spec_options_and_split_run_operation_kwargs",
486+
"yt_framework.yt._client_prod_runtime._apply_spec_options_split_run_kwargs",
489487
lambda sb, kw: (sb, {}),
490488
)
491489

tests/test_dependency_strategy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
"""Tests for yt_framework.operations.dependency_strategy.TarArchiveDependencyBuilder."""
1+
"""Tests for yt_framework.operations._internal.dependency_strategy.TarArchiveDependencyBuilder."""
22

33
import logging
44
from pathlib import Path
55

66
import pytest
77
from omegaconf import OmegaConf
88

9-
from yt_framework.operations.dependency_strategy import TarArchiveDependencyBuilder
9+
from yt_framework.operations._internal.dependency_strategy import (
10+
TarArchiveDependencyBuilder,
11+
)
1012

1113
_LOG = logging.getLogger("tests.dependency_strategy")
1214

tests/test_map.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
from yt_framework.core.dependencies import PipelineStageDependencies
1111
from yt_framework.core.stage import StageContext
12-
from yt_framework.operations.dependency_strategy import DependencyBuildResult
12+
from yt_framework.operations._internal.dependency_strategy import (
13+
DependencyBuildResult,
14+
)
1315
from yt_framework.operations.map import run_map
1416
from yt_framework.yt.client_base import BaseYTClient
1517

tests/test_map_reduce.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
from yt_framework.core.dependencies import PipelineStageDependencies
1111
from yt_framework.core.stage import StageContext
12-
from yt_framework.operations.dependency_strategy import DependencyBuildResult
12+
from yt_framework.operations._internal.dependency_strategy import (
13+
DependencyBuildResult,
14+
)
1315
from yt_framework.operations.map_reduce import run_map_reduce, run_reduce
1416
from yt_framework.yt.client_base import BaseYTClient
1517

tests/test_operation_secure_env.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
merge_secure_vault,
1111
partition_env_for_yt_spec,
1212
promote_secure_vault_environment,
13-
wrap_shell_command_with_secure_vault_promotion,
13+
wrap_shell_cmd_secure_vault_promote,
1414
)
1515

1616

@@ -67,15 +67,15 @@ def test_promote_skips_pickling_key() -> None:
6767

6868
def test_wrap_command_roundtrip_shell_words() -> None:
6969
inner = "python3 mapper.py 'a b'"
70-
wrapped = wrap_shell_command_with_secure_vault_promotion(inner)
70+
wrapped = wrap_shell_cmd_secure_vault_promote(inner)
7171
assert wrapped.startswith("python3 -c ")
7272
assert wrapped.count(" bash -c ") == 1
7373
_, tail = wrapped.split(" bash -c ", 1)
7474
assert shlex.split(tail, posix=True) == [inner]
7575

7676

7777
def test_wrap_command_contract_requires_python3_and_bash() -> None:
78-
wrapped = wrap_shell_command_with_secure_vault_promotion("echo ok")
78+
wrapped = wrap_shell_cmd_secure_vault_promote("echo ok")
7979
assert wrapped.startswith("python3 -c ")
8080
assert " bash -c " in wrapped
8181

tests/test_tar_command_wiring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"""Tests for yt_framework.operations.tar_command_wiring helpers."""
1+
"""Tests for yt_framework.operations._internal.tar_command_wiring helpers."""
22

33
import logging
44

5-
from yt_framework.operations.tar_command_wiring import (
5+
from yt_framework.operations._internal.tar_command_wiring import (
66
bootstrap_shell_run_wrapper,
77
map_reduce_wrapper_names,
88
reduce_wrapper_name,

0 commit comments

Comments
 (0)