Skip to content

Commit 794f8a3

Browse files
feat: add common resource helper paths; expose client transport (#49)
* 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(py-library): enable snippet-bot Co-authored-by: Benjamin E. Coe <[email protected]> Source-Author: Takashi Matsuo <[email protected]> Source-Date: Tue Sep 1 17:14:08 2020 +0000 Source-Repo: googleapis/synthtool Source-Sha: d91dd8aac77f7a9c5506c238038a26fa4f9e361e Source-Link: googleapis/synthtool@d91dd8a * chore: manual regen Co-authored-by: Bu Sun Kim <[email protected]> Co-authored-by: Bu Sun Kim <[email protected]>
1 parent 8a41556 commit 794f8a3

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

datalabeling/snippets/noxfile.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,28 @@
3737

3838
TEST_CONFIG = {
3939
# You can opt out from the test for specific Python versions.
40-
"ignored_versions": ["2.7"],
40+
'ignored_versions': ["2.7"],
41+
42+
# Old samples are opted out of enforcing Python type hints
43+
# All new samples should feature them
44+
'enforce_type_hints': False,
45+
4146
# An envvar key for determining the project id to use. Change it
4247
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
4348
# build specific Cloud project. You can also use your own string
4449
# to use your own Cloud project.
45-
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
50+
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
4651
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
52+
4753
# A dictionary you want to inject into your test. Don't put any
4854
# secrets here. These values will override predefined values.
49-
"envs": {},
55+
'envs': {},
5056
}
5157

5258

5359
try:
5460
# Ensure we can import noxfile_config in the project's directory.
55-
sys.path.append(".")
61+
sys.path.append('.')
5662
from noxfile_config import TEST_CONFIG_OVERRIDE
5763
except ImportError as e:
5864
print("No user noxfile_config found: detail: {}".format(e))
@@ -67,12 +73,12 @@ def get_pytest_env_vars():
6773
ret = {}
6874

6975
# Override the GCLOUD_PROJECT and the alias.
70-
env_key = TEST_CONFIG["gcloud_project_env"]
76+
env_key = TEST_CONFIG['gcloud_project_env']
7177
# This should error out if not set.
72-
ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key]
78+
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
7379

7480
# Apply user supplied envs.
75-
ret.update(TEST_CONFIG["envs"])
81+
ret.update(TEST_CONFIG['envs'])
7682
return ret
7783

7884

@@ -81,7 +87,7 @@ def get_pytest_env_vars():
8187
ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"]
8288

8389
# Any default versions that should be ignored.
84-
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]
90+
IGNORED_VERSIONS = TEST_CONFIG['ignored_versions']
8591

8692
TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])
8793

@@ -130,16 +136,29 @@ def _determine_local_import_names(start_dir):
130136

131137
@nox.session
132138
def lint(session):
133-
session.install("flake8", "flake8-import-order")
139+
if not TEST_CONFIG['enforce_type_hints']:
140+
session.install("flake8", "flake8-import-order")
141+
else:
142+
session.install("flake8", "flake8-import-order", "flake8-annotations")
134143

135144
local_names = _determine_local_import_names(".")
136145
args = FLAKE8_COMMON_ARGS + [
137146
"--application-import-names",
138147
",".join(local_names),
139-
".",
148+
"."
140149
]
141150
session.run("flake8", *args)
151+
#
152+
# Black
153+
#
154+
142155

156+
@nox.session
157+
def blacken(session):
158+
session.install("black")
159+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
160+
161+
session.run("black", *python_files)
143162

144163
#
145164
# Sample Tests
@@ -180,9 +199,9 @@ def py(session):
180199
if session.python in TESTED_VERSIONS:
181200
_session_tests(session)
182201
else:
183-
session.skip(
184-
"SKIPPED: {} tests are disabled for this sample.".format(session.python)
185-
)
202+
session.skip("SKIPPED: {} tests are disabled for this sample.".format(
203+
session.python
204+
))
186205

187206

188207
#
@@ -199,6 +218,11 @@ def _get_repo_root():
199218
break
200219
if Path(p / ".git").exists():
201220
return str(p)
221+
# .git is not available in repos cloned via Cloud Build
222+
# setup.py is always in the library's root, so use that instead
223+
# https://github.com/googleapis/synthtool/issues/792
224+
if Path(p / "setup.py").exists():
225+
return str(p)
202226
p = p.parent
203227
raise Exception("Unable to detect repository root.")
204228

0 commit comments

Comments
 (0)