diff --git a/.coveragerc b/.coveragerc index a398577..a52613e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,6 +5,7 @@ branch = True show_missing = True omit = google/cloud/optimization/__init__.py + google/cloud/optimization/gapic_version.py exclude_lines = # Re-enable the standard pragma pragma: NO COVER diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 889f77d..f0f3b24 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,4 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:c43f1d918bcf817d337aa29ff833439494a158a0831508fda4ec75dc4c0d0320 + digest: sha256:f946c75373c2b0040e8e318c5e85d0cf46bc6e61d0a01f3ef94d8de974ac6790 diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 9049e2f..0bb4db2 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.3.1" + ".": "1.3.2" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 27df7bc..44e3412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.3.2](https://github.com/googleapis/python-optimization/compare/v1.3.1...v1.3.2) (2023-02-03) + + +### Documentation + +* Clarification for deprecated fields ([#108](https://github.com/googleapis/python-optimization/issues/108)) ([2879fcb](https://github.com/googleapis/python-optimization/commit/2879fcbb5a18b63f3c6bffd6425e3482936c85cd)) + ## [1.3.1](https://github.com/googleapis/python-optimization/compare/v1.3.0...v1.3.1) (2023-01-20) diff --git a/google/cloud/optimization/gapic_version.py b/google/cloud/optimization/gapic_version.py index c17d0b7..fe27a49 100644 --- a/google/cloud/optimization/gapic_version.py +++ b/google/cloud/optimization/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.3.1" # {x-release-please-version} +__version__ = "1.3.2" # {x-release-please-version} diff --git a/google/cloud/optimization_v1/__init__.py b/google/cloud/optimization_v1/__init__.py index 0f37610..d20bf1a 100644 --- a/google/cloud/optimization_v1/__init__.py +++ b/google/cloud/optimization_v1/__init__.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from google.cloud.optimization import gapic_version as package_version +from google.cloud.optimization_v1 import gapic_version as package_version __version__ = package_version.__version__ diff --git a/google/cloud/optimization_v1/gapic_version.py b/google/cloud/optimization_v1/gapic_version.py index c17d0b7..fe27a49 100644 --- a/google/cloud/optimization_v1/gapic_version.py +++ b/google/cloud/optimization_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.3.1" # {x-release-please-version} +__version__ = "1.3.2" # {x-release-please-version} diff --git a/google/cloud/optimization_v1/services/fleet_routing/async_client.py b/google/cloud/optimization_v1/services/fleet_routing/async_client.py index 6545dc4..47e5cc6 100644 --- a/google/cloud/optimization_v1/services/fleet_routing/async_client.py +++ b/google/cloud/optimization_v1/services/fleet_routing/async_client.py @@ -46,6 +46,7 @@ from google.api_core import operation_async # type: ignore from google.cloud.optimization_v1.types import async_model from google.cloud.optimization_v1.types import fleet_routing +from google.longrunning import operations_pb2 from .transports.base import FleetRoutingTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import FleetRoutingGrpcAsyncIOTransport from .client import FleetRoutingClient @@ -463,6 +464,60 @@ async def sample_batch_optimize_tours(): # Done; return the response. return response + async def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def __aenter__(self): return self diff --git a/google/cloud/optimization_v1/services/fleet_routing/client.py b/google/cloud/optimization_v1/services/fleet_routing/client.py index 87f6825..c25a91c 100644 --- a/google/cloud/optimization_v1/services/fleet_routing/client.py +++ b/google/cloud/optimization_v1/services/fleet_routing/client.py @@ -50,6 +50,7 @@ from google.api_core import operation_async # type: ignore from google.cloud.optimization_v1.types import async_model from google.cloud.optimization_v1.types import fleet_routing +from google.longrunning import operations_pb2 from .transports.base import FleetRoutingTransport, DEFAULT_CLIENT_INFO from .transports.grpc import FleetRoutingGrpcTransport from .transports.grpc_asyncio import FleetRoutingGrpcAsyncIOTransport @@ -669,6 +670,60 @@ def __exit__(self, type, value, traceback): """ self.transport.close() + def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ diff --git a/google/cloud/optimization_v1/services/fleet_routing/transports/base.py b/google/cloud/optimization_v1/services/fleet_routing/transports/base.py index 9fac391..b890eda 100644 --- a/google/cloud/optimization_v1/services/fleet_routing/transports/base.py +++ b/google/cloud/optimization_v1/services/fleet_routing/transports/base.py @@ -28,6 +28,7 @@ from google.oauth2 import service_account # type: ignore from google.cloud.optimization_v1.types import fleet_routing +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -190,6 +191,15 @@ def batch_optimize_tours( ]: raise NotImplementedError() + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def kind(self) -> str: raise NotImplementedError() diff --git a/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py b/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py index 176b9be..8ca03fe 100644 --- a/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py +++ b/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py @@ -26,6 +26,7 @@ import grpc # type: ignore from google.cloud.optimization_v1.types import fleet_routing +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import FleetRoutingTransport, DEFAULT_CLIENT_INFO @@ -350,6 +351,23 @@ def batch_optimize_tours( def close(self): self.grpc_channel.close() + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + @property def kind(self) -> str: return "grpc" diff --git a/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py b/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py index 85c7d0a..281541b 100644 --- a/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py +++ b/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py @@ -26,6 +26,7 @@ from grpc.experimental import aio # type: ignore from google.cloud.optimization_v1.types import fleet_routing +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import FleetRoutingTransport, DEFAULT_CLIENT_INFO from .grpc import FleetRoutingGrpcTransport @@ -358,5 +359,22 @@ def batch_optimize_tours( def close(self): return self.grpc_channel.close() + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + __all__ = ("FleetRoutingGrpcAsyncIOTransport",) diff --git a/google/cloud/optimization_v1/types/fleet_routing.py b/google/cloud/optimization_v1/types/fleet_routing.py index 70b1ab3..4be48d2 100644 --- a/google/cloud/optimization_v1/types/fleet_routing.py +++ b/google/cloud/optimization_v1/types/fleet_routing.py @@ -82,7 +82,7 @@ class OptimizeToursRequest(proto.Message): solving_mode (google.cloud.optimization_v1.types.OptimizeToursRequest.SolvingMode): By default, the solving mode is ``DEFAULT_SOLVE`` (0). max_validation_errors (int): - Truncates the number of validation errors returned. Those + Truncates the number of validation errors returned. These errors are typically attached to an INVALID_ARGUMENT error payload as a BadRequest error detail (https://cloud.google.com/apis/design/errors#error_details), @@ -275,7 +275,7 @@ class OptimizeToursRequest(proto.Message): [OptimizeToursResponse.request_label][google.cloud.optimization.v1.OptimizeToursResponse.request_label]. populate_travel_step_polylines (bool): Deprecated: Use - [OptimizeToursRequest.populate_transition_polylines][] + [OptimizeToursRequest.populate_transition_polylines][google.cloud.optimization.v1.OptimizeToursRequest.populate_transition_polylines] instead. If true, polylines will be populated in response [ShipmentRoute.transitions][google.cloud.optimization.v1.ShipmentRoute.transitions]. Note that in this case, the polylines will also be populated @@ -441,11 +441,12 @@ class OptimizeToursResponse(proto.Message): Duration, distance and usage metrics for this solution. total_cost (float): - Deprecated: Use [Metrics.total_cost][] instead. Total cost - of the solution. This takes into account all costs: costs - per per hour and travel hour, fixed vehicle costs, - unperformed shipment penalty costs, global duration cost, - etc. + Deprecated: Use + [Metrics.total_cost][google.cloud.optimization.v1.OptimizeToursResponse.Metrics.total_cost] + instead. Total cost of the solution. This takes into account + all costs: costs per per hour and travel hour, fixed vehicle + costs, unperformed shipment penalty costs, global duration + cost, etc. """ class Metrics(proto.Message): @@ -957,20 +958,21 @@ class PrecedenceRule(proto.Message): ) class BreakRule(proto.Message): - r"""Deprecated: Use top level [BreakRule][] instead. Rules to generate - time breaks for a vehicle (e.g. lunch breaks). A break is a - contiguous period of time during which the vehicle remains idle at - its current position and cannot perform any visit. A break may - occur: + r"""Deprecated: Use top level + [BreakRule][google.cloud.optimization.v1.ShipmentModel.BreakRule] + instead. Rules to generate time breaks for a vehicle (e.g. lunch + breaks). A break is a contiguous period of time during which the + vehicle remains idle at its current position and cannot perform any + visit. A break may occur: - during the travel between two visits (which includes the time right before or right after a visit, but not in the middle of a visit), in which case it extends the corresponding transit time - between the visits, - - or before the vehicle start (the vehicle may not start in the - middle of a break), in which case it does not affect the vehicle - start time. - - or after the vehicle end (ditto, with the vehicle end time). + between the visits + - before the vehicle start (the vehicle may not start in the middle + of a break), in which case it does not affect the vehicle start + time. + - after the vehicle end (ditto, with the vehicle end time). Attributes: break_requests (MutableSequence[google.cloud.optimization_v1.types.ShipmentModel.BreakRule.BreakRequest]): @@ -1319,7 +1321,9 @@ class Shipment(proto.Message): performing route. ``precedence_rules`` that reference ignored shipments will also be ignored. demands (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantity]): - Deprecated: Use [Shipment.load_demands][] instead. + Deprecated: Use + [Shipment.load_demands][google.cloud.optimization.v1.Shipment.load_demands] + instead. """ class VisitRequest(proto.Message): @@ -1404,7 +1408,9 @@ class VisitRequest(proto.Message): corresponding [ShipmentRoute.Visit][google.cloud.optimization.v1.ShipmentRoute.Visit]. demands (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantity]): - Deprecated: Use [VisitRequest.load_demands][] instead. + Deprecated: Use + [VisitRequest.load_demands][google.cloud.optimization.v1.Shipment.VisitRequest.load_demands] + instead. """ arrival_location: latlng_pb2.LatLng = proto.Field( @@ -1873,18 +1879,23 @@ class Vehicle(proto.Message): vehicles are ignored, it is skipped in the response. break_rule_indices (MutableSequence[int]): Deprecated: No longer used. Indices in the ``break_rule`` - field in the source [ShipmentModel][]. They correspond to - break rules enforced on the vehicle. + field in the source + [ShipmentModel][google.cloud.optimization.v1.ShipmentModel]. + They correspond to break rules enforced on the vehicle. As of 2018/03, at most one rule index per vehicle can be specified. capacities (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantity]): - Deprecated: Use [Vehicle.load_limits][] instead. + Deprecated: Use + [Vehicle.load_limits][google.cloud.optimization.v1.Vehicle.load_limits] + instead. start_load_intervals (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantityInterval]): - Deprecated: Use [Vehicle.LoadLimit.start_load_interval][] + Deprecated: Use + [Vehicle.LoadLimit.start_load_interval][google.cloud.optimization.v1.Vehicle.LoadLimit.start_load_interval] instead. end_load_intervals (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantityInterval]): - Deprecated: Use [Vehicle.LoadLimit.end_load_interval][] + Deprecated: Use + [Vehicle.LoadLimit.end_load_interval][google.cloud.optimization.v1.Vehicle.LoadLimit.end_load_interval] instead. """ @@ -2354,8 +2365,9 @@ class TimeWindow(proto.Message): class CapacityQuantity(proto.Message): - r"""Deprecated: Use [Shipment.Load][], [Vehicle.LoadLimit][] and - [ShipmentRoute.VehicleLoad][] instead. + r"""Deprecated: Use + [Vehicle.LoadLimit.Interval][google.cloud.optimization.v1.Vehicle.LoadLimit.Interval] + instead. Attributes: type_ (str): @@ -2375,7 +2387,10 @@ class CapacityQuantity(proto.Message): class CapacityQuantityInterval(proto.Message): - r"""Deprecated: Use [Vehicle.LoadLimit.Interval][] instead. + r"""Deprecated: Use + [Vehicle.LoadLimit.Interval][google.cloud.optimization.v1.Vehicle.LoadLimit.Interval] + instead. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields @@ -2433,10 +2448,10 @@ class DistanceLimit(proto.Message): This field is a member of `oneof`_ ``_soft_max_meters``. cost_per_kilometer_above_soft_max (float): - Cost per kilometer incurred if ``soft_max_meters`` limit is - violated. The additional cost is 0 if the distance is under - the limit, otherwise the formula used to compute the cost is - the following: + Cost per kilometer incurred if distance is above + ``soft_max_meters`` limit. The additional cost is 0 if the + distance is under the limit, otherwise the formula used to + compute the cost is the following: :: @@ -2940,36 +2955,40 @@ class ShipmentRoute(proto.Message): Total cost of the route. The sum of all costs in the cost map. end_loads (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantity]): - Deprecated: Use [ShipmentRoute.Transition.loads][] instead. - Vehicle loads upon arrival at its end location, for each - type specified in + Deprecated: Use + [Transition.vehicle_loads][google.cloud.optimization.v1.ShipmentRoute.Transition.vehicle_loads] + instead. Vehicle loads upon arrival at its end location, for + each type specified in [Vehicle.capacities][google.cloud.optimization.v1.Vehicle.capacities], ``start_load_intervals``, ``end_load_intervals`` or demands. Exception: we omit loads for quantity types unconstrained by intervals and that don't have any non-zero demand on the route. travel_steps (MutableSequence[google.cloud.optimization_v1.types.ShipmentRoute.TravelStep]): - Deprecated: Use [ShipmentRoute.Transition][] instead. - Ordered list of travel steps for the route. + Deprecated: Use + [ShipmentRoute.transitions][google.cloud.optimization.v1.ShipmentRoute.transitions] + instead. Ordered list of travel steps for the route. vehicle_detour (google.protobuf.duration_pb2.Duration): Deprecated: No longer used. This field will only be populated at the [ShipmentRoute.Visit][google.cloud.optimization.v1.ShipmentRoute.Visit] - level. Extra detour time due to the shipments visited on the - route. + level. + + This field is the extra detour time due to the shipments + visited on the route. It is equal to ``vehicle_end_time`` - ``vehicle_start_time`` - travel duration from the vehicle's start_location to its ``end_location``. delay_before_vehicle_end (google.cloud.optimization_v1.types.ShipmentRoute.Delay): - Deprecated: Use [ShipmentRoute.Transition.delay_duration][] - instead. Delay occurring before the vehicle end. See + Deprecated: Delay occurring before the vehicle end. See [TransitionAttributes.delay][google.cloud.optimization.v1.TransitionAttributes.delay]. """ class Delay(proto.Message): - r"""Deprecated: Use [ShipmentRoute.Transition.delay_duration][] instead. - Time interval spent on the route resulting from a + r"""Deprecated: Use + [ShipmentRoute.Transition.delay_duration][google.cloud.optimization.v1.ShipmentRoute.Transition.delay_duration] + instead. Time interval spent on the route resulting from a [TransitionAttributes.delay][google.cloud.optimization.v1.TransitionAttributes.delay]. Attributes: @@ -3043,9 +3062,10 @@ class Visit(proto.Message): [VisitRequest.label][google.cloud.optimization.v1.Shipment.VisitRequest.label], if specified in the ``VisitRequest``. arrival_loads (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantity]): - Deprecated: Use [ShipmentRoute.Transition.loads][] instead. - Vehicle loads upon arrival at the visit location, for each - type specified in + Deprecated: Use + [Transition.vehicle_loads][google.cloud.optimization.v1.ShipmentRoute.Transition.vehicle_loads] + instead. Vehicle loads upon arrival at the visit location, + for each type specified in [Vehicle.capacities][google.cloud.optimization.v1.Vehicle.capacities], ``start_load_intervals``, ``end_load_intervals`` or ``demands``. @@ -3054,10 +3074,13 @@ class Visit(proto.Message): intervals and that don't have any non-zero demand on the route. delay_before_start (google.cloud.optimization_v1.types.ShipmentRoute.Delay): - Deprecated: Use [ShipmentRoute.Transition.delay_duration][] - instead. + Deprecated: Use + [ShipmentRoute.Transition.delay_duration][google.cloud.optimization.v1.ShipmentRoute.Transition.delay_duration] + instead. Delay occurring before the visit starts. demands (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantity]): - Deprecated: Use [Visit.load_demands][] instead. + Deprecated: Use + [Visit.load_demands][google.cloud.optimization.v1.ShipmentRoute.Visit.load_demands] + instead. """ shipment_index: int = proto.Field( @@ -3182,7 +3205,9 @@ class Transition(proto.Message): next transition's loads, depending on whether the visit was a pickup or a delivery. loads (MutableSequence[google.cloud.optimization_v1.types.CapacityQuantity]): - Deprecated: Use [Transition.vehicle_loads][] instead. + Deprecated: Use + [Transition.vehicle_loads][google.cloud.optimization.v1.ShipmentRoute.Transition.vehicle_loads] + instead. """ travel_duration: duration_pb2.Duration = proto.Field( @@ -3298,14 +3323,16 @@ class Break(proto.Message): ) class TravelStep(proto.Message): - r"""Deprecated: Use [ShipmentRoute.transitions][] instead. Travel - between each visit, along the route: from the vehicle's - ``start_location`` to the first visit's ``arrival_location``, then - from the first visit's ``departure_location`` to the second visit's - ``arrival_location``, and so on until the vehicle's - ``end_location``. This accounts only for the actual travel between - visits, not counting the waiting time, the time spent performing a - visit, nor the distance covered during a visit. + r"""Deprecated: Use + [ShipmentRoute.Transition][google.cloud.optimization.v1.ShipmentRoute.Transition] + instead. Travel between each visit along the route: from the + vehicle's ``start_location`` to the first visit's + ``arrival_location``, then from the first visit's + ``departure_location`` to the second visit's ``arrival_location``, + and so on until the vehicle's ``end_location``. This accounts only + for the actual travel between visits, not counting the waiting time, + the time spent performing a visit, nor the distance covered during a + visit. Invariant: ``travel_steps_size() == visits_size() + 1``. @@ -3628,11 +3655,17 @@ class AggregatedMetrics(proto.Message): (resp. [ShipmentRoute.metrics.max_loads][google.cloud.optimization.v1.AggregatedMetrics.max_loads]. costs (MutableMapping[str, float]): - Deprecated: Use [ShipmentRoute.route_costs][] and - [OptimizeToursResponse.Metrics.costs][] instead. + Deprecated: Use + [ShipmentRoute.route_costs][google.cloud.optimization.v1.ShipmentRoute.route_costs] + and + [OptimizeToursResponse.Metrics.costs][google.cloud.optimization.v1.OptimizeToursResponse.Metrics.costs] + instead. total_cost (float): - Deprecated: Use [ShipmentRoute.route_total_cost][] and - [OptimizeToursResponse.Metrics.total_cost][] instead. + Deprecated: Use + [ShipmentRoute.route_total_cost][google.cloud.optimization.v1.ShipmentRoute.route_total_cost] + and + [OptimizeToursResponse.Metrics.total_cost][google.cloud.optimization.v1.OptimizeToursResponse.Metrics.total_cost] + instead. """ performed_shipment_count: int = proto.Field( @@ -3782,7 +3815,7 @@ class Relaxation(proto.Message): level (google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation.Relaxation.Level): The constraint relaxation level that applies when the conditions at or after ``threshold_time`` AND at least - ``threshold_visit_count`` are satified. + ``threshold_visit_count`` are satisfied. threshold_time (google.protobuf.timestamp_pb2.Timestamp): The time at or after which the relaxation ``level`` may be applied. @@ -3800,7 +3833,7 @@ class Relaxation(proto.Message): class Level(proto.Enum): r"""Expresses the different constraint relaxation levels, which - are applied for a visit and those that follow when it satifies + are applied for a visit and those that follow when it satisfies the threshold conditions. The enumeration below is in order of increasing relaxation. @@ -3810,7 +3843,7 @@ class Level(proto.Enum): Implicit default relaxation level: no constraints are relaxed, i.e., all visits are fully constrained. - This value must not be explicly used in ``level``. + This value must not be explicitly used in ``level``. RELAX_VISIT_TIMES_AFTER_THRESHOLD (1): Visit start times and vehicle start/end times will be relaxed, but each visit remains bound to @@ -3939,6 +3972,13 @@ class OptimizeToursValidationError(proto.Message): - INJECTED_SOLUTION_MISSING_LABEL = 2000; - INJECTED_SOLUTION_DUPLICATE_LABEL = 2001; - INJECTED_SOLUTION_AMBIGUOUS_INDEX = 2002; + - INJECTED_SOLUTION_INFEASIBLE_AFTER_GETTING_TRAVEL_TIMES + = 2003; + - INJECTED_SOLUTION_TRANSITION_INCONSISTENT_WITH_ACTUAL_TRAVEL + = 2004; + - INJECTED_SOLUTION_CONCURRENT_SOLUTION_TYPES = 2005; + - INJECTED_SOLUTION_MORE_THAN_ONE_PER_TYPE = 2006; + - INJECTED_SOLUTION_REFRESH_WITHOUT_POPULATE = 2008; - SHIPMENT_MODEL_ERROR = 22; @@ -3951,6 +3991,9 @@ class OptimizeToursValidationError(proto.Message): - SHIPMENT_MODEL_GLOBAL_START_TIME_AFTER_GLOBAL_END_TIME = 2204; - SHIPMENT_MODEL_GLOBAL_DURATION_TOO_LONG = 2205; + - SHIPMENT_MODEL_MAX_ACTIVE_VEHICLES_NOT_POSITIVE = + 2206; + - SHIPMENT_MODEL_DURATION_MATRIX_TOO_LARGE = 2207; - INDEX_ERROR = 24; @@ -4074,10 +4117,14 @@ class OptimizeToursValidationError(proto.Message): - SHIPMENT_ERROR = 40; + - SHIPMENT_PD_LIMIT_WITHOUT_PICKUP_AND_DELIVERY = 4014; - SHIPMENT_PD_ABSOLUTE_DETOUR_LIMIT_DURATION_NEGATIVE_OR_NAN = 4000; - SHIPMENT_PD_ABSOLUTE_DETOUR_LIMIT_DURATION_EXCEEDS_GLOBAL_DURATION = 4001; + - SHIPMENT_PD_RELATIVE_DETOUR_LIMIT_INVALID = 4015; + - SHIPMENT_PD_DETOUR_LIMIT_AND_EXTRA_VISIT_DURATION = + 4016; - SHIPMENT_PD_TIME_LIMIT_DURATION_NEGATIVE_OR_NAN = 4002; - SHIPMENT_PD_TIME_LIMIT_DURATION_EXCEEDS_GLOBAL_DURATION @@ -4094,7 +4141,6 @@ class OptimizeToursValidationError(proto.Message): - SHIPMENT_INVALID_COST_FOR_VEHICLE = 4011; - SHIPMENT_COST_FOR_VEHICLE_INDEX_OUT_OF_BOUNDS = 4012; - SHIPMENT_DUPLICATE_COST_FOR_VEHICLE_INDEX = 4013; - - SHIPMENT_DETOUR_WITHOUT_PICKUP_AND_DELIVERY = 4014; - VEHICLE_ERROR = 42; @@ -4122,6 +4168,10 @@ class OptimizeToursValidationError(proto.Message): - VEHICLE_INVALID_COST_PER_TRAVELED_HOUR = 4219; - VEHICLE_INVALID_FIXED_COST = 4220; - VEHICLE_INVALID_TRAVEL_DURATION_MULTIPLE = 4221; + - VEHICLE_TRAVEL_DURATION_MULTIPLE_WITH_SHIPMENT_PD_DETOUR_LIMITS + = 4223; + - VEHICLE_MATRIX_INDEX_WITH_SHIPMENT_PD_DETOUR_LIMITS = + 4224; - VEHICLE_MINIMUM_DURATION_LONGER_THAN_DURATION_LIMIT = 4222; @@ -4206,11 +4256,6 @@ class OptimizeToursValidationError(proto.Message): 5600; - DURATION_SECONDS_MATRIX_DURATION_EXCEEDS_GLOBAL_DURATION = 5601; - - - GRAPH_ARC_ERROR = 58; - - - GRAPH_ARC_DURATION_NEGATIVE_OR_NAN = 5800; - - GRAPH_ARC_DURATION_EXCEEDS_GLOBAL_DURATION = 5801; display_name (str): The error display name. fields (MutableSequence[google.cloud.optimization_v1.types.OptimizeToursValidationError.FieldReference]): diff --git a/noxfile.py b/noxfile.py index d1f2496..e9649dc 100644 --- a/noxfile.py +++ b/noxfile.py @@ -188,9 +188,9 @@ def unit(session): def install_systemtest_dependencies(session, *constraints): # Use pre-release gRPC for system tests. - # Exclude version 1.49.0rc1 which has a known issue. - # See https://github.com/grpc/grpc/pull/30642 - session.install("--pre", "grpcio!=1.49.0rc1") + # Exclude version 1.52.0rc1 which has a known issue. + # See https://github.com/grpc/grpc/issues/32163 + session.install("--pre", "grpcio!=1.52.0rc1") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -345,9 +345,7 @@ def prerelease_deps(session): unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES session.install(*unit_deps_all) system_deps_all = ( - SYSTEM_TEST_STANDARD_DEPENDENCIES - + SYSTEM_TEST_EXTERNAL_DEPENDENCIES - + SYSTEM_TEST_EXTRAS + SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES ) session.install(*system_deps_all) @@ -377,8 +375,8 @@ def prerelease_deps(session): # dependency of grpc "six", "googleapis-common-protos", - # Exclude version 1.49.0rc1 which has a known issue. See https://github.com/grpc/grpc/pull/30642 - "grpcio!=1.49.0rc1", + # Exclude version 1.52.0rc1 which has a known issue. See https://github.com/grpc/grpc/issues/32163 + "grpcio!=1.52.0rc1", "grpcio-status", "google-api-core", "proto-plus", diff --git a/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json b/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json index 10214ad..9891dc2 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-optimization", - "version": "1.3.1" + "version": "1.3.2" }, "snippets": [ { diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index afbcfad..342a40d 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-optimization==1.3.0 +google-cloud-optimization==1.3.1 google-cloud-storage==2.7.0 diff --git a/tests/unit/gapic/optimization_v1/test_fleet_routing.py b/tests/unit/gapic/optimization_v1/test_fleet_routing.py index bcdbfa7..648af90 100644 --- a/tests/unit/gapic/optimization_v1/test_fleet_routing.py +++ b/tests/unit/gapic/optimization_v1/test_fleet_routing.py @@ -1123,6 +1123,7 @@ def test_fleet_routing_base_transport(): methods = ( "optimize_tours", "batch_optimize_tours", + "get_operation", ) for method in methods: with pytest.raises(NotImplementedError): @@ -1636,6 +1637,151 @@ async def test_transport_close_async(): close.assert_called_once() +def test_get_operation(transport: str = "grpc"): + client = FleetRoutingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation_async(transport: str = "grpc"): + client = FleetRoutingAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = FleetRoutingClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = FleetRoutingAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = FleetRoutingClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = FleetRoutingAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_transport_close(): transports = { "grpc": "_grpc_channel",