Skip to content

Commit a0b285e

Browse files
author
Sylvain MARIE
committed
Now using virtualenv as nox backend. Added python 3.11 and 3.12. Fixed gitignore. Fixed #100
1 parent d2526b2 commit a0b285e

7 files changed

Lines changed: 121 additions & 83 deletions

File tree

.github/workflows/base.yml

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,32 @@ on:
1212
pull_request:
1313
branches:
1414
- main
15+
16+
defaults:
17+
run:
18+
shell: bash -l {0}
19+
1520
jobs:
1621
# pre-job to read nox tests matrix - see https://stackoverflow.com/q/66747359/7262247
1722
list_nox_test_sessions:
1823
runs-on: ubuntu-latest
1924
steps:
20-
- uses: actions/checkout@v2
21-
- uses: actions/setup-python@v1
25+
- name: Checkout
26+
uses: actions/checkout@v4.1.1
27+
28+
- name: Install python 3.9
29+
uses: actions/setup-python@v5.0.0
2230
with:
23-
python-version: 3.7
31+
python-version: 3.9
2432
architecture: x64
2533

2634
- name: Install noxfile requirements
27-
shell: bash -l {0}
2835
run: pip install -r noxfile-requirements.txt
2936

30-
- name: List 'tests' nox sessions
37+
- name: List 'tests' nox sessions and required python versions
3138
id: set-matrix
32-
run: echo "::set-output name=matrix::$(nox -s gha_list -- tests)"
39+
run: echo "::set-output name=matrix::$(nox -s gha_list -- -s tests -v)"
40+
3341
outputs:
3442
matrix: ${{ steps.set-matrix.outputs.matrix }} # save nox sessions list to outputs
3543

@@ -38,45 +46,72 @@ jobs:
3846
strategy:
3947
fail-fast: false
4048
matrix:
49+
# see https://github.com/actions/setup-python/issues/544
50+
# os: [ ubuntu-20.04 ]
4151
os: [ ubuntu-latest ] # , macos-latest, windows-latest]
4252
# all nox sessions: manually > dynamically from previous job
4353
# nox_session: ["tests-2.7", "tests-3.7"]
4454
nox_session: ${{ fromJson(needs.list_nox_test_sessions.outputs.matrix) }}
4555

46-
name: ${{ matrix.os }} ${{ matrix.nox_session }} # ${{ matrix.name_suffix }}
56+
name: ${{ matrix.os }} ${{ matrix.nox_session.python }} ${{ matrix.nox_session.session }} # ${{ matrix.name_suffix }}
4757
runs-on: ${{ matrix.os }}
4858
steps:
49-
- uses: actions/checkout@v2
59+
- name: Checkout
60+
uses: actions/checkout@v4.1.1
61+
62+
- name: Install python ${{ matrix.nox_session.python }} for tests
63+
uses: MatteoH2O1999/setup-python@v3.0.0 # actions/setup-python@v5.0.0
64+
id: set-py
65+
with:
66+
python-version: ${{ matrix.nox_session.python }}
67+
architecture: x64
68+
allow-build: info
69+
cache-build: true
5070

51-
# Conda install
52-
- name: Install conda v3.7
53-
uses: conda-incubator/setup-miniconda@v2
71+
- name: Install python 3.12 for nox
72+
uses: actions/setup-python@v5.0.0
5473
with:
55-
# auto-update-conda: true
56-
python-version: 3.7
57-
activate-environment: noxenv
58-
- run: conda info
59-
shell: bash -l {0} # so that conda works
60-
- run: conda list
61-
shell: bash -l {0} # so that conda works
62-
63-
# Nox install + run
74+
python-version: 3.12
75+
architecture: x64
76+
77+
- name: pin virtualenv==20.15.1 in old python versions
78+
# pinned to keep compatibility with old versions, see https://github.com/MatteoH2O1999/setup-python/issues/28#issuecomment-1745613621
79+
if: contains(fromJson('["2.7", "3.5", "3.6"]'), matrix.nox_session.python )
80+
run: sed -i "s/virtualenv/virtualenv==20.15.1/g" noxfile-requirements.txt
81+
6482
- name: Install noxfile requirements
65-
shell: bash -l {0} # so that conda works
6683
run: pip install -r noxfile-requirements.txt
67-
- run: conda list
68-
shell: bash -l {0} # so that conda works
69-
- run: nox -s "${{ matrix.nox_session }}"
70-
shell: bash -l {0} # so that conda works
84+
85+
- name: Run nox session ${{ matrix.nox_session.session }}
86+
run: nox -s "${{ matrix.nox_session.session }}" -v
7187

