Skip to content

Commit

Permalink
[antlir][buck2][typing][codemod] Remove .type from types
Browse files Browse the repository at this point in the history
Summary: `.type` is deprecated.

Test Plan: CI

Reviewed By: JakobDegen

Differential Revision: D49068266

fbshipit-source-id: 814a04f9b489dbcbc59a703a3d3698241a8ea0ee
  • Loading branch information
stepancheg authored and facebook-github-bot committed Sep 8, 2023
1 parent 538a6b1 commit 9343d8a
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/feature/antlir1_no_equivalent.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
load("//antlir/antlir2/bzl:macro_dep.bzl", "antlir2_dep")
load(":feature_info.bzl", "ParseTimeFeature", "data_only_feature_analysis_fn")

def antlir1_no_equivalent(*, label: str, description: str) -> ParseTimeFeature.type:
def antlir1_no_equivalent(*, label: str, description: str) -> ParseTimeFeature:
return ParseTimeFeature(
impl = antlir2_dep("features:antlir1_no_equivalent"),
feature_type = "antlir1_no_equivalent",
Expand Down
6 changes: 3 additions & 3 deletions antlir/antlir2/bzl/feature/clone.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def clone(
*,
src_layer: str | Select,
src_path: str | Select,
dst_path: str | Select) -> ParseTimeFeature.type:
dst_path: str | Select) -> ParseTimeFeature:
"""
Copies a subtree of an existing layer into the one under construction. To
the extent possible, filesystem metadata are preserved.
Expand Down Expand Up @@ -72,7 +72,7 @@ def clone(
)

clone_record = record(
src_layer = layer_dep.type,
src_layer = layer_dep,
src_path = str,
dst_path = str,
omit_outer_dir = bool,
Expand All @@ -82,7 +82,7 @@ clone_record = record(
def clone_analyze(
src_path: str,
dst_path: str,
deps: dict[str, Dependency]) -> FeatureAnalysis.type:
deps: dict[str, Dependency]) -> FeatureAnalysis:
omit_outer_dir = src_path.endswith("/")
pre_existing_dest = dst_path.endswith("/")
if omit_outer_dir and not pre_existing_dest:
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/feature/dependency_layer_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ layer_dep = record(
appears_to_be_antlir1_layer = [bool, None],
)

def layer_dep_analyze(layer: Dependency) -> layer_dep.type:
def layer_dep_analyze(layer: Dependency) -> layer_dep:
"""
Serialize a Layer dependency to a subset of LayerInfo that can be serialized
and passed to antlir2
Expand Down
6 changes: 3 additions & 3 deletions antlir/antlir2/bzl/feature/dot_meta.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def dot_meta(
*,
revision: [str, None] = None,
package_name: [str, None] = None,
package_version: [str, None] = None) -> ParseTimeFeature.type:
package_version: [str, None] = None) -> ParseTimeFeature:
"""
Stamp build info into /.meta in the built layer
"""
Expand Down Expand Up @@ -45,12 +45,12 @@ build_info_record = record(
)

dot_meta_record = record(
build_info = [build_info_record.type, None],
build_info = [build_info_record, None],
)

