From 245db767888402612e65a1e68c5eec5d4021bf4e Mon Sep 17 00:00:00 2001 From: Dan Cardin Date: Wed, 15 Jun 2022 12:07:36 -0400 Subject: [PATCH] chore: Convert to github actions. --- .circleci/config.yml | 206 ------------------ .github/workflows/build.yml | 22 ++ .github/workflows/lint_and_test.yml | 104 +++++++++ poetry.lock | 32 ++- pyproject.toml | 2 + .../fixture/database/relational/generic.py | 12 +- 6 files changed, 165 insertions(+), 213 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/lint_and_test.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index b1a6ca60..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,206 +0,0 @@ -version: 2.1 - -executors: - python36: - docker: - - image: circleci/python:3.6 - - image: postgres:9.6.10-alpine - environment: - POSTGRES_DB: dev - POSTGRES_USER: user - POSTGRES_PASSWORD: password - - image: circleci/mongo:3.6.12 - command: "mongod --journal" - - image: redis:5.0.7 - - image: mysql:5.6 - environment: - MYSQL_DATABASE: dev - MYSQL_ROOT_PASSWORD: password - - python37: - docker: - - image: circleci/python:3.7 - - image: postgres:9.6.10-alpine - environment: - POSTGRES_DB: dev - POSTGRES_USER: user - POSTGRES_PASSWORD: password - - image: circleci/mongo:3.6.12 - command: "mongod --journal" - - image: redis:5.0.7 - - image: mysql:5.6 - environment: - MYSQL_DATABASE: dev - MYSQL_ROOT_PASSWORD: password - - python38: - docker: - - image: circleci/python:3.8 - - image: postgres:9.6.10-alpine - environment: - POSTGRES_DB: dev - POSTGRES_USER: user - POSTGRES_PASSWORD: password - - image: circleci/mongo:3.6.12 - command: "mongod --journal" - - image: redis:5.0.7 - - image: mysql:5.6 - environment: - MYSQL_DATABASE: dev - MYSQL_ROOT_PASSWORD: password - - publish: - docker: - - image: circleci/python:3.6 - -commands: - setup: - steps: - - checkout - - run: - name: Execute prerequisite setup - command: | - curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python - echo 'export PATH="$HOME/.poetry/bin:$PATH"' >> $BASH_ENV - - setup-python-base: - description: Install python dependencies - steps: - - setup - - restore_cache: - key: v1-{{ checksum "pyproject.toml" }}-{{ checksum "poetry.lock" }} - - run: - command: make install-base - - save_cache: - paths: - - /home/circleci/.cache/pypoetry/virtualenvs - key: v1-{{ checksum "pyproject.toml" }}-{{ checksum "poetry.lock" }} - - setup-python: - description: Install python dependencies - steps: - - setup - - restore_cache: - key: v1-{{ checksum "pyproject.toml" }}-{{ checksum "poetry.lock" }} - - run: - command: make install - - save_cache: - paths: - - /home/circleci/.cache/pypoetry/virtualenvs - key: v1-{{ checksum "pyproject.toml" }}-{{ checksum "poetry.lock" }} - - persist-coverage: - steps: - - persist_to_workspace: - root: . - paths: - - .coverage - - coverage.xml - - publish: - steps: - - attach_workspace: - at: . - - run: bash <(curl -s https://codecov.io/bash) - -jobs: - test-without-extras: - executor: python36 - steps: - - setup-python-base - - setup_remote_docker: - docker_layer_caching: true - - run: - command: poetry run make test-base - - persist-coverage - - test-python36: - executor: python36 - steps: - - setup-python - - setup_remote_docker: - docker_layer_caching: true - - attach_workspace: - at: . - - run: - command: poetry run make test - - persist-coverage - - test-python37: - executor: python37 - steps: - - setup-python - - setup_remote_docker: - docker_layer_caching: true - - run: - command: poetry run make test - - test-python38: - executor: python38 - steps: - - setup-python - - setup_remote_docker: - docker_layer_caching: true - - run: - command: poetry run make test - - test-pytest6: - executor: python38 - steps: - - setup-python - - setup_remote_docker: - docker_layer_caching: true - - run: pip install pytest==6.1.1 - - run: - command: poetry run make test - - test-sqlalchemy13: - executor: python38 - steps: - - setup-python - - setup_remote_docker: - docker_layer_caching: true - - run: pip install pytest==6.1.1 - - run: - command: | - pip install 'sqlalchemy==1.3' - poetry run make test - - lint: - executor: python36 - steps: - - setup-python - - run: - command: poetry run make lint - - publish: - executor: publish - steps: - - setup-python - - publish - - -workflows: - build_all: - jobs: - - test-without-extras - - test-python36: - requires: - - test-without-extras - - test-python37 - - test-python38 - - test-pytest6 - - test-sqlalchemy13 - - - publish: - requires: - - test-without-extras - - test-python36 - - test-python37 - - test-python38 - - test-pytest6 - - test-sqlalchemy13 - filters: - branches: - only: - - /^master$/ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..0961d83a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: CI +on: pull_request + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test-base: + uses: ./.github/workflows/lint_and_test.yml + with: + install: poetry install + lint: false + run: poetry run make test-base + python-versions: '["3.6"]' + + test: + uses: ./.github/workflows/lint_and_test.yml + with: + install: make install + run: poetry run make test + python-versions: '["3.6", "3.7", "3.8", "3.9", "3.10"]' diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml new file mode 100644 index 00000000..e51f6cda --- /dev/null +++ b/.github/workflows/lint_and_test.yml @@ -0,0 +1,104 @@ +name: Reusable lint and test workflow +on: + workflow_call: + inputs: + install: + required: false + type: string + default: make install + description: Command to run + run: + required: false + type: string + default: poetry run make test + description: Command to run + lint: + required: false + type: boolean + default: true + description: Whether to run linters + python-versions: + required: false + type: string + default: >- + ["3.9"] + description: The python versions to utilize in workflow. + sqlalchemy-versions: + required: false + type: string + default: >- + ["1.3", "1.4"] + description: The sqlalchemy versions to utilize in workflow. + +jobs: + test: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:9.6.10 + env: + POSTGRES_DB: dev + POSTGRES_USER: user + POSTGRES_PASSWORD: password + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + redis: + image: redis:5.0.7 + ports: + - 6379:6379 + mongo: + image: mongo:3.6.12 + ports: + - 27017:27017 + mysql: + image: mysql:5.6 + ports: + - 3306:3306 + env: + MYSQL_DATABASE: dev + MYSQL_ROOT_PASSWORD: password + + strategy: + fail-fast: false + matrix: + python-version: ${{fromJson(inputs.python-versions)}} + sqlalchemy-version: ${{fromJson(inputs.sqlalchemy-versions)}} + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Run image + uses: abatilo/actions-poetry@v2.0.0 + with: + poetry-version: 1.1.8 + + - name: Set up cache + uses: actions/cache@v2 + with: + path: ~/.cache/pypoetry/virtualenvs + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} + restore-keys: | + ${{ runner.os }}-poetry- + - name: Install dependencies + run: ${{ inputs.install }} + + - name: Install dependencies + run: pip install 'sqlalchemy==${{ matrix.sqlalchemy-version }}' + + - name: Run linters + run: poetry run make lint + + - if: ${{ inputs.lint }} + name: Run tests + run: ${{ inputs.run }} + + - name: Store test result artifacts + uses: actions/upload-artifact@v3 + with: + path: coverage.xml + + - name: Codecov + uses: codecov/codecov-action@v2 diff --git a/poetry.lock b/poetry.lock index 3c4d9543..a46d06fc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -824,6 +824,22 @@ category = "dev" optional = false python-versions = ">=3.6" +[[package]] +name = "types-dataclasses" +version = "0.6.5" +description = "Typing stubs for dataclasses" +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "types-filelock" +version = "3.2.7" +description = "Typing stubs for filelock" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "types-pymysql" version = "1.0.13" @@ -925,6 +941,7 @@ docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] [extras] +docker = ["docker", "filelock"] mongo = ["pymongo", "docker", "filelock"] mysql = ["pymysql", "docker", "filelock"] postgres = ["psycopg2", "docker", "filelock"] @@ -936,7 +953,7 @@ redshift = ["boto3", "moto", "sqlparse", "docker", "filelock"] [metadata] lock-version = "1.1" python-versions = ">=3.6, <4" -content-hash = "b5e1097b35bbf03596a20974dfbbb2881190e2f57187c90391ff16d3cd99e766" +content-hash = "f68d41f0d10bb833cba82670a8b77e64446b0185cff87c4536805ee72e735ce3" [metadata.files] appdirs = [ @@ -1165,6 +1182,7 @@ greenlet = [ {file = "greenlet-1.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:97e5306482182170ade15c4b0d8386ded995a07d7cc2ca8f27958d34d6736497"}, {file = "greenlet-1.1.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e6a36bb9474218c7a5b27ae476035497a6990e21d04c279884eb10d9b290f1b1"}, {file = "greenlet-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:abb7a75ed8b968f3061327c433a0fbd17b729947b400747c334a9c29a9af6c58"}, + {file = "greenlet-1.1.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b336501a05e13b616ef81ce329c0e09ac5ed8c732d9ba7e3e983fcc1a9e86965"}, {file = "greenlet-1.1.2-cp310-cp310-win_amd64.whl", hash = "sha256:14d4f3cd4e8b524ae9b8aa567858beed70c392fdec26dbdb0a8a418392e71708"}, {file = "greenlet-1.1.2-cp35-cp35m-macosx_10_14_x86_64.whl", hash = "sha256:17ff94e7a83aa8671a25bf5b59326ec26da379ace2ebc4411d690d80a7fbcf23"}, {file = "greenlet-1.1.2-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:9f3cba480d3deb69f6ee2c1825060177a22c7826431458c697df88e6aeb3caee"}, @@ -1177,6 +1195,7 @@ greenlet = [ {file = "greenlet-1.1.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f9d29ca8a77117315101425ec7ec2a47a22ccf59f5593378fc4077ac5b754fce"}, {file = "greenlet-1.1.2-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:21915eb821a6b3d9d8eefdaf57d6c345b970ad722f856cd71739493ce003ad08"}, {file = "greenlet-1.1.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eff9d20417ff9dcb0d25e2defc2574d10b491bf2e693b4e491914738b7908168"}, + {file = "greenlet-1.1.2-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:b8c008de9d0daba7b6666aa5bbfdc23dcd78cafc33997c9b7741ff6353bafb7f"}, {file = "greenlet-1.1.2-cp36-cp36m-win32.whl", hash = "sha256:32ca72bbc673adbcfecb935bb3fb1b74e663d10a4b241aaa2f5a75fe1d1f90aa"}, {file = "greenlet-1.1.2-cp36-cp36m-win_amd64.whl", hash = "sha256:f0214eb2a23b85528310dad848ad2ac58e735612929c8072f6093f3585fd342d"}, {file = "greenlet-1.1.2-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:b92e29e58bef6d9cfd340c72b04d74c4b4e9f70c9fa7c78b674d1fec18896dc4"}, @@ -1185,6 +1204,7 @@ greenlet = [ {file = "greenlet-1.1.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1e12bdc622676ce47ae9abbf455c189e442afdde8818d9da983085df6312e7a1"}, {file = "greenlet-1.1.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8c790abda465726cfb8bb08bd4ca9a5d0a7bd77c7ac1ca1b839ad823b948ea28"}, {file = "greenlet-1.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f276df9830dba7a333544bd41070e8175762a7ac20350786b322b714b0e654f5"}, + {file = "greenlet-1.1.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8c5d5b35f789a030ebb95bff352f1d27a93d81069f2adb3182d99882e095cefe"}, {file = "greenlet-1.1.2-cp37-cp37m-win32.whl", hash = "sha256:64e6175c2e53195278d7388c454e0b30997573f3f4bd63697f88d855f7a6a1fc"}, {file = "greenlet-1.1.2-cp37-cp37m-win_amd64.whl", hash = "sha256:b11548073a2213d950c3f671aa88e6f83cda6e2fb97a8b6317b1b5b33d850e06"}, {file = "greenlet-1.1.2-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:9633b3034d3d901f0a46b7939f8c4d64427dfba6bbc5a36b1a67364cf148a1b0"}, @@ -1193,6 +1213,7 @@ greenlet = [ {file = "greenlet-1.1.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e859fcb4cbe93504ea18008d1df98dee4f7766db66c435e4882ab35cf70cac43"}, {file = "greenlet-1.1.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:00e44c8afdbe5467e4f7b5851be223be68adb4272f44696ee71fe46b7036a711"}, {file = "greenlet-1.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec8c433b3ab0419100bd45b47c9c8551248a5aee30ca5e9d399a0b57ac04651b"}, + {file = "greenlet-1.1.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:2bde6792f313f4e918caabc46532aa64aa27a0db05d75b20edfc5c6f46479de2"}, {file = "greenlet-1.1.2-cp38-cp38-win32.whl", hash = "sha256:288c6a76705dc54fba69fbcb59904ae4ad768b4c768839b8ca5fdadec6dd8cfd"}, {file = "greenlet-1.1.2-cp38-cp38-win_amd64.whl", hash = "sha256:8d2f1fb53a421b410751887eb4ff21386d119ef9cde3797bf5e7ed49fb51a3b3"}, {file = "greenlet-1.1.2-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:166eac03e48784a6a6e0e5f041cfebb1ab400b394db188c48b3a84737f505b67"}, @@ -1201,6 +1222,7 @@ greenlet = [ {file = "greenlet-1.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b1692f7d6bc45e3200844be0dba153612103db241691088626a33ff1f24a0d88"}, {file = "greenlet-1.1.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7227b47e73dedaa513cdebb98469705ef0d66eb5a1250144468e9c3097d6b59b"}, {file = "greenlet-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7ff61ff178250f9bb3cd89752df0f1dd0e27316a8bd1465351652b1b4a4cdfd3"}, + {file = "greenlet-1.1.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:0051c6f1f27cb756ffc0ffbac7d2cd48cb0362ac1736871399a739b2885134d3"}, {file = "greenlet-1.1.2-cp39-cp39-win32.whl", hash = "sha256:f70a9e237bb792c7cc7e44c531fd48f5897961701cdaa06cf22fc14965c496cf"}, {file = "greenlet-1.1.2-cp39-cp39-win_amd64.whl", hash = "sha256:013d61294b6cd8fe3242932c1c5e36e5d1db2c8afb58606c5a67efce62c1f5fd"}, {file = "greenlet-1.1.2.tar.gz", hash = "sha256:e30f5ea4ae2346e62cedde8794a56858a67b878dd79f7df76a0767e356b1744a"}, @@ -1752,6 +1774,14 @@ typed-ast = [ {file = "typed_ast-1.5.2-cp39-cp39-win_amd64.whl", hash = "sha256:df05aa5b241e2e8045f5f4367a9f6187b09c4cdf8578bb219861c4e27c443db5"}, {file = "typed_ast-1.5.2.tar.gz", hash = "sha256:525a2d4088e70a9f75b08b3f87a51acc9cde640e19cc523c7e41aa355564ae27"}, ] +types-dataclasses = [ + {file = "types-dataclasses-0.6.5.tar.gz", hash = "sha256:c3226d0a93289f53aac7b55ced17fb18473e278247abdb8d85a8956f5fb4faa6"}, + {file = "types_dataclasses-0.6.5-py3-none-any.whl", hash = "sha256:2d6347ff290a17e802400ddc747c2e2c05f3d64dc4c29de9818dc497b808180a"}, +] +types-filelock = [ + {file = "types-filelock-3.2.7.tar.gz", hash = "sha256:0673a25b45725c5c45661fe3744c3d8058653a16e683f0ae4a74afb44a0cdef4"}, + {file = "types_filelock-3.2.7-py3-none-any.whl", hash = "sha256:ee0ee2b4ec3d491ebe71f7343e21435c3a07f910881275a94788cac42acf4339"}, +] types-pymysql = [ {file = "types-PyMySQL-1.0.13.tar.gz", hash = "sha256:6facc31e968e47a1755f50dcfbaec302145e8f802cb53a3103f99b9a5b72154d"}, {file = "types_PyMySQL-1.0.13-py3-none-any.whl", hash = "sha256:eac4efcee094bf0e93ff46cfefcae219401ddb8a114227055fc4c9e13f8dd1fb"}, diff --git a/pyproject.toml b/pyproject.toml index e4ebb990..ecf4bbcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,8 @@ types-six = "^1.16.0" types-PyMySQL = "^1.0.2" types-redis = "^3.5.6" sqlalchemy2-stubs = "^0.0.2-alpha.19" +types-filelock = "^3.2.7" +types-dataclasses = "^0.6.5" [tool.poetry.extras] docker = ['docker', 'filelock'] diff --git a/src/pytest_mock_resources/fixture/database/relational/generic.py b/src/pytest_mock_resources/fixture/database/relational/generic.py index e5a2ab04..7100c8d6 100644 --- a/src/pytest_mock_resources/fixture/database/relational/generic.py +++ b/src/pytest_mock_resources/fixture/database/relational/generic.py @@ -5,8 +5,6 @@ from sqlalchemy import MetaData, text from sqlalchemy.engine import Engine -from sqlalchemy.ext.asyncio.session import AsyncSession -from sqlalchemy.ext.declarative import DeclarativeMeta from sqlalchemy.orm import scoped_session, Session, sessionmaker from sqlalchemy.sql.ddl import CreateSchema from sqlalchemy.sql.schema import Table @@ -78,8 +76,8 @@ class StaticStatements(Statements): static_safe = True -StaticAction = Union[MetaData, DeclarativeMeta, Rows, StaticStatements] -Action = Union[MetaData, DeclarativeMeta, AbstractAction] +StaticAction = Union[MetaData, compat.sqlalchemy.DeclarativeMeta, Rows, StaticStatements] +Action = Union[MetaData, compat.sqlalchemy.DeclarativeMeta, AbstractAction] T = TypeVar("T", StaticAction, Action) @@ -136,6 +134,8 @@ def manage_sync(self): self.engine.dispose() async def manage_async(self, session=None): + from sqlalchemy.ext.asyncio.session import AsyncSession + engine = create_async_engine(self.engine.pmr_credentials) try: @@ -225,7 +225,7 @@ def normalize_actions(ordered_actions: Iterable[T]) -> Iterable[T]: unique_metadata: Set[MetaData] = set() normalized_actions: List[T] = [] for action in ordered_actions: - if isinstance(action, DeclarativeMeta): + if isinstance(action, compat.sqlalchemy.DeclarativeMeta): action = action.metadata normalized_actions.append(action) @@ -269,7 +269,7 @@ def bifurcate_actions(ordered_actions): def identify_matching_tables(metadata, table_specifier): - if isinstance(table_specifier, DeclarativeMeta): + if isinstance(table_specifier, compat.sqlalchemy.DeclarativeMeta): return [table_specifier.__table__] if isinstance(table_specifier, Table):