Skip to content

Commit

Permalink
upgrade fbpcs to per-target typechecking
Browse files Browse the repository at this point in the history
Summary:
We're migrating fbcode to use  Pyre's new architecture.

To type check your project:

```
arc pyre check //fbpcs/...
```

You can enable this by adding `typing = True` to individual buck targets OR

```
# in a PACKAGE file
load("fbcode_macros//build_defs:python.bzl", "python")
python.set_typing(True)
```
will type check all buck targets nested underneath.

This diff removes the configuration and replaces it with our new buck based architecture and silences any resulting errors.

The test failure is preexisting.

Reviewed By: joe1234wu

Differential Revision: D64347224
  • Loading branch information
dluo authored and facebook-github-bot committed Oct 15, 2024
1 parent aee6278 commit 5529356
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 3 deletions.
5 changes: 4 additions & 1 deletion fbpcs/bolt/bolt_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ async def _run_hooks(
{stage, None}, {role, None}, {when, None}, {event, None}
)
for hook in job.hooks.get(
BoltHookKey(event=e, when=w, stage=s.name if s else s, role=r), []
# pyre-fixme[6]: For 3rd argument expected `Optional[str]` but got
# `Union[None, PrivateComputationBaseStageFlow, str]`.
BoltHookKey(event=e, when=w, stage=s.name if s else s, role=r),
[],
)
)

Expand Down
5 changes: 5 additions & 0 deletions fbpcs/bolt/read_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from fbpcs.bolt.bolt_runner import BoltRunner
from fbpcs.bolt.constants import DEFAULT_POLL_INTERVAL_SEC
from fbpcs.bolt.oss_bolt_pcs import BoltPCSClient, BoltPCSCreateInstanceArgs

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation_cli.private_computation_service_wrapper`.
from fbpcs.private_computation_cli.private_computation_service_wrapper import (
build_private_computation_service,
)
Expand Down Expand Up @@ -45,6 +48,7 @@ def create_bolt_runner(
runner_config["partner_client_config"]
)
publisher_client = BoltPCSClient(
# pyre-fixme[16]: Module `fbpcs` has no attribute `private_computation_cli`.
build_private_computation_service(
publisher_client_config["private_computation"],
publisher_client_config["mpc"],
Expand All @@ -54,6 +58,7 @@ def create_bolt_runner(
)
)
partner_client = BoltPCSClient(
# pyre-fixme[16]: Module `fbpcs` has no attribute `private_computation_cli`.
build_private_computation_service(
partner_client_config["private_computation"],
partner_client_config["mpc"],
Expand Down
37 changes: 37 additions & 0 deletions fbpcs/common/feature/pcs_feature_gate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,90 @@
# pyre-strict
from typing import Optional, Set, Type

# pyre-fixme[21]: Could not find module `fbpcs.private_computation.entity.infra_config`.
from fbpcs.private_computation.entity.infra_config import PrivateComputationGameType

# pyre-fixme[21]: Could not find module `fbpcs.private_computation.entity.pcs_feature`.
from fbpcs.private_computation.entity.pcs_feature import PCSFeature

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.stage_flows.private_computation_base_stage_flow`.
from fbpcs.private_computation.stage_flows.private_computation_base_stage_flow import (
PrivateComputationBaseStageFlow,
)

# pyre-fixme[21]: Could not find module `fbpcs.private_computation.stage_flows.privat...
from fbpcs.private_computation.stage_flows.private_computation_mr_pid_pcf2_lift_stage_flow import (
PrivateComputationMrPidPCF2LiftStageFlow,
)

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.stage_flows.private_computation_mr_stage_flow`.
from fbpcs.private_computation.stage_flows.private_computation_mr_stage_flow import (
PrivateComputationMRStageFlow,
)

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.stage_flows.private_computation_pcf2_lift_udp_stage_flow`.
from fbpcs.private_computation.stage_flows.private_computation_pcf2_lift_udp_stage_flow import (
PrivateComputationPCF2LiftUDPStageFlow,
)

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.stage_flows.private_computation_pcf2_stage_flow`.
from fbpcs.private_computation.stage_flows.private_computation_pcf2_stage_flow import (
PrivateComputationPCF2StageFlow,
)

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.stage_flows.private_computation_stage_flow`.
from fbpcs.private_computation.stage_flows.private_computation_stage_flow import (
PrivateComputationStageFlow,
)
from fbpcs.utils.optional import unwrap_or_default


