Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

chore: remove obsolete workarounds in owlbot.py #564

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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

Expand All @@ -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
Expand All @@ -75,6 +64,6 @@ Changelog
For a list of all ``google-cloud-asset`` releases:

.. toctree::
:maxdepth: 2
:maxdepth: 2

changelog
changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions google/cloud/asset_v1/services/asset_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions google/cloud/asset_v1p5beta1/services/asset_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
83 changes: 33 additions & 50 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import json
from pathlib import Path
import re
import shutil

import synthtool as s
Expand All @@ -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()

# ----------------------------------------------------------------------------
Expand All @@ -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)

Expand Down
14 changes: 6 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"

Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions testing/constraints-3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
google-cloud-os-config
grpc-google-iam-v1
2 changes: 2 additions & 0 deletions testing/constraints-3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
google-cloud-os-config
grpc-google-iam-v1
2 changes: 2 additions & 0 deletions testing/constraints-3.12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
google-cloud-os-config
grpc-google-iam-v1
6 changes: 3 additions & 3 deletions testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions testing/constraints-3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
google-cloud-os-config
grpc-google-iam-v1
2 changes: 2 additions & 0 deletions testing/constraints-3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
google-cloud-os-config
grpc-google-iam-v1
Loading