Skip to content

Commit e69027b

Browse files
rinarakakiparthea
andauthored
feat: migrate to pyproject.toml (#13550)
Tracking issue #13171 Previous PR: googleapis/python-grpc-google-iam-v1#112 Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-cloud-python/issues) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕 --------- Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 7dda4d0 commit e69027b

File tree

4 files changed

+224
-62
lines changed

4 files changed

+224
-62
lines changed

packages/grpc-google-iam-v1/README.rst

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ In order to use this library, you first need to go through the following steps:
2626
1. `Select or create a Cloud Platform project.`_
2727
2. `Enable billing for your project.`_
2828
3. `Enable the Cloud Identity and Access Management.`_
29-
4. `Setup Authentication.`_
29+
4. `Set up Authentication.`_
3030

3131
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
3232
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
3333
.. _Enable the Cloud Identity and Access Management.: https://cloud.google.com/iam/docs/
34-
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
34+
.. _Set up Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
3535

3636
Installation
3737
~~~~~~~~~~~~
@@ -106,3 +106,92 @@ Next Steps
106106

107107
.. _Cloud Identity and Access Management Product documentation: https://cloud.google.com/iam/docs/
108108
.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst
109+
110+
Logging
111+
-------
112+
113+
This library uses the standard Python :code:`logging` functionality to log some RPC events that could be of interest for debugging and monitoring purposes.
114+
Note the following:
115+
116+
#. Logs may contain sensitive information. Take care to **restrict access to the logs** if they are saved, whether it be on local storage or on Google Cloud Logging.
117+
#. Google may refine the occurrence, level, and content of various log messages in this library without flagging such changes as breaking. **Do not depend on immutability of the logging events**.
118+
#. By default, the logging events from this library are not handled. You must **explicitly configure log handling** using one of the mechanisms below.
119+
120+
Simple, environment-based configuration
121+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122+
123+
To enable logging for this library without any changes in your code, set the :code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable to a valid Google
124+
logging scope. This configures handling of logging events (at level :code:`logging.DEBUG` or higher) from this library in a default manner, emitting the logged
125+
messages in a structured format. It does not currently allow customizing the logging levels captured nor the handlers, formatters, etc. used for any logging
126+
event.
127+
128+
A logging scope is a period-separated namespace that begins with :code:`google`, identifying the Python module or package to log.
129+
130+
- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc.
131+
- Invalid logging scopes: :code:`foo`, :code:`123`, etc.
132+
133+
**NOTE**: If the logging scope is invalid, the library does not set up any logging handlers.
134+
135+
Environment-Based Examples
136+
^^^^^^^^^^^^^^^^^^^^^^^^^^
137+
138+
- Enabling the default handler for all Google-based loggers
139+
140+
.. code-block:: console
141+
142+
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
143+
144+
- Enabling the default handler for a specific Google module (for a client library called :code:`library_v1`):
145+
146+
.. code-block:: console
147+
148+
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1
149+
150+
151+
Advanced, code-based configuration
152+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153+
154+
You can also configure a valid logging scope using Python's standard `logging` mechanism.
155+
156+
Code-Based Examples
157+
^^^^^^^^^^^^^^^^^^^
158+
159+
- Configuring a handler for all Google-based loggers
160+
161+
.. code-block:: python
162+
163+
import logging
164+
165+
from google.cloud.translate_v3 import translate
166+
167+
base_logger = logging.getLogger("google")
168+
base_logger.addHandler(logging.StreamHandler())
169+
base_logger.setLevel(logging.DEBUG)
170+
171+
- Configuring a handler for a specific Google module (for a client library called :code:`library_v1`):
172+
173+
.. code-block:: python
174+
175+
import logging
176+
177+
from google.cloud.translate_v3 import translate
178+
179+
base_logger = logging.getLogger("google.cloud.library_v1")
180+
base_logger.addHandler(logging.StreamHandler())
181+
base_logger.setLevel(logging.DEBUG)
182+
183+
Logging details
184+
~~~~~~~~~~~~~~~
185+
186+
#. Regardless of which of the mechanisms above you use to configure logging for this library, by default logging events are not propagated up to the root
187+
logger from the `google`-level logger. If you need the events to be propagated to the root logger, you must explicitly set
188+
:code:`logging.getLogger("google").propagate = True` in your code.
189+
#. You can mix the different logging configurations above for different Google modules. For example, you may want use a code-based logging configuration for
190+
one library, but decide you need to also set up environment-based logging configuration for another library.
191+
192+
#. If you attempt to use both code-based and environment-based configuration for the same module, the environment-based configuration will be ineffectual
193+
if the code -based configuration gets applied first.
194+
195+
#. The Google-specific logging configurations (default handlers for environment-based configuration; not propagating logging events to the root logger) get
196+
executed the first time *any* client library is instantiated in your application, and only if the affected loggers have not been previously configured.
197+
(This is the reason for 2.i. above.)

packages/grpc-google-iam-v1/noxfile.py

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,20 +382,29 @@ def docfx(session):
382382
["python", "upb", "cpp"],
383383
)
384384
def prerelease_deps(session, protobuf_implementation):
385-
"""Run all tests with prerelease versions of dependencies installed."""
385+
"""
386+
Run all tests with pre-release versions of dependencies installed
387+
rather than the standard non pre-release versions.
388+
Pre-releases versions can be installed using
389+
`pip install --pre <package>`.
390+
"""
386391

