diff --git a/.github/workflows/_pdm-publish.yml b/.github/workflows/_pdm-publish.yml new file mode 100644 index 0000000..d52ec42 --- /dev/null +++ b/.github/workflows/_pdm-publish.yml @@ -0,0 +1,13 @@ +on: + workflow_call: + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + - uses: pdm-project/setup-pdm@v3 + - run: pdm publish -u "__token__" -P "${{ secrets.PYPI_API_TOKEN }}" diff --git a/.github/workflows/_pre-commit-autoupdate.yml b/.github/workflows/_pre-commit-autoupdate.yml new file mode 100644 index 0000000..897f9cd --- /dev/null +++ b/.github/workflows/_pre-commit-autoupdate.yml @@ -0,0 +1,27 @@ +on: + workflow_call: + schedule: + - cron: "0 0 * * *" + +jobs: + auto-update: + # browniebroke/pre-commit-autoupdate-action + runs-on: ubuntu-latest + + permissions: + contents: write + pull-requests: write + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - run: python -m pip install pre-commit + - run: pre-commit autoupdate --freeze + - run: pre-commit run -a + - uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: pre-commit-autoupdate + title: Update pre-commit hooks + commit-message: "chore: update pre-commit hooks" + body: Update versions of pre-commit hooks to latest version. diff --git a/.github/workflows/_pre-commit.yml b/.github/workflows/_pre-commit.yml new file mode 100644 index 0000000..f33f179 --- /dev/null +++ b/.github/workflows/_pre-commit.yml @@ -0,0 +1,10 @@ +on: + workflow_call: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/_python-semantic-release.yml b/.github/workflows/_python-semantic-release.yml new file mode 100644 index 0000000..fad7704 --- /dev/null +++ b/.github/workflows/_python-semantic-release.yml @@ -0,0 +1,25 @@ +on: + workflow_call: + +jobs: + release: + runs-on: ubuntu-latest + + concurrency: + group: python-semantic-release + # cancel-in-progress: true + + permissions: + # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#defining-access-for-the-github_token-scopes + contents: write + + defaults: + run: + working-directory: ./ + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: python-semantic-release/python-semantic-release@v8.7.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml new file mode 100644 index 0000000..88aad1b --- /dev/null +++ b/.github/workflows/_test.yml @@ -0,0 +1,30 @@ +on: + workflow_call: + +jobs: + test: + strategy: + fail-fast: false + matrix: + # https://github.com/actions/runner-images#available-images + os: [ubuntu-latest] + py_ver: + - "3.12" + - "3.11" + - "3.10" + - "3.9" + - "3.8" + pw_browser: [chromium] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - uses: pdm-project/setup-pdm@v4 + with: + python-version: ${{ matrix.py_ver }} + cache: true + cache-dependency-path: "**/pdm.lock" + - run: pdm install + - run: pdm list --graph + - run: pdm run playwright install --with-deps ${{ matrix.pw_browser }} + - run: pdm run pytest --browser=${{ matrix.pw_browser }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 233b2cb..1c58d87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,79 +1,21 @@ -name: main - on: - pull_request_review: push: - branches: - - "*" + pull_request: jobs: - test: - # if: false + # permissions -> https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions - strategy: - matrix: - os: [ubuntu-latest] - py_ver: - - "3.12" - - "3.11" - - "3.10" - - "3.9" - - "3.8" - pw_browser: [chromium] - runs-on: ${{ matrix.os }} + test: + uses: ./.github/workflows/_test.yml - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.py_ver }} - - uses: pdm-project/setup-pdm@v3 - - run: pdm install - - run: pdm list --graph - - run: pdm run playwright install --with-deps ${{ matrix.pw_browser }} - - run: pdm run pytest --browser=${{ matrix.pw_browser }} + pre-commit: + uses: ./.github/workflows/_pre-commit.yml - release: # https://github.com/python-semantic-release/python-semantic-release/blob/master/.github/workflows/main.yml + python-semantic-release: if: ${{ github.ref == 'refs/heads/master' }} - needs: - - test - - strategy: - matrix: - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} - - concurrency: release + uses: ./.github/workflows/_python-semantic-release.yml permissions: - id-token: write contents: write - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: python-semantic-release/python-semantic-release@v8.7.2 - id: release - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - root_options: "-vv" - - # https://python-semantic-release.readthedocs.io/en/latest/migrating_from_v7.html - - - name: Publish package distributions to PyPI - id: pypi-publish - if: steps.release.outputs.released == 'true' - uses: pypa/gh-action-pypi-publish@release/v1 - with: - verbose: true - user: ${{ secrets.PYPI_USERNAME }} - password: ${{ secrets.PYPI_PASSWORD }} - - - name: Publish package distributions to GitHub Releases - id: github-release - if: steps.release.outputs.released == 'true' - uses: python-semantic-release/upload-to-gh-release@main - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ steps.release.outputs.tag }} + needs: + - test + - pre-commit diff --git a/.github/workflows/post-main.yml b/.github/workflows/post-main.yml new file mode 100644 index 0000000..f444c29 --- /dev/null +++ b/.github/workflows/post-main.yml @@ -0,0 +1,29 @@ +on: + workflow_run: + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run + workflows: + - .github/workflows/main.yml + types: + - completed + +jobs: + is-success: + if: ${{ github.ref == 'refs/heads/master' }} && ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + steps: + - run: echo "is-success" + + pre-commit-autoupdate: + uses: ./.github/workflows/_pre-commit-autoupdate.yml + permissions: + contents: write + pull-requests: write + + pdm-publish: + needs: + - is-success + uses: ./.github/workflows/_pdm-publish.yml + permissions: + contents: read + id-token: write + secrets: inherit diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e227629..1bf5d4f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,33 +1,47 @@ +# fail_fast: true + exclude: | (?x)^( + .*/migrations/.*| CHANGELOG.md )$ repos: - ### PYTHON + ### LOCAL - - repo: https://github.com/pre-commit/mirrors-mypy - rev: 8cd2d4056637e242709fe09f15a36f0b4b682bda # frozen: v1.8.0 + - repo: local hooks: - - id: mypy - language_version: python3.9 - # additional_dependencies: - # - types-all - # args: - # - --explicit-package-bases + - id: sh -c + name: sh -c + entry: sh -c + args: + - echo "pre-commit!" + language: system + require_serial: true + # verbose: true + + ### PYTHON - repo: https://github.com/psf/black - rev: e026c93888f91a47a9c9f4e029f3eb07d96375e6 # frozen: 24.1.1 + rev: 6fdf8a4af28071ed1d079c01122b34c5d587207a # frozen: 24.2.0 hooks: # https://black.readthedocs.io/en/stable/integrations/source_version_control.html - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 1bd02b3569e3ac5cc66552b1336a96a8880d1bae # frozen: v0.2.1 + rev: cc575a3e5800b42ffbb5182b53d87203b2c4fc26 # frozen: v0.2.2 hooks: # https://beta.ruff.rs/docs/installation-and-usage/#usage - id: ruff + - repo: https://github.com/pre-commit/mirrors-mypy + rev: "8cd2d4056637e242709fe09f15a36f0b4b682bda" # frozen: v1.8.0 + hooks: + - id: mypy + additional_dependencies: [types-all] + args: + - --explicit-package-bases + - repo: https://github.com/asottile/pyupgrade - rev: 1bbebc88c6925a4e56fd5446b830b12c38c1c24a # frozen: v3.15.0 + rev: df17dfa3911b81b4a27190b0eea5b1debc7ffa0a # frozen: v3.15.1 hooks: - id: pyupgrade @@ -40,20 +54,10 @@ repos: - id: python-use-type-annotations - id: text-unicode-replacement-char - ### MD - - - repo: https://github.com/igorshubovych/markdownlint-cli - rev: c9ea83146232fb263effdfe6f222d87f5395b27a # frozen: v0.39.0 - hooks: - - id: markdownlint-fix - args: - - --disable=line-length - - --disable=no-inline-html - ### MISC - repo: https://github.com/crate-ci/typos - rev: c9a8c2e546451910cab4b467188a6c4e18a1743d # frozen: v1.18.1 + rev: 15c3fd95cb1c654bec86ec94bef057cc08a1c1c1 # frozen: typos-v0.10.21 hooks: - id: typos @@ -75,15 +79,15 @@ repos: - id: check-builtin-literals # requires literal syntax when initializing empty or zero python builtin types. - id: check-case-conflict # checks for files that would conflict in case-insensitive filesystems. # - id: check-docstring-first # checks a common error of defining a docstring after code. - # - id: check-executables-have-shebangs # ensures that (non-binary) executables have a shebang. - # - id: check-json # checks json files for parseable syntax. + - id: check-executables-have-shebangs # ensures that (non-binary) executables have a shebang. + - id: check-json # checks json files for parseable syntax. - id: check-shebang-scripts-are-executable # ensures that (non-binary) files with a shebang are executable. - # - id: pretty-format-json # sets a standard for formatting json files. - # args: - # - --autofix - # - --indent=2 - # - --no-sort-keys - # - --no-ensure-ascii + - id: pretty-format-json # sets a standard for formatting json files. + args: + - --autofix + - --indent=2 + - --no-sort-keys + - --no-ensure-ascii - id: check-merge-conflict # checks for files that contain merge conflict strings. # - id: check-symlinks # checks for symlinks which do not point to anything. - id: check-toml # checks toml files for parseable syntax. diff --git a/pyproject.toml b/pyproject.toml index 2985830..4d2799a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,27 +1,24 @@ [project] -authors = [{ name = "m9810223", email = "m9810223@gmail.com" }] +name = "pytest-playwright-async" +version = "0.10.0" +requires-python = ">=3.8,<3.13" dependencies = [ - "pytest-playwright>=0.3.3,<=0.4.4", # https://pypi.org/project/pytest-playwright/ - "pytest-asyncio==0.20.3", # https://github.com/microsoft/playwright-python/blob/main/local-requirements.txt + "pytest-playwright>=0.3.3,<=0.4.4", # https://pypi.org/project/pytest-playwright/ + "pytest-asyncio==0.20.3", # https://github.com/microsoft/playwright-python/blob/main/local-requirements.txt ] description = "ASYNC Pytest plugin for Playwright" license = { text = "MIT" } -name = "pytest-playwright-async" readme = "README.md" -requires-python = ">=3.8,<3.13" -version = "0.10.0" + +[project.entry-points.pytest11] +playwright_async = "pytest_playwright_async" [project.urls] Homepage = "https://github.com/m9810223/playwright-async-pytest" Source = "https://github.com/m9810223/playwright-async-pytest" -[tool.semantic_release] -# https://python-semantic-release.readthedocs.io/en/latest/configuration.html -build_command = "pip install pdm && pdm build" -version_toml = ["pyproject.toml:project.version"] - -[project.entry-points.pytest11] -playwright_async = "pytest_playwright_async" +[tool.pdm] +distribution = true [tool.pdm.dev-dependencies] dev = ["pytest>=7.4.0", "ipython>=8.12.2", "nest-asyncio>=1.5.6"] @@ -29,36 +26,45 @@ dev = ["pytest>=7.4.0", "ipython>=8.12.2", "nest-asyncio>=1.5.6"] [tool.pdm.scripts] test = "pytest" -[tool.pytest.ini_options] -addopts = "--exitfirst --failed-first -r fEsxXp --disable-warnings --showlocals --tb=short" +[tool.semantic_release] +# https://python-semantic-release.readthedocs.io/en/latest/configuration.html +version_toml = ["pyproject.toml:project.version"] +version_variables = ["src/pytest_playwright_async/__version__.py:VERSION"] -[tool.black] # https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html +[tool.black] +# https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html line-length = 100 skip-string-normalization = true [tool.ruff] line-length = 100 -show-source = true fix = true show-fixes = true +output-format = "full" + +[tool.ruff.lint] extend-select = [ - "W", # pycodestyle Warning - "I", # isort - "N", # pep8-naming - "S", # flake8-bandit - "PGH", # pygrep-hooks - "TRY", # tryceratops + "W", # pycodestyle Warning + "I", # isort + "N", # pep8-naming + "S", # flake8-bandit + # "PTH", # flake8-use-pathlib + "PGH", # pygrep-hooks + "TRY", # tryceratops ] ignore = [ - "E501", # line-too-long - "S101", # Use of `assert` detected + "S101", # Use of `assert` detected ] [tool.ruff.lint.isort] # https://beta.ruff.rs/docs/settings/#isort -force-single-line = true lines-after-imports = 2 +force-single-line = true +force-sort-within-sections = true known-local-folder = [] [tool.mypy] ignore_missing_imports = true + +[tool.pytest.ini_options] +addopts = "--exitfirst --failed-first -r fEsxXp --disable-warnings --showlocals --tb=short" diff --git a/src/pytest_playwright_async/__init__.py b/src/pytest_playwright_async/__init__.py index 52a9fc8..95b9a64 100644 --- a/src/pytest_playwright_async/__init__.py +++ b/src/pytest_playwright_async/__init__.py @@ -2,8 +2,6 @@ import sys import typing as t -import pytest -import pytest_asyncio from playwright.async_api import Browser from playwright.async_api import BrowserContext from playwright.async_api import BrowserType @@ -11,6 +9,8 @@ from playwright.async_api import Page from playwright.async_api import Playwright from playwright.async_api import async_playwright +import pytest +import pytest_asyncio from pytest_playwright.pytest_playwright import VSCODE_PYTHON_EXTENSION_ID from pytest_playwright.pytest_playwright import _build_artifact_test_folder from pytest_playwright.pytest_playwright import _is_debugger_attached diff --git a/src/pytest_playwright_async/__version__.py b/src/pytest_playwright_async/__version__.py new file mode 100644 index 0000000..ea301cb --- /dev/null +++ b/src/pytest_playwright_async/__version__.py @@ -0,0 +1 @@ +VERSION = '0.10.0' diff --git a/tests/test_playwright.py b/tests/test_playwright.py index c85f8f6..eb5321b 100644 --- a/tests/test_playwright.py +++ b/tests/test_playwright.py @@ -1,12 +1,12 @@ import typing as t -import pytest from playwright.async_api import Browser from playwright.async_api import BrowserContext from playwright.async_api import BrowserType from playwright.async_api import Page from playwright.async_api import Playwright from playwright.async_api import async_playwright +import pytest URL = 'https://playwright.dev/'