7288
# Share ./docs/reports so that they can be deployed with doc in next job
7389
- name: Share reports with other jobs
74-
# if: matrix.nox_session == '...': not needed, if empty wont be shared
75-
uses: actions/upload-artifact@master
90+
# if: matrix.nox_session == '...': not needed, if empty won't be shared
91+
uses: actions/upload-artifact@v4.3.0
7692
with:
7793
name: reports_dir
7894
path: ./docs/reports
7995

96+
build_doc:
97+
runs-on: ubuntu-latest
98+
if: github.event_name == 'pull_request'
99+
steps:
100+
- name: Checkout
101+
uses: actions/checkout@v4.1.1
102+
103+
- name: Install python 3.9 for nox
104+
uses: actions/setup-python@v5.0.0
105+
with:
106+
python-version: 3.9
107+
architecture: x64
108+
109+
- name: Install noxfile requirements
110+
run: pip install -r noxfile-requirements.txt
111+
112+
- name: Build the doc including example gallery
113+
run: nox -s docs -- build
114+
80115
publish_release:
81116
needs: run_all_tests
82117
runs-on: ubuntu-latest
@@ -87,47 +122,37 @@ jobs:
87122
GITHUB_CONTEXT: ${{ toJSON(github) }}
88123
run: echo "$GITHUB_CONTEXT"
89124

90-
- uses: actions/checkout@v2
125+
- name: Checkout with no depth
126+
uses: actions/checkout@v4.1.1
91127
with:
92128
fetch-depth: 0 # so that gh-deploy works
93129

130+
- name: Install python 3.9 for nox
131+
uses: actions/setup-python@v5.0.0
132+
with:
133+
python-version: 3.9
134+
architecture: x64
135+
94136
# 1) retrieve the reports generated previously
95137
- name: Retrieve reports
96-
uses: actions/download-artifact@master
138+
uses: actions/download-artifact@v4.1.1
97139
with:
98140
name: reports_dir
99141
path: ./docs/reports
100142

101-
# Conda install
102-
- name: Install conda v3.7
103-
uses: conda-incubator/setup-miniconda@v2
104-
with:
105-
# auto-update-conda: true
106-
python-version: 3.7
107-
activate-environment: noxenv
108-
- run: conda info
109-
shell: bash -l {0} # so that conda works
110-
- run: conda list
111-
shell: bash -l {0} # so that conda works
112-
113143
# Nox install
114144
- name: Install noxfile requirements
115-
shell: bash -l {0} # so that conda works
116145
run: pip install -r noxfile-requirements.txt
117-
- run: conda list
118-
shell: bash -l {0} # so that conda works
119146

120147
# 5) Run the flake8 report and badge
121148
- name: Run flake8 analysis and generate corresponding badge
122-
shell: bash -l {0} # so that conda works
123149
run: nox -s flake8
124150

125151
# -------------- only on Ubuntu + MAIN PUSH (no pull request, no tag) -----------
126152

127153
# 5) Publish the doc and test reports
128154
- name: \[not on TAG\] Publish documentation, tests and coverage reports
129155
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads') # startsWith(matrix.os,'ubuntu')
130-
shell: bash -l {0} # so that conda works
131156
run: nox -s publish
132157

133158
# 6) Publish coverage report
@@ -142,7 +167,7 @@ jobs:
142167
EOF
143168
- name: \[not on TAG\] Publish coverage report
144169
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads')
145-
uses: codecov/codecov-action@v1
170+
uses: codecov/codecov-action@v4.0.1
146171
with:
147172
files: ./docs/reports/coverage/coverage.xml
148173

@@ -151,13 +176,12 @@ jobs:
151176
# 7) Create github release and build the wheel
152177
- name: \[TAG only\] Build wheel and create github release
153178
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
154-
shell: bash -l {0} # so that conda works
155179
run: nox -s release -- ${{ secrets.GITHUB_TOKEN }}
156180

