Change gcloud package to google.cloud by dhermes · Pull Request #2223 · googleapis/google-cloud-python
added
packaging
do not merge
labels
Aug 30, 2016label
Aug 30, 2016Done via: $ git grep -l 'import gcloud' | \ > xargs sed -i s/'import gcloud'/'import google.cloud'/g
Done via: $ git grep -l 'from gcloud import' | \ > xargs sed -i s/'from gcloud import'/'from google.cloud import'/g
Done via: $ git grep -l '>>> from gcloud.' | \ > xargs sed -i s/'>>> from gcloud.'/'>>> from google.cloud.'/g
This was done entirely via sed. First checked that
the remaining imports were at the start of their
respective lines:
$ git grep 'from gcloud.*import' > anywhere.txt
$ git grep '^[[:space:]]*from gcloud.*import' > line_start.txt
$ diff -s anywhere.txt line_start.txt
Files anywhere.txt and line_start.txt are identical
$ rm -f anywhere.txt line_start.txt
Then put all the imports in a text file
$ git grep -h '^[[:space:]]*from gcloud.*import' > imports.txt
Then parsed that file to get a list of the modules:
$ cat << EOF > get_mods.py
> def get_import(line):
> a, b, c, d = line.strip().split(None, 3)
> assert a == 'from'
> assert c == 'import'
> try:
> e, f, g = b.split('.', 2)
> except ValueError:
> e, f = b.split('.')
> assert e == 'gcloud'
> return f
>
> with open('imports.txt', 'rb') as file_obj:
> imported = sorted(set(map(get_import, file_obj.readlines())))
>
> for mod in imported:
> print(mod)
>
> EOF
$ python get_mods.py > mods.txt
$ rm -f imports.txt get_mods.py
Then using the list of modules to rewrite the imports
$ cat << 'EOF' > all-sed.sh
> for mod in $(cat mods.txt); do
> git grep -l "from gcloud.${mod}" | \
> xargs sed -i s/"from gcloud.${mod}"/"from google.cloud.${mod}"/g
> done
>
> EOF
$ /bin/bash all-sed.sh
$ rm -f all-sed.sh mods.txt
Done via: $ git grep -l 'hack-on-gcloud' | \ > xargs sed -i s/hack-on-gcloud/hack-on-google-cloud-python/g
Done via: $ git grep -l 'automodule:: gcloud' | \ > xargs sed -i s/'automodule:: gcloud'/'automodule:: google.cloud'/g
Done via: $ git grep -l '<gcloud.' | \ > xargs sed -i s/'<gcloud.'/'<google.cloud.'/g $ git grep -l '`gcloud\.' | \ > xargs sed -i s/'`gcloud\.'/'`google.cloud.'/g
commit 6faf161 Author: Danny Hermes <daniel.j.hermes@gmail.com> Date: Tue Aug 30 12:39:46 2016 -0700 Converting almost all packages to namespace packages. As a result, the module objects for those packages can no longer contain members. Hence the following is no longer possible: >>> from google.cloud import storage >>> client = storage.Client() The "_generated" packages have not been converted to namespace packages and neither have "google.cloud.logging.handlers" nor "google.cloud.logging.handlers.transports". In addition, some members of "google.cloud.logging" have been moved into "google.cloud.logging.client" in order to be importable. Finally, the unit tests all pass at this commit, but `tox` fails to run them: the namespace imports appear broken to `tox` even though they aren't broken to the `virtualenv` for the given `tox` environment.
dhermes
removed
the
do not merge
label
Sep 7, 2016dhermes added a commit to dhermes/google-cloud-python that referenced this pull request
Sep 7, 2016Follow-up to PR googleapis#2223. The Sphinx mechanism of using a `.` to mean "go find this class" can be confusing, so we make sure the `.` also is a relative path.
This was referenced
Sep 7, 2016dhermes added a commit to dhermes/google-cloud-python that referenced this pull request
Sep 7, 2016Follow-up to PR googleapis#2223. The Sphinx mechanism of using a `.` to mean "go find this class" can be confusing, so we make sure the `.` also is a relative path.
This was referenced
Sep 16, 2016parthea pushed a commit that referenced this pull request
Mar 6, 2026parthea pushed a commit that referenced this pull request
Apr 1, 2026This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters