Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edit presubmit for to simplify configuration #1915

Merged
merged 18 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .kokoro/presubmit/presubmit-2.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Only run these nox sessions.
env_vars: {
key: "NOX_SESSION"
value: "unit_noextras-3.7 unit_noextras-3.12" # unit-3.7 unit-3.8 unit-3.12 cover docs"
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
}
25 changes: 25 additions & 0 deletions exp-time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import time
from functools import wraps

def timed(func):
"""This decorator prints the execution time for the decorated function."""

@wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f"{func.__name__} ran in {round(end - start, 2)} seconds")
#logger.debug("{} ran in {}s".format(func.__name__, round(end - start, 2)))
return result

return wrapper

@timed
def slow_function():
"""This is a slow-running function used as an example."""
print("running a slow function...")
time.sleep(3.2)
print("done")

slow_function()
38 changes: 38 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@
"docs",
]

import time
from functools import wraps

chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
def timed(func):
"""This decorator prints the execution time for the decorated function."""

@wraps(func)
def wrapper(*args, **kwargs):
print("Starting session timer")
start = time.time()
result = func(*args, **kwargs)
end = time.time()
total_seconds = round(end - start)
hours = total_seconds // 3600 # Integer division to get hours
remaining_seconds = total_seconds % 3600 # Modulo to find remaining seconds
minutes = remaining_seconds // 60
seconds = remaining_seconds % 60
human_time = f"{hours:}:{minutes:0>2}:{seconds:0>2}"
print(f"session ran in {total_seconds} seconds ({human_time})")

#logger.debug("{} ran in {}s".format(func.__name__, round(end - start, 2)))
return result

return wrapper

def default(session, install_extras=True):
"""Default unit test session.
Expand Down Expand Up @@ -105,13 +129,15 @@ def default(session, install_extras=True):


@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
@timed
def unit(session):
"""Run the unit test suite."""

default(session)


@nox.session(python=[UNIT_TEST_PYTHON_VERSIONS[0], UNIT_TEST_PYTHON_VERSIONS[-1]])
@timed
def unit_noextras(session):
"""Run the unit test suite."""

Expand All @@ -129,6 +155,7 @@ def unit_noextras(session):


@nox.session(python=DEFAULT_PYTHON_VERSION)
@timed
def mypy(session):
"""Run type checks with mypy."""

Expand All @@ -151,6 +178,7 @@ def mypy(session):


@nox.session(python=DEFAULT_PYTHON_VERSION)
@timed
def pytype(session):
"""Run type checks with pytype."""
# An indirect dependecy attrs==21.1.0 breaks the check, and installing a less
Expand All @@ -169,6 +197,7 @@ def pytype(session):


@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
@timed
def system(session):
"""Run the system test suite."""

Expand Down Expand Up @@ -221,6 +250,7 @@ def system(session):


@nox.session(python=DEFAULT_PYTHON_VERSION)
@timed
def mypy_samples(session):
"""Run type checks with mypy."""

Expand Down Expand Up @@ -260,6 +290,7 @@ def mypy_samples(session):


@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
@timed
def snippets(session):
"""Run the snippets test suite."""

Expand Down Expand Up @@ -299,6 +330,7 @@ def snippets(session):


@nox.session(python=DEFAULT_PYTHON_VERSION)
@timed
def cover(session):
"""Run the final coverage report.

Expand All @@ -312,6 +344,7 @@ def cover(session):


@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
@timed
def prerelease_deps(session):
"""Run all tests with prerelease versions of dependencies installed.

Expand Down Expand Up @@ -402,6 +435,7 @@ def prerelease_deps(session):


@nox.session(python=DEFAULT_PYTHON_VERSION)
@timed
def lint(session):
"""Run linters.

Expand All @@ -424,6 +458,7 @@ def lint(session):


@nox.session(python=DEFAULT_PYTHON_VERSION)
@timed
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""

Expand All @@ -436,6 +471,7 @@ def lint_setup_py(session):


@nox.session(python=DEFAULT_PYTHON_VERSION)
@timed
def blacken(session):
"""Run black.
Format code to uniform standard.
Expand All @@ -450,6 +486,7 @@ def blacken(session):


@nox.session(python="3.9")
@timed
def docs(session):
"""Build the docs."""

Expand Down Expand Up @@ -486,6 +523,7 @@ def docs(session):


@nox.session(python="3.10")
@timed
def docfx(session):
"""Build the docfx yaml files for this library."""

Expand Down