1load(
2    "//tensorflow:tensorflow.bzl",
3    "py_test",
4    "tf_cc_test",  # @unused
5    "tf_copts",  # @unused
6)
7load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable")
8
9package(
10    default_visibility = ["//tensorflow:internal"],
11    licenses = ["notice"],  # Apache 2.0
12)
13
14py_library(
15    name = "ipynb",
16    srcs = ["ipynb.py"],
17    srcs_version = "PY3",
18    deps = ["@six_archive//:six"],
19)
20
21py_library(
22    name = "ast_edits",
23    srcs = ["ast_edits.py"],
24    srcs_version = "PY3",
25    deps = [
26        "@pasta",
27        "@six_archive//:six",
28    ],
29)
30
31py_test(
32    name = "ast_edits_test",
33    srcs = ["ast_edits_test.py"],
34    python_version = "PY3",
35    srcs_version = "PY3",
36    deps = [
37        ":ast_edits",
38        "//tensorflow/python:client_testlib",
39        "//tensorflow/python:framework_test_lib",
40        "@six_archive//:six",
41    ],
42)
43
44py_binary(
45    name = "tf_upgrade",
46    srcs = ["tf_upgrade.py"],
47    python_version = "PY3",
48    srcs_version = "PY3",
49    deps = [
50        ":tf_upgrade_lib",
51        "@six_archive//:six",
52    ],
53)
54
55py_library(
56    name = "tf_upgrade_lib",
57    srcs = ["tf_upgrade.py"],
58    srcs_version = "PY3",
59    deps = [
60        ":ast_edits",
61        "@six_archive//:six",
62    ],
63)
64
65py_test(
66    name = "tf_upgrade_test",
67    srcs = ["tf_upgrade_test.py"],
68    python_version = "PY3",
69    srcs_version = "PY3",
70    tags = [
71        "no_pip",
72    ],
73    deps = [
74        ":tf_upgrade_lib",
75        "//tensorflow/python:client_testlib",
76        "//tensorflow/python:framework_test_lib",
77        "@six_archive//:six",
78    ],
79)
80
81py_library(
82    name = "renames_v2",
83    srcs = ["renames_v2.py"],
84    compatible_with = get_compatible_with_portable(),
85    srcs_version = "PY3",
86)
87
88py_library(
89    name = "reorders_v2",
90    srcs = ["reorders_v2.py"],
91    srcs_version = "PY3",
92)
93
94py_library(
95    name = "all_renames_v2",
96    srcs = ["all_renames_v2.py"],
97    compatible_with = get_compatible_with_portable(),
98    srcs_version = "PY3",
99    visibility = [
100        "//tensorflow:__pkg__",
101        "//tensorflow:__subpackages__",
102    ],
103    deps = [":renames_v2"],
104)
105
106py_test(
107    name = "all_renames_v2_test",
108    srcs = ["all_renames_v2_test.py"],
109    python_version = "PY3",
110    srcs_version = "PY3",
111    deps = [
112        ":all_renames_v2",
113        "//tensorflow/python:client_testlib",
114        "//tensorflow/python:framework_test_lib",
115        "@six_archive//:six",
116    ],
117)
118
119py_library(
120    name = "module_deprecations_v2",
121    srcs = ["module_deprecations_v2.py"],
122    srcs_version = "PY3",
123    deps = [":ast_edits"],
124)
125
126py_library(
127    name = "tf_upgrade_v2_lib",
128    srcs = ["tf_upgrade_v2.py"],
129    srcs_version = "PY3",
130    deps = [
131        ":all_renames_v2",
132        ":ast_edits",
133        ":module_deprecations_v2",
134        ":reorders_v2",
135        "@six_archive//:six",
136    ],
137)
138
139py_library(
140    name = "tf_upgrade_v2_safety_lib",
141    srcs = ["tf_upgrade_v2_safety.py"],
142    srcs_version = "PY3",
143    deps = [
144        ":all_renames_v2",
145        ":ast_edits",
146        ":module_deprecations_v2",
147    ],
148)
149
150py_binary(
151    name = "tf_upgrade_v2",
152    srcs = ["tf_upgrade_v2_main.py"],
153    main = "tf_upgrade_v2_main.py",
154    python_version = "PY3",
155    srcs_version = "PY3",
156    deps = [
157        ":ast_edits",
158        ":ipynb",
159        ":tf_upgrade_v2_lib",
160        ":tf_upgrade_v2_safety_lib",
161        "@six_archive//:six",
162    ],
163)
164
165py_test(
166    name = "tf_upgrade_v2_test",
167    srcs = ["tf_upgrade_v2_test.py"],
168    python_version = "PY3",
169    srcs_version = "PY3",
170    tags = [
171        "no_windows",
172        "v1only",
173    ],
174    deps = [
175        ":tf_upgrade_v2_lib",
176        "//tensorflow:tensorflow_py",
177        "//tensorflow/python:client_testlib",
178        "//tensorflow/python:framework_test_lib",
179        "//tensorflow/tools/common:public_api",
180        "//tensorflow/tools/common:traverse",
181        "@absl_py//absl/testing:parameterized",
182        "@six_archive//:six",
183    ],
184)
185
186py_test(
187    name = "tf_upgrade_v2_safety_test",
188    srcs = ["tf_upgrade_v2_safety_test.py"],
189    python_version = "PY3",
190    srcs_version = "PY3",
191    deps = [
192        ":tf_upgrade_v2_safety_lib",
193        "//tensorflow/python:client_testlib",
194        "//tensorflow/python:framework_test_lib",
195        "@six_archive//:six",
196    ],
197)
198
199# Keep for reference, this test will succeed in 0.11 but fail in 1.0
200# py_test(
201#     name = "test_file_v0_11",
202#     size = "small",
203#     srcs = ["testdata/test_file_v0_11.py"],
204#     srcs_version = "PY3",
205#     deps = [
206#         "//tensorflow:tensorflow_py",
207#     ],
208# )
209
210genrule(
211    name = "generate_upgraded_file",
212    testonly = 1,
213    srcs = ["testdata/test_file_v0_11.py"],
214    outs = [
215        "test_file_v1_0.py",
216        "report.txt",
217    ],
218    cmd = ("$(location :tf_upgrade)" +
219           " --infile $(location testdata/test_file_v0_11.py)" +
220           " --outfile $(location test_file_v1_0.py)" +
221           " --reportfile $(location report.txt)"),
222    tools = [":tf_upgrade"],
223)
224
225py_test(
226    name = "test_file_v1_0",
227    size = "small",
228    srcs = ["test_file_v1_0.py"],
229    python_version = "PY3",
230    srcs_version = "PY3",
231    deps = [
232        "//tensorflow:tensorflow_py",
233    ],
234)
235
236genrule(
237    name = "generate_upgraded_file_v2",
238    testonly = 1,
239    srcs = ["testdata/test_file_v1_12.py"],
240    outs = [
241        "test_file_v2_0.py",
242        "report_v2.txt",
243    ],
244    cmd = ("$(location :tf_upgrade_v2)" +
245           " --infile $(location testdata/test_file_v1_12.py)" +
246           " --outfile $(location test_file_v2_0.py)" +
247           " --reportfile $(location report_v2.txt) && " +
248           "sed -i'.original' 's/_TEST_VERSION = 1/_TEST_VERSION = 2/g' $(location test_file_v2_0.py)"),
249    tools = [":tf_upgrade_v2"],
250)
251
252py_test(
253    name = "test_file_v1_12",
254    size = "small",
255    srcs = ["testdata/test_file_v1_12.py"],
256    python_version = "PY3",
257    srcs_version = "PY3",
258    tags = [
259        "no_windows",
260        "v1only",
261    ],
262    deps = [
263        "//tensorflow:tensorflow_py",
264    ],
265)
266
267py_test(
268    name = "test_file_v2_0",
269    size = "small",
270    srcs = ["test_file_v2_0.py"],
271    python_version = "PY3",
272    srcs_version = "PY3",
273    deps = [
274        "//tensorflow:tensorflow_py",
275    ],
276)
277
278exports_files(
279    [
280        "all_renames_v2.py",
281        "ast_edits.py",
282        "tf_upgrade.py",
283        "renames_v2.py",
284        "testdata/test_file_v0_11.py",
285        "testdata/test_file_v1_12.py",
286    ],
287)
288