387392
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"):
388393
session.skip("cpp implementation is not supported in python 3.11+")
389394

390395
# Install all dependencies
391-
session.install("-e", ".[all, tests, tracing]")
396+
session.install("-e", ".")
397+
392398
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
399+
# Install dependencies for the unit test environment
393400
session.install(*unit_deps_all)
401+
394402
system_deps_all = (
395403
SYSTEM_TEST_STANDARD_DEPENDENCIES
396404
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
397405
+ SYSTEM_TEST_EXTRAS
398406
)
407+
# Install dependencies for the system test environment
399408
session.install(*system_deps_all)
400409

401410
# Because we test minimum dependency versions on the minimum Python
@@ -417,6 +426,7 @@ def prerelease_deps(session, protobuf_implementation):
417426
)
418427
]
419428

429+
# Install dependencies specified in `testing/constraints-X.txt`.
420430
session.install(*constraints_deps)
421431

422432
prerel_deps = [
@@ -458,3 +468,70 @@ def prerelease_deps(session, protobuf_implementation):
458468
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
459469
},
460470
)
471+
472+
473+
@nox.session(python="3.13")
474+
@nox.parametrize(
475+
"protobuf_implementation",
476+
["python", "upb"],
477+
)
478+
def core_deps_from_source(session, protobuf_implementation):
479+
"""Run all tests with local versions of core dependencies installed,
480+
rather than pulling core dependencies from PyPI.
481+
"""
482+
483+
# Install all dependencies
484+
session.install(".")
485+
486+
# Install dependencies for the unit test environment
487+
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
488+
session.install(*unit_deps_all)
489+
490+
# Install dependencies for the system test environment
491+
system_deps_all = (
492+
SYSTEM_TEST_STANDARD_DEPENDENCIES
493+
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
494+
+ SYSTEM_TEST_EXTRAS
495+
)
496+
session.install(*system_deps_all)
497+
498+
# Because we test minimum dependency versions on the minimum Python
499+
# version, the first version we test with in the unit tests sessions has a
500+
# constraints file containing all dependencies and extras that should be installed.
501+
with open(
502+
CURRENT_DIRECTORY
503+
/ "testing"
504+
/ f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
505+
encoding="utf-8",
506+
) as constraints_file:
507+
constraints_text = constraints_file.read()
508+
509+
# Ignore leading whitespace and comment lines.
510+
constraints_deps = [
511+
match.group(1)
512+
for match in re.finditer(
513+
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
514+
)
515+
]
516+
517+
# Install dependencies specified in `testing/constraints-X.txt`.
518+
session.install(*constraints_deps)
519+
520+
core_dependencies_from_source = [
521+
"google-api-core @ git+https://github.com/googleapis/python-api-core.git",
522+
"google-auth @ git+https://github.com/googleapis/google-auth-library-python.git",
523+
f"{CURRENT_DIRECTORY}/../googleapis-common-protos",
524+
f"{CURRENT_DIRECTORY}/../grpc-google-iam-v1",
525+
"proto-plus @ git+https://github.com/googleapis/proto-plus-python.git",
526+
]
527+
528+
for dep in core_dependencies_from_source:
529+
session.install(dep, "--ignore-installed", "--no-deps")
530+
531+
session.run(
532+
"py.test",
533+
"tests/unit",
534+
env={
535+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
536+
},
537+
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[build-system]
16+
requires = ["setuptools"]
17+
build-backend = "setuptools.build_meta"
18+
19+
[project]
20+
name = "grpc-google-iam-v1"
21+
version = "0.14.0"
22+
authors = [{ name = "Google LLC", email = "googleapis-packages@google.com" }]
23+
license = { text = "Apache 2.0" }
24+
requires-python = ">=3.7"
25+
description = "IAM API client library"
26+
readme = "README.rst"
27+
classifiers = [
28+
"Development Status :: 4 - Beta",
29+
"Intended Audience :: Developers",
30+
"License :: OSI Approved :: Apache Software License",
31+
"Programming Language :: Python",
32+
"Programming Language :: Python :: 3",
33+
"Programming Language :: Python :: 3.7",
34+
"Programming Language :: Python :: 3.8",
35+
"Programming Language :: Python :: 3.9",
36+
"Programming Language :: Python :: 3.10",
37+
"Programming Language :: Python :: 3.11",
38+
"Programming Language :: Python :: 3.12",
39+
"Programming Language :: Python :: 3.13",
40+
"Operating System :: OS Independent",
41+
"Topic :: Internet",
42+
]
43+
dependencies = [
44+
"grpcio >= 1.44.0, < 2.0.0dev",
45+
"googleapis-common-protos[grpc] >= 1.56.0, < 2.0.0dev",
46+
"protobuf >= 3.20.2, < 6.0.0dev, != 4.21.1, != 4.21.2, != 4.21.3, != 4.21.4, != 4.21.5",
47+
]
48+
49+
[project.urls]
50+
Repository = "https://github.com/googleapis/google-cloud-python"
51+
52+
[tool.setuptools.packages.find]
53+
include = ["google*"]

packages/grpc-google-iam-v1/setup.py

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import io
18-
import os
19-
2017
import setuptools
2118

22-
name = "grpc-google-iam-v1"
23-
description = "IAM API client library"
24-
version = "0.14.0"
25-
url = "https://github.com/googleapis/google-cloud-python"
26-
release_status = "Development Status :: 4 - Beta"
27-
dependencies = [
28-
"grpcio>=1.44.0, <2.0.0dev",
29-
"googleapis-common-protos[grpc]>=1.56.0, <2.0.0dev",
30-
"protobuf>=3.20.2,<6.0.0dev,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
31-
]
32-
33-
package_root = os.path.abspath(os.path.dirname(__file__))
34-
35-
readme_filename = os.path.join(package_root, "README.rst")
36-
with io.open(readme_filename, encoding="utf-8") as readme_file:
37-
readme = readme_file.read()
38-
39-
packages = [
40-
package
41-
for package in setuptools.find_namespace_packages()
42-
if package.startswith("google")
43-
]
44-
45-
setuptools.setup(
46-
name=name,
47-
version=version,
48-
description=description,
49-
long_description=readme,
50-
author="Google LLC",
51-
author_email="googleapis-packages@google.com",
52-
license="Apache 2.0",
53-
url=url,
54-
classifiers=[
55-
release_status,
56-
"Intended Audience :: Developers",
57-
"License :: OSI Approved :: Apache Software License",
58-
"Programming Language :: Python",
59-
"Programming Language :: Python :: 3",
60-
"Programming Language :: Python :: 3.7",
61-
"Programming Language :: Python :: 3.8",
62-
"Programming Language :: Python :: 3.9",
63-
"Programming Language :: Python :: 3.10",
64-
"Programming Language :: Python :: 3.11",
65-
"Programming Language :: Python :: 3.12",
66-
"Programming Language :: Python :: 3.13",
67-
"Operating System :: OS Independent",
68-
"Topic :: Internet",
69-
],
70-
platforms="Posix; MacOS X; Windows",
71-
packages=packages,
72-
python_requires=">=3.7",
73-
install_requires=dependencies,
74-
include_package_data=True,
75-
zip_safe=False,
76-
)
19+
setuptools.setup()

0 commit comments

Comments
 (0)