Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8edcd93
commit fad201d
Showing
14 changed files
with
107 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
formats: | ||
- htmlzip | ||
python: | ||
install: | ||
- method: pip | ||
extra_requirements: | ||
- readthedocs | ||
path: . | ||
version: 3.8 | ||
version: '3.8' | ||
version: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
include CHANGES.rst LICENSE.txt README.rst praw_license.txt | ||
include asyncpraw/praw.ini | ||
include "asyncpraw/images/PRAW logo.png" | ||
include docs/Makefile | ||
recursive-include docs *.png *.py *.rst | ||
recursive-include tests *.json *.py | ||
recursive-include tests/files * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,122 @@ | ||
#!/usr/bin/env python3 | ||
"""Run static analysis on the project.""" | ||
|
||
import argparse | ||
import enum | ||
import sys | ||
from contextlib import contextmanager | ||
from subprocess import CalledProcessError, check_call | ||
from tempfile import TemporaryDirectory | ||
from typing import List | ||
|
||
import click | ||
|
||
def do_process(args, shell=False): | ||
"""Run program provided by args. | ||
Return ``True`` on success. | ||
|
||
Output failed message on non-zero exit and return False. | ||
class Stage(enum.IntFlag): | ||
"""Enum to represent the different stages of linting.""" | ||
|
||
Exit if command is not found. | ||
BUILD_DOCS = enum.auto() | ||
PRE_COMMIT = enum.auto() | ||
UNIT_TESTS = enum.auto() | ||
ALL = BUILD_DOCS | PRE_COMMIT | UNIT_TESTS | ||
|
||
""" | ||
print(f"Running: {' '.join(args)}") | ||
try: | ||
check_call(args, shell=shell) | ||
except CalledProcessError: | ||
print(f"\nFailed: {' '.join(args)}") | ||
return False | ||
except Exception as exc: | ||
sys.stderr.write(f"{str(exc)}\n") | ||
sys.exit(1) | ||
return True | ||
@contextmanager | ||
def get_commands(self) -> List[List[str]]: | ||
"""Return the commands to run for the given stage.""" | ||
commands = [] | ||
with TemporaryDirectory() as tmp_dir: | ||
if self & Stage.PRE_COMMIT: | ||
commands.append(["pre-commit", "run", "--all-files"]) | ||
if self & Stage.BUILD_DOCS: | ||
commands.append(["sphinx-build", "-W", "--keep-going", "docs", tmp_dir]) | ||
if self & Stage.UNIT_TESTS: | ||
commands.append(["pytest"]) | ||
yield commands | ||
|
||
|
||
def run_static(): | ||
"""Runs the static tests. | ||
def execute_check(check: List[str]) -> int: | ||
"""Runs the checks in the given list. | ||
Returns a statuscode of 0 if everything ran correctly. Otherwise, it will return | ||
statuscode 1 | ||
status code 1 | ||
""" | ||
success = True | ||
success &= do_process(["pre-commit", "run", "--all-files"]) | ||
|
||
with TemporaryDirectory() as tmp_dir: | ||
success &= do_process(["sphinx-build", "-W", "--keep-going", "docs", tmp_dir]) | ||
|
||
click.echo(f"Running: {' '.join(check)}") | ||
try: | ||
check_call(check, shell=False) | ||
except CalledProcessError: | ||
click.echo(f"\nFailed: {' '.join(check)}", err=True) | ||
success = False | ||
except Exception as exc: | ||
click.echo(f"{str(exc)}\n", err=True) | ||
sys.exit(1) | ||
return success | ||
|
||
|
||
def run_unit(): | ||
"""Runs the unit-tests. | ||
Follows the behavior of the static tests, where any failed tests cause pre_push.py | ||
to fail. | ||
""" | ||
return do_process(["pytest"]) | ||
|
||
|
||
def main(): | ||
"""Runs the main function. | ||
usage: pre_push.py [-h] [-n] [-u] [-a] | ||
Run static and/or unit-tests | ||
@click.command() | ||
@click.option( | ||
"-a", | ||
"--all", | ||
"all_checks", | ||
default=False, | ||
help="Run all the checks (building docs, linting, and unit tests). If this is" | ||
" provided, all other parameters are ignored.", | ||
is_flag=True, | ||
) | ||
@click.option( | ||
"-s", | ||
"--skip-build-docs", | ||
"skip_build_docs", | ||
default=False, | ||
help="Skip building the docs.", | ||
is_flag=True, | ||
) | ||
@click.option( | ||
"-n", | ||
"--skip-linting", | ||
"skip_linting", | ||
default=False, | ||
help="Skip static pre-commit linting checks and formatters.", | ||
is_flag=True, | ||
) | ||
@click.option( | ||
"-u", | ||
"--unit", | ||
"--unit-tests", | ||
"unit_tests", | ||
default=False, | ||
help="Run the unit tests.", | ||
is_flag=True, | ||
) | ||
def main(all_checks, skip_build_docs, skip_linting, unit_tests): | ||
"""Run the main function. | ||
Runs the linting, unit tests, and building of the docs. | ||
""" | ||
parser = argparse.ArgumentParser(description="Run static and/or unit-tests") | ||
parser.add_argument( | ||
"-n", | ||
"--unstatic", | ||
action="store_true", | ||
help="Do not run static tests (black/flake8/pydocstyle/sphinx-build)", | ||
default=False, | ||
) | ||
parser.add_argument( | ||
"-u", | ||
"--unit-tests", | ||
"--unit", | ||
action="store_true", | ||
default=False, | ||
help="Run the unit tests", | ||
) | ||
parser.add_argument( | ||
"-a", | ||
"--all", | ||
action="store_true", | ||
default=False, | ||
help="Run all the tests (static and unit). Overrides the unstatic argument.", | ||
) | ||
args = parser.parse_args() | ||
success = True | ||
try: | ||
if not args.unstatic or args.all: | ||
success &= run_static() | ||
if args.all or args.unit_tests: | ||
success &= run_unit() | ||
if all_checks: | ||
checks = Stage.ALL | ||
else: | ||
checks = Stage(0) # 0 means no checks | ||
if not skip_linting: | ||
checks |= Stage.PRE_COMMIT | ||
if not skip_build_docs: | ||
checks |= Stage.BUILD_DOCS | ||
if unit_tests: | ||
checks |= Stage.UNIT_TESTS | ||
with checks.get_commands() as commands: | ||
success = True | ||
for command in commands: | ||
success &= execute_check(command) | ||
except KeyboardInterrupt: | ||
return int(not False) | ||
return int(not success) | ||
|
||
|
||
if __name__ == "__main__": | ||
exit_code = main() | ||
print("\npre_push.py: Success!" if not exit_code else "\npre_push.py: Fail") | ||
click.echo( | ||
"\npre_push.py: Success!" if not exit_code else "\npre_push.py: Fail", | ||
err=not exit_code, | ||
) | ||
sys.exit(exit_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,8 @@ | ||
[tox] | ||
envlist = py36,py37,py38 | ||
skip_missing_interpreters = true | ||
skipsdist = true | ||
envlist = py37,py38,py39,py310 | ||
skip_missing_interpreters = false | ||
|
||
[testenv] | ||
deps = | ||
betamax >=0.8, <0.9 | ||
betamax-matchers >=0.3.0, <0.5 | ||
pytest >=2.7.3 | ||
flake8 | ||
commands = | ||
pytest | ||
flake8 --exclude=.eggs,build,docs | ||
passenv = | ||
prawtest_client_id | ||
prawtest_client_secret | ||
prawtest_password | ||
prawtest_refresh_token | ||
prawtest_test_subreddit | ||
prawtest_username | ||
prawtest_user_agent | ||
extras = dev |