def dot_meta_analyze(
build_info: [dict[str, typing.Any], None],
impl: [RunInfo, None] = None) -> FeatureAnalysis.type:
impl: [RunInfo, None] = None) -> FeatureAnalysis:
return FeatureAnalysis(
feature_type = "dot_meta",
data = dot_meta_record(
Expand Down
4 changes: 2 additions & 2 deletions antlir/antlir2/bzl/feature/ensure_dirs_exist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def ensure_subdirs_exist(
subdirs_to_create: str | Select,
mode: int | str | Select = 0o755,
user: str | Select = "root",
group: str | Select = "root") -> list[ParseTimeFeature.type]:
group: str | Select = "root") -> list[ParseTimeFeature]:
"""
`ensure_subdirs_exist("/w/x", "y/z")` creates the directories `/w/x/y` and
`/w/x/y/z` in the image, if they do not exist. `/w/x` must have already been
Expand Down Expand Up @@ -54,7 +54,7 @@ def ensure_dirs_exist(
dirs: str,
mode: int | str = 0o755,
user: str = "root",
group: str = "root") -> list[ParseTimeFeature.type]:
group: str = "root") -> list[ParseTimeFeature]:
"""Equivalent to `ensure_subdirs_exist("/", dirs, ...)`."""
return ensure_subdirs_exist(
into_dir = "/",
Expand Down
12 changes: 6 additions & 6 deletions antlir/antlir2/bzl/feature/extract.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ load(":feature_info.bzl", "FeatureAnalysis", "ParseTimeDependency", "ParseTimeFe

def extract_from_layer(
layer: str | Select,
binaries: list[str | Select] | Select) -> ParseTimeFeature.type:
binaries: list[str | Select] | Select) -> ParseTimeFeature:
"""
Extract binaries that are installed into `layer`, most commonly by RPMs.
Expand All @@ -58,7 +58,7 @@ def extract_from_layer(
def extract_buck_binary(
src: str | Select,
dst: str | Select,
strip: bool | Select = True) -> ParseTimeFeature.type:
strip: bool | Select = True) -> ParseTimeFeature:
"""
Extract a binary built by buck into the target layer.
Expand All @@ -84,13 +84,13 @@ extract_buck_record = record(
)

extract_layer_record = record(
layer = layer_dep.type,
layer = layer_dep,
binaries = list[str],
)

extract_record = record(
buck = [extract_buck_record.type, None],
layer = [extract_layer_record.type, None],
buck = [extract_buck_record, None],
layer = [extract_layer_record, None],
)

def extract_analyze(
Expand All @@ -100,7 +100,7 @@ def extract_analyze(
binaries: list[str] | None = None,
src: str | None = None,
dst: str | None = None,
strip: bool | None = None) -> FeatureAnalysis.type:
strip: bool | None = None) -> FeatureAnalysis:
if source == "layer":
layer = deps["layer"]
return FeatureAnalysis(
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/feature/feature.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ feature_record = record(
run_info = RunInfo,
)

def _feature_as_json(feat: feature_record.type) -> struct:
def _feature_as_json(feat: feature_record) -> struct:
return struct(
feature_type = feat.feature_type,
label = feat.label,
Expand Down
18 changes: 9 additions & 9 deletions antlir/antlir2/bzl/feature/feature_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ ParseTimeFeature = record(
srcs = field([dict[str, [str, Select]], None], default = None),
# These items must be `deps` and will be validated early in analysis time to
# contain the required providers
deps = field([dict[str, ParseTimeDependency.type], None], default = None),
deps = field([dict[str, ParseTimeDependency], None], default = None),
# Deps resolved for the execution platform. These should not be installed
# into images because they are produced only to be run on the build worker
exec_deps = field([dict[str, ParseTimeDependency.type], None], default = None),
exec_deps = field([dict[str, ParseTimeDependency], None], default = None),
# Sources/deps that do not require named tracking between the parse and
# analysis phases. Useful to support `select` in features that accept lists
# of dependencies.
Expand All @@ -51,7 +51,7 @@ ParseTimeFeature = record(
# discovered in the depgraph, so those features are grouped together in
# hidden internal layer(s) that acts as the parent layer(s) for the final
# image.
build_phase = field(BuildPhase.type, default = BuildPhase("compile")),
build_phase = field(BuildPhase, default = BuildPhase("compile")),
)

# Produced by the feature implementation, this tells the rule how to build it
Expand Down Expand Up @@ -79,7 +79,7 @@ FeatureAnalysis = record(
# discovered in the depgraph, so those features are grouped together in
# hidden internal layer(s) that acts as the parent layer(s) for the final
# image.
build_phase = field(BuildPhase.type, default = BuildPhase("compile")),
build_phase = field(BuildPhase, default = BuildPhase("compile")),
)

Tools = record(
Expand All @@ -90,14 +90,14 @@ AnalyzeFeatureContext = record(
label = Label,
unique_action_identifier = str,
actions = AnalysisActions,
tools = Tools.type,
tools = Tools,
)

def data_only_feature_analysis_fn(
record_type,
feature_type: str,
build_phase: BuildPhase.type = BuildPhase("compile")):
def inner(impl: RunInfo | None = None, **kwargs) -> FeatureAnalysis.type:
build_phase: BuildPhase = BuildPhase("compile")):
def inner(impl: RunInfo | None = None, **kwargs) -> FeatureAnalysis:
return FeatureAnalysis(
feature_type = feature_type,
data = record_type(**kwargs),
Expand All @@ -108,9 +108,9 @@ def data_only_feature_analysis_fn(
return inner

def with_phase_override(
feature: FeatureAnalysis.type,
feature: FeatureAnalysis,
*,
phase: BuildPhase.type) -> FeatureAnalysis.type:
phase: BuildPhase) -> FeatureAnalysis:
kwargs = {k: getattr(feature, k) for k in dir(feature)}
kwargs["build_phase"] = phase
return FeatureAnalysis(**kwargs)
4 changes: 2 additions & 2 deletions antlir/antlir2/bzl/feature/genrule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def genrule(
user: str | Select = "nobody",
boot: bool | Select = False,
bind_repo_ro: bool | Select = False,
mount_platform: bool | Select = False) -> ParseTimeFeature.type:
mount_platform: bool | Select = False) -> ParseTimeFeature:
return ParseTimeFeature(
feature_type = "genrule",
impl = antlir2_dep("features:genrule"),
Expand Down Expand Up @@ -44,7 +44,7 @@ def genrule_analyze(
boot: bool,
bind_repo_ro: bool,
mount_platform: bool,
args: dict[str, str | "resolved_macro"]) -> FeatureAnalysis.type:
args: dict[str, str | "resolved_macro"]) -> FeatureAnalysis:
cmd = {int(key.removeprefix("cmd_")): val for key, val in args.items() if key.startswith("cmd_")}
cmd = [val for _key, val in sorted(cmd.items())]
return FeatureAnalysis(
Expand Down
10 changes: 5 additions & 5 deletions antlir/antlir2/bzl/feature/install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def install(
dst: str | Select,
mode: int | str | Select | None = None,
user: str | Select = "root",
group: str | Select = "root") -> ParseTimeFeature.type:
group: str | Select = "root") -> ParseTimeFeature:
"""
`install("//path/fs:data", "dir/bar")` installs file or directory `data` to
`dir/bar` in the image. `dir/bar` must not exist, otherwise the operation
Expand Down Expand Up @@ -60,7 +60,7 @@ def install_text(
dst: str | Select,
mode: int | str | Select | None = None,
user: str | Select = "root",
group: str | Select = "root") -> ParseTimeFeature.type:
group: str | Select = "root") -> ParseTimeFeature:
# the default mode is determined later, after we know if the thing being
# installed is a binary or not
mode = stat.mode(mode) if mode != None else None
Expand All @@ -85,7 +85,7 @@ installed_binary = record(

binary_record = record(
dev = field([bool, None], default = None),
installed = field([installed_binary.type, None], default = None),
installed = field([installed_binary, None], default = None),
)

install_record = record(
Expand All @@ -94,7 +94,7 @@ install_record = record(
mode = int,
user = str,
group = str,
binary_info = field([binary_record.type, None], default = None),
binary_info = field([binary_record, None], default = None),
)

def get_feature_anaylsis_for_install(
Expand Down Expand Up @@ -185,7 +185,7 @@ def install_analyze(
user: str,
text: str | None,
deps_or_srcs: dict[str, Artifact | Dependency] | None = None,
impl: RunInfo | None = None) -> FeatureAnalysis.type:
impl: RunInfo | None = None) -> FeatureAnalysis:
src = None if not deps_or_srcs else deps_or_srcs["src"]
return get_feature_anaylsis_for_install(
ctx,
Expand Down
8 changes: 4 additions & 4 deletions antlir/antlir2/bzl/feature/metakv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def metakv_store(
key: str | Select,
value: str | Select,
require_keys: list[str | Select] | Select = [],
store_if_not_exists: bool | Select = False) -> ParseTimeFeature.type:
store_if_not_exists: bool | Select = False) -> ParseTimeFeature:
"""
`metakv_store("key", "value")` writes the key value pair into
the META_KEY_VALUE_STORE_FILE in the image. This can be read later. It is enforced that
Expand Down Expand Up @@ -74,13 +74,13 @@ metakv_remove_record = record(
)

metakv_record = record(
store = [metakv_store_record.type, None],
remove = [metakv_remove_record.type, None],
store = [metakv_store_record, None],
remove = [metakv_remove_record, None],
)

def metakv_analyze(
store: dict[str, typing.Any] | None = None,
remove: dict[str, typing.Any] | None = None) -> FeatureAnalysis.type:
remove: dict[str, typing.Any] | None = None) -> FeatureAnalysis:
return FeatureAnalysis(
feature_type = "metakv",
data = metakv_record(
Expand Down
14 changes: 7 additions & 7 deletions antlir/antlir2/bzl/feature/mount.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def layer_mount(
*,
source: str | Select,
mountpoint: str | None = None,
_implicit_from_antlir1: bool = False) -> list[ParseTimeFeature.type]:
_implicit_from_antlir1: bool = False) -> list[ParseTimeFeature]:
features = [
ParseTimeFeature(
feature_type = "mount",
Expand Down Expand Up @@ -50,7 +50,7 @@ def host_mount(
source: str,
is_directory: bool,
mountpoint: str | None = None,
_implicit_from_antlir1: bool = False) -> list[ParseTimeFeature.type]:
_implicit_from_antlir1: bool = False) -> list[ParseTimeFeature]:
mountpoint = mountpoint or source
features = [ParseTimeFeature(
feature_type = "mount",
Expand Down Expand Up @@ -93,7 +93,7 @@ layer_mount_record = record(
# TODO: this is only nullable because implicit conversions from antlir1
# don't correctly set this in many cases
mountpoint = [str, None],
src = layer_dep.type,
src = layer_dep,
)

host_mount_record = record(
Expand All @@ -103,17 +103,17 @@ host_mount_record = record(
)

mount_record = record(
layer = [layer_mount_record.type, None],
host = [host_mount_record.type, None],
layer = [layer_mount_record, None],
host = [host_mount_record, None],
)

def mount_analyze(
mountpoint: str | None,
source_kind: _source_kind.type,
source_kind: str,
is_directory: bool | None,
host_source: str | None,
_implicit_from_antlir1: bool,
deps: dict[str, Dependency] = {}) -> FeatureAnalysis.type:
deps: dict[str, Dependency] = {}) -> FeatureAnalysis:
if source_kind == "layer":
source = deps.pop("source")
if not mountpoint:
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/feature/remove.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ load(":feature_info.bzl", "ParseTimeFeature", "data_only_feature_analysis_fn")
def remove(
*,
path: str,
must_exist: bool = True) -> ParseTimeFeature.type:
must_exist: bool = True) -> ParseTimeFeature:
"""
Recursively remove a file or directory
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/feature/requires.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def requires(
*,
files: list[str] = [],
groups: list[str] = [],
users: list[str] = []) -> ParseTimeFeature.type:
users: list[str] = []) -> ParseTimeFeature:
"""
Add rule-level requirements on image layers.
Expand Down
Loading

0 comments on commit 9343d8a

Please sign in to comment.