Skip to content

Commit

Permalink
Update noxfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mlafarga committed May 27, 2024
1 parent e1ff56f commit 188b88f
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ def tests(session):
session.run("pytest", *session.posargs)


# Integrate with GitHub Actions
# source: https://stackoverflow.com/questions/66747359/how-to-generate-a-github-actions-build-matrix-that-dynamically-includes-a-list-o
import itertools
import json

@nox.session(python=False)
def gha_list(session):
"""(mandatory arg: <base_session_name>) Prints all sessions available for <base_session_name>, for GithubActions."""

# get the desired base session to generate the list for
if len(session.posargs) != 1:
raise ValueError("This session has a mandatory argument: <base_session_name>")
session_func = globals()[session.posargs[0]]

# list all sessions for this base session
try:
session_func.parametrize
except AttributeError:
sessions_list = ["%s-%s" % (session_func.__name__, py) for py in session_func.python]
else:
sessions_list = ["%s-%s(%s)" % (session_func.__name__, py, param)
for py, param in itertools.product(session_func.python, session_func.parametrize)]

# print the list so that it can be caught by GHA.
# Note that json.dumps is optional since this is a list of string.
# However it is to remind us that GHA expects a well-formatted json list of strings.
print(json.dumps(sessions_list))
# # Integrate with GitHub Actions
# # source: https://stackoverflow.com/questions/66747359/how-to-generate-a-github-actions-build-matrix-that-dynamically-includes-a-list-o
# import itertools
# import json

# @nox.session(python=False)
# def gha_list(session):
# """(mandatory arg: <base_session_name>) Prints all sessions available for <base_session_name>, for GithubActions."""

# # get the desired base session to generate the list for
# if len(session.posargs) != 1:
# raise ValueError("This session has a mandatory argument: <base_session_name>")
# session_func = globals()[session.posargs[0]]

# # list all sessions for this base session
# try:
# session_func.parametrize
# except AttributeError:
# sessions_list = ["%s-%s" % (session_func.__name__, py) for py in session_func.python]
# else:
# sessions_list = ["%s-%s(%s)" % (session_func.__name__, py, param)
# for py, param in itertools.product(session_func.python, session_func.parametrize)]

# # print the list so that it can be caught by GHA.
# # Note that json.dumps is optional since this is a list of string.
# # However it is to remind us that GHA expects a well-formatted json list of strings.
# print(json.dumps(sessions_list))

0 comments on commit 188b88f

Please sign in to comment.