Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed object paths in autogenerated code in owlbot.py #804

Merged
merged 4 commits into from Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 105 additions & 0 deletions owlbot.py
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import glob
import json
import os
import shutil
Expand Down Expand Up @@ -139,6 +140,110 @@ def place_before(path, text, *before_text, escape=None):

python.py_samples()

# For autogenerated sample code, resolve object paths by finding the specific subpackage
# the object belongs to. This is because we leave out all autogenerated packages from the
# __init__.py of logging_v2. For now, this is manually copy-pasted from the __all__s of each
# subpackage's __init__.py.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we discussed the possibility of eventually restructuring the gapic/veneer files into different folders, which should remove the need for this fix, right?

It might be a good idea to open a bug for that and add a link to the comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on how the gapic/veneer files are structured we might need to have a different fix for replacing logging_v2 with something like logging_v2.gapic, but yeah we wouldn't need a dictionary structure like it is now.

gapic_objects = {
"logging_v2.services.config_service_v2": [
"ConfigServiceV2Client",
"ConfigServiceV2AsyncClient"
],
"logging_v2.services.logging_service_v2": [
"LoggingServiceV2Client",
"LoggingServiceV2AsyncClient"
],
"logging_v2.services.metrics_service_v2": [
"MetricsServiceV2Client",
"MetricsServiceV2AsyncClient"
],
"logging_v2.types": [
"LogEntry",
"LogEntryOperation",
"LogEntrySourceLocation",
"LogSplit",
"DeleteLogRequest",
"ListLogEntriesRequest",
"ListLogEntriesResponse",
"ListLogsRequest",
"ListLogsResponse",
"ListMonitoredResourceDescriptorsRequest",
"ListMonitoredResourceDescriptorsResponse",
"TailLogEntriesRequest",
"TailLogEntriesResponse",
"WriteLogEntriesPartialErrors",
"WriteLogEntriesRequest",
"WriteLogEntriesResponse",
"BigQueryDataset",
"BigQueryOptions",
"BucketMetadata",
"CmekSettings",
"CopyLogEntriesMetadata",
"CopyLogEntriesRequest",
"CopyLogEntriesResponse",
"CreateBucketRequest",
"CreateExclusionRequest",
"CreateLinkRequest",
"CreateSinkRequest",
"CreateViewRequest",
"DeleteBucketRequest",
"DeleteExclusionRequest",
"DeleteLinkRequest",
"DeleteSinkRequest",
"DeleteViewRequest",
"GetBucketRequest",
"GetCmekSettingsRequest",
"GetExclusionRequest",
"GetLinkRequest",
"GetSettingsRequest",
"GetSinkRequest",
"GetViewRequest",
"IndexConfig",
"Link",
"LinkMetadata",
"ListBucketsRequest",
"ListBucketsResponse",
"ListExclusionsRequest",
"ListExclusionsResponse",
"ListLinksRequest",
"ListLinksResponse",
"ListSinksRequest",
"ListSinksResponse",
"ListViewsRequest",
"ListViewsResponse",
"LocationMetadata",
"LogBucket",
"LogExclusion",
"LogSink",
"LogView",
"Settings",
"UndeleteBucketRequest",
"UpdateBucketRequest",
"UpdateCmekSettingsRequest",
"UpdateExclusionRequest",
"UpdateSettingsRequest",
"UpdateSinkRequest",
"UpdateViewRequest",
"IndexType",
"LifecycleState",
"OperationState",
"CreateLogMetricRequest",
"DeleteLogMetricRequest",
"GetLogMetricRequest",
"ListLogMetricsRequest",
"ListLogMetricsResponse",
"LogMetric",
"UpdateLogMetricRequest"
]
}

sample_files = glob.glob("samples/generated_samples/logging_v2_*.py")
for subpackage_name in gapic_objects:
for object_name in gapic_objects[subpackage_name]:
text = "logging_v2." + object_name
replacement = subpackage_name + "." + object_name
s.replace(sample_files, text, replacement)