157181
# 8) Publish the wheel on PyPi
158182
- name: \[TAG only\] Deploy on PyPi
159183
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
160-
uses: pypa/gh-action-pypi-publish@release/v1
184+
uses: pypa/gh-action-pypi-publish@v1.8.11
161185
with:
162186
user: __token__
163187
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ coverage.xml
5050
*.py,cover
5151
.hypothesis/
5252
.pytest_cache/
53-
makefun/_version.py
53+
src/makefun/_version.py
5454

5555
# Translations
5656
*.mo

ci_tools/nox_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ def _f_wrapper(**kwargs):
633633
except KeyError:
634634
# Skip this session, it is a dummy one
635635
nox_logger.warning(
636-
"Skipping configuration, this is not supported in python version %r" % session.python
636+
"Skipping configuration, %r is not meant to be executed in this session for python version %r" %
637+
(grid_param if has_parameter else "this", session.python)
637638
)
638639
return
639640

noxfile-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
virtualenv
12
nox
23
toml
34
makefun

noxfile.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
from itertools import product
23
from json import dumps
34
import logging
@@ -9,16 +10,17 @@
910
# add parent folder to python path so that we can import noxfile_utils.py
1011
# note that you need to "pip install -r noxfile-requiterements.txt" for this file to work.
1112
sys.path.append(str(Path(__file__).parent / "ci_tools"))
12-
from nox_utils import PY27, PY37, PY36, PY35, PY38, PY39, PY310, power_session, rm_folder, rm_file, PowerSession # noqa
13+
from nox_utils import PY27, PY37, PY36, PY35, PY38, PY39, PY310, PY311, PY312, power_session, rm_folder, rm_file, PowerSession, DONT_INSTALL # noqa
1314

1415

1516
pkg_name = "makefun"
1617
gh_org = "smarie"
1718
gh_repo = "python-makefun"
1819

