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

chore(retail): migrate code from googleapis/python-retail #8781

Merged
merged 95 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
3f60989
chore: add scripts to setup and teardown test resources (#137)
t-karasova Jan 28, 2022
bbdcb0c
docs(samples): add retail search service samples (#133)
t-karasova Jan 28, 2022
5ba9b71
docs(samples): add resources for interactive tutorials (#145)
t-karasova Feb 8, 2022
7f8ab66
test: create_test_resources path to schemas is fixed (#148)
t-karasova Feb 8, 2022
6f5e4ce
fix: resolve DuplicateCredentialArgs error when using credentials_fil…
gcf-owl-bot[bot] Feb 8, 2022
26ca656
chore(deps): update all dependencies (#141)
renovate-bot Feb 10, 2022
e22fb0b
chore: use gapic-generator-python 0.63.2 (#151)
gcf-owl-bot[bot] Feb 11, 2022
2f7f95d
chore(deps): update dependency pytest to v7.0.1 (#152)
renovate-bot Feb 12, 2022
1fe06e0
docs(samples): add product import samples (#149)
tetiana-karasova Feb 15, 2022
c6444fc
test: fix for product import tests (#156)
tetiana-karasova Feb 18, 2022
2cf7f35
chore(deps): update all dependencies (#153)
renovate-bot Feb 18, 2022
7cd2340
docs(samples): add samples to create, read, update, and delete produc…
tetiana-karasova Feb 18, 2022
effa950
docs(samples): remove project_number in interactive-tutorials (#158)
tetiana-karasova Feb 18, 2022
f69c740
chore(deps): update dependency google-cloud-bigquery to v2.34.0 (#159)
renovate-bot Feb 21, 2022
ed42736
docs(samples): add samples for events (#155)
tetiana-karasova Feb 25, 2022
f270bbe
docs(samples): add samples for write/rejoin/purge user events (#157)
tetiana-karasova Feb 25, 2022
4b95cb4
docs(samples): read the project id from google.auth (#160)
tetiana-karasova Feb 25, 2022
29c0b23
docs(samples): Additional guidance in samples/interactive-tutorials/R…
tetiana-karasova Feb 25, 2022
dcb43a1
chore: additional replacements to read the project id from google.aut…
tetiana-karasova Feb 25, 2022
62222d4
chore: use gapic-generator-python 0.63.4 (#163)
gcf-owl-bot[bot] Feb 25, 2022
839fe6d
chore: update copyright year to 2022 (#167)
gcf-owl-bot[bot] Feb 26, 2022
a117f72
chore(deps): update all dependencies (#168)
renovate-bot Feb 28, 2022
acb3a26
chore(deps): update all dependencies (#170)
renovate-bot Mar 1, 2022
f12c3c3
chore(deps): update all dependencies (#177)
renovate-bot Mar 3, 2022
bd48246
docs(samples): fix create bucket for user events (#173)
tetiana-karasova Mar 3, 2022
323781b
chore: Adding support for pytest-xdist and pytest-parallel (#181)
gcf-owl-bot[bot] Mar 4, 2022
f6eaade
chore(deps): update all dependencies (#183)
renovate-bot Mar 8, 2022
413da95
test: create bq table fixed (#184)
t-karasova Mar 10, 2022
89baec0
chore: Replace str.format() and string concatenation in samples with …
t-karasova Mar 10, 2022
adb6d5a
chore(deps): update dependency pytest to v7.1.0 (#188)
renovate-bot Mar 13, 2022
4d1fac6
chore(deps): update dependency google-cloud-storage to v2.2.0 (#189)
renovate-bot Mar 14, 2022
ba72d6e
chore: Scripts were added to simplify the work environment creation (…
t-karasova Mar 15, 2022
1bbbdfb
chore(deps): update dependency google-cloud-storage to v2.2.1 (#191)
renovate-bot Mar 15, 2022
1a8f07c
chore: fix for the import data to the catalog script (#190)
t-karasova Mar 16, 2022
291df3d
chore(deps): update dependency pytest to v7.1.1 (#192)
renovate-bot Mar 18, 2022
b0dad35
docs: users can self enroll retail search feature on cloud console (#…
gcf-owl-bot[bot] Mar 28, 2022
9fb4fca
chore(python): use black==22.3.0 (#197)
gcf-owl-bot[bot] Mar 29, 2022
8c433b6
chore(deps): update dependency google-cloud-bigquery to v2.34.3 (#201)
renovate-bot Mar 30, 2022
c0f16a7
chore: update README and setup scripts (#193)
t-karasova Mar 30, 2022
fd3e846
chore(deps): update all dependencies (#203)
renovate-bot Apr 1, 2022
994bc5c
docs(samples): improve the setup scripts (#207)
t-karasova Apr 7, 2022
9ff9978
chore(deps): update dependency google-cloud-storage to v2.3.0 (#214)
renovate-bot Apr 14, 2022
db71bb0
chore: use gapic-generator-python 0.65.1 (#215)
gcf-owl-bot[bot] Apr 14, 2022
a3f6375
chore(python): add nox session to sort python imports (#217)
gcf-owl-bot[bot] Apr 21, 2022
a4b0c4a
chore(deps): update dependency pytest to v7.1.2 (#220)
renovate-bot Apr 25, 2022
1fa69f9
chore(deps): update dependency google-cloud-bigquery to v3.1.0 (#225)
renovate-bot May 9, 2022
d23a525
feat: generate v2alpha/v2beta (#226)
parthea May 19, 2022
9a6169a
chore(deps): update dependency google-cloud-retail to v1.6.0 (#228)
renovate-bot May 19, 2022
99a8b41
chore: add prerelease nox session (#281)
gcf-owl-bot[bot] Jun 21, 2022
48193c1
fix: require python 3.7+ (#284)
gcf-owl-bot[bot] Jul 10, 2022
6e8dabb
chore(deps): update all dependencies (#279)
renovate-bot Jul 17, 2022
b97b6c9
fix: add an error message on user import data script in case of any e…
kchertenko Jul 19, 2022
fecd579
chore(samples): fix product name and remove time params. (#289)
kchertenko Jul 19, 2022
eaae346
fix: add an error message on user environment setup in case of any er…
kchertenko Jul 19, 2022
ece59bd
feat: new model service to manage recommendation models (#304)
gcf-owl-bot[bot] Aug 2, 2022
c12cdc0
chore(samples): fix BQ Dataset creation. (#293)
kchertenko Aug 2, 2022
f4c03f3
chore(samples): fix path to products files. (#296)
kchertenko Aug 2, 2022
9308dc4
chore(samples): remove env setup (#299)
kchertenko Aug 2, 2022
a8a22a4
chore(samples): add function invoking (#300)
kchertenko Aug 2, 2022
a4dae10
chore(deps): update all dependencies (#303)
renovate-bot Aug 2, 2022
ece7c10
chore(deps): update all dependencies (#307)
renovate-bot Aug 5, 2022
b866b34
chore(samples): add user_events_some_invalid.json to the setup events…
kchertenko Aug 6, 2022
383c652
chore(samples): remove unnecessary commands (#309)
kchertenko Aug 6, 2022
e98a3a4
chore(deps): update all dependencies (#310)
renovate-bot Aug 9, 2022
a4ebaf2
chore(samples): add and fix comments (#312)
kchertenko Aug 12, 2022
80133c6
chore(samples): remove unnecessary permission (#315)
kchertenko Aug 12, 2022
f004702
chore(deps): update all dependencies (#317)
renovate-bot Aug 19, 2022
c8253f4
feat: release Control and ServingConfig serivces to v2 version (#319)
gcf-owl-bot[bot] Aug 23, 2022
05b4eb3
chore(deps): update dependency google-cloud-retail to v1.9.0 (#321)
renovate-bot Aug 23, 2022
2fe066d
feat: release Model Services to v2beta version (#333)
gcf-owl-bot[bot] Sep 2, 2022
5ba60bb
chore(deps): update dependency pytest to v7.1.3 (#332)
renovate-bot Sep 6, 2022
2237de6
chore(deps): update dependency google-cloud-retail to v1.10.0 (#338)
renovate-bot Sep 6, 2022
7c73e04
fix: remove add_time param from LRO requests. (#336)
kchertenko Sep 6, 2022
139d575
chore: Bump gapic-generator-python version to 1.3.0 (#340)
gcf-owl-bot[bot] Sep 7, 2022
14c9127
chore(samples): remove delays from LRO operations samples. (#335)
kchertenko Sep 7, 2022
0b911fb
chore(samples): remove region tags. (#337)
kchertenko Sep 12, 2022
0b12db8
chore: detect samples tests in nested directories (#343)
gcf-owl-bot[bot] Sep 13, 2022
fefff91
fix: remove user setup environment error. (#345)
kchertenko Sep 19, 2022
b74da9f
fix: improve message in case of an empty search result. (#346)
kchertenko Sep 20, 2022
d5a1a7c
chore(samples): add comment about out-of-order requests (#347)
kchertenko Sep 23, 2022
54b7f15
chore(deps): update dependency google-cloud-bigquery to v3.3.3 (#351)
renovate-bot Sep 29, 2022
2821c17
chore(deps): update dependency google-cloud-retail to v1.10.1 (#352)
renovate-bot Oct 4, 2022
6603342
chore(deps): update dependency google-cloud-retail to v1.10.2 (#355)
renovate-bot Oct 10, 2022
935d89a
chore(deps): update dependency google-cloud-bigquery to v3.3.5 (#356)
renovate-bot Oct 11, 2022
a812b28
chore(deps): update all dependencies (#357)
renovate-bot Oct 26, 2022
a82db90
chore(python): drop flake8-import-order in samples noxfile (#363)
gcf-owl-bot[bot] Nov 25, 2022
516001b
chore(deps): update all dependencies (#359)
renovate-bot Nov 25, 2022
b064d15
chore: Update gapic-generator-python to v1.6.1 (#358)
gcf-owl-bot[bot] Nov 25, 2022
229f193
Merge remote-tracking branch 'migration/main' into python-retail-migr…
telpirion Dec 2, 2022
5b29f4e
fixing bad migration :/
telpirion Dec 2, 2022
1a176fb
header fix
telpirion Dec 2, 2022
2b767d1
moar header fix
telpirion Dec 2, 2022
c15551d
fix
telpirion Dec 2, 2022
17e05bc
CODEOWNERS and blunderbuss.yaml
telpirion Dec 2, 2022
199e5cf
Update .github/CODEOWNERS
dandhlee Dec 2, 2022
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
/profiler/**/* @GoogleCloudPlatform/python-samples-reviewers
/pubsub/**/* @anguillanneuf @hongalex @GoogleCloudPlatform/python-samples-reviewers
/pubsublite/**/* @anguillanneuf @hongalex @GoogleCloudPlatform/python-samples-reviewers
/retail/**/* @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/python-samples-reviewers
/run/**/* @GoogleCloudPlatform/aap-dpes @GoogleCloudPlatform/python-samples-reviewers
/run/django/**/* @glasnt @GoogleCloudPlatform/aap-dpes @GoogleCloudPlatform/python-samples-reviewers
/secretmanager/**/* @GoogleCloudPlatform/aap-dpes @GoogleCloudPlatform/python-samples-reviewers
Expand Down
8 changes: 6 additions & 2 deletions .github/blunderbuss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ assign_issues_by:
- labels:
- 'api: language'
- 'api: texttospeech'
- 'api: retail'
to:
- GoogleCloudPlatform/dee-data-ai
- GoogleCloudPlatform/dee-data-ai
- labels:
- 'api: ml'
to:
Expand Down Expand Up @@ -186,7 +187,10 @@ assign_prs_by:
- 'api: cloudtasks'
to:
- GoogleCloudPlatform/infra-db-dpes

- labels:
- 'api: retail'
to:
- GoogleCloudPlatform/dee-data-ai
assign_issues:
- GoogleCloudPlatform/python-samples-owners

Expand Down
188 changes: 188 additions & 0 deletions retail/interactive-tutorials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#Retail Search Interactive Tutorials

##Run tutorials in Cloud Shell

To advance with the interactive tutorials, use Retail Search step-by-step manuals on the right side of the Cloud Shell IDE:
![Interactive tutorials](images/tutorial1.png)

The interactive tutorial should open by default. If it didn’t, click on the Tutorial symbol in the menu bar to open the step-by-step manual:
![Toggle tutorial](images/tutorials2.png)

For more details about the Cloud Shell environment, refer to the [Cloud Shell documentation](https://cloud.google.com/shell/docs).

## Interactive tutorial flow

Interactive guides are intended to help you understand the features provided by Google Cloud Retail Search and test the Retail API in action.

To proceed with the tutorial, choose a language you’ll be deploying your project in:
![Select a programming language](images/tutorials3.png)


To begin with the tutorial workflow, click the Start button:
![Begin with the tutorial](images/tutorials4.png)

Then, you can use Next and Previous buttons to navigate the tutorial pages.

## Get started with the Google Cloud Retail API

The Retail API provides you with the following possibilities to:
- Create and maintaining the catalog data.
- Fine-tune the search configuration.
- Import and maintain the user events data.

You can find the information about the Retail services in the [documentation](https://cloud.google.com/retail/docs)

<!--TODO(tkarasova) update the link to the tutorials when will be published-->
If you would like to have a closer look at the Retail API features and try them yourself,
the best option is to use the [Interactive Tutorials](https://cloud.google.com/retail/docs/overview). The tutorials will be launched in the CloudShell environment, and you will be able to request the Retail services and check the response with minimum time and effort.

The code samples in the directory **python-retail/samples/interactive-tutorials** are explicitly created for use with the Retail Interactive Tutorials.

If, for some reason, you have decided to proceed with these code samples without the tutorial, please go through the following steps and set up the required preconditions.

### Select your project and enable the Retail API

Google Cloud organizes resources into projects. This lets you
collect all related resources for a single application in one place.

If you don't have a Google Cloud project yet or you're not the owner of an existing one, you can
[create a new project](https://console.cloud.google.com/projectcreate).

After the project is created, set your PROJECT_ID to a ```project``` variable:

1. Run the following command in the Terminal:

```bash
gcloud config set project <YOUR_PROJECT_ID>
```

1. Ensure that the Retail API is enabled for your project in the [API & Services page](https://console.cloud.google.com/apis/api/retail.googleapis.com/).

## Prepare your work environment

To prepare the work environment you should perform the following steps:
- Create a service account.
- Create service account key and set it to authorize your calls to the Retail API.
- Install Google Cloud Retail library.

### Create service account

To access the Retail API, you must create a service account. Check that you are an owner of your Google Cloud project on the [IAM page](https://console.cloud.google.com/iam-admin/iam).

1. To create a service account, perform the following command:

```bash
gcloud iam service-accounts create <YOUR_SERVICE_ACCOUNT_ID>
```

1. Assign the needed roles to your service account:

```bash
for role in {retail.admin,storage.admin}
do gcloud projects add-iam-policy-binding <YOUR_PROJECT_ID> --member="serviceAccount:<YOUR_SERVICE_ACCOUNT_ID>@<YOUR_PROJECT_ID>.iam.gserviceaccount.com" --role="roles/${role}"
done
```

1. Use the following command to print out the service account email:

```bash
gcloud iam service-accounts list|grep <YOUR_SERVICE_ACCOUNT_ID>
```

Copy the service account email.


1. Upload your service account key JSON file and use it to activate the service
account:

```bash
gcloud iam service-accounts keys create ~/key.json --iam-account <YOUR_SERVICE_ACCOUNT_EMAIL>
```

```bash
gcloud auth activate-service-account --key-file ~/key.json
```

1. Set the key as the GOOGLE_APPLICATION_CREDENTIALS environment variable to
use it for sending requests to the Retail API.

```bash
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json
```

### Install Google Cloud Retail libraries

To run Python code samples for the Retail API tutorial, you need to set up your virtual environment.

1. Run the following commands in a Terminal to create an isolated Python environment:

```bash
virtualenv -p python3 myenv
source myenv/bin/activate
```

1. Next, install Google packages:

```bash
pip install google
pip install google-cloud-retail
pip install google-cloud-storage
pip install google-cloud-bigquery

```

## Import catalog data

There is a python-retail/samples/interactive-tutorials/resources/products.json file with valid products prepared in the `resources` directory.

The other file, python-retail/samples/interactive-tutorials/resources/products_some_invalid.json, contains both valid and invalid products. You will use it to check the error handling.

### Upload catalog data to Cloud Storage

In your own project you need to create a Cloud Storage bucket and put the JSON file there.
The bucket name must be unique. For convenience, you can name it `<YOUR_PROJECT_ID>_<TIMESTAMP>`.

1. The code samples for each of the Retail services are stored in different directories.

Go to the code samples directory, your starting point to run more commands.

```bash
cd python-retail/samples/interactive-tutorials
```

1. To create the bucket and upload the JSON file, open python-retail/samples/interactive-tutorials/product/setup_product/products_create_gcs_bucket.py file

1. Go to the **product** directory and run the following command in the Terminal:

```bash
python product/setup_product/products_create_gcs_bucket.py
```

Now you can see the bucket is created in the [Cloud Storage](https://console.cloud.google.com/storage/browser), and the files are uploaded.

1. The name of the created Cloud Storage bucket is printed in the Terminal.

```
The gcs bucket <YOUR_PROJECT_ID>_<TIMESTAMP> was created
```

Copy the name and set it as the environment variable `BUCKET_NAME`:

```bash
export BUCKET_NAME=<YOUR_BUCKET_NAME>
```

### Import products to the Retail Catalog

To import the prepared products to a catalog, open python-retail/samples/interactive-tutorials/product/import_products_gcs.py file and run the following command in the Terminal:

```bash
python product/import_products_gcs.py
```

## Run your code sample

Run the sample in a terminal with the following command:
```bash
python search/search_with_boost_spec.py
```
50 changes: 50 additions & 0 deletions retail/interactive-tutorials/TEST_RESOURCES_SETUP_CLEANUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# How to set up/ tear down the test resources

## Required environment variables

To successfully import the catalog data for tests, the following environment variables should be set:
- BUCKET_NAME
- EVENTS_BUCKET_NAME
These values are stored in the Secret Manager and will be submitted as
docker environment variables before the test run.

The Secret Manager name is set in .kokoro/presubmit/common.cfg file, SECRET_MANAGER_KEYS variable.

## Import catalog data

There are JSON files with valid products and user events prepared in `resources` directory:
`samples/resources/products.json` and `samples/resources/user_events.json` respectively.

Run the `create_test_resources.py` to perform the following actions:
- create the GCS bucket <BUCKET_NAME>,
- upload the product data from `resources/products.json` file to products bucket,
- import products to the default branch of the Retail catalog,
- create the GCS bucket <EVENTS_BUCKET_NAME>,
- upload the product data from `resources/user_events.json` file to events bucket,
- create a BigQuery dataset and table `products`,
- insert products from resources/products.json to the created products table,
- create a BigQuery dataset and table `events`,
- insert user events from resources/user_events.json to the created events table


```
$ python create_test_resources.py
```

In the result 316 products should be created in the test project catalog.


## Remove catalog data

Run the `remove_test_resources.py` to perform the following actions:
- remove all objects from the GCS bucket <BUCKET_NAME>,
- remove the <BUCKET_NAME> bucket,
- delete all products from the Retail catalog.
- remove all objects from the GCS bucket <EVENTS_BUCKET_NAME>,
- remove the <EVENTS_BUCKET_NAME> bucket,
- remove dataset `products` along with tables
- remove dataset `user_events` along with tables

```
$ python remove_test_resources.py
```
30 changes: 30 additions & 0 deletions retail/interactive-tutorials/events/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import test_utils.prefixer

prefixer = test_utils.prefixer.Prefixer(
"python-retail", "samples/interactive-tutorials/product"
)


@pytest.fixture(scope="session")
def table_id_prefix() -> str:
return prefixer.create_prefix()


@pytest.fixture(scope="session")
def bucket_name_prefix() -> str:
return prefixer.create_prefix()
Loading