Skip to content

chore: Migrate gsutil usage to gcloud storage#1902

Open
bhandarivijay-png wants to merge 1 commit intodatacommonsorg:masterfrom
bhandarivijay-png:ai-gsutil-migration-50b6180b353644edacf436fa866307a2
Open

chore: Migrate gsutil usage to gcloud storage#1902
bhandarivijay-png wants to merge 1 commit intodatacommonsorg:masterfrom
bhandarivijay-png:ai-gsutil-migration-50b6180b353644edacf436fa866307a2

Conversation

@bhandarivijay-png
Copy link

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates various shell scripts and documentation to standardize Google Cloud Storage operations. By migrating from the older gsutil command-line tool to gcloud storage, it aligns with Google Cloud's recommended practices for interacting with storage services, potentially offering improved performance, consistency, and future compatibility across different environments.

Highlights

  • Migration to gcloud storage: All instances of gsutil commands for copying data to and from Google Cloud Storage have been migrated to use the gcloud storage cp command.
  • Command Syntax Update: The -r and -R flags for recursive copying in gsutil have been replaced with --recursive for gcloud storage cp. The -m (multi-threaded) flag from gsutil has been removed as gcloud storage cp handles this implicitly or it's not required for the specific operations.
Changelog
  • copydata.sh
    • Updated gsutil cp -r to gcloud storage cp --recursive for copying data.
  • scripts/us_census/decennial/download.sh
    • Replaced gsutil -m cp -R with gcloud storage cp --recursive for downloading census data.
  • scripts/us_nces/demographics/private_school/run.sh
    • Migrated gsutil -m cp -r to gcloud storage cp --recursive for copying input files.
  • scripts/us_nces/demographics/public_school/run.sh
    • Migrated gsutil -m cp -r to gcloud storage cp --recursive for copying input files.
  • scripts/us_nces/demographics/school_district/run.sh
    • Migrated gsutil -m cp -r to gcloud storage cp --recursive for copying input files.
  • statvar_imports/cdc/social_vulnerability_index/README.md
    • Updated gsutil cp commands to gcloud storage cp in the documentation for copying input files.
  • statvar_imports/cdc/social_vulnerability_index/run.sh
    • Replaced gsutil cp with gcloud storage cp for copying SVI files.
  • statvar_imports/southkorea_statistics/run.sh
    • Updated gsutil -m cp to gcloud storage cp for copying CSV files.
  • statvar_imports/us_cdc/single_race/download.sh
    • Migrated gsutil -m cp to gcloud storage cp for downloading input files.
  • statvar_imports/us_newyork/ny_diabetes/run.sh
    • Replaced gsutil cp with gcloud storage cp for copying diabetes input files.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly migrates gsutil commands to the recommended gcloud storage equivalent across several shell scripts and documentation files. The changes are consistent and accurate. I've added a few suggestions to make the gcloud storage cp commands more robust and idiomatic by removing wildcard usage for copying entire directory contents. This avoids potential issues with shell globbing and improves clarity.

# TODO(shifucun): Handle copy GCS reference. In this case, user would
# store a link but not actual data in this repo.
gsutil cp -r "$folder/$import_group/data/*" "$gcs_path/$import_group/data/"
gcloud storage cp --recursive "$folder/$import_group/data/*" "$gcs_path/$import_group/data/"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For copying the contents of a local directory, it's more robust to specify the source directory with a trailing slash instead of using a wildcard (*). This avoids reliance on shell globbing, which can behave unexpectedly if the directory is empty. Using a trailing slash is the idiomatic way to copy directory contents with gcloud storage cp.

Suggested change
gcloud storage cp --recursive "$folder/$import_group/data/*" "$gcs_path/$import_group/data/"
gcloud storage cp --recursive "$folder/$import_group/data/" "$gcs_path/$import_group/data/"

#!/bin/bash
mkdir -p scratch
gsutil -m cp -R gs://datcom-csv/census/decennial/* scratch/
gcloud storage cp --recursive gs://datcom-csv/census/decennial/* scratch/
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For clarity and consistency, it's better to specify the GCS source directory path without a trailing /* when copying its contents recursively. The gcloud storage cp --recursive command will correctly copy the contents of the specified GCS directory.

Suggested change
gcloud storage cp --recursive gs://datcom-csv/census/decennial/* scratch/
gcloud storage cp --recursive gs://datcom-csv/census/decennial/ scratch/

@@ -1,2 +1,2 @@
mkdir -p gcs_folder/input_files
gsutil -m cp -r gs://unresolved_mcf/us_nces/demographics/private_school/semi_automation_input_files/* gcs_folder/input_files/
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/private_school/semi_automation_input_files/* gcs_folder/input_files/
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For clarity and consistency, it's better to specify the GCS source directory path without a trailing /* when copying its contents recursively. The gcloud storage cp --recursive command will correctly copy the contents of the specified GCS directory.

Suggested change
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/private_school/semi_automation_input_files/* gcs_folder/input_files/
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/private_school/semi_automation_input_files/ gcs_folder/input_files/

@@ -1,2 +1,2 @@
mkdir -p gcs_folder/input_files
gsutil -m cp -r gs://unresolved_mcf/us_nces/demographics/public_school/semi_automation_input_files/* gcs_folder/input_files/
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/public_school/semi_automation_input_files/* gcs_folder/input_files/
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For clarity and consistency, it's better to specify the GCS source directory path without a trailing /* when copying its contents recursively. The gcloud storage cp --recursive command will correctly copy the contents of the specified GCS directory.

Suggested change
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/public_school/semi_automation_input_files/* gcs_folder/input_files/
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/public_school/semi_automation_input_files/ gcs_folder/input_files/

@@ -1,2 +1,2 @@
mkdir -p gcs_folder/input_files
gsutil -m cp -r gs://unresolved_mcf/us_nces/demographics/school_district/semi_automation_input_files/* gcs_folder/input_files/
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/school_district/semi_automation_input_files/* gcs_folder/input_files/
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For clarity and consistency, it's better to specify the GCS source directory path without a trailing /* when copying its contents recursively. The gcloud storage cp --recursive command will correctly copy the contents of the specified GCS directory.

Suggested change
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/school_district/semi_automation_input_files/* gcs_folder/input_files/
gcloud storage cp --recursive gs://unresolved_mcf/us_nces/demographics/school_district/semi_automation_input_files/ gcs_folder/input_files/

bash

gsutil cp gs://unresolved_mcf/cdc/social_vulnerability_index/latest/input_files/* source_files/
gcloud storage cp gs://unresolved_mcf/cdc/social_vulnerability_index/latest/input_files/* source_files/
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve clarity in the documentation, you can remove the trailing /* from the GCS path. When copying objects from the top level of a GCS directory (non-recursively), specifying the directory path is sufficient and cleaner.

Suggested change
gcloud storage cp gs://unresolved_mcf/cdc/social_vulnerability_index/latest/input_files/* source_files/
gcloud storage cp gs://unresolved_mcf/cdc/social_vulnerability_index/latest/input_files/ source_files/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant