Skip to content

Commit

Permalink
chore: update shared templates (googleapis#468)
Browse files Browse the repository at this point in the history
* 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 <tseaver@palladion.com>
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 <bot@renovateapp.com>
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 <6719667+leahecole@users.noreply.github.com>
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 <tseaver@palladion.com>

Source-Author: WhiteSource Renovate <bot@renovateapp.com>
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 <tseaver@palladion.com>
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 <swast@google.com>
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 <8822365+busunkim96@users.noreply.github.com>
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 <swast@google.com>

Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
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 <8822365+busunkim96@users.noreply.github.com>
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 <8822365+busunkim96@users.noreply.github.com>
Source-Date: Mon Jan 11 09:43:06 2021 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 16ec872dd898d7de6e1822badfac32484b5d9031
Source-Link: googleapis/synthtool@16ec872
  • Loading branch information
yoshi-automation committed Feb 1, 2021
1 parent 1cf9f4f commit c090323
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 31 deletions.
1 change: 1 addition & 0 deletions .flake8
Expand Up @@ -26,6 +26,7 @@ exclude =
*_pb2.py

# Standard linting exemptions.
**/.nox/**
__pycache__,
.git,
*.pyc,
Expand Down
2 changes: 1 addition & 1 deletion .kokoro/docs/docs-presubmit.cfg
Expand Up @@ -25,4 +25,4 @@ env_vars: {
env_vars: {
key: "NOX_SESSION"
value: "docs docfx"
}
}
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,17 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
21 changes: 15 additions & 6 deletions CONTRIBUTING.rst
Expand Up @@ -21,8 +21,8 @@ In order to add a feature:
- The feature must be documented in both the API and narrative
documentation.

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

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

- This repository contains configuration for the
`pre-commit <https://pre-commit.com/>`__ tool, which automates checking
our linters during a commit. If you have it installed on your ``$PATH``,
you can enable enforcing those checks via:

.. code-block:: bash
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
Exceptions to PEP8:

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

We support:

- `Python 3.5`_
- `Python 3.6`_
- `Python 3.7`_
- `Python 3.8`_
- `Python 3.9`_

.. _Python 3.5: https://docs.python.org/3.5/
.. _Python 3.6: https://docs.python.org/3.6/
.. _Python 3.7: https://docs.python.org/3.7/
.. _Python 3.8: https://docs.python.org/3.8/
.. _Python 3.9: https://docs.python.org/3.9/


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

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

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

We also explicitly decided to support Python 3 beginning with version
3.5. Reasons for this include:
3.6. Reasons for this include:

- Encouraging use of newest versions of Python 3
- Taking the lead of `prominent`_ open-source `projects`_
Expand Down
7 changes: 4 additions & 3 deletions LICENSE
@@ -1,6 +1,7 @@
Apache License

Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

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

https://www.apache.org/licenses/LICENSE-2.0
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,
Expand Down
7 changes: 6 additions & 1 deletion docs/_static/custom.css
@@ -1,4 +1,9 @@
div#python2-eol {
border-color: red;
border-width: medium;
}
}

/* Ensure minimum width for 'Parameters' / 'Returns' column */
dl.field-list > dt {
min-width: 100px
}
19 changes: 11 additions & 8 deletions samples/geography/noxfile.py
Expand Up @@ -17,6 +17,7 @@
import os
from pathlib import Path
import sys
from typing import Callable, Dict, List, Optional

import nox

Expand Down Expand Up @@ -65,7 +66,7 @@
TEST_CONFIG.update(TEST_CONFIG_OVERRIDE)


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

Expand Down Expand Up @@ -94,7 +95,7 @@ def get_pytest_env_vars():
#


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


@nox.session
def lint(session):
def lint(session: nox.sessions.Session) -> None:
if not TEST_CONFIG["enforce_type_hints"]:
session.install("flake8", "flake8-import-order")
else:
Expand All @@ -153,7 +154,7 @@ def lint(session):


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

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


def _session_tests(session, post_install=None):
def _session_tests(
session: nox.sessions.Session, post_install: Callable = None
) -> None:
"""Runs py.test for a particular project."""
if os.path.exists("requirements.txt"):
session.install("-r", "requirements.txt")
Expand All @@ -194,7 +197,7 @@ def _session_tests(session, post_install=None):


@nox.session(python=ALL_VERSIONS)
def py(session):
def py(session: nox.sessions.Session) -> None:
"""Runs py.test for a sample using the specified version of Python."""
if session.python in TESTED_VERSIONS:
_session_tests(session)
Expand All @@ -209,7 +212,7 @@ def py(session):
#


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

@nox.session
@nox.parametrize("path", GENERATED_READMES)
def readmegen(session, path):
def readmegen(session: nox.sessions.Session, path: str) -> None:
"""(Re-)generates the readme for a sample."""
session.install("jinja2", "pyyaml")
dir_ = os.path.dirname(path)
Expand Down
19 changes: 11 additions & 8 deletions samples/snippets/noxfile.py
Expand Up @@ -17,6 +17,7 @@
import os
from pathlib import Path
import sys
from typing import Callable, Dict, List, Optional

import nox

Expand Down Expand Up @@ -65,7 +66,7 @@
TEST_CONFIG.update(TEST_CONFIG_OVERRIDE)


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

Expand Down Expand Up @@ -94,7 +95,7 @@ def get_pytest_env_vars():
#


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


@nox.session
def lint(session):
def lint(session: nox.sessions.Session) -> None:
if not TEST_CONFIG["enforce_type_hints"]:
session.install("flake8", "flake8-import-order")
else:
Expand All @@ -153,7 +154,7 @@ def lint(session):


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

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


def _session_tests(session, post_install=None):
def _session_tests(
session: nox.sessions.Session, post_install: Callable = None
) -> None:
"""Runs py.test for a particular project."""
if os.path.exists("requirements.txt"):
session.install("-r", "requirements.txt")
Expand All @@ -194,7 +197,7 @@ def _session_tests(session, post_install=None):


@nox.session(python=ALL_VERSIONS)
def py(session):
def py(session: nox.sessions.Session) -> None:
"""Runs py.test for a sample using the specified version of Python."""
if session.python in TESTED_VERSIONS:
_session_tests(session)
Expand All @@ -209,7 +212,7 @@ def py(session):
#


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

@nox.session
@nox.parametrize("path", GENERATED_READMES)
def readmegen(session, path):
def readmegen(session: nox.sessions.Session, path: str) -> None:
"""(Re-)generates the readme for a sample."""
session.install("jinja2", "pyyaml")
dir_ = os.path.dirname(path)
Expand Down

0 comments on commit c090323

Please sign in to comment.