Add Simple Server and Coverage action (#2168)
* Add Simple Server and CodeCov action * Remove token * Codecov to tox.ini * fix tox * Set coverage location * Add ignore to codecov * Try glob ignore * Setup CodeClimate * Allow coverage check to run * Change coverage check * Add codeclimate exclusions
This commit is contained in:
parent
f39b8b32f7
commit
7c180376d6
12
.codeclimate.yml
Normal file
12
.codeclimate.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
exclude_patterns:
|
||||
- "sanic/__main__.py"
|
||||
- "sanic/reloader_helpers.py"
|
||||
- "sanic/simple.py"
|
||||
- "sanic/utils.py"
|
||||
- ".github/"
|
||||
- "changelogs/"
|
||||
- "docker/"
|
||||
- "docs/"
|
||||
- "examples/"
|
||||
- "hack/"
|
||||
- "scripts/"
|
|
@ -1,7 +1,12 @@
|
|||
[run]
|
||||
branch = True
|
||||
source = sanic
|
||||
omit = site-packages, sanic/utils.py, sanic/__main__.py
|
||||
omit =
|
||||
site-packages
|
||||
sanic/__main__.py
|
||||
sanic/reloader_helpers.py
|
||||
sanic/simple.py
|
||||
sanic/utils.py
|
||||
|
||||
[html]
|
||||
directory = coverage
|
||||
|
|
40
.github/workflows/coverage.yml
vendored
Normal file
40
.github/workflows/coverage.yml
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
name: Coverage check
|
||||
# on:
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
# tags:
|
||||
# - "!*" # Do not execute on tags
|
||||
# paths:
|
||||
# - sanic/*
|
||||
# - tests/*
|
||||
# pull_request:
|
||||
# paths:
|
||||
# - "!*.MD"
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [3.9]
|
||||
os: [ubuntu-latest]
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install dependencies 🔨
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install tox
|
||||
- uses: paambaati/codeclimate-action@v2.5.3
|
||||
if: always()
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE }}
|
||||
with:
|
||||
coverageCommand: tox -e coverage
|
3
.github/workflows/pr-python37.yml
vendored
3
.github/workflows/pr-python37.yml
vendored
|
@ -6,6 +6,9 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- sanic/*
|
||||
- tests/*
|
||||
|
||||
jobs:
|
||||
testPy37:
|
||||
|
|
3
.github/workflows/pr-python38.yml
vendored
3
.github/workflows/pr-python38.yml
vendored
|
@ -6,6 +6,9 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- sanic/*
|
||||
- tests/*
|
||||
|
||||
jobs:
|
||||
testPy38:
|
||||
|
|
3
.github/workflows/pr-python39.yml
vendored
3
.github/workflows/pr-python39.yml
vendored
|
@ -6,6 +6,9 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- sanic/*
|
||||
- tests/*
|
||||
|
||||
jobs:
|
||||
testPy39:
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@
|
|||
.coverage
|
||||
.coverage.*
|
||||
coverage
|
||||
coverage.xml
|
||||
.tox
|
||||
settings.py
|
||||
.idea/*
|
||||
|
|
3
Makefile
3
Makefile
|
@ -49,6 +49,9 @@ test: clean
|
|||
test-coverage: clean
|
||||
python setup.py test --pytest-args="--cov sanic --cov-report term --cov-append "
|
||||
|
||||
view-coverage:
|
||||
sanic ./coverage --simple
|
||||
|
||||
install:
|
||||
python setup.py install
|
||||
|
||||
|
|
14
codecov.yml
14
codecov.yml
|
@ -1,14 +0,0 @@
|
|||
codecov:
|
||||
require_ci_to_pass: no
|
||||
coverage:
|
||||
precision: 3
|
||||
round: nearest
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
target: auto
|
||||
threshold: 0.5%
|
||||
patch:
|
||||
default:
|
||||
target: auto
|
||||
threshold: 0.75%
|
|
@ -3,6 +3,7 @@ import sys
|
|||
|
||||
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from sanic_routing import __version__ as __routing_version__ # type: ignore
|
||||
|
@ -11,6 +12,7 @@ from sanic import __version__
|
|||
from sanic.app import Sanic
|
||||
from sanic.config import BASE_LOGO
|
||||
from sanic.log import error_logger
|
||||
from sanic.simple import create_simple_server
|
||||
|
||||
|
||||
class SanicArgumentParser(ArgumentParser):
|
||||
|
@ -37,13 +39,28 @@ def main():
|
|||
action="version",
|
||||
version=f"Sanic {__version__}; Routing {__routing_version__}",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--factory",
|
||||
action="store_true",
|
||||
help=(
|
||||
"Treat app as an application factory, "
|
||||
"i.e. a () -> <Sanic app> callable"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--simple",
|
||||
dest="simple",
|
||||
action="store_true",
|
||||
help="Run Sanic as a Simple Server (module arg should be a path)\n ",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-H",
|
||||
"--host",
|
||||
dest="host",
|
||||
type=str,
|
||||
default="127.0.0.1",
|
||||
help="host address [default 127.0.0.1]",
|
||||
help="Host address [default 127.0.0.1]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
|
@ -51,7 +68,7 @@ def main():
|
|||
dest="port",
|
||||
type=int,
|
||||
default=8000,
|
||||
help="port to serve on [default 8000]",
|
||||
help="Port to serve on [default 8000]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-u",
|
||||
|
@ -62,7 +79,7 @@ def main():
|
|||
help="location of unix socket\n ",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cert", dest="cert", type=str, help="location of certificate for SSL"
|
||||
"--cert", dest="cert", type=str, help="Location of certificate for SSL"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--key", dest="key", type=str, help="location of keyfile for SSL\n "
|
||||
|
@ -70,14 +87,6 @@ def main():
|
|||
parser.add_bool_arguments(
|
||||
"--access-logs", dest="access_log", help="display access logs"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--factory",
|
||||
action="store_true",
|
||||
help=(
|
||||
"Treat app as an application factory, "
|
||||
"i.e. a () -> <Sanic app> callable\n "
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"-w",
|
||||
"--workers",
|
||||
|
@ -103,7 +112,12 @@ def main():
|
|||
help="Extra directories to watch and reload on changes\n ",
|
||||
)
|
||||
parser.add_argument(
|
||||
"module", help="path to your Sanic app. Example: path.to.server:app"
|
||||
"module",
|
||||
help=(
|
||||
"Path to your Sanic app. Example: path.to.server:app\n"
|
||||
"If running a Simple Server, path to directory to serve. "
|
||||
"Example: ./\n"
|
||||
),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -112,6 +126,10 @@ def main():
|
|||
if module_path not in sys.path:
|
||||
sys.path.append(module_path)
|
||||
|
||||
if args.simple:
|
||||
path = Path(args.module)
|
||||
app = create_simple_server(path)
|
||||
else:
|
||||
delimiter = ":" if ":" in args.module else "."
|
||||
module_name, app_name = args.module.rsplit(delimiter, 1)
|
||||
|
||||
|
|
21
sanic/simple.py
Normal file
21
sanic/simple.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from pathlib import Path
|
||||
|
||||
from sanic import Sanic
|
||||
from sanic.exceptions import SanicException
|
||||
from sanic.response import redirect
|
||||
|
||||
|
||||
def create_simple_server(directory: Path):
|
||||
if not directory.is_dir():
|
||||
raise SanicException(
|
||||
"Cannot setup Sanic Simple Server without a path to a directory"
|
||||
)
|
||||
|
||||
app = Sanic("SimpleServer")
|
||||
app.static("/", directory, name="main")
|
||||
|
||||
@app.get("/")
|
||||
def index(_):
|
||||
return redirect(app.url_for("main", filename="index.html"))
|
||||
|
||||
return app
|
19
tox.ini
19
tox.ini
|
@ -76,6 +76,23 @@ deps =
|
|||
docutils
|
||||
pygments
|
||||
gunicorn==20.0.4
|
||||
|
||||
commands =
|
||||
make docs-test
|
||||
|
||||
[testenv:coverage]
|
||||
usedevelop = True
|
||||
deps =
|
||||
sanic-testing>=0.6.0
|
||||
coverage==5.3
|
||||
pytest==5.2.1
|
||||
pytest-cov
|
||||
pytest-sanic
|
||||
pytest-sugar
|
||||
pytest-benchmark
|
||||
chardet==3.*
|
||||
beautifulsoup4
|
||||
gunicorn==20.0.4
|
||||
uvicorn
|
||||
websockets>=9.0
|
||||
commands =
|
||||
pytest tests --cov=./sanic --cov-report=xml
|
||||
|
|
Loading…
Reference in New Issue
Block a user