Skip to content

Commit c090323

Browse files
chore: update shared templates (googleapis#468)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * chore: add config / docs for 'pre-commit' support Source-Author: Tres Seaver <[email protected]> Source-Date: Tue Dec 1 16:01:20 2020 -0500 Source-Repo: googleapis/synthtool Source-Sha: 32af6da519a6b042e3da62008e2a75e991efb6b4 Source-Link: googleapis/synthtool@32af6da * chore(deps): update precommit hook pre-commit/pre-commit-hooks to v3.3.0 Source-Author: WhiteSource Renovate <[email protected]> Source-Date: Wed Dec 2 17:18:24 2020 +0100 Source-Repo: googleapis/synthtool Source-Sha: 69629b64b83c6421d616be2b8e11795738ec8a6c Source-Link: googleapis/synthtool@69629b6 * chore: update noxfile.py.j2 * Update noxfile.py.j2 add changes from @glasnt to the template template to ensure that enforcing type hinting doesn't fail for repos with the sample noxfile (aka all samples repos) See https://github.com/GoogleCloudPlatform/python-docs-samples/pull/4869/files for context * fix typo Source-Author: Leah E. Cole <[email protected]> Source-Date: Thu Dec 3 13:44:30 2020 -0800 Source-Repo: googleapis/synthtool Source-Sha: 18c5dbdb4ac8cf75d4d8174e7b4558f48e76f8a1 Source-Link: googleapis/synthtool@18c5dbd * chore(deps): update precommit hook pre-commit/pre-commit-hooks to v3.4.0 Co-authored-by: Tres Seaver <[email protected]> Source-Author: WhiteSource Renovate <[email protected]> Source-Date: Wed Dec 16 18:13:24 2020 +0100 Source-Repo: googleapis/synthtool Source-Sha: aa255b15d52b6d8950cca48cfdf58f7d27a60c8a Source-Link: googleapis/synthtool@aa255b1 * docs(python): document adding Python 3.9 support, dropping 3.5 support Closes googleapis#787 Source-Author: Tres Seaver <[email protected]> Source-Date: Thu Dec 17 16:08:02 2020 -0500 Source-Repo: googleapis/synthtool Source-Sha: b670a77a454f415d247907908e8ee7943e06d718 Source-Link: googleapis/synthtool@b670a77 * chore: exclude `.nox` directories from linting The samples tests create `.nox` directories with all dependencies installed. These directories should be excluded from linting. I've tested this change locally, and it significantly speeds up linting on my machine. Source-Author: Tim Swast <[email protected]> Source-Date: Tue Dec 22 13:04:04 2020 -0600 Source-Repo: googleapis/synthtool Source-Sha: 373861061648b5fe5e0ac4f8a38b32d639ee93e4 Source-Link: googleapis/synthtool@3738610 * chore(python): fix column sizing issue in docs Source-Author: Bu Sun Kim <[email protected]> Source-Date: Thu Jan 7 11:58:32 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: f15b57ccfd71106c2299e9b89835fe6e55015662 Source-Link: googleapis/synthtool@f15b57c * chore(python): use 'http' in LICENSE Co-authored-by: Tim Swast <[email protected]> Source-Author: Bu Sun Kim <[email protected]> Source-Date: Thu Jan 7 13:05:12 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: 41a4e56982620d3edcf110d76f4fcdfdec471ac8 Source-Link: googleapis/synthtool@41a4e56 * chore(python): skip docfx in main presubmit * chore(python): skip docfx in main presubmit * fix: properly template the repo name Source-Author: Bu Sun Kim <[email protected]> Source-Date: Fri Jan 8 10:32:13 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: fb53b6fb373b7c3edf4e55f3e8036bc6d73fa483 Source-Link: googleapis/synthtool@fb53b6f * chore: add missing quotation mark Source-Author: Bu Sun Kim <[email protected]> Source-Date: Mon Jan 11 09:43:06 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: 16ec872dd898d7de6e1822badfac32484b5d9031 Source-Link: googleapis/synthtool@16ec872
1 parent 1cf9f4f commit c090323

File tree

9 files changed

+154
-31
lines changed

9 files changed

+154
-31
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ exclude =
2626
*_pb2.py
2727

2828
# Standard linting exemptions.
29+
**/.nox/**
2930
__pycache__,
3031
.git,
3132
*.pyc,

.kokoro/docs/docs-presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ env_vars: {
2525
env_vars: {
2626
key: "NOX_SESSION"
2727
value: "docs docfx"
28-
}
28+
}

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v3.4.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- repo: https://github.com/psf/black
11+
rev: 19.10b0
12+
hooks:
13+
- id: black
14+
- repo: https://gitlab.com/pycqa/flake8
15+
rev: 3.8.4
16+
hooks:
17+
- id: flake8

CONTRIBUTING.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ In order to add a feature:
2121
- The feature must be documented in both the API and narrative
2222
documentation.
2323

24-
- The feature must work fully on the following CPython versions: 2.7,
25-
3.5, 3.6, 3.7 and 3.8 on both UNIX and Windows.
24+
- The feature must work fully on the following CPython versions:
25+
3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows.
2626

2727
- The feature must not add unnecessary dependencies (where
2828
"unnecessary" is of course subjective, but new dependencies should
@@ -111,6 +111,16 @@ Coding Style
111111
should point to the official ``googleapis`` checkout and the
112112
the branch should be the main branch on that remote (``master``).
113113

114+
- This repository contains configuration for the
115+
`pre-commit <https://pre-commit.com/>`__ tool, which automates checking
116+
our linters during a commit. If you have it installed on your ``$PATH``,
117+
you can enable enforcing those checks via:
118+
119+
.. code-block:: bash
120+
121+
$ pre-commit install
122+
pre-commit installed at .git/hooks/pre-commit
123+
114124
Exceptions to PEP8:
115125

116126
- Many unit tests use a helper method, ``_call_fut`` ("FUT" is short for
@@ -192,25 +202,24 @@ Supported Python Versions
192202

193203
We support:
194204

195-
- `Python 3.5`_
196205
- `Python 3.6`_
197206
- `Python 3.7`_
198207
- `Python 3.8`_
208+
- `Python 3.9`_
199209

200-
.. _Python 3.5: https://docs.python.org/3.5/
201210
.. _Python 3.6: https://docs.python.org/3.6/
202211
.. _Python 3.7: https://docs.python.org/3.7/
203212
.. _Python 3.8: https://docs.python.org/3.8/
213+
.. _Python 3.9: https://docs.python.org/3.9/
204214

205215

206216
Supported versions can be found in our ``noxfile.py`` `config`_.
207217

208218
.. _config: https://github.com/googleapis/python-bigquery/blob/master/noxfile.py
209219

210-
Python 2.7 support is deprecated. All code changes should maintain Python 2.7 compatibility until January 1, 2020.
211220

212221
We also explicitly decided to support Python 3 beginning with version
213-
3.5. Reasons for this include:
222+
3.6. Reasons for this include:
214223

215224
- Encouraging use of newest versions of Python 3
216225
- Taking the lead of `prominent`_ open-source `projects`_

LICENSE

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Apache License
1+
2+
Apache License
23
Version 2.0, January 2004
3-
https://www.apache.org/licenses/
4+
http://www.apache.org/licenses/
45

56
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
67

@@ -192,7 +193,7 @@
192193
you may not use this file except in compliance with the License.
193194
You may obtain a copy of the License at
194195

195-
https://www.apache.org/licenses/LICENSE-2.0
196+
http://www.apache.org/licenses/LICENSE-2.0
196197

197198
Unless required by applicable law or agreed to in writing, software
198199
distributed under the License is distributed on an "AS IS" BASIS,

docs/_static/custom.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
div#python2-eol {
22
border-color: red;
33
border-width: medium;
4-
}
4+
}
5+
6+
/* Ensure minimum width for 'Parameters' / 'Returns' column */
7+
dl.field-list > dt {
8+
min-width: 100px
9+
}

samples/geography/noxfile.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
from pathlib import Path
1919
import sys
20+
from typing import Callable, Dict, List, Optional
2021

2122
import nox
2223

@@ -65,7 +66,7 @@
6566
TEST_CONFIG.update(TEST_CONFIG_OVERRIDE)
6667

6768

68-
def get_pytest_env_vars():
69+
def get_pytest_env_vars() -> Dict[str, str]:
6970
"""Returns a dict for pytest invocation."""
7071
ret = {}
7172

@@ -94,7 +95,7 @@ def get_pytest_env_vars():
9495
#
9596

9697

97-
def _determine_local_import_names(start_dir):
98+
def _determine_local_import_names(start_dir: str) -> List[str]:
9899
"""Determines all import names that should be considered "local".
99100
100101
This is used when running the linter to insure that import order is
@@ -132,7 +133,7 @@ def _determine_local_import_names(start_dir):
132133

133134

134135
@nox.session
135-
def lint(session):
136+
def lint(session: nox.sessions.Session) -> None:
136137
if not TEST_CONFIG["enforce_type_hints"]:
137138
session.install("flake8", "flake8-import-order")
138139
else:
@@ -153,7 +154,7 @@ def lint(session):
153154

154155

155156
@nox.session
156-
def blacken(session):
157+
def blacken(session: nox.sessions.Session) -> None:
157158
session.install("black")
158159
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
159160

@@ -168,7 +169,9 @@ def blacken(session):
168169
PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"]
169170

170171

171-
def _session_tests(session, post_install=None):
172+
def _session_tests(
173+
session: nox.sessions.Session, post_install: Callable = None
174+
) -> None:
172175
"""Runs py.test for a particular project."""
173176
if os.path.exists("requirements.txt"):
174177
session.install("-r", "requirements.txt")
@@ -194,7 +197,7 @@ def _session_tests(session, post_install=None):
194197

195198

196199
@nox.session(python=ALL_VERSIONS)
197-
def py(session):
200+
def py(session: nox.sessions.Session) -> None:
198201
"""Runs py.test for a sample using the specified version of Python."""
199202
if session.python in TESTED_VERSIONS:
200203
_session_tests(session)
@@ -209,7 +212,7 @@ def py(session):
209212
#
210213

211214

212-
def _get_repo_root():
215+
def _get_repo_root() -> Optional[str]:
213216
""" Returns the root folder of the project. """
214217
# Get root of this repository. Assume we don't have directories nested deeper than 10 items.
215218
p = Path(os.getcwd())
@@ -232,7 +235,7 @@ def _get_repo_root():
232235

233236
@nox.session
234237
@nox.parametrize("path", GENERATED_READMES)
235-
def readmegen(session, path):
238+
def readmegen(session: nox.sessions.Session, path: str) -> None:
236239
"""(Re-)generates the readme for a sample."""
237240
session.install("jinja2", "pyyaml")
238241
dir_ = os.path.dirname(path)

samples/snippets/noxfile.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
from pathlib import Path
1919
import sys
20+
from typing import Callable, Dict, List, Optional
2021

2122
import nox
2223

@@ -65,7 +66,7 @@
6566
TEST_CONFIG.update(TEST_CONFIG_OVERRIDE)
6667

6768

68-
def get_pytest_env_vars():
69+
def get_pytest_env_vars() -> Dict[str, str]:
6970
"""Returns a dict for pytest invocation."""
7071
ret = {}
7172

@@ -94,7 +95,7 @@ def get_pytest_env_vars():
9495
#
9596

9697

97-
def _determine_local_import_names(start_dir):
98+
def _determine_local_import_names(start_dir: str) -> List[str]:
9899
"""Determines all import names that should be considered "local".
99100
100101
This is used when running the linter to insure that import order is
@@ -132,7 +133,7 @@ def _determine_local_import_names(start_dir):
132133

133134

134135
@nox.session
135-
def lint(session):
136+
def lint(session: nox.sessions.Session) -> None:
136137
if not TEST_CONFIG["enforce_type_hints"]:
137138
session.install("flake8", "flake8-import-order")
138139
else:
@@ -153,7 +154,7 @@ def lint(session):
153154

154155

155156
@nox.session
156-
def blacken(session):
157+
def blacken(session: nox.sessions.Session) -> None:
157158
session.install("black")
158159
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
159160

@@ -168,7 +169,9 @@ def blacken(session):
168169
PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"]
169170

170171

171-
def _session_tests(session, post_install=None):
172+
def _session_tests(
173+
session: nox.sessions.Session, post_install: Callable = None
174+
) -> None:
172175
"""Runs py.test for a particular project."""
173176
if os.path.exists("requirements.txt"):
174177
session.install("-r", "requirements.txt")
@@ -194,7 +197,7 @@ def _session_tests(session, post_install=None):
194197

195198

196199
@nox.session(python=ALL_VERSIONS)
197-
def py(session):
200+
def py(session: nox.sessions.Session) -> None:
198201
"""Runs py.test for a sample using the specified version of Python."""
199202
if session.python in TESTED_VERSIONS:
200203
_session_tests(session)
@@ -209,7 +212,7 @@ def py(session):
209212
#
210213

211214

212-
def _get_repo_root():
215+
def _get_repo_root() -> Optional[str]:
213216
""" Returns the root folder of the project. """
214217
# Get root of this repository. Assume we don't have directories nested deeper than 10 items.
215218
p = Path(os.getcwd())
@@ -232,7 +235,7 @@ def _get_repo_root():
232235

233236
@nox.session
234237
@nox.parametrize("path", GENERATED_READMES)
235-
def readmegen(session, path):
238+
def readmegen(session: nox.sessions.Session, path: str) -> None:
236239
"""(Re-)generates the readme for a sample."""
237240
session.install("jinja2", "pyyaml")
238241
dir_ = os.path.dirname(path)

0 commit comments

Comments
 (0)