Skip to content

Commit

Permalink
chore: lints and blackens
Browse files Browse the repository at this point in the history
  • Loading branch information
danoscarmike authored and leahecole committed Sep 15, 2023
1 parent ff5b317 commit 356724c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
34 changes: 17 additions & 17 deletions videointelligence/samples/quickstart/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,25 @@

TEST_CONFIG = {
# You can opt out from the test for specific Python versions.
'ignored_versions': ["2.7"],

"ignored_versions": ["2.7"],
# Old samples are opted out of enforcing Python type hints
# All new samples should feature them
'enforce_type_hints': False,

"enforce_type_hints": False,
# An envvar key for determining the project id to use. Change it
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
# build specific Cloud project. You can also use your own string
# to use your own Cloud project.
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',

# A dictionary you want to inject into your test. Don't put any
# secrets here. These values will override predefined values.
'envs': {},
"envs": {},
}


try:
# Ensure we can import noxfile_config in the project's directory.
sys.path.append('.')
sys.path.append(".")
from noxfile_config import TEST_CONFIG_OVERRIDE
except ImportError as e:
print("No user noxfile_config found: detail: {}".format(e))
Expand All @@ -73,12 +70,12 @@ def get_pytest_env_vars():
ret = {}

# Override the GCLOUD_PROJECT and the alias.
env_key = TEST_CONFIG['gcloud_project_env']
env_key = TEST_CONFIG["gcloud_project_env"]
# This should error out if not set.
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key]

# Apply user supplied envs.
ret.update(TEST_CONFIG['envs'])
ret.update(TEST_CONFIG["envs"])
return ret


Expand All @@ -87,7 +84,7 @@ def get_pytest_env_vars():
ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"]

# Any default versions that should be ignored.
IGNORED_VERSIONS = TEST_CONFIG['ignored_versions']
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]

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

Expand Down Expand Up @@ -136,7 +133,7 @@ def _determine_local_import_names(start_dir):

@nox.session
def lint(session):
if not TEST_CONFIG['enforce_type_hints']:
if not TEST_CONFIG["enforce_type_hints"]:
session.install("flake8", "flake8-import-order")
else:
session.install("flake8", "flake8-import-order", "flake8-annotations")
Expand All @@ -145,9 +142,11 @@ def lint(session):
args = FLAKE8_COMMON_ARGS + [
"--application-import-names",
",".join(local_names),
"."
".",
]
session.run("flake8", *args)


#
# Black
#
Expand All @@ -160,6 +159,7 @@ def blacken(session):

session.run("black", *python_files)


#
# Sample Tests
#
Expand Down Expand Up @@ -199,9 +199,9 @@ def py(session):
if session.python in TESTED_VERSIONS:
_session_tests(session)
else:
session.skip("SKIPPED: {} tests are disabled for this sample.".format(
session.python
))
session.skip(
"SKIPPED: {} tests are disabled for this sample.".format(session.python)
)


#
Expand Down
37 changes: 21 additions & 16 deletions videointelligence/samples/quickstart/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,38 @@ def run_quickstart():
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.LABEL_DETECTION]
operation = video_client.annotate_video(
'gs://cloud-samples-data/video/cat.mp4', features=features)
print('\nProcessing video for label annotations:')
"gs://cloud-samples-data/video/cat.mp4", features=features
)
print("\nProcessing video for label annotations:")

result = operation.result(timeout=120)
print('\nFinished processing.')
print("\nFinished processing.")

# first result is retrieved because a single video was processed
segment_labels = result.annotation_results[0].segment_label_annotations
for i, segment_label in enumerate(segment_labels):
print('Video label description: {}'.format(
segment_label.entity.description))
print("Video label description: {}".format(segment_label.entity.description))
for category_entity in segment_label.category_entities:
print('\tLabel category description: {}'.format(
category_entity.description))
print(
"\tLabel category description: {}".format(category_entity.description)
)

for i, segment in enumerate(segment_label.segments):
start_time = (segment.segment.start_time_offset.seconds +
segment.segment.start_time_offset.nanos / 1e9)
end_time = (segment.segment.end_time_offset.seconds +
segment.segment.end_time_offset.nanos / 1e9)
positions = '{}s to {}s'.format(start_time, end_time)
start_time = (
segment.segment.start_time_offset.seconds
+ segment.segment.start_time_offset.nanos / 1e9
)
end_time = (
segment.segment.end_time_offset.seconds
+ segment.segment.end_time_offset.nanos / 1e9
)
positions = "{}s to {}s".format(start_time, end_time)
confidence = segment.confidence
print('\tSegment {}: {}'.format(i, positions))
print('\tConfidence: {}'.format(confidence))
print('\n')
print("\tSegment {}: {}".format(i, positions))
print("\tConfidence: {}".format(confidence))
print("\n")
# [END video_quickstart]


if __name__ == '__main__':
if __name__ == "__main__":
run_quickstart()
2 changes: 1 addition & 1 deletion videointelligence/samples/quickstart/quickstart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
def test_quickstart(capsys):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert 'Video label description: cat' in out
assert "Video label description: cat" in out

0 comments on commit 356724c

Please sign in to comment.