def get_stage_flow(
# pyre-fixme[11]: Annotation `PrivateComputationGameType` is not defined as a type.
game_type: PrivateComputationGameType,
# pyre-fixme[11]: Annotation `PCSFeature` is not defined as a type.
pcs_feature_enums: Set[PCSFeature],
# pyre-fixme[11]: Annotation `PrivateComputationBaseStageFlow` is not defined as
# a type.
stage_flow_cls: Optional[Type[PrivateComputationBaseStageFlow]] = None,
) -> Type[PrivateComputationBaseStageFlow]:
selected_stage_flow_cls = unwrap_or_default(
optional=stage_flow_cls,
default=(
# pyre-fixme[16]: Module `private_computation` has no attribute
# `stage_flows`.
PrivateComputationPCF2StageFlow
# pyre-fixme[16]: Module `entity` has no attribute `infra_config`.
if game_type is PrivateComputationGameType.ATTRIBUTION
# pyre-fixme[16]: Module `private_computation` has no attribute
# `stage_flows`.
else PrivateComputationStageFlow
),
)

# warning, enabled feature gating will override stage flow, Please contact PSI team to have a similar adoption
if PCSFeature.PRIVATE_ATTRIBUTION_MR_PID in pcs_feature_enums:
selected_stage_flow_cls = (
# pyre-fixme[16]: Module `private_computation` has no attribute
# `stage_flows`.
PrivateComputationMRStageFlow
# pyre-fixme[16]: Module `entity` has no attribute `infra_config`.
if game_type is PrivateComputationGameType.ATTRIBUTION
# pyre-fixme[16]: Module `private_computation` has no attribute
# `stage_flows`.
else PrivateComputationMrPidPCF2LiftStageFlow
)
if PCSFeature.PRIVATE_LIFT_UNIFIED_DATA_PROCESS in pcs_feature_enums:
selected_stage_flow_cls = (
# pyre-fixme[16]: Module `private_computation` has no attribute
# `stage_flows`.
PrivateComputationPCF2LiftUDPStageFlow
# pyre-fixme[16]: Module `entity` has no attribute `infra_config`.
if game_type is PrivateComputationGameType.LIFT
else selected_stage_flow_cls
)
Expand Down
8 changes: 8 additions & 0 deletions fbpcs/data_processing/pid_preparer/preparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
import pathlib
from typing import Optional

# pyre-fixme[21]: Could not find module `fbpcp.entity.container_instance`.
from fbpcp.entity.container_instance import ContainerInstance

# pyre-fixme[21]: Could not find module `fbpcp.service.onedocker`.
from fbpcp.service.onedocker import OneDockerService

# pyre-fixme[21]: Could not find module `fbpcp.service.storage`.
from fbpcp.service.storage import StorageService


Expand All @@ -24,6 +29,7 @@ def prepare(
output_path: str,
log_path: Optional[pathlib.Path] = None,
log_level: int = logging.INFO,
# pyre-fixme[11]: Annotation `StorageService` is not defined as a type.
storage_svc: Optional[StorageService] = None,
) -> None:
pass
Expand All @@ -34,10 +40,12 @@ def prepare_on_container(
input_path: str,
output_path: str,
# TODO: Support custom log path
# pyre-fixme[11]: Annotation `OneDockerService` is not defined as a type.
onedocker_svc: OneDockerService,
binary_version: str,
tmp_directory: str = "/tmp/",
wait_for_container: bool = True,
# pyre-fixme[11]: Annotation `ContainerInstance` is not defined as a type.
) -> ContainerInstance:
pass

Expand Down
20 changes: 20 additions & 0 deletions fbpcs/data_processing/pid_preparer/union_pid_preparer_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@
import tempfile
from typing import Dict, Optional

# pyre-fixme[21]: Could not find module `fbpcp.entity.container_instance`.
from fbpcp.entity.container_instance import ContainerInstance, ContainerInstanceStatus

# pyre-fixme[21]: Could not find module `fbpcp.error.pcp`.
from fbpcp.error.pcp import ThrottlingError

# pyre-fixme[21]: Could not find module `fbpcp.service.onedocker`.
from fbpcp.service.onedocker import OneDockerService

# pyre-fixme[21]: Could not find module `fbpcp.service.storage`.
from fbpcp.service.storage import PathType, StorageService

# pyre-fixme[21]: Could not find module `fbpcs.common.service.retry_handler`.
from fbpcs.common.service.retry_handler import RetryHandler
from fbpcs.data_processing.pid_preparer.preparer import UnionPIDDataPreparerService

