{"action":"created","comment":{"url":"https://api.github.com/repos/googleapis/toolkit/pulls/comments/93149069","pull_request_review_id":13664907,"id":93149069,"diff_hunk":"@@ -0,0 +1,182 @@\n+/* Copyright 2016 Google Inc\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.google.api.codegen.transformer.py;\n+\n+import com.google.api.codegen.SnippetSetRunner;\n+import com.google.api.codegen.config.ApiConfig;\n+import com.google.api.codegen.config.PackageMetadataConfig;\n+import com.google.api.codegen.transformer.ModelToViewTransformer;\n+import com.google.api.codegen.viewmodel.PackageMetadataView;\n+import com.google.api.codegen.viewmodel.ViewModel;\n+import com.google.api.tools.framework.model.Model;\n+import com.google.common.base.Function;\n+import com.google.common.base.Predicate;\n+import com.google.common.base.Splitter;\n+import com.google.common.collect.Iterables;\n+import com.google.common.collect.Lists;\n+import java.io.File;\n+import java.nio.file.Paths;\n+import java.util.ArrayList;\n+import java.util.List;\n+import javax.annotation.Nullable;\n+\n+public class PythonPackageMetadataTransformer implements ModelToViewTransformer {\n+\n+  PackageMetadataConfig packageConfig;\n+\n+  public PythonPackageMetadataTransformer(PackageMetadataConfig packageConfig) {\n+    this.packageConfig = packageConfig;\n+  }\n+\n+  @Override\n+  public List<ViewModel> transform(final Model model, final ApiConfig apiConfig) {\n+    String version = packageConfig.apiVersion();\n+    List<ViewModel> initFiles =\n+        computeInitFiles(computePackages(apiConfig.getPackageName()), version);\n+    List<ViewModel> topLevelMetadata =\n+        Lists.transform(\n+            getTopLevelTemplateFileNames(),\n+            new Function<String, ViewModel>() {\n+              @Override\n+              @Nullable\n+              public ViewModel apply(@Nullable String templateFileName) {\n+                return generateMetadataView(model, apiConfig, templateFileName);\n+              }\n+            });\n+\n+    List<ViewModel> metadata = new ArrayList<>();\n+    metadata.addAll(initFiles);\n+    metadata.addAll(topLevelMetadata);\n+    return metadata;\n+  }\n+\n+  @Override\n+  public List<String> getTemplateFileNames() {\n+    List<String> templates = new ArrayList<>();\n+    templates.addAll(getTopLevelTemplateFileNames());\n+    templates.addAll(getInitTemplateFileNames());\n+    return templates;\n+  }\n+\n+  public List<String> getTopLevelTemplateFileNames() {\n+    return Lists.newArrayList(\n+        \"LICENSE.snip\",\n+        \"py/MANIFEST.in.snip\",\n+        \"py/PUBLISHING.rst.snip\",\n+        \"py/setup.py.snip\",\n+        \"py/requirements.txt.snip\",\n+        \"py/README.rst.snip\",\n+        \"py/tox.ini.snip\");\n+  }\n+\n+  public List<String> getInitTemplateFileNames() {\n+    return Lists.newArrayList(\"py/__init__.py.snip\", \"py/namespace__init__.py.snip\");\n+  }\n+\n+  private ViewModel generateMetadataView(Model model, ApiConfig apiConfig, String template) {\n+    int extensionIndex = template.lastIndexOf(\".\");\n+    String outputPath = template.substring(0, extensionIndex);\n+\n+    return PackageMetadataView.newBuilder()\n+        .templateFileName(template)\n+        .outputPath(outputPath)\n+        .identifier(apiConfig.getDomainLayerLocation())\n+        .packageVersion(packageConfig.packageVersion(\"python\"))\n+        .protoPath(packageConfig.protoPath())\n+        .shortName(packageConfig.shortName())\n+        .gaxVersion(packageConfig.gaxVersion(\"python\"))\n+        .protoVersion(packageConfig.protoVersion(\"python\"))\n+        .commonProtosVersion(packageConfig.commonProtosVersion(\"python\"))\n+        .packageName(packageConfig.packageName(\"python\"))\n+        .majorVersion(packageConfig.apiVersion())\n+        .author(packageConfig.author())\n+        .email(packageConfig.email())\n+        .homepage(packageConfig.homepage())\n+        .license(packageConfig.license())\n+        .fullName(model.getServiceConfig().getTitle())\n+        .serviceName(apiConfig.getPackageName())\n+        .namespacePackages(\n+            computeNamespacePackages(apiConfig.getPackageName(), packageConfig.apiVersion()))\n+        .build();\n+  }\n+\n+  private List<String> computePackages(String packageName) {\n+    ArrayList<String> packages = new ArrayList<>();\n+    StringBuilder current = new StringBuilder();\n+    boolean first = true;\n+    for (String pkg : Splitter.on(\".\").split(packageName)) {\n+      if (!first) {\n+        current.append(\".\" + pkg);\n+      } else {\n+        current.append(pkg);\n+        first = false;\n+      }\n+      packages.add(current.toString());\n+    }","path":"src/main/java/com/google/api/codegen/transformer/py/PythonPackageMetadataTransformer.java","position":128,"original_position":127,"commit_id":"b89305ec4939587febdb0b80e2a4f2552254ca63","original_commit_id":"6ccc6c354ee1a2073f410c650f482a01b1ef8e5c","user":{"login":"geigerj","id":14222439,"avatar_url":"https://avatars.githubusercontent.com/u/14222439?v=3","gravatar_id":"","url":"https://api.github.com/users/geigerj","html_url":"https://github.com/geigerj","followers_url":"https://api.github.com/users/geigerj/followers","following_url":"https://api.github.com/users/geigerj/following{/other_user}","gists_url":"https://api.github.com/users/geigerj/gists{/gist_id}","starred_url":"https://api.github.com/users/geigerj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geigerj/subscriptions","organizations_url":"https://api.github.com/users/geigerj/orgs","repos_url":"https://api.github.com/users/geigerj/repos","events_url":"https://api.github.com/users/geigerj/events{/privacy}","received_events_url":"https://api.github.com/users/geigerj/received_events","type":"User","site_admin":false},"body":"A Python package name `foo.bar.baz` implicitly defines three packages: `foo`, `foo.bar`, and `foo.bar.baz`. Is there a more concise way to express this in Java?","created_at":"2016-12-20T00:20:05Z","updated_at":"2016-12-20T00:43:51Z","html_url":"https://github.com/googleapis/toolkit/pull/870#discussion_r93149069","pull_request_url":"https://api.github.com/repos/googleapis/toolkit/pulls/870","_links":{"self":{"href":"https://api.github.com/repos/googleapis/toolkit/pulls/comments/93149069"},"html":{"href":"https://github.com/googleapis/toolkit/pull/870#discussion_r93149069"},"pull_request":{"href":"https://api.github.com/repos/googleapis/toolkit/pulls/870"}}},"pull_request":{"url":"https://api.github.com/repos/googleapis/toolkit/pulls/870","id":98643303,"html_url":"https://github.com/googleapis/toolkit/pull/870","diff_url":"https://github.com/googleapis/toolkit/pull/870.diff","patch_url":"https://github.com/googleapis/toolkit/pull/870.patch","issue_url":"https://api.github.com/repos/googleapis/toolkit/issues/870","number":870,"state":"open","locked":false,"title":"Port GAPIC metadata generation for Python","user":{"login":"geigerj","id":14222439,"avatar_url":"https://avatars.githubusercontent.com/u/14222439?v=3","gravatar_id":"","url":"https://api.github.com/users/geigerj","html_url":"https://github.com/geigerj","followers_url":"https://api.github.com/users/geigerj/followers","following_url":"https://api.github.com/users/geigerj/following{/other_user}","gists_url":"https://api.github.com/users/geigerj/gists{/gist_id}","starred_url":"https://api.github.com/users/geigerj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geigerj/subscriptions","organizations_url":"https://api.github.com/users/geigerj/orgs","repos_url":"https://api.github.com/users/geigerj/repos","events_url":"https://api.github.com/users/geigerj/events{/privacy}","received_events_url":"https://api.github.com/users/geigerj/received_events","type":"User","site_admin":false},"body":"Move the functionality of generating Python GAPIC package\r\nmetadata from Packman to GAPIC. To do so, introduce a new package\r\nmetadata configuration format, which lives at the same level as the\r\nGAPIC config in terms of input/test input. This new config file\r\nfixes #848.\r\n\r\nSorry, this PR is big, but a lot of the LOC changed are just test data.\r\n\r\nThe following follow-up PRs are planned:\r\n- A PR to Artman, introducing a task to generate the\r\n  new package metadata config from the artman config, and removing the\r\n  Python Packman task.\r\n- A PR to Toolkit, replacing all inputs to GrpcMetadataGen with the\r\n  new package metadata config, which addresses #780\r\n- (Potentially) A PR to Toolkit investigating the consolidation of\r\n  gRPC and GAPIC Python package metadata snippet templates. Note that\r\n  Packman currently uses separate templates for gRPC and GAPIC.\r\n\r\ncc: @bjwatson, @shinfan ","created_at":"2016-12-19T21:30:20Z","updated_at":"2016-12-20T00:43:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"41d5687a1dc8e3cd2e44943e571c66ae30e447c8","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/googleapis/toolkit/pulls/870/commits","review_comments_url":"https://api.github.com/repos/googleapis/toolkit/pulls/870/comments","review_comment_url":"https://api.github.com/repos/googleapis/toolkit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/googleapis/toolkit/issues/870/comments","statuses_url":"https://api.github.com/repos/googleapis/toolkit/statuses/b89305ec4939587febdb0b80e2a4f2552254ca63","head":{"label":"geigerj:python-gapic-metadata","ref":"python-gapic-metadata","sha":"b89305ec4939587febdb0b80e2a4f2552254ca63","user":{"login":"geigerj","id":14222439,"avatar_url":"https://avatars.githubusercontent.com/u/14222439?v=3","gravatar_id":"","url":"https://api.github.com/users/geigerj","html_url":"https://github.com/geigerj","followers_url":"https://api.github.com/users/geigerj/followers","following_url":"https://api.github.com/users/geigerj/following{/other_user}","gists_url":"https://api.github.com/users/geigerj/gists{/gist_id}","starred_url":"https://api.github.com/users/geigerj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geigerj/subscriptions","organizations_url":"https://api.github.com/users/geigerj/orgs","repos_url":"https://api.github.com/users/geigerj/repos","events_url":"https://api.github.com/users/geigerj/events{/privacy}","received_events_url":"https://api.github.com/users/geigerj/received_events","type":"User","site_admin":false},"repo":{"id":57069851,"name":"toolkit","full_name":"geigerj/toolkit","owner":{"login":"geigerj","id":14222439,"avatar_url":"https://avatars.githubusercontent.com/u/14222439?v=3","gravatar_id":"","url":"https://api.github.com/users/geigerj","html_url":"https://github.com/geigerj","followers_url":"https://api.github.com/users/geigerj/followers","following_url":"https://api.github.com/users/geigerj/following{/other_user}","gists_url":"https://api.github.com/users/geigerj/gists{/gist_id}","starred_url":"https://api.github.com/users/geigerj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geigerj/subscriptions","organizations_url":"https://api.github.com/users/geigerj/orgs","repos_url":"https://api.github.com/users/geigerj/repos","events_url":"https://api.github.com/users/geigerj/events{/privacy}","received_events_url":"https://api.github.com/users/geigerj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/geigerj/toolkit","description":null,"fork":true,"url":"https://api.github.com/repos/geigerj/toolkit","forks_url":"https://api.github.com/repos/geigerj/toolkit/forks","keys_url":"https://api.github.com/repos/geigerj/toolkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/geigerj/toolkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/geigerj/toolkit/teams","hooks_url":"https://api.github.com/repos/geigerj/toolkit/hooks","issue_events_url":"https://api.github.com/repos/geigerj/toolkit/issues/events{/number}","events_url":"https://api.github.com/repos/geigerj/toolkit/events","assignees_url":"https://api.github.com/repos/geigerj/toolkit/assignees{/user}","branches_url":"https://api.github.com/repos/geigerj/toolkit/branches{/branch}","tags_url":"https://api.github.com/repos/geigerj/toolkit/tags","blobs_url":"https://api.github.com/repos/geigerj/toolkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/geigerj/toolkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/geigerj/toolkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/geigerj/toolkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/geigerj/toolkit/statuses/{sha}","languages_url":"https://api.github.com/repos/geigerj/toolkit/languages","stargazers_url":"https://api.github.com/repos/geigerj/toolkit/stargazers","contributors_url":"https://api.github.com/repos/geigerj/toolkit/contributors","subscribers_url":"https://api.github.com/repos/geigerj/toolkit/subscribers","subscription_url":"https://api.github.com/repos/geigerj/toolkit/subscription","commits_url":"https://api.github.com/repos/geigerj/toolkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/geigerj/toolkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/geigerj/toolkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/geigerj/toolkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/geigerj/toolkit/contents/{+path}","compare_url":"https://api.github.com/repos/geigerj/toolkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/geigerj/toolkit/merges","archive_url":"https://api.github.com/repos/geigerj/toolkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/geigerj/toolkit/downloads","issues_url":"https://api.github.com/repos/geigerj/toolkit/issues{/number}","pulls_url":"https://api.github.com/repos/geigerj/toolkit/pulls{/number}","milestones_url":"https://api.github.com/repos/geigerj/toolkit/milestones{/number}","notifications_url":"https://api.github.com/repos/geigerj/toolkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/geigerj/toolkit/labels{/name}","releases_url":"https://api.github.com/repos/geigerj/toolkit/releases{/id}","deployments_url":"https://api.github.com/repos/geigerj/toolkit/deployments","created_at":"2016-04-25T19:29:38Z","updated_at":"2016-04-25T19:29:40Z","pushed_at":"2016-12-20T00:42:13Z","git_url":"git://github.com/geigerj/toolkit.git","ssh_url":"git@github.com:geigerj/toolkit.git","clone_url":"https://github.com/geigerj/toolkit.git","svn_url":"https://github.com/geigerj/toolkit","homepage":null,"size":11178,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"googleapis:master","ref":"master","sha":"4ef2d99d73d71011b7137ff37230a767e5e40d2c","user":{"login":"googleapis","id":16785467,"avatar_url":"https://avatars.githubusercontent.com/u/16785467?v=3","gravatar_id":"","url":"https://api.github.com/users/googleapis","html_url":"https://github.com/googleapis","followers_url":"https://api.github.com/users/googleapis/followers","following_url":"https://api.github.com/users/googleapis/following{/other_user}","gists_url":"https://api.github.com/users/googleapis/gists{/gist_id}","starred_url":"https://api.github.com/users/googleapis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googleapis/subscriptions","organizations_url":"https://api.github.com/users/googleapis/orgs","repos_url":"https://api.github.com/users/googleapis/repos","events_url":"https://api.github.com/users/googleapis/events{/privacy}","received_events_url":"https://api.github.com/users/googleapis/received_events","type":"Organization","site_admin":false},"repo":{"id":56533838,"name":"toolkit","full_name":"googleapis/toolkit","owner":{"login":"googleapis","id":16785467,"avatar_url":"https://avatars.githubusercontent.com/u/16785467?v=3","gravatar_id":"","url":"https://api.github.com/users/googleapis","html_url":"https://github.com/googleapis","followers_url":"https://api.github.com/users/googleapis/followers","following_url":"https://api.github.com/users/googleapis/following{/other_user}","gists_url":"https://api.github.com/users/googleapis/gists{/gist_id}","starred_url":"https://api.github.com/users/googleapis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googleapis/subscriptions","organizations_url":"https://api.github.com/users/googleapis/orgs","repos_url":"https://api.github.com/users/googleapis/repos","events_url":"https://api.github.com/users/googleapis/events{/privacy}","received_events_url":"https://api.github.com/users/googleapis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/googleapis/toolkit","description":null,"fork":false,"url":"https://api.github.com/repos/googleapis/toolkit","forks_url":"https://api.github.com/repos/googleapis/toolkit/forks","keys_url":"https://api.github.com/repos/googleapis/toolkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/googleapis/toolkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/googleapis/toolkit/teams","hooks_url":"https://api.github.com/repos/googleapis/toolkit/hooks","issue_events_url":"https://api.github.com/repos/googleapis/toolkit/issues/events{/number}","events_url":"https://api.github.com/repos/googleapis/toolkit/events","assignees_url":"https://api.github.com/repos/googleapis/toolkit/assignees{/user}","branches_url":"https://api.github.com/repos/googleapis/toolkit/branches{/branch}","tags_url":"https://api.github.com/repos/googleapis/toolkit/tags","blobs_url":"https://api.github.com/repos/googleapis/toolkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/googleapis/toolkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/googleapis/toolkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/googleapis/toolkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/googleapis/toolkit/statuses/{sha}","languages_url":"https://api.github.com/repos/googleapis/toolkit/languages","stargazers_url":"https://api.github.com/repos/googleapis/toolkit/stargazers","contributors_url":"https://api.github.com/repos/googleapis/toolkit/contributors","subscribers_url":"https://api.github.com/repos/googleapis/toolkit/subscribers","subscription_url":"https://api.github.com/repos/googleapis/toolkit/subscription","commits_url":"https://api.github.com/repos/googleapis/toolkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/googleapis/toolkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/googleapis/toolkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/googleapis/toolkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/googleapis/toolkit/contents/{+path}","compare_url":"https://api.github.com/repos/googleapis/toolkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/googleapis/toolkit/merges","archive_url":"https://api.github.com/repos/googleapis/toolkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/googleapis/toolkit/downloads","issues_url":"https://api.github.com/repos/googleapis/toolkit/issues{/number}","pulls_url":"https://api.github.com/repos/googleapis/toolkit/pulls{/number}","milestones_url":"https://api.github.com/repos/googleapis/toolkit/milestones{/number}","notifications_url":"https://api.github.com/repos/googleapis/toolkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/googleapis/toolkit/labels{/name}","releases_url":"https://api.github.com/repos/googleapis/toolkit/releases{/id}","deployments_url":"https://api.github.com/repos/googleapis/toolkit/deployments","created_at":"2016-04-18T18:58:04Z","updated_at":"2016-11-29T21:55:14Z","pushed_at":"2016-12-20T00:42:15Z","git_url":"git://github.com/googleapis/toolkit.git","ssh_url":"git@github.com:googleapis/toolkit.git","clone_url":"https://github.com/googleapis/toolkit.git","svn_url":"https://github.com/googleapis/toolkit","homepage":null,"size":11342,"stargazers_count":19,"watchers_count":19,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":104,"forks":21,"open_issues":104,"watchers":19,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/googleapis/toolkit/pulls/870"},"html":{"href":"https://github.com/googleapis/toolkit/pull/870"},"issue":{"href":"https://api.github.com/repos/googleapis/toolkit/issues/870"},"comments":{"href":"https://api.github.com/repos/googleapis/toolkit/issues/870/comments"},"review_comments":{"href":"https://api.github.com/repos/googleapis/toolkit/pulls/870/comments"},"review_comment":{"href":"https://api.github.com/repos/googleapis/toolkit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/googleapis/toolkit/pulls/870/commits"},"statuses":{"href":"https://api.github.com/repos/googleapis/toolkit/statuses/b89305ec4939587febdb0b80e2a4f2552254ca63"}}}}
{"actor":{"display_login":"geigerj"}}