From c3396b9786b07b10d71d2b224888c7cd32be3625 Mon Sep 17 00:00:00 2001 From: "Paul J. Dorn" Date: Thu, 7 Dec 2023 10:38:30 +0100 Subject: [PATCH] github actions: cache and test run_module (-m) --- .github/workflows/lint.yml | 6 +++++- .github/workflows/tox.yml | 9 ++++++++- gunicorn/__main__.py | 6 +++++- gunicorn/app/wsgiapp.py | 4 ++-- pyproject.toml | 2 +- requirements_test.txt | 1 - tox.ini | 5 ++++- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 795946e4..b0a862cd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,6 +2,9 @@ name: lint on: [push, pull_request] permissions: contents: read # to fetch code (actions/checkout) +env: + # note that some tools care only for the name, not the value + FORCE_COLOR: 1 jobs: lint: name: tox-${{ matrix.toxenv }} @@ -14,9 +17,10 @@ jobs: steps: - uses: actions/checkout@v4 - name: Using Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + cache: pip - name: Install Dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index d253148f..c188a4db 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -2,6 +2,9 @@ name: tox on: [push, pull_request] permissions: contents: read # to fetch code (actions/checkout) +env: + # note that some tools care only for the name, not the value + FORCE_COLOR: 1 jobs: tox: name: ${{ matrix.os }} / ${{ matrix.python-version }} @@ -14,11 +17,15 @@ jobs: steps: - uses: actions/checkout@v4 - name: Using Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: requirements_test.txt + check-latest: true - name: Install Dependencies run: | python -m pip install --upgrade pip python -m pip install tox + - run: tox -e run-module - run: tox -e py diff --git a/gunicorn/__main__.py b/gunicorn/__main__.py index 49ba6960..fda83157 100644 --- a/gunicorn/__main__.py +++ b/gunicorn/__main__.py @@ -4,4 +4,8 @@ # See the NOTICE for more information. from gunicorn.app.wsgiapp import run -run() + +if __name__ == "__main__": + # see config.py - argparse defaults to basename(argv[0]) == "__main__.py" + # todo: let runpy.run_module take care of argv[0] rewriting + run(prog="gunicorn") diff --git a/gunicorn/app/wsgiapp.py b/gunicorn/app/wsgiapp.py index 36cfba9d..4e003123 100644 --- a/gunicorn/app/wsgiapp.py +++ b/gunicorn/app/wsgiapp.py @@ -58,13 +58,13 @@ class WSGIApplication(Application): return self.load_wsgiapp() -def run(): +def run(prog=None): """\ The ``gunicorn`` command line runner for launching Gunicorn with generic WSGI applications. """ from gunicorn.app.wsgiapp import WSGIApplication - WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run() + WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]", prog=prog).run() if __name__ == '__main__': diff --git a/pyproject.toml b/pyproject.toml index f4afa721..ffe20515 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,13 +57,13 @@ setproctitle = ["setproctitle"] testing = [ "gevent", "eventlet", - "cryptography", "coverage", "pytest", "pytest-cov", ] [tool.pytest.ini_options] +# # can override these: python -m pytest --override-ini="addopts=" norecursedirs = ["examples", "lib", "local", "src"] testpaths = ["tests/"] addopts = "--assert=plain --cov=gunicorn --cov-report=xml" diff --git a/requirements_test.txt b/requirements_test.txt index 4c6b0250..fad22e31 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,6 +1,5 @@ gevent eventlet -cryptography coverage pytest pytest-cov diff --git a/tox.ini b/tox.ini index a7b7d38c..83ce3374 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{37,38,39,310,311,py3}, lint, docs-lint, pycodestyle +envlist = py{37,38,39,310,311,py3}, lint, docs-lint, pycodestyle, run-module skipsdist = false ; Can't set skipsdist and use_develop in tox v4 to true due to https://github.com/tox-dev/tox/issues/2730 @@ -9,6 +9,9 @@ commands = pytest --cov=gunicorn {posargs} deps = -rrequirements_test.txt +[testenv:run-module] +commands = python3 -m gunicorn --version + [testenv:lint] commands = pylint -j0 \