Add new django tutorial by glasnt · Pull Request #4869 · GoogleCloudPlatform/python-docs-samples
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 @@ -68,7 +69,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 @@ -98,7 +99,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 @@ -136,7 +137,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 @@ -156,7 +157,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 @@ -171,7 +172,7 @@ 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 @@ -197,7 +198,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 @@ -212,9 +213,10 @@ 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. # Get root of this repository. # Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): if p is None: Expand All @@ -230,7 +232,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
import nox
Expand Down Expand Up @@ -68,7 +69,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 @@ -98,7 +99,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 @@ -136,7 +137,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 @@ -156,7 +157,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 @@ -171,7 +172,7 @@ 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 @@ -197,7 +198,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 @@ -212,9 +213,10 @@ 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. # Get root of this repository. # Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): if p is None: Expand All @@ -230,7 +232,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