Skip to content

Commit

Permalink
feat: add __version__ in GAPIC clients (#1350)
Browse files Browse the repository at this point in the history
* Chore: update setup.py to new standards

* added end block

* changed required python version

* Edited golden files

* Edited ads-templates setup.py

* added missing commas to setup.py

* changed classifiers for ads-template setup.py

* changed ads-templates setup.py

* Reverted ads-template changes

* Added templeted version and updated protobuf

* added package_root

* Updated golden test files

* Revert "added package_root"

This reverts commit b8ce614.

* Revert "Updated golden test files"

This reverts commit ba37d13.

* updated setup.py

* Updated Golden files

* added version to __init__.py

* updated api-core dependency

* updated setup.py to match golden

* Changed version.py path to be set automatically

* added version import into _base.py.j2

* changed version import placement

* added changes from incremental-changes-setup-py

* moved constraints file

* updated golden files

Co-authored-by: Anthonios Partheniou <[email protected]>
  • Loading branch information
galz10 and parthea authored Oct 16, 2022
1 parent 7225dea commit 1c91347
Show file tree
Hide file tree
Showing 55 changed files with 728 additions and 179 deletions.
5 changes: 5 additions & 0 deletions gapic/templates/%namespace/%name/__init__.py.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{% extends '_base.py.j2' %}
{% block content %}

{% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.module_name %}
from {{package_path}} import version as package_version

__version__ = package_version.__version__

{# Import subpackages. -#}
{% for subpackage in api.subpackages|dictsort %}
from {% if api.naming.module_namespace %}{{ api.naming.module_namespace|join('.') }}.{% endif %}
Expand Down
5 changes: 5 additions & 0 deletions gapic/templates/%namespace/%name/version.py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '_base.py.j2' %}
{% block content %}

__version__ = "0.1.0"
{% endblock %}
5 changes: 5 additions & 0 deletions gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

{% block content %}

{% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.module_name %}
from {{package_path}} import version as package_version

__version__ = package_version.__version__

{# Import subpackages. -#}
{% for subpackage, _ in api.subpackages|dictsort %}
from . import {{ subpackage }}
Expand Down
106 changes: 68 additions & 38 deletions gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,86 @@

import io
import os
import setuptools # type: ignore

version = '0.1.0'
import setuptools # type: ignore

package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, 'README.rst')
with io.open(readme_filename, encoding='utf-8') as readme_file:
readme = readme_file.read()
name = '{{ api.naming.warehouse_package_name }}'

setuptools.setup(
name='{{ api.naming.warehouse_package_name }}',
author="Google LLC",
author_email="[email protected]",
url="https://github.com/googleapis/python-{{ api.naming.warehouse_package_name }}",
version=version,
long_description=readme,
{% if api.naming.namespace %}
packages=setuptools.PEP420PackageFinder.find(),
namespace_packages={{ api.naming.namespace_packages }},
{% else %}
packages=setuptools.PEP420PackageFinder.find(),
{% endif %}
platforms='Posix; MacOS X; Windows',
include_package_data=True,
install_requires=(
'google-api-core[grpc] >= 2.10.0, < 3.0.0dev',
'libcst >= 0.2.5',
'googleapis-common-protos >= 1.55.0, <2.0.0dev',
'proto-plus >= 1.19.7',
{% set warehouse_description = api.naming.warehouse_package_name.replace('-',' ')|title %}
{% set package_path = api.naming.module_namespace|join('/') + "/" + api.naming.module_name %}

description = "{{ warehouse_description }} API client library"

version = {}
with open(os.path.join(package_root, '{{ package_path }}/version.py')) as fp:
exec(fp.read(), version)
version = version["__version__"]

if version[0] == "0":
release_status = "Development Status :: 4 - Beta"
else:
release_status = "Development Status :: 5 - Production/Stable"

dependencies = [
"google-api-core[grpc] >= 1.33.2, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*",
"proto-plus >= 1.22.0, <2.0.0dev",
"protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
{# TODO: Remove after https://github.com/googleapis/gapic-generator-python/pull/1240 is merged. #}
{% if api.requires_package(('google', 'iam', 'v1')) or opts.add_iam_methods or api.has_iam_mixin %}
'grpc-google-iam-v1 >= 0.12.4, < 0.13dev',
'grpc-google-iam-v1 >= 0.12.4, < 1.0.0dev',
{% endif %}
{% if api.requires_package(('google', 'cloud', 'documentai', 'v1')) %}
'google-cloud-documentai >= 1.2.1, < 2.0.0dev',
{% endif %}
),
python_requires='>=3.7',
]
url = "https://github.com/googleapis/python-{{ api.naming.warehouse_package_name|replace("google-cloud-", "") }}"
package_root = os.path.abspath(os.path.dirname(__file__))
readme_filename = os.path.join(package_root, "README.rst")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()
packages = [
package
for package in setuptools.PEP420PackageFinder.find()
if package.startswith("google")
]
namespaces = ["google"]
if "google.cloud" in packages:
namespaces.append("google.cloud")
setuptools.setup(
name=name,
version=version,
description=description,
long_description=readme,
author="Google LLC",
author_email="[email protected]",
license="Apache 2.0",
url=url,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Internet',
'Topic :: Software Development :: Libraries :: Python Modules',
release_status,
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Operating System :: OS Independent",
"Topic :: Internet",
],
platforms="Posix; MacOS X; Windows",
packages=packages,
python_requires=">=3.7",
namespace_packages=namespaces,
install_requires=dependencies,
include_package_data=True,
zip_safe=False,
)
{% endblock %}
{% endblock %}
11 changes: 11 additions & 0 deletions gapic/templates/testing/_default_constraints.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
{% if api.requires_package(('google', 'iam', 'v1')) or opts.add_iam_methods or api.has_iam_mixin %}
grpc-google-iam-v1
{% endif %}
{% if api.requires_package(('google', 'cloud', 'documentai', 'v1')) %}
google-cloud-documentai
{% endif %}
4 changes: 4 additions & 0 deletions gapic/templates/testing/constraints-3.10.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
{% block constraints %}
{% include "testing/_default_constraints.j2" %}
{% endblock %}
4 changes: 4 additions & 0 deletions gapic/templates/testing/constraints-3.11.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
{% block constraints %}
{% include "testing/_default_constraints.j2" %}
{% endblock %}
17 changes: 17 additions & 0 deletions gapic/templates/testing/constraints-3.7.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This constraints file is used to check that lower bounds
# are correct in setup.py
# List all library dependencies and extras in this file.
# Pin the version to the lower bound.
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
# Then this file should have google-cloud-foo==1.14.0
# This file is intentionally left empty to test the
# latest versions of dependencies.
google-api-core==1.33.2
proto-plus==1.22.0
protobuf==3.19.5
{% if api.requires_package(('google', 'iam', 'v1')) or opts.add_iam_methods or api.has_iam_mixin %}
grpc-google-iam-v1=0.12.4
{% endif %}
{% if api.requires_package(('google', 'cloud', 'documentai', 'v1')) %}
google-cloud-documentai=1.2.1
{% endif %}
4 changes: 4 additions & 0 deletions gapic/templates/testing/constraints-3.8.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
{% block constraints %}
{% include "testing/_default_constraints.j2" %}
{% endblock %}
4 changes: 4 additions & 0 deletions gapic/templates/testing/constraints-3.9.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
{% block constraints %}
{% include "testing/_default_constraints.j2" %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from google.cloud.asset import version as package_version

__version__ = package_version.__version__


from google.cloud.asset_v1.services.asset_service.client import AssetServiceClient
from google.cloud.asset_v1.services.asset_service.async_client import AssetServiceAsyncClient
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/goldens/asset/google/cloud/asset/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from google.cloud.asset import version as package_version

__version__ = package_version.__version__


from .services.asset_service import AssetServiceClient
from .services.asset_service import AssetServiceAsyncClient
Expand Down
90 changes: 61 additions & 29 deletions tests/integration/goldens/asset/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,77 @@
#
import io
import os
import setuptools # type: ignore

version = '0.1.0'
import setuptools # type: ignore

package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, 'README.rst')
with io.open(readme_filename, encoding='utf-8') as readme_file:
name = 'google-cloud-asset'


description = "Google Cloud Asset API client library"

version = {}
with open(os.path.join(package_root, 'google/cloud/asset/version.py')) as fp:
exec(fp.read(), version)
version = version["__version__"]

if version[0] == "0":
release_status = "Development Status :: 4 - Beta"
else:
release_status = "Development Status :: 5 - Production/Stable"

dependencies = [
"google-api-core[grpc] >= 1.33.2, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*",
"proto-plus >= 1.22.0, <2.0.0dev",
"protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
'grpc-google-iam-v1 >= 0.12.4, < 1.0.0dev',
]
url = "https://github.com/googleapis/python-asset"

package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, "README.rst")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

packages = [
package
for package in setuptools.PEP420PackageFinder.find()
if package.startswith("google")
]

namespaces = ["google"]
if "google.cloud" in packages:
namespaces.append("google.cloud")

setuptools.setup(
name='google-cloud-asset',
author="Google LLC",
author_email="[email protected]",
url="https://github.com/googleapis/python-google-cloud-asset",
name=name,
version=version,
description=description,
long_description=readme,
packages=setuptools.PEP420PackageFinder.find(),
namespace_packages=('google', 'google.cloud'),
platforms='Posix; MacOS X; Windows',
include_package_data=True,
install_requires=(
'google-api-core[grpc] >= 2.10.0, < 3.0.0dev',
'libcst >= 0.2.5',
'googleapis-common-protos >= 1.55.0, <2.0.0dev',
'proto-plus >= 1.19.7',
'grpc-google-iam-v1 >= 0.12.4, < 0.13dev',
),
python_requires='>=3.7',
author="Google LLC",
author_email="[email protected]",
license="Apache 2.0",
url=url,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Internet',
'Topic :: Software Development :: Libraries :: Python Modules',
release_status,
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Operating System :: OS Independent",
"Topic :: Internet",
],
platforms="Posix; MacOS X; Windows",
packages=packages,
python_requires=">=3.7",
namespace_packages=namespaces,
install_requires=dependencies,
include_package_data=True,
zip_safe=False,
)
7 changes: 7 additions & 0 deletions tests/integration/goldens/asset/testing/constraints-3.10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
grpc-google-iam-v1
7 changes: 7 additions & 0 deletions tests/integration/goldens/asset/testing/constraints-3.11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
grpc-google-iam-v1
12 changes: 12 additions & 0 deletions tests/integration/goldens/asset/testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This constraints file is used to check that lower bounds
# are correct in setup.py
# List all library dependencies and extras in this file.
# Pin the version to the lower bound.
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
# Then this file should have google-cloud-foo==1.14.0
# This file is intentionally left empty to test the
# latest versions of dependencies.
google-api-core==1.33.2
proto-plus==1.22.0
protobuf==3.19.5
grpc-google-iam-v1=0.12.4
7 changes: 7 additions & 0 deletions tests/integration/goldens/asset/testing/constraints-3.8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
grpc-google-iam-v1
Loading

0 comments on commit 1c91347

Please sign in to comment.