|
12 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | 13 | # See the License for the specific language governing permissions and
|
14 | 14 | # limitations under the License.
|
| 15 | +from hashlib import sha1 |
15 | 16 |
|
16 | 17 | from typing import List, Optional
|
17 | 18 | from library_generation.model.gapic_config import GapicConfig
|
@@ -71,3 +72,70 @@ def __init__(
|
71 | 72 | self.cloud_api = cloud_api
|
72 | 73 | self.requires_billing = requires_billing
|
73 | 74 | self.extra_versioned_modules = extra_versioned_modules
|
| 75 | + |
| 76 | + def get_library_name(self) -> str: |
| 77 | + """ |
| 78 | + Return the library name of a given LibraryConfig object |
| 79 | + :return: the library name |
| 80 | + """ |
| 81 | + return self.library_name if self.library_name else self.api_shortname |
| 82 | + |
| 83 | + def __eq__(self, other): |
| 84 | + return ( |
| 85 | + self.api_shortname == other.api_shortname |
| 86 | + and self.api_description == other.api_description |
| 87 | + and self.name_pretty == other.name_pretty |
| 88 | + and self.product_documentation == other.product_documentation |
| 89 | + and self.gapic_configs == other.gapic_configs |
| 90 | + and self.library_type == other.library_type |
| 91 | + and self.release_level == other.release_level |
| 92 | + and self.api_id == other.api_id |
| 93 | + and self.api_reference == other.api_reference |
| 94 | + and self.codeowner_team == other.codeowner_team |
| 95 | + and self.excluded_dependencies == other.excluded_dependencies |
| 96 | + and self.excluded_poms == other.excluded_poms |
| 97 | + and self.client_documentation == other.client_documentation |
| 98 | + and self.distribution_name == other.distribution_name |
| 99 | + and self.googleapis_commitish == other.googleapis_commitish |
| 100 | + and self.group_id == other.group_id |
| 101 | + and self.issue_tracker == other.issue_tracker |
| 102 | + and self.library_name == other.library_name |
| 103 | + and self.rest_documentation == other.rest_documentation |
| 104 | + and self.rpc_documentation == other.rpc_documentation |
| 105 | + and self.cloud_api == other.cloud_api |
| 106 | + and self.requires_billing == other.requires_billing |
| 107 | + and self.extra_versioned_modules == other.extra_versioned_modules |
| 108 | + ) |
| 109 | + |
| 110 | + def __hash__(self): |
| 111 | + m = sha1() |
| 112 | + m.update( |
| 113 | + str( |
| 114 | + [ |
| 115 | + self.api_shortname, |
| 116 | + self.api_description, |
| 117 | + self.name_pretty, |
| 118 | + self.product_documentation, |
| 119 | + self.library_type, |
| 120 | + self.release_level, |
| 121 | + self.api_id, |
| 122 | + self.api_reference, |
| 123 | + self.codeowner_team, |
| 124 | + self.excluded_dependencies, |
| 125 | + self.excluded_poms, |
| 126 | + self.client_documentation, |
| 127 | + self.distribution_name, |
| 128 | + self.googleapis_commitish, |
| 129 | + self.group_id, |
| 130 | + self.issue_tracker, |
| 131 | + self.library_name, |
| 132 | + self.rest_documentation, |
| 133 | + self.rpc_documentation, |
| 134 | + self.cloud_api, |
| 135 | + self.requires_billing, |
| 136 | + self.extra_versioned_modules, |
| 137 | + ] |
| 138 | + + [config.proto_path for config in self.gapic_configs] |
| 139 | + ).encode("utf-8") |
| 140 | + ) |
| 141 | + return int(m.hexdigest(), 16) |
0 commit comments