| 595 | } |
| 596 | |
| 597 | void GenPythonOp::AddExport() { |
| 598 | if (api_def_.visibility() != ApiDef::VISIBLE) { |
| 599 | return; |
| 600 | } |
| 601 | // Whether op should be available in latest export version. |
| 602 | bool op_available_in_latest = |
| 603 | !api_def_.deprecation_version() || |
| 604 | api_def_.deprecation_version() > kLatestAPIExportVersion; |
| 605 | |
| 606 | string names; |
| 607 | string names_v1; |
| 608 | string deprecated_endpoints; |
| 609 | |
| 610 | for (const auto& endpoint : api_def_.endpoint()) { |
| 611 | string endpoint_name; |
| 612 | python_op_gen_internal::GenerateLowerCaseOpName(endpoint.name(), |
| 613 | &endpoint_name); |
| 614 | if (endpoint.deprecated() || endpoint.deprecation_version() > 0) { |
| 615 | AddDelimiter(&deprecated_endpoints, ", "); |
| 616 | strings::StrAppend(&deprecated_endpoints, "'", endpoint_name, "'"); |
| 617 | } |
| 618 | // Add all endpoints to TensorFlow 1.* API. |
| 619 | AddDelimiter(&names_v1, ", "); |
| 620 | strings::StrAppend(&names_v1, "'", endpoint_name, "'"); |
| 621 | // Add non-deprecated endpoints to TensorFlow 2.* API. |
| 622 | if (op_available_in_latest && |
| 623 | (!endpoint.deprecation_version() || |
| 624 | endpoint.deprecation_version() > kLatestAPIExportVersion)) { |
| 625 | AddDelimiter(&names, ", "); |
| 626 | strings::StrAppend(&names, "'", endpoint_name, "'"); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | // tf_export decorator has the following format: |
| 631 | // @tf_export(v2_name, v2_name, v1=[v1_name, v1_name]) |
| 632 | if (names != names_v1) { |
| 633 | AddDelimiter(&names, ", "); |
| 634 | strings::StrAppend(&names, "v1=[", names_v1, "]"); |
| 635 | } |
| 636 | strings::StrAppend(&result_, "@tf_export(", names, ")\n"); |
| 637 | |
| 638 | // If all endpoints are deprecated, add @deprecated decorator. |
| 639 | if (!api_def_.deprecation_message().empty()) { |
| 640 | const string instructions = api_def_.deprecation_message(); |
| 641 | strings::StrAppend(&result_, "@deprecated(None, '", instructions, "')\n"); |
| 642 | } |
| 643 | // Add @deprecated_endpoints decorator. |
| 644 | if (!deprecated_endpoints.empty()) { |
| 645 | strings::StrAppend(&result_, "@deprecated_endpoints(", deprecated_endpoints, |
| 646 | ")\n"); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | void GenPythonOp::AddDefLine(const string& function_name, |
| 651 | const string& parameters) { |
nothing calls this directly
no test coverage detected