diff --git a/docs/index.rst b/docs/index.rst index 5eee2f9d..5ef0e009 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -2,55 +2,44 @@ .. include:: multiprocessing.rst -Api Reference -------------- +This package includes clients for multiple versions of Cloud Asset Inventory. +By default, you will get version ``asset_v1``. -This package includes clients for multiple versions of the Cloud Asset API. By default, you will get ``v1`` -the latest stable version. -v1 -~~~~~~~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 asset_v1/services asset_v1/types -Beta releases with additional features over the current stable version. These are expected to move into the stable release soon; -until then, the usual beta admonishment (changes are possible, etc.) applies. - -In order to use it, you will want to import from -``google.cloud.asset_v1p4beta1`` in lieu of ``google.cloud.asset_v1``. - -v1p1beta1 -~~~~~~~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 asset_v1p1beta1/services asset_v1p1beta1/types - -v1p2beta1 -~~~~~~~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 asset_v1p2beta1/services asset_v1p2beta1/types - -v1p4beta1 -~~~~~~~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 asset_v1p4beta1/services asset_v1p4beta1/types - -v1p5beta1 -~~~~~~~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 @@ -61,12 +50,12 @@ v1p5beta1 Migration Guide --------------- -See the guide below for instructions on migrating to the 2.x release of this library. +See the guide below for instructions on migrating to the latest version. .. toctree:: :maxdepth: 2 - UPGRADING +  UPGRADING Changelog @@ -75,6 +64,6 @@ Changelog For a list of all ``google-cloud-asset`` releases: .. toctree:: - :maxdepth: 2 + :maxdepth: 2 - changelog + changelog diff --git a/google/cloud/asset_v1/services/asset_service/async_client.py b/google/cloud/asset_v1/services/asset_service/async_client.py index 692fb57f..d5d2a86d 100644 --- a/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1/services/asset_service/async_client.py @@ -70,7 +70,7 @@ class AssetServiceAsyncClient: access_policy_path = staticmethod(AssetServiceClient.access_policy_path) parse_access_policy_path = staticmethod(AssetServiceClient.parse_access_policy_path) asset_path = staticmethod(AssetServiceClient.asset_path) - + parse_asset_path = staticmethod(AssetServiceClient.parse_asset_path) feed_path = staticmethod(AssetServiceClient.feed_path) parse_feed_path = staticmethod(AssetServiceClient.parse_feed_path) inventory_path = staticmethod(AssetServiceClient.inventory_path) diff --git a/google/cloud/asset_v1/services/asset_service/client.py b/google/cloud/asset_v1/services/asset_service/client.py index dbacd132..46e8e2a3 100644 --- a/google/cloud/asset_v1/services/asset_service/client.py +++ b/google/cloud/asset_v1/services/asset_service/client.py @@ -222,6 +222,12 @@ def asset_path() -> str: """Returns a fully-qualified asset string.""" return "*".format() + @staticmethod + def parse_asset_path(path: str) -> Dict[str, str]: + """Parses a asset path into its component segments.""" + m = re.match(r"^.*$", path) + return m.groupdict() if m else {} + @staticmethod def feed_path( project: str, diff --git a/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py b/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py index 0a5f7ba9..3c24b882 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py @@ -64,7 +64,7 @@ class AssetServiceAsyncClient: access_policy_path = staticmethod(AssetServiceClient.access_policy_path) parse_access_policy_path = staticmethod(AssetServiceClient.parse_access_policy_path) asset_path = staticmethod(AssetServiceClient.asset_path) - + parse_asset_path = staticmethod(AssetServiceClient.parse_asset_path) service_perimeter_path = staticmethod(AssetServiceClient.service_perimeter_path) parse_service_perimeter_path = staticmethod( AssetServiceClient.parse_service_perimeter_path diff --git a/google/cloud/asset_v1p5beta1/services/asset_service/client.py b/google/cloud/asset_v1p5beta1/services/asset_service/client.py index 299c6fcf..08ab0a0d 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/client.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/client.py @@ -216,6 +216,12 @@ def asset_path() -> str: """Returns a fully-qualified asset string.""" return "*".format() + @staticmethod + def parse_asset_path(path: str) -> Dict[str, str]: + """Parses a asset path into its component segments.""" + m = re.match(r"^.*$", path) + return m.groupdict() if m else {} + @staticmethod def service_perimeter_path( access_policy: str, diff --git a/owlbot.py b/owlbot.py index 8f351856..fe360350 100644 --- a/owlbot.py +++ b/owlbot.py @@ -14,7 +14,6 @@ import json from pathlib import Path -import re import shutil import synthtool as s @@ -36,55 +35,39 @@ if clean_up_generated_samples: shutil.rmtree("samples/generated_samples", ignore_errors=True) clean_up_generated_samples = False - # Fix import of 'osconfig' type - s.replace( - library / f"google/cloud/asset_{library.name}/types/assets.py", - f"from google\.cloud\.osconfig\.{library.name} import inventory_pb2", - f"from google.cloud.osconfig_{library.name} import Inventory" - ) - s.replace( - library / f"google/cloud/asset_{library.name}/types/assets.py", - "inventory_pb2\.Inventory", - "Inventory" - ) - - s.replace( - library / f"google/cloud/asset_{library.name}/types/assets.py", - "google\.cloud\.osconfig\.v1\.inventory_pb2\.Inventory", - "google.cloud.osconfig_v1.Inventory" - ) - - # Remove broken `parse_asset_path` method - # The resource pattern is '*' which breaks the regex match - s.replace( - library / "google/cloud/**/client.py", - """@staticmethod - def parse_asset_path.*?@staticmethod""", - """@staticmethod""", - flags=re.MULTILINE | re.DOTALL - ) - - s.replace( - library / "google/cloud/**/async_client.py", - """parse_asset_path = staticmethod\(AssetServiceClient\.parse_asset_path\)""", - "" - ) - - s.replace( - library / "tests/unit/**/test_asset_service.py", - """def test_parse_asset_path.*?def""", - """def""", - flags=re.MULTILINE | re.DOTALL, - ) - - s.replace( - library / "google/cloud/asset_v*/__init__.py", - "from google.cloud.asset import gapic_version as package_version", - f"from google.cloud.asset_{library.name} import gapic_version as package_version", - ) - - s.move([library], excludes=["**/gapic_version.py", "docs/index.rst", "setup.py", "testing/constraints-3.7.txt"]) + # ---------------------------------------------------------------------------- + # Workarounds to be migrated to the monorepo + # ---------------------------------------------------------------------------- + + # Generator issue: https://github.com/googleapis/gapic-generator-python/issues/1806 + # Description: google-cloud-org-policy is not defined in https://github.com/googleapis/gapic-generator-python/blob/main/gapic/templates/_pypi_packages.j2. + # An attempt was made to add the dependency via https://github.com/googleapis/gapic-generator-python/pull/1805 however mypy checks + # failed with error `google.cloud.orgpolicy.v1.orgpolicy_pb2.Policy is not valid as a type`. + + # Only the setup.py and testing/constraints-3.7.txt from the default version need to be updated + if library.name == default_version: + replacement_count = 1 + assert replacement_count == s.replace( + library / "setup.py", + """\"google-cloud-access-context-manager >= 0.1.2, <1.0.0dev\", + \"google-cloud-os-config >= 1.0.0, <2.0.0dev\",""", + """"google-cloud-access-context-manager >= 0.1.2, <1.0.0dev", + "google-cloud-org-policy >= 0.1.2, <2.0.0dev", + "google-cloud-os-config >= 1.0.0, <2.0.0dev",""", + ) + + replacement_count = 1 + assert replacement_count == s.replace( + library / "testing/constraints-3.7.txt", + """google-cloud-access-context-manager==0.1.2 +google-cloud-os-config==1.0.0""", + """google-cloud-access-context-manager==0.1.2 +google-cloud-org-policy==0.1.2 +google-cloud-os-config==1.0.0""", + ) + + s.move([library], excludes=["**/gapic_version.py"]) s.remove_staging_dirs() # ---------------------------------------------------------------------------- @@ -96,7 +79,7 @@ def parse_asset_path.*?@staticmethod""", microgenerator=True, versions=gcp.common.detect_versions(path="./google", default_first=True), ) -s.move(templated_files, excludes=[".coveragerc", ".github/release-please.yml", "docs/index.rst"]) +s.move(templated_files, excludes=[".coveragerc", ".github/release-please.yml"]) python.py_samples(skip_readmes=True) diff --git a/setup.py b/setup.py index e0fdcc42..f3b4c9ff 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -37,13 +37,13 @@ dependencies = [ "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", - "grpc-google-iam-v1 >=0.12.4, <1.0.0dev", - "google-cloud-access-context-manager >= 0.1.2, <1.0.0dev", - "google-cloud-org-policy>=0.1.2, <2.0.0", - "google-cloud-os-config >= 1.0.0, <2.0.0dev", "proto-plus >= 1.22.0, <2.0.0dev", "proto-plus >= 1.22.2, <2.0.0dev; python_version>='3.11'", "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "google-cloud-access-context-manager >= 0.1.2, <1.0.0dev", + "google-cloud-org-policy >= 0.1.2, <2.0.0dev", + "google-cloud-os-config >= 1.0.0, <2.0.0dev", + "grpc-google-iam-v1 >= 0.12.4, <1.0.0dev", ] url = "https://github.com/googleapis/python-asset" @@ -59,9 +59,7 @@ if package.startswith("google") ] -namespaces = ["google"] -if "google.cloud" in packages: - namespaces.append("google.cloud") +namespaces = ["google", "google.cloud"] setuptools.setup( name=name, diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt index 307e89fe..05de978b 100644 --- a/testing/constraints-3.7.txt +++ b/testing/constraints-3.7.txt @@ -5,9 +5,9 @@ # e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", # Then this file should have google-cloud-foo==1.14.0 google-api-core==1.34.0 -grpc-google-iam-v1==0.12.4 +proto-plus==1.22.0 +protobuf==3.19.5 google-cloud-access-context-manager==0.1.2 google-cloud-org-policy==0.1.2 google-cloud-os-config==1.0.0 -proto-plus==1.22.0 -protobuf==3.19.5 +grpc-google-iam-v1==0.12.4 diff --git a/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/unit/gapic/asset_v1/test_asset_service.py index 7a485be4..a3c35e8c 100644 --- a/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1/test_asset_service.py @@ -14685,6 +14685,15 @@ def test_asset_path(): assert expected == actual +def test_parse_asset_path(): + expected = {} + path = AssetServiceClient.asset_path(**expected) + + # Check that the path construction is reversible. + actual = AssetServiceClient.parse_asset_path(path) + assert expected == actual + + def test_feed_path(): project = "cuttlefish" feed = "mussel" diff --git a/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py b/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py index 81a432c4..d169a712 100644 --- a/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py @@ -2024,6 +2024,15 @@ def test_asset_path(): assert expected == actual +def test_parse_asset_path(): + expected = {} + path = AssetServiceClient.asset_path(**expected) + + # Check that the path construction is reversible. + actual = AssetServiceClient.parse_asset_path(path) + assert expected == actual + + def test_service_perimeter_path(): access_policy = "cuttlefish" service_perimeter = "mussel"