Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Python: update metadata. (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
landrito authored Aug 24, 2017
1 parent a73a4cb commit dc12d90
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.api.codegen.config.FlatteningConfig;
import com.google.api.codegen.config.GapicProductConfig;
import com.google.api.codegen.config.PackageMetadataConfig;
import com.google.api.codegen.config.VersionBound;
import com.google.api.codegen.transformer.DefaultFeatureConfig;
import com.google.api.codegen.transformer.DynamicLangApiMethodTransformer;
import com.google.api.codegen.transformer.GapicInterfaceContext;
Expand All @@ -38,6 +39,7 @@
import com.google.api.codegen.viewmodel.OptionalArrayMethodView;
import com.google.api.codegen.viewmodel.SimpleViewModel;
import com.google.api.codegen.viewmodel.ViewModel;
import com.google.api.codegen.viewmodel.metadata.PackageDependencyView;
import com.google.api.codegen.viewmodel.metadata.ReadmeMetadataView;
import com.google.api.tools.framework.model.Interface;
import com.google.api.tools.framework.model.Method;
Expand All @@ -49,7 +51,9 @@
import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* Responsible for producing package metadata related views for Python
Expand All @@ -74,7 +78,6 @@ public class PythonPackageMetadataTransformer implements ModelToViewTransformer
"py/MANIFEST.in.snip",
"py/PUBLISHING.rst.snip",
"py/setup.py.snip",
"py/requirements.txt.snip",
"py/README.rst.snip",
"py/tox.ini.snip",
"py/docs/conf.py.snip",
Expand Down Expand Up @@ -175,6 +178,8 @@ private ViewModel generateMetadataView(
.clientModules(clientModules(surfaceNamer))
.apiModules(apiModules(packageConfig.apiVersion()))
.typeModules(typesModules(surfaceNamer))
.protoPackageDependencies(generateProtoPackageDependencies())
.additionalDependencies(generateAdditionalDependencies())
.readmeMetadata(
ReadmeMetadataView.newBuilder()
.moduleName("")
Expand All @@ -198,6 +203,41 @@ private ViewModel generateMetadataView(
.build();
}

private List<PackageDependencyView> generateProtoPackageDependencies() {
Map<String, VersionBound> dependencies =
packageConfig.protoPackageDependencies(TargetLanguage.PYTHON);
if (dependencies == null) {
return ImmutableList.of();
}
List<PackageDependencyView> protoPackageDependencies = new ArrayList<>();
for (Map.Entry<String, VersionBound> entry : dependencies.entrySet()) {
if (entry.getValue() == null || entry.getKey().startsWith("proto-google-cloud-")) {
break;
}
String dependencyName = entry.getKey();
if ("googleapis-common-protos".equals(dependencyName)) {
dependencyName = String.format("%s[grpc]", dependencyName);
}
protoPackageDependencies.add(PackageDependencyView.create(dependencyName, entry.getValue()));
}
// Ensures deterministic test results.
Collections.sort(protoPackageDependencies);
return protoPackageDependencies;
}

private List<PackageDependencyView> generateAdditionalDependencies() {
ImmutableList.Builder<PackageDependencyView> dependencies = ImmutableList.builder();
dependencies.add(
PackageDependencyView.create(
"google-gax", packageConfig.gaxVersionBound(TargetLanguage.PYTHON)));
dependencies.add(
PackageDependencyView.create(
"google-auth", packageConfig.authVersionBound(TargetLanguage.PYTHON)));
dependencies.add(
PackageDependencyView.create("requests", VersionBound.create("2.18.4", "3.0dev")));
return dependencies.build();
}

private List<String> clientModules(SurfaceNamer surfaceNamer) {
return ImmutableList.of(surfaceNamer.getVersionedDirectoryNamespace());
}
Expand Down Expand Up @@ -267,6 +307,8 @@ private List<String> computeNamespacePackages(String packageName, SurfaceNamer n
namespacePackages.add(subPackage);
}
}
namespacePackages.add("google.cloud.proto");
namespacePackages.add(String.format("google.cloud.proto.%s", packageConfig.shortName()));
return namespacePackages;
}

Expand Down

This file was deleted.

10 changes: 2 additions & 8 deletions src/main/resources/com/google/api/codegen/py/setup.py.snip
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
import sys

install_requires = [
'google-gax>={@metadata.gaxVersionBound.lower}, <{@metadata.gaxVersionBound.upper}',
'oauth2client>={@metadata.authVersionBound.lower}, <{@metadata.authVersionBound.upper}',
'{@metadata.protoPackageName}[grpc]>={@metadata.packageVersionBound.lower}, <{@metadata.packageVersionBound.upper}',
@join packageDep : metadata.protoPackageDependencies
@if or(packageDep.name == "googleapis-common-protos", packageDep.name.startsWith("proto-"))
'{@packageDep.name}[grpc]>={@packageDep.versionBound.lower}, <{@packageDep.versionBound.upper}',
@else
@join packageDep : metadata.dependencies
'{@packageDep.name}>={@packageDep.versionBound.lower}, <{@packageDep.versionBound.upper}',
@end
@end
]

Expand All @@ -40,6 +33,7 @@
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
],
description='GAPIC library for the {@metadata.fullName}',
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ from setuptools import setup, find_packages
import sys

