From aa802f71e395721925f701fe637b956fd275cd8c Mon Sep 17 00:00:00 2001 From: aleksul Date: Tue, 14 Sep 2021 14:49:56 +0300 Subject: [PATCH 01/18] Update yapfignore --- .yapfignore | 2 -- pyproject.toml | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 .yapfignore diff --git a/.yapfignore b/.yapfignore deleted file mode 100644 index 891d6f7..0000000 --- a/.yapfignore +++ /dev/null @@ -1,2 +0,0 @@ -venvs -build \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9579372..68a2d3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,9 @@ fail_under = 79 [tool.yapf] column_limit = 100 +[tool.yapfignore] +ignore_patterns = ["venvs", "build"] + [tool.pytest.ini_options] addopts = "--strict-markers" testpaths = ["tests"] From c6076c5c7da374862750fa80518a284d631ba23b Mon Sep 17 00:00:00 2001 From: aleksul Date: Tue, 14 Sep 2021 16:32:17 +0300 Subject: [PATCH 02/18] Change venvs to .venv and update gitignore --- .gitignore | 7 +++---- {dist => .venv}/.gitkeep | 0 venvs/.gitkeep | 0 3 files changed, 3 insertions(+), 4 deletions(-) rename {dist => .venv}/.gitkeep (100%) delete mode 100644 venvs/.gitkeep diff --git a/.gitignore b/.gitignore index 86f70c9..72ba09c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ *.pyc -/venvs/* -!/venvs/.gitkeep -/dist/* -!/dist/.gitkeep +/.venv/* +!/.venv/.gitkeep /*coverage* +/.mypy_cache /.mongod /.mongo_databases diff --git a/dist/.gitkeep b/.venv/.gitkeep similarity index 100% rename from dist/.gitkeep rename to .venv/.gitkeep diff --git a/venvs/.gitkeep b/venvs/.gitkeep deleted file mode 100644 index e69de29..0000000 From 423c0089941ae56cc8bb914743577f5e66e4d1b0 Mon Sep 17 00:00:00 2001 From: aleksul Date: Tue, 14 Sep 2021 16:33:10 +0300 Subject: [PATCH 03/18] Delete init.py from tests --- tests/__init__.py | 0 tests/integration/__init__.py | 0 tests/unit/__init__.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/__init__.py delete mode 100644 tests/integration/__init__.py delete mode 100644 tests/unit/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py deleted file mode 100644 index e69de29..0000000 From abcd713ab1944252c9c28365890172a2228553bb Mon Sep 17 00:00:00 2001 From: aleksul Date: Tue, 14 Sep 2021 16:34:09 +0300 Subject: [PATCH 04/18] Delete scripts and requirements --- requirements/basic_requirements.txt | 3 - requirements/build_requirements.txt | 0 requirements/coverage_requirements.txt | 2 - requirements/deployment_requirements.txt | 1 - requirements/format_requirements.txt | 3 - .../frozen/frozen_basic_requirements.txt | 1 - .../frozen/frozen_build_requirements.txt | 1 - .../frozen/frozen_coverage_requirements.txt | 31 ----- .../frozen/frozen_deployment_requirements.txt | 28 ---- .../frozen/frozen_format_requirements.txt | 3 - .../frozen/frozen_lint_requirements.txt | 36 ----- .../frozen/frozen_test_requirements.txt | 29 ---- .../frozen/frozen_type_check_requirements.txt | 32 ----- requirements/lint_requirements.txt | 2 - requirements/requirements.txt | 5 - requirements/test_requirements.txt | 3 - requirements/type_check_requirements.txt | 2 - scripts/all.sh | 15 -- scripts/build.sh | 15 -- scripts/coverage.sh | 13 -- scripts/format.sh | 17 --- scripts/freeze.sh | 38 ------ scripts/integration.sh | 10 -- scripts/library/cpus.sh | 6 - scripts/library/string.sh | 21 --- scripts/library/venv.sh | 129 ------------------ scripts/lint.sh | 13 -- scripts/publish.sh | 30 ---- scripts/test.sh | 13 -- scripts/type_check.sh | 13 -- scripts/unit.sh | 10 -- 31 files changed, 525 deletions(-) delete mode 100644 requirements/basic_requirements.txt delete mode 100644 requirements/build_requirements.txt delete mode 100644 requirements/coverage_requirements.txt delete mode 100644 requirements/deployment_requirements.txt delete mode 100644 requirements/format_requirements.txt delete mode 100644 requirements/frozen/frozen_basic_requirements.txt delete mode 100644 requirements/frozen/frozen_build_requirements.txt delete mode 100644 requirements/frozen/frozen_coverage_requirements.txt delete mode 100644 requirements/frozen/frozen_deployment_requirements.txt delete mode 100644 requirements/frozen/frozen_format_requirements.txt delete mode 100644 requirements/frozen/frozen_lint_requirements.txt delete mode 100644 requirements/frozen/frozen_test_requirements.txt delete mode 100644 requirements/frozen/frozen_type_check_requirements.txt delete mode 100644 requirements/lint_requirements.txt delete mode 100644 requirements/requirements.txt delete mode 100644 requirements/test_requirements.txt delete mode 100644 requirements/type_check_requirements.txt delete mode 100755 scripts/all.sh delete mode 100755 scripts/build.sh delete mode 100755 scripts/coverage.sh delete mode 100755 scripts/format.sh delete mode 100755 scripts/freeze.sh delete mode 100755 scripts/integration.sh delete mode 100644 scripts/library/cpus.sh delete mode 100644 scripts/library/string.sh delete mode 100644 scripts/library/venv.sh delete mode 100755 scripts/lint.sh delete mode 100755 scripts/publish.sh delete mode 100755 scripts/test.sh delete mode 100755 scripts/type_check.sh delete mode 100755 scripts/unit.sh diff --git a/requirements/basic_requirements.txt b/requirements/basic_requirements.txt deleted file mode 100644 index 20502e1..0000000 --- a/requirements/basic_requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -pip==21.1.3 -setuptools==57.0.0 -wheel==0.36.2 diff --git a/requirements/build_requirements.txt b/requirements/build_requirements.txt deleted file mode 100644 index e69de29..0000000 diff --git a/requirements/coverage_requirements.txt b/requirements/coverage_requirements.txt deleted file mode 100644 index 5993923..0000000 --- a/requirements/coverage_requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r test_requirements.txt -pytest-cov==2.12.1 diff --git a/requirements/deployment_requirements.txt b/requirements/deployment_requirements.txt deleted file mode 100644 index 7e9e179..0000000 --- a/requirements/deployment_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -twine==3.4.1 diff --git a/requirements/format_requirements.txt b/requirements/format_requirements.txt deleted file mode 100644 index ef058a5..0000000 --- a/requirements/format_requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -isort==5.8.0 -yapf==0.31.0 -toml==0.10.2 \ No newline at end of file diff --git a/requirements/frozen/frozen_basic_requirements.txt b/requirements/frozen/frozen_basic_requirements.txt deleted file mode 100644 index 8b13789..0000000 --- a/requirements/frozen/frozen_basic_requirements.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/requirements/frozen/frozen_build_requirements.txt b/requirements/frozen/frozen_build_requirements.txt deleted file mode 100644 index 8b13789..0000000 --- a/requirements/frozen/frozen_build_requirements.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/requirements/frozen/frozen_coverage_requirements.txt b/requirements/frozen/frozen_coverage_requirements.txt deleted file mode 100644 index f1d4d82..0000000 --- a/requirements/frozen/frozen_coverage_requirements.txt +++ /dev/null @@ -1,31 +0,0 @@ -aiodns==3.0.0 -aiohttp==3.7.4.post0 -async-timeout==3.0.1 -attrs==21.2.0 -brotlipy==0.7.0 -cchardet==2.1.7 -cffi==1.14.6 -chardet==4.0.0 -coverage==5.5 -distro==1.5.0 -idna==3.2 -idna-ssl==1.1.0 -importlib-metadata==4.6.1 -iniconfig==1.1.1 -motor==2.4.0 -multidict==5.1.0 -packaging==21.0 -pluggy==0.13.1 -py==1.10.0 -pycares==4.0.0 -pycparser==2.20 -pymongo==3.12.0 -pyparsing==2.4.7 -pytest==6.2.4 -pytest-asyncio==0.15.1 -pytest-cov==2.12.1 -pytest-lazy-fixture==0.6.3 -toml==0.10.2 -typing-extensions==3.10.0.0 -yarl==1.6.3 -zipp==3.5.0 diff --git a/requirements/frozen/frozen_deployment_requirements.txt b/requirements/frozen/frozen_deployment_requirements.txt deleted file mode 100644 index 7da7859..0000000 --- a/requirements/frozen/frozen_deployment_requirements.txt +++ /dev/null @@ -1,28 +0,0 @@ -bleach==3.3.1 -certifi==2021.5.30 -cffi==1.14.6 -charset-normalizer==2.0.3 -colorama==0.4.4 -cryptography==3.4.7 -docutils==0.17.1 -idna==3.2 -importlib-metadata==4.6.1 -jeepney==0.7.0 -keyring==23.0.1 -packaging==21.0 -pkginfo==1.7.1 -pycparser==2.20 -Pygments==2.9.0 -pyparsing==2.4.7 -readme-renderer==29.0 -requests==2.26.0 -requests-toolbelt==0.9.1 -rfc3986==1.5.0 -SecretStorage==3.3.1 -six==1.16.0 -tqdm==4.61.2 -twine==3.4.1 -typing-extensions==3.10.0.0 -urllib3==1.26.6 -webencodings==0.5.1 -zipp==3.5.0 diff --git a/requirements/frozen/frozen_format_requirements.txt b/requirements/frozen/frozen_format_requirements.txt deleted file mode 100644 index 2e6c738..0000000 --- a/requirements/frozen/frozen_format_requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -isort==5.8.0 -toml==0.10.2 -yapf==0.31.0 diff --git a/requirements/frozen/frozen_lint_requirements.txt b/requirements/frozen/frozen_lint_requirements.txt deleted file mode 100644 index 3521818..0000000 --- a/requirements/frozen/frozen_lint_requirements.txt +++ /dev/null @@ -1,36 +0,0 @@ -aiodns==3.0.0 -aiohttp==3.7.4.post0 -astroid==2.5.6 -async-timeout==3.0.1 -attrs==21.2.0 -brotlipy==0.7.0 -cchardet==2.1.7 -cffi==1.14.6 -chardet==4.0.0 -distro==1.5.0 -idna==3.2 -idna-ssl==1.1.0 -importlib-metadata==4.6.1 -iniconfig==1.1.1 -isort==5.9.2 -lazy-object-proxy==1.6.0 -mccabe==0.6.1 -motor==2.4.0 -multidict==5.1.0 -packaging==21.0 -pluggy==0.13.1 -py==1.10.0 -pycares==4.0.0 -pycparser==2.20 -pylint==2.8.3 -pymongo==3.12.0 -pyparsing==2.4.7 -pytest==6.2.4 -pytest-asyncio==0.15.1 -pytest-lazy-fixture==0.6.3 -toml==0.10.2 -typed-ast==1.4.3 -typing-extensions==3.10.0.0 -wrapt==1.12.1 -yarl==1.6.3 -zipp==3.5.0 diff --git a/requirements/frozen/frozen_test_requirements.txt b/requirements/frozen/frozen_test_requirements.txt deleted file mode 100644 index 445632d..0000000 --- a/requirements/frozen/frozen_test_requirements.txt +++ /dev/null @@ -1,29 +0,0 @@ -aiodns==3.0.0 -aiohttp==3.7.4.post0 -async-timeout==3.0.1 -attrs==21.2.0 -brotlipy==0.7.0 -cchardet==2.1.7 -cffi==1.14.6 -chardet==4.0.0 -distro==1.5.0 -idna==3.2 -idna-ssl==1.1.0 -importlib-metadata==4.6.1 -iniconfig==1.1.1 -motor==2.4.0 -multidict==5.1.0 -packaging==21.0 -pluggy==0.13.1 -py==1.10.0 -pycares==4.0.0 -pycparser==2.20 -pymongo==3.12.0 -pyparsing==2.4.7 -pytest==6.2.4 -pytest-asyncio==0.15.1 -pytest-lazy-fixture==0.6.3 -toml==0.10.2 -typing-extensions==3.10.0.0 -yarl==1.6.3 -zipp==3.5.0 diff --git a/requirements/frozen/frozen_type_check_requirements.txt b/requirements/frozen/frozen_type_check_requirements.txt deleted file mode 100644 index 5d7d7b7..0000000 --- a/requirements/frozen/frozen_type_check_requirements.txt +++ /dev/null @@ -1,32 +0,0 @@ -aiodns==3.0.0 -aiohttp==3.7.4.post0 -async-timeout==3.0.1 -attrs==21.2.0 -brotlipy==0.7.0 -cchardet==2.1.7 -cffi==1.14.6 -chardet==4.0.0 -distro==1.5.0 -idna==3.2 -idna-ssl==1.1.0 -importlib-metadata==4.6.1 -iniconfig==1.1.1 -motor==2.4.0 -multidict==5.1.0 -mypy==0.902 -mypy-extensions==0.4.3 -packaging==21.0 -pluggy==0.13.1 -py==1.10.0 -pycares==4.0.0 -pycparser==2.20 -pymongo==3.12.0 -pyparsing==2.4.7 -pytest==6.2.4 -pytest-asyncio==0.15.1 -pytest-lazy-fixture==0.6.3 -toml==0.10.2 -typed-ast==1.4.3 -typing-extensions==3.10.0.0 -yarl==1.6.3 -zipp==3.5.0 diff --git a/requirements/lint_requirements.txt b/requirements/lint_requirements.txt deleted file mode 100644 index e4a67c5..0000000 --- a/requirements/lint_requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r test_requirements.txt -pylint==2.8.3 diff --git a/requirements/requirements.txt b/requirements/requirements.txt deleted file mode 100644 index b2c0cf9..0000000 --- a/requirements/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -motor==2.4.0 -pytest==6.2.4 -pytest-asyncio==0.15.1 # Needed for async pytest fixtures -aiohttp[speedups]==3.7.4.post0 -distro==1.5.0 diff --git a/requirements/test_requirements.txt b/requirements/test_requirements.txt deleted file mode 100644 index 6fd9354..0000000 --- a/requirements/test_requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ --r requirements.txt -pytest-asyncio==0.15.1 -pytest-lazy-fixture==0.6.3 diff --git a/requirements/type_check_requirements.txt b/requirements/type_check_requirements.txt deleted file mode 100644 index 9c3c76c..0000000 --- a/requirements/type_check_requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r test_requirements.txt -mypy==0.902 diff --git a/scripts/all.sh b/scripts/all.sh deleted file mode 100755 index 2e8da71..0000000 --- a/scripts/all.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" - -cd "${HERE}" - -./format.sh - -./lint.sh - -./coverage.sh - -./type_check.sh diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index ec42215..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${REPO_ROOT}" - -source "${REPO_ROOT}/scripts/library/venv.sh" -use_venv "build" frozen_build_requirements.txt - -python3 setup.py sdist bdist_wheel - -rm -rf pytest_motor.egg-info build diff --git a/scripts/coverage.sh b/scripts/coverage.sh deleted file mode 100755 index 9beb1ec..0000000 --- a/scripts/coverage.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${REPO_ROOT}" - -source "${REPO_ROOT}/scripts/library/venv.sh" -use_venv "coverage" frozen_coverage_requirements.txt - -python3 -m pytest -m unit --cov-report term-missing --cov-report xml --cov=pytest_motor diff --git a/scripts/format.sh b/scripts/format.sh deleted file mode 100755 index 3fb15f9..0000000 --- a/scripts/format.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${REPO_ROOT}" - -source "${REPO_ROOT}/scripts/library/venv.sh" -use_venv "format" frozen_format_requirements.txt - -source "${REPO_ROOT}/scripts/library/cpus.sh" -NUMBER_OF_CPUS="$(get_number_of_cpus)" - -python3 -m yapf --parallel -i -r . -python3 -m isort --jobs "${NUMBER_OF_CPUS}" . diff --git a/scripts/freeze.sh b/scripts/freeze.sh deleted file mode 100755 index 8bbe739..0000000 --- a/scripts/freeze.sh +++ /dev/null @@ -1,38 +0,0 @@ -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" -REQUIREMENTS_DIRECTORY="${REPO_ROOT}/requirements" -FROZEN_REQUIREMENTS_DIRECTORY="${REQUIREMENTS_DIRECTORY}/frozen" - -source "${REPO_ROOT}/scripts/library/string.sh" -source "${REPO_ROOT}/scripts/library/venv.sh" - -function freeze_requirements() { - local REQUIREMENTS_FILE_PATH="$1" - echo "Freezing '${REQUIREMENTS_FILE_PATH}'..." - - local VENV_NAME="$(get_venv_name_from_requirements_file "${REQUIREMENTS_FILE_PATH}")" - echo "Using virtual environment name '${VENV_NAME}'." - - local REQUIREMENTS_FILE="$(basename "${REQUIREMENTS_FILE_PATH}")" - use_clean_venv "${VENV_NAME}" "${REQUIREMENTS_FILE}" - - local FROZEN_REQUIREMENTS="$(get_frozen_requirements)" - - deactivate_venv - - FROZEN_REQUIREMENTS_FILE_NAME="frozen_${REQUIREMENTS_FILE}" - FROZEN_REQUIREMENTS_FILE_PATH="${FROZEN_REQUIREMENTS_DIRECTORY}/${FROZEN_REQUIREMENTS_FILE_NAME}" - - touch "${FROZEN_REQUIREMENTS_FILE_PATH}" - echo "${FROZEN_REQUIREMENTS}" > "${FROZEN_REQUIREMENTS_FILE_PATH}" - - echo "Done freezing requirements for '${REQUIREMENTS_FILE_PATH}'." -} - -REQUIREMENTS_FILE_PATHS="$(find "${REQUIREMENTS_DIRECTORY}" -maxdepth 1 -name "*_requirements.txt")" - -NUMBER_OF_REQUIREMENTS_FILE_PATHS="$(number_of_lines "${REQUIREMENTS_FILE_PATHS}")" - -echo "Found ${NUMBER_OF_REQUIREMENTS_FILE_PATHS} requirements files to freeze." - -for_each_line "${REQUIREMENTS_FILE_PATHS}" freeze_requirements diff --git a/scripts/integration.sh b/scripts/integration.sh deleted file mode 100755 index e4e8d26..0000000 --- a/scripts/integration.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${HERE}" - -./test.sh -m integration diff --git a/scripts/library/cpus.sh b/scripts/library/cpus.sh deleted file mode 100644 index af0e73d..0000000 --- a/scripts/library/cpus.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -function get_number_of_cpus() { - local NUMBER_OF_CPUS="$(nproc)" - echo "${NUMBER_OF_CPUS}" -} diff --git a/scripts/library/string.sh b/scripts/library/string.sh deleted file mode 100644 index 6c03e0a..0000000 --- a/scripts/library/string.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -function number_of_lines() { - local STRING="$1" - local NUMBER_OF_LINES - if [[ -z "${STRING}" ]]; then - NUMBER_OF_LINES=0 - else - NUMBER_OF_LINES="$(echo "${STRING}" | wc -l)" - fi - echo "${NUMBER_OF_LINES}" -} - -function for_each_line() { - local STRING="$1" - local FUNCTION="$2" - - while read line; do - $FUNCTION "${line}" - done <<< "${STRING}" -} diff --git a/scripts/library/venv.sh b/scripts/library/venv.sh deleted file mode 100644 index e6f371a..0000000 --- a/scripts/library/venv.sh +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/bash - -set -eu - -function _venv_exists() { - local VENV_NAME="$1" - - local VENV_PATH="$(get_venv_path "${VENV_NAME}")" - if [[ -d "${VENV_PATH}" ]]; then - echo "yes" - else - echo "no" - fi -} - -function _make_venv() { - local VENV_PATH="$1" - python3 -m venv --clear "${VENV_PATH}" -} - -function _activate_venv() { - source "${VENV_PATH}/bin/activate" -} - -function deactivate_venv() { - set +u - deactivate - set -u -} - -function _install_requirements() { - local REQUIREMENTS_FILE_NAME="$1" - local REQUIREMENTS_FILE_PATH="${REPO_ROOT}/requirements/${REQUIREMENTS_FILE_NAME}" - python3 -m pip install -r "${REQUIREMENTS_FILE_PATH}" -} - -function _install_frozen_requirements() { - local FROZEN_REQUIREMENTS_FILE_NAME="$1" - local FROZEN_REQUIREMENTS_FILE_PATH="${REPO_ROOT}/requirements/frozen/${FROZEN_REQUIREMENTS_FILE_NAME}" - python3 -m pip install -r "${FROZEN_REQUIREMENTS_FILE_PATH}" -} - -function get_venv_name_from_requirements_file() { - local REQUIREMENTS_FILE_PATH="$1" - local REQUIREMENTS_FILE_NAME="$(basename "${REQUIREMENTS_FILE_PATH}")" - local VENV_NAME="$( echo "${REQUIREMENTS_FILE_NAME}" | rev | cut --delimiter=_ --fields=2- | rev)" - echo "${VENV_NAME}" -} - -function get_venv_path() { - local VENV_NAME="$1" - local VENV_PATH="${REPO_ROOT}/venvs/${VENV_NAME}" - echo "${VENV_PATH}" -} - -function get_frozen_requirements() { - local FROZEN_REQUIREMENTS="$(pip freeze | sed '/pkg-resources/d')" - echo "${FROZEN_REQUIREMENTS}" -} - -function requirements_match() { - local VENV_NAME="$1" - local FROZEN_REQUIREMENTS_FILE_NAME="$2" - - local VENV_PATH="$(get_venv_path "${VENV_NAME}")" - - _activate_venv "${VENV_PATH}" - local ACTUAL_FROZEN_REQUIREMENTS="$(get_frozen_requirements)" - deactivate_venv - - local FROZEN_REQUIREMENTS_FILE_PATH="${REPO_ROOT}/requirements/frozen/${FROZEN_REQUIREMENTS_FILE_NAME}" - local EXPECTED_FROZEN_REQUIREMENTS="$(cat "${FROZEN_REQUIREMENTS_FILE_PATH}")" - - if [[ "${ACTUAL_FROZEN_REQUIREMENTS}" == "${EXPECTED_FROZEN_REQUIREMENTS}" ]]; then - echo "yes" - else - echo "no" - fi -} - -function use_clean_venv() { - local VENV_NAME="$1" - local REQUIREMENTS_FILE_NAME="$2" - - local VENV_PATH="$(get_venv_path "${VENV_NAME}")" - - _make_venv "${VENV_PATH}" - _activate_venv "${VENV_PATH}" - _install_requirements "basic_requirements.txt" - _install_requirements "${REQUIREMENTS_FILE_NAME}" -} - -function use_clean_venv_from_frozen_requirements() { - local VENV_NAME="$1" - local FROZEN_REQUIREMENTS_FILE_NAME="$2" - - local VENV_PATH="$(get_venv_path "${VENV_NAME}")" - - _make_venv "${VENV_PATH}" - _activate_venv "${VENV_PATH}" - _install_requirements "basic_requirements.txt" - _install_frozen_requirements "${FROZEN_REQUIREMENTS_FILE_NAME}" -} - -function _maybe_reuse_venv() { - local VENV_NAME="$1" - local FROZEN_REQUIREMENTS_FILE_NAME="$2" - - local REQUIREMENTS_MATCH="$(requirements_match "${VENV_NAME}" "${FROZEN_REQUIREMENTS_FILE_NAME}")" - if [[ "${REQUIREMENTS_MATCH}" == "yes" ]]; then - local VENV_PATH="$(get_venv_path "${VENV_NAME}")" - _activate_venv "${VENV_PATH}" - else - use_clean_venv_from_frozen_requirements "${VENV_NAME}" "${FROZEN_REQUIREMENTS_FILE_NAME}" - fi -} - -function use_venv() { - local VENV_NAME="$1" - local FROZEN_REQUIREMENTS_FILE_NAME="$2" - - local VENV_EXISTS="$(_venv_exists "${VENV_NAME}" )" - - if [[ "${VENV_EXISTS}" == "yes" ]]; then - _maybe_reuse_venv "${VENV_NAME}" "${FROZEN_REQUIREMENTS_FILE_NAME}" - else - use_clean_venv_from_frozen_requirements "${VENV_NAME}" "${FROZEN_REQUIREMENTS_FILE_NAME}" - fi -} diff --git a/scripts/lint.sh b/scripts/lint.sh deleted file mode 100755 index 73217cf..0000000 --- a/scripts/lint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${REPO_ROOT}" - -source "${REPO_ROOT}/scripts/library/venv.sh" -use_venv "lint" frozen_lint_requirements.txt - -python3 -m pylint -j 0 --output-format=colorized pytest_motor tests setup.py diff --git a/scripts/publish.sh b/scripts/publish.sh deleted file mode 100755 index 234a885..0000000 --- a/scripts/publish.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" -DISTRIBUTION_DIRECTORY="${REPO_ROOT}/dist" - -VERSION_FILE="${REPO_ROOT}/VERSION.txt" -VERSION="$(cat "${VERSION_FILE}")" - -WHEEL="${DISTRIBUTION_DIRECTORY}/pytest_motor-${VERSION}-py3-none-any.whl" -SOURCE_DISTRIBUTION="${DISTRIBUTION_DIRECTORY}/pytest-motor-${VERSION}.tar.gz" - -# Check that the API token has been provided. -set +u -if [[ -z "${PYPI_TOKEN}" ]]; then - echo "ERROR: PyPI API token not set. Please provide it as an environment varibale." - exit 1 -fi -set -u - -source "${REPO_ROOT}/scripts/library/venv.sh" -use_venv deployment frozen_deployment_requirements.txt - -python3 -m twine upload \ - --non-interactive \ - --username __token__ \ - --password "${PYPI_TOKEN}" \ - "${WHEEL}" "${SOURCE_DISTRIBUTION}" diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index 9db2425..0000000 --- a/scripts/test.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${REPO_ROOT}" - -source "${REPO_ROOT}/scripts/library/venv.sh" -use_venv "test" frozen_test_requirements.txt - -python3 -m pytest "$@" diff --git a/scripts/type_check.sh b/scripts/type_check.sh deleted file mode 100755 index 9ff1248..0000000 --- a/scripts/type_check.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${REPO_ROOT}" - -source "${REPO_ROOT}/scripts/library/venv.sh" -use_venv "type_check" frozen_type_check_requirements.txt - -python3 -m mypy . diff --git a/scripts/unit.sh b/scripts/unit.sh deleted file mode 100755 index 0404e17..0000000 --- a/scripts/unit.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -eu - -HERE="$(dirname "$(readlink -f "$BASH_SOURCE")")" -REPO_ROOT="$(realpath "${HERE}/..")" - -cd "${HERE}" - -./test.sh -m unit From f94432e72722cd0851ea8c7a18aa707c78668765 Mon Sep 17 00:00:00 2001 From: aleksul Date: Tue, 14 Sep 2021 16:34:32 +0300 Subject: [PATCH 05/18] Add pre-commit hooks --- .pre-commit-config.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d44b074 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/pycqa/isort + rev: 5.9.3 + hooks: + - id: isort + - repo: https://github.com/google/yapf + rev: v0.31.0 + hooks: + - id: yapf + additional_dependencies: [toml] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910 + hooks: + - id: mypy + name: mypy-plugin + files: pytest_motor/ + - id: mypy + name: mypy-unit-tests + files: tests/unit/ + - id: mypy + name: mypy-integration-tests + files: tests/integration/ + - repo: https://github.com/pycqa/pylint + rev: v2.10.2 + hooks: + - id: pylint + args: ["--output-format=colorized", "pytest_motor", "tests", "setup.py", "--disable=E0401"] \ No newline at end of file From 4950746e4f8fa75f360983b170b1a4cc760bd07e Mon Sep 17 00:00:00 2001 From: aleksul Date: Sat, 18 Sep 2021 16:19:01 +0300 Subject: [PATCH 06/18] Update settings in pyproject --- pyproject.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 68a2d3a..34f5b70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ fail_under = 79 column_limit = 100 [tool.yapfignore] -ignore_patterns = ["venvs", "build"] +ignore_patterns = [".venv"] [tool.pytest.ini_options] addopts = "--strict-markers" @@ -26,7 +26,7 @@ disable = ["duplicate-code"] python_version = "3.6" warn_return_any = true warn_unused_configs = true -exclude = "venvs/" +exclude = ".venv/" disallow_untyped_defs = true no_implicit_optional = true warn_unused_ignores = true @@ -43,6 +43,10 @@ module = [ ignore_missing_imports = true [tool.isort] +src_paths = ["pytest_motor", "tests", "test_data"] quiet = true line_length = 100 -skip_glob = ["venvs", "build"] + +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" From d83248a22e118ba9d494f4d2c77d3c998af10879 Mon Sep 17 00:00:00 2001 From: aleksul Date: Sat, 18 Sep 2021 16:19:22 +0300 Subject: [PATCH 07/18] List dev dependecies in setup.py --- setup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8214a59..51f14a1 100644 --- a/setup.py +++ b/setup.py @@ -36,5 +36,11 @@ 'Typing :: Typed', ], python_requires='>=3.6', - install_requires=['pytest', 'motor', 'aiohttp[speedups]', 'distro'], + install_requires=['pytest>=5.0', 'motor>=2.0', 'aiohttp[speedups]', 'distro'], + extras_require={ + "dev": [ + "pre-commit", "tox", "pytest-cov", "pytest-asyncio", "pytest-lazy-fixture", "pylint", + "yapf[toml]", "isort", "mypy" + ], + }, ) From 7c2ae1df2b680e9fcfbb8f818f66c033d2159b4d Mon Sep 17 00:00:00 2001 From: aleksul Date: Sat, 18 Sep 2021 21:08:33 +0300 Subject: [PATCH 08/18] Add test and dev requirements to setup.py --- setup.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 51f14a1..0f5c468 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,12 @@ _PACKAGES: List[str] = setuptools.find_packages(where=_HERE, include=['pytest_motor*']) +_PACKAGE_REQUIREMENTS: List[str] = ['pytest>=5.0', 'motor>=2.0', 'aiohttp[speedups]', 'distro'] +_TEST_REQUIREMENTS: List[str] = [ + "tox>=3.24.0", "pytest-cov", "pytest-asyncio", "pytest-lazy-fixture" +] +_DEV_REQUIREMENTS: List[str] = ["pre-commit", "pylint", "yapf[toml]", "isort", "mypy"] + setuptools.setup( name='pytest-motor', version=_VERSION, @@ -36,11 +42,9 @@ 'Typing :: Typed', ], python_requires='>=3.6', - install_requires=['pytest>=5.0', 'motor>=2.0', 'aiohttp[speedups]', 'distro'], + install_requires=_PACKAGE_REQUIREMENTS, extras_require={ - "dev": [ - "pre-commit", "tox", "pytest-cov", "pytest-asyncio", "pytest-lazy-fixture", "pylint", - "yapf[toml]", "isort", "mypy" - ], + "dev": _DEV_REQUIREMENTS + _TEST_REQUIREMENTS, + "test": _TEST_REQUIREMENTS, }, ) From a0bec1c6849491703d28e1e0e50a62b771d87edd Mon Sep 17 00:00:00 2001 From: aleksul Date: Sat, 18 Sep 2021 21:08:41 +0300 Subject: [PATCH 09/18] Add tox.ini --- tox.ini | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..7873793 --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +envlist = py{36,37,38,39,310},integration + +[testenv] +extras = test # will install all `test` dependecies from `setup.py` +commands = pytest -m unit --cov-report term-missing --cov-report xml --cov=pytest_motor tests/ + +[testenv:integration] +basepython = python3.6 +commands = pytest -m integration tests/ From 22bc3e5832ba056f177ded0b9433aae082b6d18a Mon Sep 17 00:00:00 2001 From: aleksul Date: Sat, 18 Sep 2021 23:13:47 +0300 Subject: [PATCH 10/18] Update CI and multiple fixes --- .github/workflows/main.yaml | 50 +++++ .github/workflows/python.yaml | 181 ------------------ setup.py | 29 +-- tests/conftest.py | 2 +- ...t_plugin.py => test_plugin_integration.py} | 0 tox.ini | 5 +- 6 files changed, 62 insertions(+), 205 deletions(-) create mode 100644 .github/workflows/main.yaml delete mode 100644 .github/workflows/python.yaml rename tests/integration/{test_plugin.py => test_plugin_integration.py} (100%) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..2ffb5b8 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,50 @@ +name: main + +on: + push: + branches: + - 'master' + tags: + - "*" + pull_request: + branches: + - 'master' + +jobs: + tests: + name: Python ${{ matrix.python-version }} + runs-on: ubuntu-20.04 + env: + PYTEST_ADDOPTS: "--color=yes" + + strategy: + matrix: + python-version: + - 3.6 + - 3.7 + - 3.8 + - 3.9 + - 3.10-dev + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + python -m pip install --upgrade tox tox-py + + - name: Run tox targets for ${{ matrix.python-version }} + run: tox --py current + + - name: Upload code coverage + if: matrix.python-version == '3.6' + uses: codecov/codecov-action@v2 + with: + files: ./coverage.xml + flags: unittests diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml deleted file mode 100644 index dcee0b8..0000000 --- a/.github/workflows/python.yaml +++ /dev/null @@ -1,181 +0,0 @@ -name: Python - -on: - push: - branches: - - 'master' - pull_request: - branches: - - 'master' - -jobs: - unit-test: - name: Unit tests - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - with: - python-version: 3.6 - - - name: Cache pip packages - uses: actions/cache@v2 - env: - cache-name: pip-packages-cache - with: - path: ~/.cache/pip - key: ${{ env.cache-name }}-unit-test-${{ hashFiles('requirements/frozen/frozen_test_requirements.txt') }} - restore-keys: | - ${{ env.cache-name }}-unit-test- - ${{ env.cache-name }}- - - - name: Run unit tests with pytest and check coverage - run: ./scripts/coverage.sh - - - name: Upload code coverage - uses: codecov/codecov-action@v2 - with: - files: ./coverage.xml - flags: unittests - - integration-test: - name: Integration tests - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - with: - python-version: 3.6 - - - name: Cache pip packages - uses: actions/cache@v2 - env: - cache-name: pip-packages-cache - with: - path: ~/.cache/pip - key: ${{ env.cache-name }}-integration-test-${{ hashFiles('requirements/frozen/frozen_test_requirements.txt') }} - restore-keys: | - ${{ env.cache-name }}-integration-test- - ${{ env.cache-name }}- - - - name: Run integration tests with pytest - run: ./scripts/integration.sh - - lint: - name: Lint - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - with: - python-version: 3.6 - - - name: Cache pip packages - uses: actions/cache@v2 - env: - cache-name: pip-packages-cache - with: - path: ~/.cache/pip - key: ${{ env.cache-name }}-lint-${{ hashFiles('requirements/frozen/frozen_lint_requirements.txt') }} - restore-keys: | - ${{ env.cache-name }}-lint- - ${{ env.cache-name }}- - - - name: Lint with pylint - run: | - ./scripts/lint.sh - - type-check: - name: Type Check - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - with: - python-version: 3.6 - - - name: Cache pip packages - uses: actions/cache@v2 - env: - cache-name: pip-packages-cache - with: - path: ~/.cache/pip - key: ${{ env.cache-name }}-type-check-${{ hashFiles('requirements/frozen/frozen_type_check_requirements.txt') }} - restore-keys: | - ${{ env.cache-name }}-type-check- - ${{ env.cache-name }}- - - - name: Cache mypy cache - uses: AustinScola/mypy-cache-github-action@v1 - - - name: Type Check with mypy - run: | - ./scripts/type_check.sh - - build: - name: Build - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - with: - python-version: 3.6 - - - name: Cache pip packages - uses: actions/cache@v2 - env: - cache-name: pip-packages-cache - with: - path: ~/.cache/pip - key: ${{ env.cache-name }}-build-${{ hashFiles('requirements/frozen/frozen_type_check_requirements.txt') }} - restore-keys: | - ${{ env.cache-name }}-build- - ${{ env.cache-name }}- - - - name: Build distributions - run: | - ./scripts/build.sh - - check-formatting: - name: Check formatting - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - with: - python-version: 3.6 - - - name: Cache pip packages - uses: actions/cache@v2 - env: - cache-name: pip-packages-cache - with: - path: ~/.cache/pip - key: ${{ env.cache-name }}-format-${{ hashFiles('requirements/frozen/frozen_type_check_requirements.txt') }} - restore-keys: | - ${{ env.cache-name }}-format- - ${{ env.cache-name }}- - - - name: Format the repository - run: ./scripts/format.sh - - - name: Check formatting - run: git diff --exit-code diff --git a/setup.py b/setup.py index 0f5c468..4f2aad7 100644 --- a/setup.py +++ b/setup.py @@ -1,35 +1,20 @@ """A build script using setuptools for the pytest motor package.""" -import pathlib -from typing import List - import setuptools -_HERE = pathlib.Path(__file__).parent - -_README = _HERE / 'README.md' -_LONG_DESCRIPTION = _README.read_text() - -_VERSION_FILE = _HERE / 'VERSION.txt' -_VERSION = _VERSION_FILE.read_text() - -_PACKAGES: List[str] = setuptools.find_packages(where=_HERE, include=['pytest_motor*']) - -_PACKAGE_REQUIREMENTS: List[str] = ['pytest>=5.0', 'motor>=2.0', 'aiohttp[speedups]', 'distro'] -_TEST_REQUIREMENTS: List[str] = [ - "tox>=3.24.0", "pytest-cov", "pytest-asyncio", "pytest-lazy-fixture" -] -_DEV_REQUIREMENTS: List[str] = ["pre-commit", "pylint", "yapf[toml]", "isort", "mypy"] +_PACKAGE_REQUIREMENTS = ['pytest>=5.0', 'motor>=2.0', 'aiohttp[speedups]', 'distro'] +_TEST_REQUIREMENTS = ["tox>=3.24.0", "pytest-cov", "pytest-asyncio", "pytest-lazy-fixture"] +_DEV_REQUIREMENTS = ["pre-commit", "pylint", "yapf[toml]", "isort", "mypy"] setuptools.setup( name='pytest-motor', - version=_VERSION, + version=open("VERSION.txt", encoding="utf-8").read(), author='Austin Scola', author_email='austinscola@gmail.com', description='A pytest plugin for motor, the non-blocking MongoDB driver.', - long_description=_LONG_DESCRIPTION, + long_description=open("README.md", encoding="utf-8").read(), long_description_content_type='text/markdown', url='https://github.com/AustinScola/pytest-motor', - packages=_PACKAGES, + packages=setuptools.find_packages(where="pytest_motor"), package_data={'pytest_motor': ['py.typed']}, entry_points={'pytest11': ['pytest_motor = pytest_motor.plugin']}, classifiers=[ @@ -46,5 +31,5 @@ extras_require={ "dev": _DEV_REQUIREMENTS + _TEST_REQUIREMENTS, "test": _TEST_REQUIREMENTS, - }, + } ) diff --git a/tests/conftest.py b/tests/conftest.py index cd9d915..595f1ef 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,3 @@ """Pytest configuration.""" -pytest_plugins = ['pytester', 'pytest_asyncio', 'pytest_motor.plugin'] +pytest_plugins = ['pytester', 'pytest_asyncio'] diff --git a/tests/integration/test_plugin.py b/tests/integration/test_plugin_integration.py similarity index 100% rename from tests/integration/test_plugin.py rename to tests/integration/test_plugin_integration.py diff --git a/tox.ini b/tox.ini index 7873793..182045f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,11 @@ [tox] envlist = py{36,37,38,39,310},integration +skipsdist=True [testenv] -extras = test # will install all `test` dependecies from `setup.py` +usedevelop=True +extras = test +# will install all `test` dependecies from `setup.py` commands = pytest -m unit --cov-report term-missing --cov-report xml --cov=pytest_motor tests/ [testenv:integration] From 8b79499c66a8ad2aa7176087ed62d01403ba7d83 Mon Sep 17 00:00:00 2001 From: aleksul Date: Sat, 18 Sep 2021 23:26:20 +0300 Subject: [PATCH 11/18] Add CI for integration tests --- .github/workflows/main.yaml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2ffb5b8..fbccd6d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -12,7 +12,7 @@ on: jobs: tests: - name: Python ${{ matrix.python-version }} + name: Unit Tests (Python ${{ matrix.python-version }}) runs-on: ubuntu-20.04 env: PYTEST_ADDOPTS: "--color=yes" @@ -48,3 +48,33 @@ jobs: with: files: ./coverage.xml flags: unittests + + integration-tests: + name: Integration Tests (Python 3.6 ${{ matrix.os }}) + runs-on: ${{ matrix.os }} + env: + PYTEST_ADDOPTS: "--color=yes" + + strategy: + matrix: + os: + - ubuntu-18.04 + - ubuntu-20.04 + - windows-latest + - macos-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.6 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + python -m pip install --upgrade tox + + - name: Run tox + run: tox -e integration From b2b8d0e369d1c52a4e9bf15f2f69bfe6e0f0fffb Mon Sep 17 00:00:00 2001 From: aleksul Date: Sat, 18 Sep 2021 23:45:59 +0300 Subject: [PATCH 12/18] Update Publish CI --- .github/workflows/main.yaml | 7 +++--- .github/workflows/publish.yaml | 43 +++++++++++++++++----------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index fbccd6d..d28814b 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -10,12 +10,13 @@ on: branches: - 'master' +env: + PYTEST_ADDOPTS: "--color=yes" + jobs: tests: name: Unit Tests (Python ${{ matrix.python-version }}) runs-on: ubuntu-20.04 - env: - PYTEST_ADDOPTS: "--color=yes" strategy: matrix: @@ -52,8 +53,6 @@ jobs: integration-tests: name: Integration Tests (Python 3.6 ${{ matrix.os }}) runs-on: ${{ matrix.os }} - env: - PYTEST_ADDOPTS: "--color=yes" strategy: matrix: diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 1d1c7fd..864e5dd 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,6 +1,10 @@ -name: Publish +name: publish -on: workflow_dispatch +on: + release: + types: + - published + workflow_dispatch: jobs: publish: @@ -8,34 +12,29 @@ jobs: environment: name: PyPI url: https://pypi.org/project/pytest-motor/ - env: - PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python 3.6 uses: actions/setup-python@v2 with: python-version: 3.6 - - name: Cache pip packages - uses: actions/cache@v2 - env: - cache-name: pip-packages-cache - with: - path: ~/.cache/pip - key: ${{ env.cache-name }}-publish-${{ hashFiles('requirements/frozen/frozen_test_requirements.txt') }} - restore-keys: | - ${{ env.cache-name }}-publish- - ${{ env.cache-name }}- - - - name: Build a Python source distrubution and wheel - run: | - ./scripts/build.sh - - - name: Publish the distributions - run: | - ./scripts/publish.sh + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade wheel setuptools + + - name: Build package + run: python setup.py sdist bdist_wheel + + - name: Publish package + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} From 9d1687fb4a1c35f06fa0c7963cc20550276fd77a Mon Sep 17 00:00:00 2001 From: aleksul Date: Sun, 19 Sep 2021 00:01:25 +0300 Subject: [PATCH 13/18] Add more python versions to setup.py --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index 4f2aad7..a029edc 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,9 @@ classifiers=[ 'Development Status :: 3 - Alpha', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Framework :: Pytest', From 8578a2a99b6d2e836e21a61176cf2138448e295e Mon Sep 17 00:00:00 2001 From: aleksul Date: Sun, 19 Sep 2021 00:11:15 +0300 Subject: [PATCH 14/18] YAPF doesn't need extra toml anymore --- setup.py | 64 +++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/setup.py b/setup.py index a029edc..29b1e7d 100644 --- a/setup.py +++ b/setup.py @@ -1,38 +1,36 @@ """A build script using setuptools for the pytest motor package.""" -import setuptools +from setuptools import setup, find_packages _PACKAGE_REQUIREMENTS = ['pytest>=5.0', 'motor>=2.0', 'aiohttp[speedups]', 'distro'] _TEST_REQUIREMENTS = ["tox>=3.24.0", "pytest-cov", "pytest-asyncio", "pytest-lazy-fixture"] -_DEV_REQUIREMENTS = ["pre-commit", "pylint", "yapf[toml]", "isort", "mypy"] +_DEV_REQUIREMENTS = ["pre-commit", "pylint", "yapf", "isort", "mypy"] -setuptools.setup( - name='pytest-motor', - version=open("VERSION.txt", encoding="utf-8").read(), - author='Austin Scola', - author_email='austinscola@gmail.com', - description='A pytest plugin for motor, the non-blocking MongoDB driver.', - long_description=open("README.md", encoding="utf-8").read(), - long_description_content_type='text/markdown', - url='https://github.com/AustinScola/pytest-motor', - packages=setuptools.find_packages(where="pytest_motor"), - package_data={'pytest_motor': ['py.typed']}, - entry_points={'pytest11': ['pytest_motor = pytest_motor.plugin']}, - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Framework :: Pytest', - 'Topic :: Software Development :: Testing', - 'Typing :: Typed', - ], - python_requires='>=3.6', - install_requires=_PACKAGE_REQUIREMENTS, - extras_require={ - "dev": _DEV_REQUIREMENTS + _TEST_REQUIREMENTS, - "test": _TEST_REQUIREMENTS, - } -) +setup(name='pytest-motor', + version=open("VERSION.txt", encoding="utf-8").read(), + author='Austin Scola', + author_email='austinscola@gmail.com', + description='A pytest plugin for motor, the non-blocking MongoDB driver.', + long_description=open("README.md", encoding="utf-8").read(), + long_description_content_type='text/markdown', + url='https://github.com/AustinScola/pytest-motor', + packages=find_packages(where="pytest_motor"), + package_data={'pytest_motor': ['py.typed']}, + entry_points={'pytest11': ['pytest_motor = pytest_motor.plugin']}, + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Framework :: Pytest', + 'Topic :: Software Development :: Testing', + 'Typing :: Typed', + ], + python_requires='>=3.6', + install_requires=_PACKAGE_REQUIREMENTS, + extras_require={ + "dev": _DEV_REQUIREMENTS + _TEST_REQUIREMENTS, + "test": _TEST_REQUIREMENTS, + }) From 4f21becffed7fe290471a8177fd8763424acec35 Mon Sep 17 00:00:00 2001 From: aleksul Date: Sun, 19 Sep 2021 00:20:21 +0300 Subject: [PATCH 15/18] Small fixes --- .github/workflows/publish.yaml | 16 ++++++++-------- .pre-commit-config.yaml | 2 +- CONTRIBUTING.md | 2 +- pytest_motor/mongod_binary.py | 1 - setup.py | 3 ++- tests/unit/test_mongod_binary.py | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 864e5dd..38affb2 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -26,15 +26,15 @@ jobs: python-version: 3.6 - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install --upgrade wheel setuptools + run: | + python -m pip install --upgrade pip + pip install --upgrade wheel setuptools - name: Build package - run: python setup.py sdist bdist_wheel + run: python setup.py sdist bdist_wheel - name: Publish package - uses: pypa/gh-action-pypi-publish@v1.4.2 - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d44b074..fb0aa3c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,4 +31,4 @@ repos: rev: v2.10.2 hooks: - id: pylint - args: ["--output-format=colorized", "pytest_motor", "tests", "setup.py", "--disable=E0401"] \ No newline at end of file + args: ["--output-format=colorized", "pytest_motor", "tests", "setup.py", "--disable=E0401"] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8f468f..255522a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to `pytest-motor` +# Contributing to `pytest-motor` Hello friend! Here are some guidelines on how to contribute to `pytest-motor`. diff --git a/pytest_motor/mongod_binary.py b/pytest_motor/mongod_binary.py index f571d3e..50edaa6 100644 --- a/pytest_motor/mongod_binary.py +++ b/pytest_motor/mongod_binary.py @@ -100,7 +100,6 @@ def __unpack(self, binary_file: IO[bytes]) -> None: return if self.url.endswith('.zip') and self.current_platform == 'windows-x86_64': with ZipFile(file=binary_file, mode='r') as archive_zip: - # pylint: disable=consider-using-with file_in_archive = archive_zip.open( f'mongodb-win32-x86_64-windows-{self.MONGO_VERSION}/bin/mongod.exe') if file_in_archive is None: # pragma: no cover diff --git a/setup.py b/setup.py index 29b1e7d..b6a632c 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,11 @@ """A build script using setuptools for the pytest motor package.""" -from setuptools import setup, find_packages +from setuptools import find_packages, setup _PACKAGE_REQUIREMENTS = ['pytest>=5.0', 'motor>=2.0', 'aiohttp[speedups]', 'distro'] _TEST_REQUIREMENTS = ["tox>=3.24.0", "pytest-cov", "pytest-asyncio", "pytest-lazy-fixture"] _DEV_REQUIREMENTS = ["pre-commit", "pylint", "yapf", "isort", "mypy"] +# pylint: disable=consider-using-with setup(name='pytest-motor', version=open("VERSION.txt", encoding="utf-8").read(), author='Austin Scola', diff --git a/tests/unit/test_mongod_binary.py b/tests/unit/test_mongod_binary.py index e53f1ac..11c3a1b 100644 --- a/tests/unit/test_mongod_binary.py +++ b/tests/unit/test_mongod_binary.py @@ -84,12 +84,12 @@ def test_mongod_url(monkeypatch: MonkeyPatch, platform_name: str, distro_name: s assert MongodBinary(Path(tempfile.gettempdir())).url == true_url -# yapf: disable # pylint: disable=line-too-long +# yapf: disable @mark.parametrize('platform_name, archive', [ ('Darwin', lazy_fixture('mongodb_archive_macos')), ('Windows', lazy_fixture('mongodb_archive_windows')) ]) -# yapf: enable # pylint: enable=line-too-long +# yapf: enable def test_unpack(monkeypatch: MonkeyPatch, platform_name: str, archive: IO[bytes]) -> None: """Test unpacking mechanism based on archive format.""" directory: Path = Path(tempfile.gettempdir()) From bba3cf2d3e84d9bffab27ec3e4a3ef7d0a6fb305 Mon Sep 17 00:00:00 2001 From: aleksul Date: Sun, 19 Sep 2021 11:50:20 +0300 Subject: [PATCH 16/18] Update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 72ba09c..d1d6450 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /.mypy_cache /.mongod /.mongo_databases +/pytest_motor.egg-info +/.tox From 752f5fbacb37e71b67a521cc73ebe2413fb84d53 Mon Sep 17 00:00:00 2001 From: aleksul Date: Sun, 19 Sep 2021 12:30:14 +0300 Subject: [PATCH 17/18] Update contributing guidelines and readme badge --- CONTRIBUTING.md | 29 +++++++---------------------- README.md | 2 +- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 255522a..281d3eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,31 +6,16 @@ Hello friend! Here are some guidelines on how to contribute to `pytest-motor`. 1. If you do not have a fork of `pytest-motor`, then [create a fork][1] and [clone it][2]. 2. Create a branch. -3. Create changes and make sure all code quality scripts pass. +3. Prepare your working environment: + ```bash + python -m venv .venv + pip install .[dev] + pre-commit install + ``` +4. Create changes and make sure all pre-commit hooks pass. 4. Commits your changes. 5. Create a [pull request from your fork][3]. -## Scripts - -`pytest-motor` has a number of bash scripts in the `scripts` directory. The scripts check the -functionality and quality of the code. - -All of the scripts first set up a virtual environment with the appropriate requirements. The first -time that a script is run it may be slow for this reason. Subsequent runs will re-use the venv if -dependencies have not changed. - -Here is a description of what each script does: - -| Script | Description | -|-----------------|-------------------------------------------------| -| `all.sh` | Formats, lints, runs coverage, and type checks. | -| `build.sh` | Builds distributions using `setuptools`. | -| `coverage.sh` | Checks test coverage using `pytest-cov`. | -| `format.sh` | Formats code using `yapf` then `isort`. | -| `lint.sh` | Lints code using `pylint`. | -| `test.sh` | Tests code using `pytest`. | -| `type_check.sh` | Type checks code using `mypy`. | - [1]: https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository [2]: https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository [3]: https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork diff --git a/README.md b/README.md index 78a884c..aa29539 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![PyPI version](https://img.shields.io/pypi/v/pytest-motor.svg)](https://pypi.org/project/pytest-motor/) [![PyPI status](https://img.shields.io/pypi/status/pytest-motor.svg)](https://pypi.python.org/pypi/pytest-motor/) [![codecov](https://codecov.io/gh/AustinScola/pytest-motor/branch/master/graph/badge.svg)](https://codecov.io/gh/AustinScola/pytest-motor) -![https://github.com/AustinScola/pytest-motor/actions/workflows/python.yaml](https://github.com/AustinScola/pytest-motor/actions/workflows/python.yaml/badge.svg) +![https://github.com/AustinScola/pytest-motor/actions/workflows/main.yaml](https://github.com/AustinScola/pytest-motor/actions/workflows/main.yaml/badge.svg) [![PyPI pyversions](https://img.shields.io/pypi/pyversions/pytest-motor.svg)](https://pypi.python.org/pypi/pytest-motor/) [![Code style](https://img.shields.io/badge/code%20style-yapf-blue.svg)](https://github.com/google/yapf) From 20dd246fce777f0e21d1d03244e494e818a3dd52 Mon Sep 17 00:00:00 2001 From: aleksul Date: Sun, 19 Sep 2021 13:08:14 +0300 Subject: [PATCH 18/18] Fix wrong coverage reports by tox --- pyproject.toml | 4 ++-- setup.py | 2 +- tox.ini | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 34f5b70..f969e77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,4 @@ -[tool.coverage] +[tool.coverage.report] fail_under = 79 [tool.yapf] @@ -8,7 +8,7 @@ column_limit = 100 ignore_patterns = [".venv"] [tool.pytest.ini_options] -addopts = "--strict-markers" +addopts = ["--strict-markers"] testpaths = ["tests"] markers = [ "unit: marks tests as a unit test", diff --git a/setup.py b/setup.py index b6a632c..6fd3b8a 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ # pylint: disable=consider-using-with setup(name='pytest-motor', - version=open("VERSION.txt", encoding="utf-8").read(), + version=open("VERSION.txt", encoding="utf-8").readline(), author='Austin Scola', author_email='austinscola@gmail.com', description='A pytest plugin for motor, the non-blocking MongoDB driver.', diff --git a/tox.ini b/tox.ini index 182045f..804e7c2 100644 --- a/tox.ini +++ b/tox.ini @@ -3,11 +3,15 @@ envlist = py{36,37,38,39,310},integration skipsdist=True [testenv] +setenv = + COV_CORE_SOURCE={toxinidir}/pytest_motor + COV_CORE_CONFIG={toxinidir}/pyproject.toml + COV_CORE_DATAFILE={toxinidir}/.coverage usedevelop=True extras = test # will install all `test` dependecies from `setup.py` -commands = pytest -m unit --cov-report term-missing --cov-report xml --cov=pytest_motor tests/ +commands = pytest -m unit --cov=pytest_motor --cov-append --cov-report xml --cov-report term-missing [testenv:integration] basepython = python3.6 -commands = pytest -m integration tests/ +commands = pytest -m integration