# pyre-fixme[21]: Could not find module `fbpcs.onedocker_binary_names`.
from fbpcs.onedocker_binary_names import OneDockerBinaryNames

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.service.run_binary_base_service`.
from fbpcs.private_computation.service.run_binary_base_service import (
RunBinaryBaseService,
)
Expand All @@ -43,6 +56,7 @@ def prepare(
output_path: str,
log_path: Optional[pathlib.Path] = None,
log_level: int = logging.INFO,
# pyre-fixme[11]: Annotation `StorageService` is not defined as a type.
storage_svc: Optional[StorageService] = None,
) -> None:
if log_path is not None:
Expand Down Expand Up @@ -95,13 +109,15 @@ def prepare_on_container(
self,
input_path: str,
output_path: str,
# pyre-fixme[11]: Annotation `OneDockerService` is not defined as a type.
onedocker_svc: OneDockerService,
binary_version: str,
max_column_count: int = 1,
tmp_directory: str = "/tmp/",
container_timeout: Optional[int] = None,
wait_for_container: bool = True,
env_vars: Optional[Dict[str, str]] = None,
# pyre-fixme[11]: Annotation `ContainerInstance` is not defined as a type.
) -> ContainerInstance:
return asyncio.run(
self.prepare_on_container_async(
Expand Down Expand Up @@ -145,6 +161,7 @@ async def prepare_on_container_async(

current_retry = 0
status = ContainerInstanceStatus.UNKNOWN
# pyre-fixme[16]: Module `fbpcs` has no attribute `onedocker_binary_names`.
exe = OneDockerBinaryNames.UNION_PID_PREPARER.value
container = None
while status is not ContainerInstanceStatus.COMPLETED:
Expand All @@ -162,6 +179,7 @@ async def prepare_on_container_async(
env_vars=env_vars,
)

# pyre-fixme[16]: Module `fbpcs` has no attribute `common`.
with RetryHandler(
ThrottlingError, logger=logger, backoff_seconds=30
) as retry_handler:
Expand All @@ -175,6 +193,8 @@ async def prepare_on_container_async(
# Busy wait until the container is finished
if wait_for_container:
container = (
# pyre-fixme[16]: Module `fbpcs` has no attribute
# `private_computation`.
await RunBinaryBaseService.wait_for_containers_async(
onedocker_svc, [container]
)
Expand Down
12 changes: 12 additions & 0 deletions fbpcs/data_processing/service/id_spine_combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@

from typing import List, Optional

# pyre-fixme[21]: Could not find module `fbpcp.util.arg_builder`.
from fbpcp.util.arg_builder import build_cmd_args

# pyre-fixme[21]: Could not find module `fbpcs.private_computation.service.constants`.
from fbpcs.private_computation.service.constants import DEFAULT_SORT_STRATEGY

# pyre-fixme[21]: Could not find module `fbpcs.private_computation.service.pid_utils`.
from fbpcs.private_computation.service.pid_utils import get_sharded_filepath

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.service.run_binary_base_service`.
from fbpcs.private_computation.service.run_binary_base_service import (
RunBinaryBaseService,
)
Expand All @@ -21,6 +28,7 @@
DEFAULT_CONTAINER_TIMEOUT_IN_SEC = 10800


