GeezerVison is showing github.com — chore: blacken samples noxfile template (#711) · ccubc/python-aiplatform@f452215
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | docker: | 2 | 2 | image: gcr.io/repo-automation-bots/owlbot-python:latest | 3 | | - digest: sha256:0ffe3bdd6c7159692df5f7744da74e5ef19966288a6bf76023e8e04e0c424d7d | | 3 | + digest: sha256:0ccd9f4d714d36e311f60f407199dd460e43a99a125b5ca64b1d75f6e5f8581b |
Collapse file Copy file name to clipboardExpand all lines: samples/model-builder/noxfile.py +25-19Lines changed: 25 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 39 | 39 |
| 40 | 40 | TEST_CONFIG = { | 41 | 41 | # You can opt out from the test for specific Python versions. | 42 | | - 'ignored_versions': [], | 43 | | - | | 42 | + "ignored_versions": [], | 44 | 43 | # Old samples are opted out of enforcing Python type hints | 45 | 44 | # All new samples should feature them | 46 | | - 'enforce_type_hints': False, | 47 | | - | | 45 | + "enforce_type_hints": False, | 48 | 46 | # An envvar key for determining the project id to use. Change it | 49 | 47 | # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a | 50 | 48 | # build specific Cloud project. You can also use your own string | 51 | 49 | # to use your own Cloud project. | 52 | | - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', | | 50 | + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", | 53 | 51 | # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', | 54 | 52 | # If you need to use a specific version of pip, | 55 | 53 | # change pip_version_override to the string representation | 56 | 54 | # of the version number, for example, "20.2.4" | 57 | 55 | "pip_version_override": None, | 58 | 56 | # A dictionary you want to inject into your test. Don't put any | 59 | 57 | # secrets here. These values will override predefined values. | 60 | | - 'envs': {}, | | 58 | + "envs": {}, | 61 | 59 | } | 62 | 60 |
| 63 | 61 |
| 64 | 62 | try: | 65 | 63 | # Ensure we can import noxfile_config in the project's directory. | 66 | | - sys.path.append('.') | | 64 | + sys.path.append(".") | 67 | 65 | from noxfile_config import TEST_CONFIG_OVERRIDE | 68 | 66 | except ImportError as e: | 69 | 67 | print("No user noxfile_config found: detail: {}".format(e)) | @@ -78,12 +76,12 @@ def get_pytest_env_vars() -> Dict[str, str]: | 78 | 76 | ret = {} | 79 | 77 |
| 80 | 78 | # Override the GCLOUD_PROJECT and the alias. | 81 | | - env_key = TEST_CONFIG['gcloud_project_env'] | | 79 | + env_key = TEST_CONFIG["gcloud_project_env"] | 82 | 80 | # This should error out if not set. | 83 | | - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] | | 81 | + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] | 84 | 82 |
| 85 | 83 | # Apply user supplied envs. | 86 | | - ret.update(TEST_CONFIG['envs']) | | 84 | + ret.update(TEST_CONFIG["envs"]) | 87 | 85 | return ret | 88 | 86 |
| 89 | 87 |
| @@ -92,11 +90,14 @@ def get_pytest_env_vars() -> Dict[str, str]: | 92 | 90 | ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] | 93 | 91 |
| 94 | 92 | # Any default versions that should be ignored. | 95 | | -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] | | 93 | +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] | 96 | 94 |
| 97 | 95 | TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) | 98 | 96 |
| 99 | | -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") | | 97 | +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( | | 98 | + "True", | | 99 | + "true", | | 100 | +) | 100 | 101 | # | 101 | 102 | # Style Checks | 102 | 103 | # | @@ -141,7 +142,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: | 141 | 142 |
| 142 | 143 | @nox.session | 143 | 144 | def lint(session: nox.sessions.Session) -> None: | 144 | | - if not TEST_CONFIG['enforce_type_hints']: | | 145 | + if not TEST_CONFIG["enforce_type_hints"]: | 145 | 146 | session.install("flake8", "flake8-import-order") | 146 | 147 | else: | 147 | 148 | session.install("flake8", "flake8-import-order", "flake8-annotations") | @@ -150,9 +151,11 @@ def lint(session: nox.sessions.Session) -> None: | 150 | 151 | args = FLAKE8_COMMON_ARGS + [ | 151 | 152 | "--application-import-names", | 152 | 153 | ",".join(local_names), | 153 | | - "." | | 154 | + ".", | 154 | 155 | ] | 155 | 156 | session.run("flake8", *args) | | 157 | + | | 158 | + | 156 | 159 | # | 157 | 160 | # Black | 158 | 161 | # | @@ -165,6 +168,7 @@ def blacken(session: nox.sessions.Session) -> None: | 165 | 168 |
| 166 | 169 | session.run("black", *python_files) | 167 | 170 |
| | 171 | + | 168 | 172 | # | 169 | 173 | # Sample Tests | 170 | 174 | # | @@ -173,7 +177,9 @@ def blacken(session: nox.sessions.Session) -> None: | 173 | 177 | PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] | 174 | 178 |
| 175 | 179 |
| 176 | | -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: | | 180 | +def _session_tests( | | 181 | + session: nox.sessions.Session, post_install: Callable = None | | 182 | +) -> None: | 177 | 183 | if TEST_CONFIG["pip_version_override"]: | 178 | 184 | pip_version = TEST_CONFIG["pip_version_override"] | 179 | 185 | session.install(f"pip=={pip_version}") | @@ -203,7 +209,7 @@ def _session_tests(session: nox.sessions.Session, post_install: Callable = None) | 203 | 209 | # on travis where slow and flaky tests are excluded. | 204 | 210 | # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html | 205 | 211 | success_codes=[0, 5], | 206 | | - env=get_pytest_env_vars() | | 212 | + env=get_pytest_env_vars(), | 207 | 213 | ) | 208 | 214 |
| 209 | 215 |
| @@ -213,9 +219,9 @@ def py(session: nox.sessions.Session) -> None: | 213 | 219 | if session.python in TESTED_VERSIONS: | 214 | 220 | _session_tests(session) | 215 | 221 | else: | 216 | | - session.skip("SKIPPED: {} tests are disabled for this sample.".format( | 217 | | - session.python | 218 | | - )) | | 222 | + session.skip( | | 223 | + "SKIPPED: {} tests are disabled for this sample.".format(session.python) | | 224 | + ) | 219 | 225 |
| 220 | 226 |
| 221 | 227 | # | |
Collapse file Copy file name to clipboardExpand all lines: samples/snippets/noxfile.py +25-19Lines changed: 25 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 39 | 39 |
| 40 | 40 | TEST_CONFIG = { | 41 | 41 | # You can opt out from the test for specific Python versions. | 42 | | - 'ignored_versions': [], | 43 | | - | | 42 | + "ignored_versions": [], | 44 | 43 | # Old samples are opted out of enforcing Python type hints | 45 | 44 | # All new samples should feature them | 46 | | - 'enforce_type_hints': False, | 47 | | - | | 45 | + "enforce_type_hints": False, | 48 | 46 | # An envvar key for determining the project id to use. Change it | 49 | 47 | # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a | 50 | 48 | # build specific Cloud project. You can also use your own string | 51 | 49 | # to use your own Cloud project. | 52 | | - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', | | 50 | + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", | 53 | 51 | # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', | 54 | 52 | # If you need to use a specific version of pip, | 55 | 53 | # change pip_version_override to the string representation | 56 | 54 | # of the version number, for example, "20.2.4" | 57 | 55 | "pip_version_override": None, | 58 | 56 | # A dictionary you want to inject into your test. Don't put any | 59 | 57 | # secrets here. These values will override predefined values. | 60 | | - 'envs': {}, | | 58 | + "envs": {}, | 61 | 59 | } | 62 | 60 |
| 63 | 61 |
| 64 | 62 | try: | 65 | 63 | # Ensure we can import noxfile_config in the project's directory. | 66 | | - sys.path.append('.') | | 64 | + sys.path.append(".") | 67 | 65 | from noxfile_config import TEST_CONFIG_OVERRIDE | 68 | 66 | except ImportError as e: | 69 | 67 | print("No user noxfile_config found: detail: {}".format(e)) | @@ -78,12 +76,12 @@ def get_pytest_env_vars() -> Dict[str, str]: | 78 | 76 | ret = {} | 79 | 77 |
| 80 | 78 | # Override the GCLOUD_PROJECT and the alias. | 81 | | - env_key = TEST_CONFIG['gcloud_project_env'] | | 79 | + env_key = TEST_CONFIG["gcloud_project_env"] | 82 | 80 | # This should error out if not set. | 83 | | - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] | | 81 | + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] | 84 | 82 |
| 85 | 83 | # Apply user supplied envs. | 86 | | - ret.update(TEST_CONFIG['envs']) | | 84 | + ret.update(TEST_CONFIG["envs"]) | 87 | 85 | return ret | 88 | 86 |
| 89 | 87 |
| @@ -92,11 +90,14 @@ def get_pytest_env_vars() -> Dict[str, str]: | 92 | 90 | ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] | 93 | 91 |
| 94 | 92 | # Any default versions that should be ignored. | 95 | | -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] | | 93 | +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] | 96 | 94 |
| 97 | 95 | TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) | 98 | 96 |
| 99 | | -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") | | 97 | +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( | | 98 | + "True", | | 99 | + "true", | | 100 | +) | 100 | 101 | # | 101 | 102 | # Style Checks | 102 | 103 | # | @@ -141,7 +142,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: | 141 | 142 |
| 142 | 143 | @nox.session | 143 | 144 | def lint(session: nox.sessions.Session) -> None: | 144 | | - if not TEST_CONFIG['enforce_type_hints']: | | 145 | + if not TEST_CONFIG["enforce_type_hints"]: | 145 | 146 | session.install("flake8", "flake8-import-order") | 146 | 147 | else: | 147 | 148 | session.install("flake8", "flake8-import-order", "flake8-annotations") | @@ -150,9 +151,11 @@ def lint(session: nox.sessions.Session) -> None: | 150 | 151 | args = FLAKE8_COMMON_ARGS + [ | 151 | 152 | "--application-import-names", | 152 | 153 | ",".join(local_names), | 153 | | - "." | | 154 | + ".", | 154 | 155 | ] | 155 | 156 | session.run("flake8", *args) | | 157 | + | | 158 | + | 156 | 159 | # | 157 | 160 | # Black | 158 | 161 | # | @@ -165,6 +168,7 @@ def blacken(session: nox.sessions.Session) -> None: | 165 | 168 |
| 166 | 169 | session.run("black", *python_files) | 167 | 170 |
| | 171 | + | 168 | 172 | # | 169 | 173 | # Sample Tests | 170 | 174 | # | @@ -173,7 +177,9 @@ def blacken(session: nox.sessions.Session) -> None: | 173 | 177 | PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] | 174 | 178 |
| 175 | 179 |
| 176 | | -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: | | 180 | +def _session_tests( | | 181 | + session: nox.sessions.Session, post_install: Callable = None | | 182 | +) -> None: | 177 | 183 | if TEST_CONFIG["pip_version_override"]: | 178 | 184 | pip_version = TEST_CONFIG["pip_version_override"] | 179 | 185 | session.install(f"pip=={pip_version}") | @@ -203,7 +209,7 @@ def _session_tests(session: nox.sessions.Session, post_install: Callable = None) | 203 | 209 | # on travis where slow and flaky tests are excluded. | 204 | 210 | # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html | 205 | 211 | success_codes=[0, 5], | 206 | | - env=get_pytest_env_vars() | | 212 | + env=get_pytest_env_vars(), | 207 | 213 | ) | 208 | 214 |
| 209 | 215 |
| @@ -213,9 +219,9 @@ def py(session: nox.sessions.Session) -> None: | 213 | 219 | if session.python in TESTED_VERSIONS: | 214 | 220 | _session_tests(session) | 215 | 221 | else: | 216 | | - session.skip("SKIPPED: {} tests are disabled for this sample.".format( | 217 | | - session.python | 218 | | - )) | | 222 | + session.skip( | | 223 | + "SKIPPED: {} tests are disabled for this sample.".format(session.python) | | 224 | + ) | 219 | 225 |
| 220 | 226 |
| 221 | 227 | # | |
|