s.shell.run(["nox", "-s", "blacken"], hide_output=False)
s.shell.run(["nox", "-s", "blacken"], cwd="samples/snippets", hide_output=False)

Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_copy_log_entries():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.CopyLogEntriesRequest(
request = logging_v2.types.CopyLogEntriesRequest(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought: these generated samples aren't covered by tests. Have you considered adding tests for these to catch this kind of issue in the future, like the other snippets? Smoke tests could be helpful here (i.e. just executing each function and making sure nothing crashes)

There may be a simple way to programmatically load and execute each sample, but if it's bit more complicated we could open a bug for later

name="name_value",
destination="destination_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_copy_log_entries():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.CopyLogEntriesRequest(
request = logging_v2.types.CopyLogEntriesRequest(
name="name_value",
destination="destination_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_create_bucket():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.CreateBucketRequest(
request = logging_v2.types.CreateBucketRequest(
parent="parent_value",
bucket_id="bucket_id_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_create_bucket_async():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.CreateBucketRequest(
request = logging_v2.types.CreateBucketRequest(
parent="parent_value",
bucket_id="bucket_id_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_create_bucket_async():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.CreateBucketRequest(
request = logging_v2.types.CreateBucketRequest(
parent="parent_value",
bucket_id="bucket_id_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_create_bucket():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.CreateBucketRequest(
request = logging_v2.types.CreateBucketRequest(
parent="parent_value",
bucket_id="bucket_id_value",
)
Expand Down
Expand Up @@ -36,14 +36,14 @@

async def sample_create_exclusion():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
exclusion = logging_v2.LogExclusion()
exclusion = logging_v2.types.LogExclusion()
exclusion.name = "name_value"
exclusion.filter = "filter_value"

request = logging_v2.CreateExclusionRequest(
request = logging_v2.types.CreateExclusionRequest(
parent="parent_value",
exclusion=exclusion,
)
Expand Down
Expand Up @@ -36,14 +36,14 @@

def sample_create_exclusion():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
exclusion = logging_v2.LogExclusion()
exclusion = logging_v2.types.LogExclusion()
exclusion.name = "name_value"
exclusion.filter = "filter_value"

request = logging_v2.CreateExclusionRequest(
request = logging_v2.types.CreateExclusionRequest(
parent="parent_value",
exclusion=exclusion,
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_create_link():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.CreateLinkRequest(
request = logging_v2.types.CreateLinkRequest(
parent="parent_value",
link_id="link_id_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_create_link():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.CreateLinkRequest(
request = logging_v2.types.CreateLinkRequest(
parent="parent_value",
link_id="link_id_value",
)
Expand Down
Expand Up @@ -36,14 +36,14 @@

async def sample_create_sink():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
sink = logging_v2.LogSink()
sink = logging_v2.types.LogSink()
sink.name = "name_value"
sink.destination = "destination_value"

request = logging_v2.CreateSinkRequest(
request = logging_v2.types.CreateSinkRequest(
parent="parent_value",
sink=sink,
)
Expand Down
Expand Up @@ -36,14 +36,14 @@

def sample_create_sink():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
sink = logging_v2.LogSink()
sink = logging_v2.types.LogSink()
sink.name = "name_value"
sink.destination = "destination_value"

request = logging_v2.CreateSinkRequest(
request = logging_v2.types.CreateSinkRequest(
parent="parent_value",
sink=sink,
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_create_view():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.CreateViewRequest(
request = logging_v2.types.CreateViewRequest(
parent="parent_value",
view_id="view_id_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_create_view():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.CreateViewRequest(
request = logging_v2.types.CreateViewRequest(
parent="parent_value",
view_id="view_id_value",
)
Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_delete_bucket():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.DeleteBucketRequest(
request = logging_v2.types.DeleteBucketRequest(
name="name_value",
)

Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_delete_bucket():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.DeleteBucketRequest(
request = logging_v2.types.DeleteBucketRequest(
name="name_value",
)

Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_delete_exclusion():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.DeleteExclusionRequest(
request = logging_v2.types.DeleteExclusionRequest(
name="name_value",
)

Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_delete_exclusion():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.DeleteExclusionRequest(
request = logging_v2.types.DeleteExclusionRequest(
name="name_value",
)

Expand Down
Expand Up @@ -36,10 +36,10 @@

async def sample_delete_link():
# Create a client
client = logging_v2.ConfigServiceV2AsyncClient()
client = logging_v2.services.config_service_v2.ConfigServiceV2AsyncClient()

# Initialize request argument(s)
request = logging_v2.DeleteLinkRequest(
request = logging_v2.types.DeleteLinkRequest(
name="name_value",
)

Expand Down
Expand Up @@ -36,10 +36,10 @@

def sample_delete_link():
# Create a client
client = logging_v2.ConfigServiceV2Client()
client = logging_v2.services.config_service_v2.ConfigServiceV2Client()

# Initialize request argument(s)
request = logging_v2.DeleteLinkRequest(
request = logging_v2.types.DeleteLinkRequest(
name="name_value",
)

Expand Down