diff --git a/src/main/java/com/google/api/codegen/transformer/py/PythonPackageMetadataTransformer.java b/src/main/java/com/google/api/codegen/transformer/py/PythonPackageMetadataTransformer.java index bfb4064ec5..b7a6090cc2 100644 --- a/src/main/java/com/google/api/codegen/transformer/py/PythonPackageMetadataTransformer.java +++ b/src/main/java/com/google/api/codegen/transformer/py/PythonPackageMetadataTransformer.java @@ -170,6 +170,8 @@ private ViewModel generateMetadataView( SurfaceNamer surfaceNamer, String outputPath) { List exampleMethods = generateExampleMethods(model, productConfig); + String gapicPackageName = + surfaceNamer.getGapicPackageName(packageConfig.packageName(TargetLanguage.PYTHON)); return metadataTransformer .generateMetadataView(packageConfig, model, template, outputPath, TargetLanguage.PYTHON) .namespacePackages(computeNamespacePackages(productConfig.getPackageName(), surfaceNamer)) @@ -178,6 +180,7 @@ private ViewModel generateMetadataView( .clientModules(clientModules(surfaceNamer)) .apiModules(apiModules(packageConfig.apiVersion())) .typeModules(typesModules(surfaceNamer)) + .gapicPackageName(gapicPackageName) .protoPackageDependencies(generateProtoPackageDependencies()) .additionalDependencies(generateAdditionalDependencies()) .readmeMetadata( @@ -187,7 +190,7 @@ private ViewModel generateMetadataView( .fullName(model.getServiceConfig().getTitle()) .apiSummary(model.getServiceConfig().getDocumentation().getSummary()) .hasMultipleServices(false) - .gapicPackageName("gapic-" + packageConfig.packageName(TargetLanguage.PYTHON)) + .gapicPackageName(gapicPackageName) .majorVersion(packageConfig.apiVersion()) .developmentStatusTitle( metadataNamer.getReleaseAnnotation( diff --git a/src/main/java/com/google/api/codegen/transformer/py/PythonSurfaceNamer.java b/src/main/java/com/google/api/codegen/transformer/py/PythonSurfaceNamer.java index ca2e2f712a..6f740815f0 100644 --- a/src/main/java/com/google/api/codegen/transformer/py/PythonSurfaceNamer.java +++ b/src/main/java/com/google/api/codegen/transformer/py/PythonSurfaceNamer.java @@ -45,8 +45,10 @@ import com.google.common.collect.Iterables; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; +import java.util.regex.Pattern; /** The SurfaceNamer for Python. */ public class PythonSurfaceNamer extends SurfaceNamer { @@ -60,6 +62,12 @@ public PythonSurfaceNamer(String packageName) { packageName); } + private static final Pattern VERSION_PATTERN = + Pattern.compile( + "^([vV]\\d+)" // Major version eg: v1 + + "([pP]\\d+)?" // Point release eg: p2 + + "(([aA]lpha|[bB]eta)\\d*)?"); // Release level eg: alpha3 + @Override public SurfaceNamer cloneWithPackageName(String packageName) { return new PythonSurfaceNamer(packageName); @@ -96,6 +104,15 @@ public String getVersionedDirectoryNamespace() { return namespace.substring(0, namespace.lastIndexOf('.')); } + @Override + public String getGapicPackageName(String configPackageName) { + List parts = Arrays.asList(configPackageName.split("-")); + if (VERSION_PATTERN.matcher(parts.get(parts.size() - 1)).matches()) { + return Joiner.on("-").join(parts.subList(0, parts.size() - 1)); + } + return configPackageName; + } + @Override public String getFormattedVariableName(Name identifier) { return localVarName(identifier); diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_README_library.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_README_library.baseline index 39a14471d5..1d0a1ae6db 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_README_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_README_library.baseline @@ -47,7 +47,7 @@ Mac/Linux pip install virtualenv virtualenv source /bin/activate - /bin/pip install gapic-google-cloud-library-v1 + /bin/pip install google-cloud-library Windows @@ -58,7 +58,7 @@ Windows pip install virtualenv virtualenv \Scripts\activate - \Scripts\pip.exe install gapic-google-cloud-library-v1 + \Scripts\pip.exe install google-cloud-library Preview ~~~~~~~ diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_README_no_path_templates.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_README_no_path_templates.baseline index da4ff1b1f9..dbc744b5c0 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_README_no_path_templates.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_README_no_path_templates.baseline @@ -47,7 +47,7 @@ Mac/Linux pip install virtualenv virtualenv source /bin/activate - /bin/pip install gapic-google-cloud-library-v1 + /bin/pip install google-cloud-library Windows @@ -58,7 +58,7 @@ Windows pip install virtualenv virtualenv \Scripts\activate - \Scripts\pip.exe install gapic-google-cloud-library-v1 + \Scripts\pip.exe install google-cloud-library Next Steps ~~~~~~~~~~ diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_library.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_library.baseline index c98a556fdc..a643c83b2b 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_library.baseline @@ -1,7 +1,7 @@ ============== file: docs/conf.py ============== # -*- coding: utf-8 -*- # -# gapic-google-cloud-library-v1 documentation build configuration file +# google-cloud-library documentation build configuration file # # This file is execfile()d with the current directory set to its # containing dir. @@ -61,7 +61,7 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'gapic-google-cloud-library-v1' +project = u'google-cloud-library' copyright = u'2017, Google' author = u'Google APIs' @@ -215,7 +215,7 @@ html_theme = 'sphinx_rtd_theme' #html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'gapic-google-cloud-library-v1-doc' +htmlhelp_basename = 'google-cloud-library-doc' # -- Options for LaTeX output --------------------------------------------- @@ -237,7 +237,7 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'gapic-google-cloud-library-v1.tex', u'gapic-google-cloud-library-v1 Documentation', + (master_doc, 'google-cloud-library.tex', u'google-cloud-library Documentation', author, 'manual'), ] @@ -267,7 +267,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'gapic-google-cloud-library-v1', u'gapic-google-cloud-library-v1 Documentation', + (master_doc, 'google-cloud-library', u'google-cloud-library Documentation', [author], 1) ] @@ -281,8 +281,8 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'gapic-google-cloud-library-v1', u'gapic-google-cloud-library-v1 Documentation', - author, 'gapic-google-cloud-library-v1', 'GAPIC library for the {metadata.shortName} v1 service', + (master_doc, 'google-cloud-library', u'google-cloud-library Documentation', + author, 'google-cloud-library', 'GAPIC library for the {metadata.shortName} v1 service', 'APIs'), ] diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_no_path_templates.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_no_path_templates.baseline index c98a556fdc..a643c83b2b 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_no_path_templates.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_docs_conf_no_path_templates.baseline @@ -1,7 +1,7 @@ ============== file: docs/conf.py ============== # -*- coding: utf-8 -*- # -# gapic-google-cloud-library-v1 documentation build configuration file +# google-cloud-library documentation build configuration file # # This file is execfile()d with the current directory set to its # containing dir. @@ -61,7 +61,7 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'gapic-google-cloud-library-v1' +project = u'google-cloud-library' copyright = u'2017, Google' author = u'Google APIs' @@ -215,7 +215,7 @@ html_theme = 'sphinx_rtd_theme' #html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'gapic-google-cloud-library-v1-doc' +htmlhelp_basename = 'google-cloud-library-doc' # -- Options for LaTeX output --------------------------------------------- @@ -237,7 +237,7 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'gapic-google-cloud-library-v1.tex', u'gapic-google-cloud-library-v1 Documentation', + (master_doc, 'google-cloud-library.tex', u'google-cloud-library Documentation', author, 'manual'), ] @@ -267,7 +267,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'gapic-google-cloud-library-v1', u'gapic-google-cloud-library-v1 Documentation', + (master_doc, 'google-cloud-library', u'google-cloud-library Documentation', [author], 1) ] @@ -281,8 +281,8 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'gapic-google-cloud-library-v1', u'gapic-google-cloud-library-v1 Documentation', - author, 'gapic-google-cloud-library-v1', 'GAPIC library for the {metadata.shortName} v1 service', + (master_doc, 'google-cloud-library', u'google-cloud-library Documentation', + author, 'google-cloud-library', 'GAPIC library for the {metadata.shortName} v1 service', 'APIs'), ] diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_library.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_library.baseline index 620c037c84..d316391045 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_library.baseline @@ -47,7 +47,7 @@ Mac/Linux pip install virtualenv virtualenv source /bin/activate - /bin/pip install gapic-google-cloud-library-v1 + /bin/pip install google-cloud-library Windows @@ -58,7 +58,7 @@ Windows pip install virtualenv virtualenv \Scripts\activate - \Scripts\pip.exe install gapic-google-cloud-library-v1 + \Scripts\pip.exe install google-cloud-library Preview ~~~~~~~ diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_no_path_templates.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_no_path_templates.baseline index cce0467767..cb0cfb5a66 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_no_path_templates.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_docs_index_no_path_templates.baseline @@ -47,7 +47,7 @@ Mac/Linux pip install virtualenv virtualenv source /bin/activate - /bin/pip install gapic-google-cloud-library-v1 + /bin/pip install google-cloud-library Windows @@ -58,7 +58,7 @@ Windows pip install virtualenv virtualenv \Scripts\activate - \Scripts\pip.exe install gapic-google-cloud-library-v1 + \Scripts\pip.exe install google-cloud-library Next Steps ~~~~~~~~~~ diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_main_library.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_main_library.baseline index 504ac1e392..05c5e9788f 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_main_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_main_library.baseline @@ -283,7 +283,7 @@ class LibraryServiceClient(object): # Finally, track the GAPIC package version. metrics_headers['gapic'] = pkg_resources.get_distribution( - 'gapic-google-cloud-library-v1', + 'google-cloud-library', ).version # Load the configuration defaults. diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_main_no_path_templates.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_main_no_path_templates.baseline index 15fd93c5ed..35332d55b2 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_main_no_path_templates.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_main_no_path_templates.baseline @@ -122,7 +122,7 @@ class NoTemplatesAPIServiceClient(object): # Finally, track the GAPIC package version. metrics_headers['gapic'] = pkg_resources.get_distribution( - 'gapic-google-cloud-library-v1', + 'google-cloud-library', ).version # Load the configuration defaults. diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_setup_library.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_setup_library.baseline index 2891bf0928..8070f81fb0 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_setup_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_setup_library.baseline @@ -18,7 +18,7 @@ install_requires = [ ] setup( - name='gapic-google-cloud-library-v1', + name='google-cloud-library', version='0.15.0', author='Google, Inc.', author_email='googleapis-packages@google.com', diff --git a/src/test/java/com/google/api/codegen/testdata/py/python_setup_no_path_templates.baseline b/src/test/java/com/google/api/codegen/testdata/py/python_setup_no_path_templates.baseline index 3170f1116b..4b6b829b28 100644 --- a/src/test/java/com/google/api/codegen/testdata/py/python_setup_no_path_templates.baseline +++ b/src/test/java/com/google/api/codegen/testdata/py/python_setup_no_path_templates.baseline @@ -18,7 +18,7 @@ install_requires = [ ] setup( - name='gapic-google-cloud-library-v1', + name='google-cloud-library', version='0.15.0', author='Google, Inc.', author_email='googleapis-packages@google.com',