install_requires = [
'google-auth>=1.0.2, <2.0dev',
'google-gax>=0.15.0, <0.16.0',
'oauth2client>=2.0.0, <4.0dev',
'proto-google-cloud-library-v1[grpc]>=0.15.0, <0.16dev',
'googleapis-common-protos[grpc]>=1.5.0, <2.0dev',
'python-other-package>=12.1.0, <13.5.1',
'requests>=2.18.4, <3.0dev',
]

setup(
Expand All @@ -33,6 +33,7 @@ setup(
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
],
description='GAPIC library for the Google Example Library API',
Expand All @@ -41,7 +42,7 @@ setup(
install_requires=install_requires,
license='Apache-2.0',
packages=find_packages(),
namespace_packages=['google', 'google.cloud', 'google.cloud.example'],
namespace_packages=['google', 'google.cloud', 'google.cloud.example', 'google.cloud.proto', 'google.cloud.proto.library'],
url='https://github.com/googleapis/googleapis'
)

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ from setuptools import setup, find_packages
import sys

install_requires = [
'google-auth>=1.0.2, <2.0dev',
'google-gax>=0.15.0, <0.16.0',
'oauth2client>=2.0.0, <4.0dev',
'proto-google-cloud-library-v1[grpc]>=0.15.0, <0.16dev',
'googleapis-common-protos[grpc]>=1.5.0, <2.0dev',
'python-other-package>=12.1.0, <13.5.1',
'requests>=2.18.4, <3.0dev',
]

setup(
Expand All @@ -33,6 +33,7 @@ setup(
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
],
description='GAPIC library for the Google Fake API',
Expand All @@ -41,7 +42,7 @@ setup(
install_requires=install_requires,
license='Apache-2.0',
packages=find_packages(),
namespace_packages=[],
namespace_packages=['google.cloud.proto', 'google.cloud.proto.library'],
url='https://github.com/googleapis/googleapis'
)

4 changes: 2 additions & 2 deletions src/test/java/com/google/api/codegen/testsrc/library_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ release_level:
# Dependencies
auth_version:
python:
lower: '2.0.0'
upper: '4.0dev'
lower: '1.0.2'
upper: '2.0dev'
nodejs:
lower: '0.9.8'
ruby:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ release_level:
# Dependencies
auth_version:
python:
lower: '2.0.0'
upper: '4.0dev'
lower: '1.0.2'
upper: '2.0dev'
nodejs:
lower: '0.9.8'
ruby:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ release_level:
# Dependencies
auth_version:
python:
lower: '2.0.0'
upper: '4.0dev'
lower: '1.0.2'
upper: '2.0dev'
nodejs:
lower: '0.9.8'
ruby:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ release_level:
# Dependencies
auth_version:
python:
lower: '2.0.0'
upper: '4.0dev'
lower: '1.0.2'
upper: '2.0dev'
nodejs:
lower: '0.9.8'
ruby:
Expand Down

0 comments on commit dc12d90

Please sign in to comment.