1920
ENVS = {
20-
# python 3.10 is not available on conda yet
21-
# PY310: {"coverage": False, "pkg_specs": {"pip": ">19"}},
21+
PY312: {"coverage": False, "pkg_specs": {"pip": ">19"}},
22+
PY311: {"coverage": False, "pkg_specs": {"pip": ">19"}},
23+
PY310: {"coverage": False, "pkg_specs": {"pip": ">19"}},
2224
PY39: {"coverage": False, "pkg_specs": {"pip": ">19"}},
2325
PY38: {"coverage": False, "pkg_specs": {"pip": ">19"}},
2426
PY27: {"coverage": False, "pkg_specs": {"pip": ">10"}},
@@ -30,10 +32,11 @@
3032

3133

3234
# set the default activated sessions, minimal for CI
33-
nox.options.sessions = ["tests", "flake8"] # , "docs", "gh_pages"
35+
nox.options.sessions = ["tests", "flake8", "docs"] # , "docs", "gh_pages"
36+
nox.options.error_on_missing_interpreters = True
3437
nox.options.reuse_existing_virtualenvs = True # this can be done using -r
3538
# if platform.system() == "Windows": >> always use this for better control
36-
nox.options.default_venv_backend = "conda"
39+
nox.options.default_venv_backend = "virtualenv"
3740
# os.environ["NO_COLOR"] = "True" # nox.options.nocolor = True does not work
3841
# nox.options.verbose = True
3942

@@ -95,10 +98,10 @@ def tests(session: PowerSession, coverage, pkg_specs):
9598

9699
# list all (conda list alone does not work correctly on github actions)
97100
# session.run2("conda list")
98-
conda_prefix = Path(session.bin)
99-
if conda_prefix.name == "bin":
100-
conda_prefix = conda_prefix.parent
101-
session.run2("conda list", env={"CONDA_PREFIX": str(conda_prefix), "CONDA_DEFAULT_ENV": session.get_session_id()})
101+
# conda_prefix = Path(session.bin)
102+
# if conda_prefix.name == "bin":
103+
# conda_prefix = conda_prefix.parent
104+
# session.run2("conda list", env={"CONDA_PREFIX": str(conda_prefix), "CONDA_DEFAULT_ENV": session.get_session_id()})
102105

103106
# Fail if the assumed python version is not the actual one
104107
session.run2("python ci_tools/check_python_version.py %s" % session.python)
@@ -111,7 +114,6 @@ def tests(session: PowerSession, coverage, pkg_specs):
111114
if not coverage:
112115
# install self so that it is recognized by pytest
113116
session.run2("pip install . --no-deps")
114-
# session.install(".", "--no-deps")
115117

116118
# simple: pytest only
117119
session.run2("python -m pytest --cache-clear -v tests/")
@@ -141,7 +143,7 @@ def tests(session: PowerSession, coverage, pkg_specs):
141143
session.run2("genbadge coverage -i %s -o %s" % (Folders.coverage_xml, Folders.coverage_badge))
142144

143145

144-
@power_session(python=PY38, logsdir=Folders.runlogs)
146+
@power_session(python=PY39, logsdir=Folders.runlogs)
145147
def flake8(session: PowerSession):
146148
"""Launch flake8 qualimetry."""
147149

@@ -162,7 +164,7 @@ def flake8(session: PowerSession):
162164
rm_file(Folders.flake8_intermediate_file)
163165

164166

165-
@power_session(python=[PY37])
167+
@power_session(python=[PY39])
166168
def docs(session: PowerSession):
167169
"""Generates the doc and serves it on a local http server. Pass '-- build' to build statically instead."""
168170

@@ -175,11 +177,11 @@ def docs(session: PowerSession):
175177
session.run2("mkdocs serve")
176178

177179

178-
@power_session(python=[PY37])
180+
@power_session(python=[PY39])
179181
def publish(session: PowerSession):
180182
"""Deploy the docs+reports on github pages. Note: this rebuilds the docs"""
181183

182-
session.install_reqs(phase="mkdocs", phase_reqs=["mkdocs-material", "mkdocs", "pymdown-extensions", "pygments"])
184+
session.install_reqs(phase="publish", phase_reqs=["mkdocs-material", "mkdocs", "pymdown-extensions", "pygments"])
183185

184186
# possibly rebuild the docs in a static way (mkdocs serve does not build locally)
185187
session.run2("mkdocs build")
@@ -200,7 +202,7 @@ def publish(session: PowerSession):
200202
# session.run2('codecov -t %s -f %s' % (codecov_token, Folders.coverage_xml))
201203

202204

203-
@power_session(python=[PY37])
205+
@power_session(python=[PY39])
204206
def release(session: PowerSession):
205207
"""Create a release on github corresponding to the latest tag"""
206208

@@ -261,19 +263,36 @@ def gha_list(session):
261263

262264
# see https://stackoverflow.com/q/66747359/7262247
263265

266+
# The options
267+
parser = argparse.ArgumentParser()
268+
parser.add_argument("-s", "--session", help="The nox base session name")
269+
parser.add_argument(
270+
"-v",
271+
"--with_version",
272+
action="store_true",
273+
default=False,
274+
help="Return a list of lists where the first element is the python version and the second the nox session.",
275+
)
276+
additional_args = parser.parse_args(session.posargs)
277+
264278
# get the desired base session to generate the list for
265-
if len(session.posargs) != 1:
266-
raise ValueError("This session has a mandatory argument: <base_session_name>")
267-
session_func = globals()[session.posargs[0]]
279+
session_func = globals()[additional_args.session]
268280

269281
# list all sessions for this base session
270282
try:
271283
session_func.parametrize
272284
except AttributeError:
273-
sessions_list = ["%s-%s" % (session_func.__name__, py) for py in session_func.python]
285+
if additional_args.with_version:
286+
sessions_list = [{"python": py, "session": "%s-%s" % (session_func.__name__, py)} for py in session_func.python]
287+
else:
288+
sessions_list = ["%s-%s" % (session_func.__name__, py) for py in session_func.python]
274289
else:
275-
sessions_list = ["%s-%s(%s)" % (session_func.__name__, py, param)
276-
for py, param in product(session_func.python, session_func.parametrize)]
290+
if additional_args.with_version:
291+
sessions_list = [{"python": py, "session": "%s-%s(%s)" % (session_func.__name__, py, param)}
292+
for py, param in product(session_func.python, session_func.parametrize)]
293+
else:
294+
sessions_list = ["%s-%s(%s)" % (session_func.__name__, py, param)
295+
for py, param in product(session_func.python, session_func.parametrize)]
277296

278297
# print the list so that it can be caught by GHA.
279298
# Note that json.dumps is optional since this is a list of string.

0 commit comments

Comments
 (0)