# pyre-fixme[11]: Annotation `RunBinaryBaseService` is not defined as a type.
class IdSpineCombinerService(RunBinaryBaseService):
@staticmethod
def build_args(
Expand All @@ -31,6 +39,7 @@ def build_args(
tmp_directory: str,
protocol_type: str,
max_id_column_cnt: int = 1,
# pyre-fixme[16]: Module `fbpcs` has no attribute `private_computation`.
sort_strategy: str = DEFAULT_SORT_STRATEGY,
# TODO T106159008: padding_size and run_name are only temporarily optional
# because Lift does not use them. It should and will be required to use them.
Expand All @@ -46,8 +55,11 @@ def build_args(
# own ThreadPoolExecutor here and instead use async primitives
cmd_args_list = []
for shard in range(num_shards):
# pyre-fixme[16]: Module `fbpcs` has no attribute `private_computation`.
next_spine_path = get_sharded_filepath(spine_path, shard)
# pyre-fixme[16]: Module `fbpcs` has no attribute `private_computation`.
next_data_path = get_sharded_filepath(data_path, shard)
# pyre-fixme[16]: Module `fbpcs` has no attribute `private_computation`.
next_output_path = get_sharded_filepath(output_path, shard)
cmd_args = build_cmd_args(
spine_path=next_spine_path,
Expand Down
14 changes: 14 additions & 0 deletions fbpcs/data_processing/service/pid_run_protocol_binary_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from fbpcs.onedocker_binary_names import OneDockerBinaryNames

from fbpcs.pid.entity.pid_instance import PIDProtocol

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.entity.private_computation_instance`.
from fbpcs.private_computation.entity.private_computation_instance import (
PrivateComputationRole,
)
Expand All @@ -35,6 +38,7 @@ def build_args(
output_path: str,
port: int,
tls_args: TlsArgs,
# pyre-fixme[11]: Annotation `PrivateComputationRole` is not defined as a type.
pc_role: PrivateComputationRole,
use_row_numbers: bool = False,
server_endpoint: Optional[str] = None,
Expand Down Expand Up @@ -66,12 +70,18 @@ def build_args(
if use_row_numbers:
cmd_ls.append("--use-row-numbers")

# pyre-fixme[16]: Module `entity` has no attribute
# `private_computation_instance`.
if tls_args.ca_cert_path and pc_role is PrivateComputationRole.PARTNER:
cmd_ls.append(f"--tls-ca {tls_args.ca_cert_path}")

# pyre-fixme[16]: Module `entity` has no attribute
# `private_computation_instance`.
if tls_args.server_cert_path and pc_role is PrivateComputationRole.PUBLISHER:
cmd_ls.append(f"--tls-cert {tls_args.server_cert_path}")

# pyre-fixme[16]: Module `entity` has no attribute
# `private_computation_instance`.
if tls_args.private_key_path and pc_role is PrivateComputationRole.PUBLISHER:
cmd_ls.append(f"--tls-key {tls_args.private_key_path}")

Expand All @@ -82,10 +92,14 @@ def build_args(

@staticmethod
def get_binary_name(protocol: PIDProtocol, pc_role: PrivateComputationRole) -> str:
# pyre-fixme[16]: Module `entity` has no attribute
# `private_computation_instance`.
if pc_role is PrivateComputationRole.PUBLISHER:
binary_name = OneDockerBinaryNames.PID_SERVER.value
if protocol is PIDProtocol.UNION_PID_MULTIKEY:
binary_name = OneDockerBinaryNames.PID_MULTI_KEY_SERVER.value
# pyre-fixme[16]: Module `entity` has no attribute
# `private_computation_instance`.
elif pc_role is PrivateComputationRole.PARTNER:
binary_name = OneDockerBinaryNames.PID_CLIENT.value
if protocol is PIDProtocol.UNION_PID_MULTIKEY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from typing import Optional

from fbpcs.infra.certificate.certificate_provider import CertificateProvider

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.entity.private_computation_instance`.
from fbpcs.private_computation.entity.private_computation_instance import (
PrivateComputationInstance,
)
Expand All @@ -20,7 +23,9 @@ class PCInstanceCaCertificateProvider(CertificateProvider):
from PC instance repo.
"""

# pyre-fixme[11]: Annotation `PrivateComputationInstance` is not defined as a type.
def __init__(self, pc_instance: PrivateComputationInstance) -> None:
# pyre-fixme[4]: Attribute must be annotated.
self.pc_instance = pc_instance

def get_certificate(self) -> Optional[str]:
Expand Down
5 changes: 5 additions & 0 deletions fbpcs/infra/certificate/pc_instance_server_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from typing import Optional

from fbpcs.infra.certificate.certificate_provider import CertificateProvider

# pyre-fixme[21]: Could not find module
# `fbpcs.private_computation.entity.private_computation_instance`.
from fbpcs.private_computation.entity.private_computation_instance import (
PrivateComputationInstance,
)
Expand All @@ -20,7 +23,9 @@ class PCInstanceServerCertificateProvider(CertificateProvider):
from PC instance repo.
"""

# pyre-fixme[11]: Annotation `PrivateComputationInstance` is not defined as a type.
def __init__(self, pc_instance: PrivateComputationInstance) -> None:
# pyre-fixme[4]: Attribute must be annotated.
self.pc_instance = pc_instance

def get_certificate(self) -> Optional[str]:
Expand Down
2 changes: 2 additions & 0 deletions fbpcs/pc_pre_validation/tests/pc_pre_validation_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def test_parsing_all_args(
expected_access_key_id = "access_key_id2"
expected_access_key_data = "access_key_data3"
expected_binary_version = "binary_version"
# pyre-fixme[9]: expected_pc_computation_role has type
# `PrivateComputationRole`; used as `str`.
expected_pc_computation_role: PrivateComputationRole = (
PrivateComputationRole.PARTNER.name
)
Expand Down
3 changes: 3 additions & 0 deletions fbpcs/pl_coordinator/token_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def validate_rule(self, rule: TokenValidationRule) -> None:
instance_id="NO_INSTANCE",
checkpoint_name="FAIL_FAST_VALIDATION",
status=CheckpointStatus.FAILED,
# pyre-fixme[6]: For 5th argument expected
# `Optional[Dict[str, str]]` but got `Dict[str,
# Union[TokenValidationRuleType, str]]`.
checkpoint_data={
"rule_name": rule.name,
"rule_type": rule.rule_type,
Expand Down
Loading

0 comments on commit 5529356

Please sign in to comment.