diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..631ac4e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ + + + + + +## Change Summary + + + +## Related issue number + + + + +## Checklist + +* [ ] Commit message and PR title is comprehensive +* [ ] Keep the change as small as possible +* [ ] Unit and integration tests for the changes exist +* [ ] Tests pass on CI and coverage does not decrease +* [ ] Documentation reflects the changes where applicable +* [ ] `docs/changelog/next_release/..rst` file added describing change + (see [CONTRIBUTING.rst](https://github.com/MobileTeleSystems/evacuator/blob/develop/CONTRIBUTING.rst) for details.) +* [ ] My PR is ready to review. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6b89502 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# Set update schedule for GitHub Actions + +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + labels: + - type:ci + # https://til.simonwillison.net/github/dependabot-python-setup + groups: + github-actions: + patterns: + - '*' diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..805320f --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,61 @@ +# config for https://github.com/marketplace/actions/github-labeler + + - name: attention:help wanted + description: Extra attention is needed + color: bfdadc + from_name: help wanted + + - name: attention:invalid + description: This doesn't seem right + color: ea2357 + from_name: invalid + + - name: ci:skip-changelog + description: Add this label to skip changelog file check + color: 04990f + + - name: kind:bug + description: Something isn't working + color: d73a4a + from_name: bug + + - name: kind:feature + description: New feature or request + color: 389a3f + + - name: kind:improvement + description: Improvement of some existing feature + color: 1a92c2 + from_name: enhancement + + - name: kind:question + description: Further information is requested + color: 0e857c + from_name: question + + - name: resolution:duplicate + description: This issue or pull request already exists + color: cfd3d7 + from_name: duplicate + + - name: resolution:wontfix + description: This will not be worked on + color: ec103b + from_name: wontfix + + - name: type:ci + description: CI-related changes + color: cdb0bd + + - name: type:dependency + description: Dependency-related changes + color: 214efe + + - name: type:documentation + description: Improvements or additions to documentation + color: 6b9f54 + from_name: documentation + + - name: type:tests + description: Tests-related changes + color: 5cca5b diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000..40bec67 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,27 @@ +name: Automerge + +on: + pull_request_target: + +jobs: + automerge: + name: Enable pull request automerge + runs-on: ubuntu-latest + if: github.event.pull_request.user.login == 'pre-commit-ci[bot]' || github.event.pull_request.user.login == 'dependabot[bot]' + + steps: + - uses: alexwilson/enable-github-automerge-action@2.0.0 + with: + github-token: ${{ secrets.AUTOMERGE_TOKEN }} + merge-method: REBASE + + autoapprove: + name: Automatically approve pull request + needs: [automerge] + runs-on: ubuntu-latest + if: github.event.pull_request.user.login == 'pre-commit-ci[bot]' || github.event.pull_request.user.login == 'dependabot[bot]' + + steps: + - uses: hmarr/auto-approve-action@v4 + with: + github-token: ${{ secrets.AUTOMERGE_TOKEN }} diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..deedcc6 --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,62 @@ +name: Changelog + +on: + pull_request: + types: [opened, synchronize, labeled, unlabeled, reopened] + branches-ignore: + - master + +env: + DEFAULT_PYTHON: '3.12' + +permissions: + contents: read + +jobs: + check-changelog: + name: Changelog Entry Check + runs-on: ubuntu-latest + timeout-minutes: 10 + if: "!contains(github.event.pull_request.labels.*.name, 'ci:skip-changelog') && github.event.pull_request.user.login != 'pre-commit-ci[bot]' && github.event.pull_request.user.login != 'dependabot[bot]'" + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + id: python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-changelog-${{ hashFiles('requirements-docs.txt') }} + restore-keys: | + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-changelog-${{ hashFiles('requirements-docs.txt') }} + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-changelog- + + - name: Upgrade pip + run: python -m pip install --upgrade pip setuptools wheel + + - name: Install dependencies + run: | + pip install -I requirements-docs.txt + + - name: Check changelog entry exists + run: | + if [ ! -s docs/changelog/next_release/${{ github.event.pull_request.number }}.*.rst ]; then + echo "Please add corresponding file 'docs/changelog/next_release/..rst' with changes description" + exit 1 + fi + + - name: Validate changelog + run: | + # Fetch the pull request' base branch so towncrier will be able to + # compare the current branch with the base branch. + git fetch --no-tags origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} + towncrier check --compare-with origin/${{ github.base_ref }} + towncrier --draft diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index f1d3b5a..bcc665f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -3,16 +3,20 @@ name: Code analysis on: push: branches: - - develop + - develop pull_request: branches-ignore: - - master + - master workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true +env: + # flake8-commas is failing on Python 3.12 + DEFAULT_PYTHON: '3.11' + jobs: linters: name: Linters @@ -23,41 +27,41 @@ jobs: security-events: write steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-python-3.11-codeql-${{ hashFiles('requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-python-3.11-codeql-${{ hashFiles('requirements*.txt') }} - ${{ runner.os }}-python-3.11-codeql- - ${{ runner.os }}-python - ${{ runner.os }}- - - - name: Upgrade pip - run: python -m pip install --upgrade pip setuptools wheel - - - name: Install dependencies - run: | - pip install -I -r requirements-dev.txt - - # Set the `CODEQL-PYTHON` environment variable to the Python executable - # that includes the dependencies - echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV - - - name: Run flake8 - run: python3 -m flake8 --config setup.cfg . - - - name: Run mypy - run: python3 -m mypy --config-file setup.cfg evacuator + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-codeql-${{ hashFiles('requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-codeql-${{ hashFiles('requirements*.txt') }} + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-codeql- + ${{ runner.os }}-python + ${{ runner.os }}- + + - name: Upgrade pip + run: python -m pip install --upgrade pip setuptools wheel + + - name: Install dependencies + run: | + pip install -I -r requirements-dev.txt + + # Set the `CODEQL-PYTHON` environment variable to the Python executable + # that includes the dependencies + echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV + + - name: Run flake8 + run: python3 -m flake8 --config setup.cfg . + + - name: Run mypy + run: python3 -m mypy --config-file setup.cfg evacuator codeql: name: CodeQL @@ -68,21 +72,21 @@ jobs: security-events: write steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: '3.11' + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.DEFAULT_PYTHON }} # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: python - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: /language:python + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: python + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: /language:python diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index c2ddb4b..dc17552 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -3,11 +3,14 @@ name: Dev release on: push: branches-ignore: - - dependabot/** - - pre-commit-ci-update-config - - master + - dependabot/** + - pre-commit-ci-update-config + - master workflow_dispatch: +env: + DEFAULT_PYTHON: '3.12' + concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true @@ -18,61 +21,31 @@ jobs: runs-on: ubuntu-latest if: github.repository == 'MobileTeleSystems/evacuator' # prevent running on forks - steps: - - uses: fountainhead/action-wait-for-check@v1.1.0 - id: wait-for-linters - with: - token: ${{ secrets.GITHUB_TOKEN }} - checkName: Linters - ref: ${{ github.sha }} - timeoutSeconds: 3600 - - - name: Fail the Build - uses: cutenode/action-always-fail@v1 - if: steps.wait-for-linters.outputs.conclusion != 'success' - - - uses: fountainhead/action-wait-for-check@v1.1.0 - id: wait-for-codeql - with: - token: ${{ secrets.GITHUB_TOKEN }} - checkName: CodeQL - ref: ${{ github.sha }} - timeoutSeconds: 3600 - - - name: Fail the Build - uses: cutenode/action-always-fail@v1 - if: steps.wait-for-codeql.outputs.conclusion != 'success' - - - uses: fountainhead/action-wait-for-check@v1.1.0 - id: wait-for-tests - with: - token: ${{ secrets.GITHUB_TOKEN }} - checkName: Tests done - ref: ${{ github.sha }} - timeoutSeconds: 3600 + environment: + name: test-pypi + url: https://test.pypi.org/p/evacuator + permissions: + id-token: write # to auth in Test PyPI - - name: Fail the Build - uses: cutenode/action-always-fail@v1 - if: steps.wait-for-tests.outputs.conclusion != 'success' - - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Upgrade pip - run: python -m pip install --upgrade pip setuptools wheel - - - name: Build package - run: python setup.py sdist bdist_wheel - - - name: Publish package - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository-url: https://test.pypi.org/legacy/ + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + id: python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + + - name: Upgrade pip + run: python -m pip install --upgrade pip setuptools wheel + + - name: Build package + run: python setup.py sdist bdist_wheel + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 006c6a3..fdf7971 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,10 @@ name: Release on: push: tags: - - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+' + +env: + DEFAULT_PYTHON: '3.12' jobs: release: @@ -11,24 +14,100 @@ jobs: runs-on: ubuntu-latest if: github.repository == 'MobileTeleSystems/evacuator' # prevent running on forks + environment: + name: pypi + url: https://pypi.org/p/evacuator + permissions: + id-token: write # to auth in PyPI + contents: write # to create Github release + steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Upgrade pip - run: python -m pip install --upgrade pip setuptools wheel - - - name: Build package - run: python setup.py sdist bdist_wheel - - - name: Publish package - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.PYPI_API_TOKEN }} + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + id: python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-release-${{ hashFiles('requirements-docs.txt') }} + restore-keys: | + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-release-${{ hashFiles('requirements-docs.txt') }} + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-release- + + - name: Upgrade pip + run: python -m pip install --upgrade pip setuptools wheel + + - name: Install dependencies + run: | + pip install -I -r requirements-docs.txt + + - name: Build package + run: python setup.py sdist bdist_wheel + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + + - name: Get changelog + run: | + cat docs/changelog/${{ github.ref_name }}.rst > changelog.rst + + - name: Prepare rST syntax for conversion to Markdown + run: | + # Replace Github links from Sphinx syntax with Markdown + sed -i -E 's/:github:issue:`(.*)`/#\1/g' changelog.rst + sed -i -E 's/:github:pull:`(.*)`/#\1/g' changelog.rst + sed -i -E 's/:github:user:`(.*)`/@\1/g' changelog.rst + sed -i -E 's/:github:org:`(.*)`/@\1/g' changelog.rst + + - name: Convert changelog to markdown + uses: docker://pandoc/core:2.9 + with: + args: >- + --output=changelog.md + --from=rst + --to=gfm + --wrap=none + changelog.rst + + - name: Fixing Markdown syntax after conversion + run: | + # Replace ``` {.python caption="abc"} with ```python caption="abc" + sed -i -E 's/``` \{\.(.*)\}/```\1/g' changelog.md + + # Replace ``` python with ```python + sed -i -E 's/``` (\w+)/```\1/g' changelog.md + + # Replace \# with # + sed -i -E 's/\\#/#/g' changelog.md + + - name: Get release name + id: release-name + run: | + # Release name looks like: 0.7.0 (2023-05-15) + echo -n name= > "$GITHUB_OUTPUT" + cat changelog.md | head -1 | sed -E "s/#+\s*//g" >> "$GITHUB_OUTPUT" + + - name: Fix headers + run: | + # Remove header with release name + sed -i -e '1,2d' changelog.md + + - name: Create Github release + id: create_release + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + draft: false + prerelease: false + name: ${{ steps.release-name.outputs.name }} + body_path: changelog.md + files: | + dist/* diff --git a/.github/workflows/repo-labels-sync.yml b/.github/workflows/repo-labels-sync.yml new file mode 100644 index 0000000..c0b1e4c --- /dev/null +++ b/.github/workflows/repo-labels-sync.yml @@ -0,0 +1,27 @@ +name: Repo labels sync + +on: + push: + branches: + - develop + paths: + - .github/labels.yml + - .github/workflows/repo-labels-sync.yml + pull_request: + paths: + - .github/labels.yml + - .github/workflows/repo-labels-sync.yml + +jobs: + labeler: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run Labeler + uses: crazy-max/ghaction-github-labeler@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + yaml-file: .github/labels.yml + dry-run: ${{ github.event_name == 'pull_request' }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7c07283..fe00cf2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,16 +2,19 @@ name: Tests on: push: branches: - - develop + - develop pull_request: branches-ignore: - - master + - master workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true +env: + DEFAULT_PYTHON: '3.12' + jobs: tests: name: Run tests (${{ matrix.python-version }} on ${{ matrix.os }}) @@ -19,53 +22,53 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.7', '3.11'] + python-version: ['3.7', '3.11', '3.12'] os: [ubuntu-latest] steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }} - ${{ runner.os }}-python-${{ matrix.python-version }}-tests- - ${{ runner.os }}-python - ${{ runner.os }}- - - - name: Upgrade pip - run: python -m pip install --upgrade pip setuptools wheel - - - name: Install dependencies - run: pip install -I -r requirements-test.txt - - - name: Build package - run: | - python setup.py --version - python setup.py bdist_wheel sdist - - - name: Run tests - run: | - mkdir reports/ || echo "Directory exists" - pip install -e . --no-build-isolation - ./pytest_runner.sh - - - name: Upload coverage results - uses: actions/upload-artifact@v3 - with: - name: coverage-${{ matrix.python-version }}-os-${{ matrix.os }} - path: reports/* + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }} + ${{ runner.os }}-python-${{ matrix.python-version }}-tests- + ${{ runner.os }}-python + ${{ runner.os }}- + + - name: Upgrade pip + run: python -m pip install --upgrade pip setuptools wheel + + - name: Install dependencies + run: pip install -I -r requirements-test.txt + + - name: Build package + run: | + python setup.py --version + python setup.py bdist_wheel sdist + + - name: Run tests + run: | + mkdir reports/ || echo "Directory exists" + pip install -e . --no-build-isolation + ./pytest_runner.sh + + - name: Upload coverage results + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.python-version }}-os-${{ matrix.os }} + path: reports/* all_done: name: Tests done @@ -73,48 +76,50 @@ jobs: needs: [tests] steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-python-3.11-coverage-${{ hashFiles('requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-python-3.11-coverage-${{ hashFiles('requirements*.txt') }} - ${{ runner.os }}-python-3.11-coverage- - ${{ runner.os }}-python - ${{ runner.os }}- - - - name: Upgrade pip - run: python -m pip install --upgrade pip setuptools wheel - - - name: Install dependencies - run: pip install -I -r requirements-test.txt - - - name: Download all coverage reports - uses: actions/download-artifact@v3 - with: - path: reports - - - name: Move coverage data to the root folder - run: find reports -type f -exec mv '{}' reports \; - - - name: Generate coverate reports - run: ./combine_coverage.sh - - - name: Check coverage - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - directory: ./reports - fail_ci_if_error: true - - - name: All done - run: echo 1 + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python ${{ env. DEFAULT_PYTHON }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-coverage-${{ hashFiles('requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-coverage-${{ hashFiles('requirements*.txt') }} + ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-coverage- + ${{ runner.os }}-python + ${{ runner.os }}- + + - name: Upgrade pip + run: python -m pip install --upgrade pip setuptools wheel + + - name: Install dependencies + run: pip install -I -r requirements-test.txt + + - name: Download all coverage reports + uses: actions/download-artifact@v4 + with: + path: reports + + - name: Move coverage data to the root folder + run: find reports -type f -exec mv '{}' reports \; + + - name: Generate coverate reports + run: ./combine_coverage.sh + + - name: Check coverage + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./reports/coverage.xml + fail_ci_if_error: true + # TODO: remove after fixing https://github.com/codecov/codecov-cli/issues/367 + plugin: gcov + + - name: All done + run: echo 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bab8c15..3ee4eec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,87 +1,128 @@ +default_language_version: + python: python3.11 + repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 - hooks: - - id: check-ast - - id: check-case-conflict - - id: check-docstring-first - - id: check-merge-conflict - - id: check-toml - - id: check-vcs-permalinks - - id: check-yaml - - id: requirements-txt-fixer - files: ^(requirements.*\.txt)$ - - id: end-of-file-fixer - exclude: ^.*/VERSION$ - - id: fix-byte-order-marker - - id: fix-encoding-pragma - args: [--remove] - - id: name-tests-test - files: ^tests/.*\.py$ - args: [--django] - - id: trailing-whitespace -- repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.1 - hooks: - - id: remove-tabs - exclude: ^docs/(make.bat|Makefile) -- repo: https://github.com/codespell-project/codespell - rev: v2.2.4 - hooks: - - id: codespell - args: [-w] -- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.9.0 - hooks: - - id: pretty-format-yaml - args: [--autofix, --indent, '2'] -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort -- repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.10.0 - hooks: - - id: python-no-log-warn - - id: python-no-eval - - id: rst-backticks - - id: rst-directive-colons - - id: rst-inline-touching-normal - - id: text-unicode-replacement-char -- repo: https://github.com/asottile/pyupgrade - rev: v3.4.0 - hooks: - - id: pyupgrade - args: [--py37-plus, --keep-runtime-typing] -- repo: https://github.com/ambv/black - rev: 23.3.0 - hooks: - - id: black - language_version: python3 -- repo: https://github.com/asottile/blacken-docs - rev: 1.13.0 - hooks: - - id: blacken-docs -- repo: meta - hooks: - - id: check-hooks-apply - - id: check-useless-excludes -- repo: local - hooks: - - id: flake8 - name: flake8 - entry: python3 -m flake8 . - language: system - types: [python] - pass_filenames: false - - id: mypy - name: mypy - entry: python3 -m mypy --config-file setup.cfg evacuator - language: system - types: [python] - pass_filenames: false + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-ast + - id: check-case-conflict + - id: check-docstring-first + - id: check-merge-conflict + - id: check-toml + - id: check-vcs-permalinks + - id: check-yaml + - id: requirements-txt-fixer + files: ^(requirements.*\.txt)$ + - id: end-of-file-fixer + exclude: ^.*/VERSION$ + - id: fix-byte-order-marker + - id: fix-encoding-pragma + args: [--remove] + - id: name-tests-test + files: ^tests/.*\.py$ + args: [--django] + - id: trailing-whitespace + + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.5 + hooks: + - id: forbid-tabs + - id: remove-tabs + args: [--whitespaces-count, '2'] + - id: chmod + args: ['644'] + exclude_types: [shell] + - id: chmod + args: ['755'] + types: [shell] + - id: insert-license + files: .*\.py$ + exclude: ^(setup\.py|docs/.*\.py|tests/.*\.py)$ + args: + - --license-filepath + - .spdx-license-header.txt + - --use-current-year + - --no-extra-eol + + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + args: [-w] + + - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.12.0 + hooks: + - id: pretty-format-yaml + args: [--autofix, --indent, '2', --offset, '2'] + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: python-no-log-warn + - id: python-no-eval + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + - id: text-unicode-replacement-char + + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.1 + hooks: + - id: pyupgrade + args: [--py37-plus, --keep-runtime-typing] + + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.3.0 + hooks: + - id: black + language_version: python3 + + - repo: https://github.com/asottile/blacken-docs + rev: 1.16.0 + hooks: + - id: blacken-docs + additional_dependencies: + - black==24.3.0 + + - repo: https://github.com/pycqa/bandit + rev: 1.7.8 + hooks: + - id: bandit + args: + - --aggregate=file + - -iii + - -ll + require_serial: true + + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + + - repo: local + hooks: + - id: flake8 + name: flake8 + entry: python3 -m flake8 . + language: system + types: [python] + pass_filenames: false + - id: mypy + name: mypy + entry: python3 -m mypy --config-file setup.cfg evacuator + language: system + types: [python] + pass_filenames: false ci: skip: - - flake8 # checked with Github Actions - - mypy # checked with Github Actions + - flake8 # checked with Github Actions + - mypy # checked with Github Actions + - chmod # failing in pre-commit.ci diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 8afe6de..655c9c1 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,8 +1,12 @@ version: 2 +build: + os: ubuntu-22.04 + tools: + python: '3.12' + python: - version: '3.7' install: - - requirements: requirements-docs.txt - - method: pip - path: . + - requirements: requirements-docs.txt + - method: pip + path: . diff --git a/.spdx-license-header.txt b/.spdx-license-header.txt new file mode 100644 index 0000000..5c16162 --- /dev/null +++ b/.spdx-license-header.txt @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2022-2024 MTS (Mobile Telesystems) +SPDX-License-Identifier: Apache-2.0 diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 18aa848..cdad053 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -6,11 +6,94 @@ reports, improving documentation, submitting feature requests, reviewing new submissions, or contributing code that can be incorporated into the project. -Please, don't use the issue tracker for support questions. Instead use: -`email `__. +Initial setup for local development +----------------------------------- -Feature Requests ----------------- +Install Git +~~~~~~~~~~~ + +Please follow `instruction `_. + +Create a fork +~~~~~~~~~~~~~ + +If you are not a member of a development team building Evacuator, you should create a fork before making any changes. + +Please follow `instruction `_. + +Clone the repo +~~~~~~~~~~~~~~ + +Open terminal and run these commands: + +.. code:: bash + + git clone git@github.com:myuser/evacuator.git -b develop + + cd evacuator + +Setup environment +~~~~~~~~~~~~~~~~~ + +Create virtualenv and install dependencies: + +.. code:: bash + + # create virtual environment + python -m venv venv + source venv/bin/activate + pip install -U wheel + pip install -U pip setuptools + + # install requirements + pip install -U \ + -r requirements-dev.txt \ + -r requirements-docs.txt \ + -r requirements-test.txt + +Enable pre-commit hooks +~~~~~~~~~~~~~~~~~~~~~~~ + +Install pre-commit hooks: + +.. code:: bash + + pre-commit install --install-hooks + +Test pre-commit hooks run: + +.. code:: bash + + pre-commit run + +How to +------ + + +Run tests +~~~~~~~~~ + +.. code:: bash + + # run tests + pytest + + +Build documentation +~~~~~~~~~~~~~~~~~~~ + +Build documentation using Sphinx: + +.. code:: bash + + cd docs + make html + +Then open in browser ``docs/_build/index.html``. + + +Review process +-------------- Please create a new GitHub issue for any significant changes and enhancements that you wish to make. Provide the feature you would like @@ -24,26 +107,184 @@ benefits of the feature. Small Changes can directly be crafted and submitted to the GitHub Repository as a Pull Request. -Pull Request Process --------------------- - -1. Update the README.md with details of changes to the interface, - including new environment variables, exposed ports, proper file - locations, and container parameters. -2. Increase the version numbers in any examples files and the README.md - to the new version that this Pull Request would represent. The - versioning scheme we use is SemVer. -3. You may merge the Pull Request in once you have the sign-off of two - other developers, or if you do not have permission to do that, you - may request the second reviewer to merge it for you. We expect to - have a minimum of one approval from someone else on the core team. - -Review Process --------------- +Create pull request +~~~~~~~~~~~~~~~~~~~ + +Commit your changes: + +.. code:: bash + + git commit -m "Commit message" + git push + +Then open Github interface and `create pull request `_. +Please follow guide from PR body template. + +After pull request is created, it get a corresponding number, e.g. 123 (``pr_number``). + +Write release notes +~~~~~~~~~~~~~~~~~~~ + +``Evacuator`` uses `towncrier `_ +for changelog management. + +To submit a change note about your PR, add a text file into the +`docs/changelog/next_release <./next_release>`_ folder. It should contain an +explanation of what applying this PR will change in the way +end-users interact with the project. One sentence is usually +enough but feel free to add as many details as you feel necessary +for the users to understand what it means. + +**Use the past tense** for the text in your fragment because, +combined with others, it will be a part of the "news digest" +telling the readers **what changed** in a specific version of +the library *since the previous version*. + +You should also use +reStructuredText syntax for highlighting code (inline or block), +linking parts of the docs or external sites. +If you wish to sign your change, feel free to add ``-- by +:user:`github-username``` at the end (replace ``github-username`` +with your own!). + +Finally, name your file following the convention that Towncrier +understands: it should start with the number of an issue or a +PR followed by a dot, then add a patch type, like ``feature``, +``doc``, ``misc`` etc., and add ``.rst`` as a suffix. If you +need to add more than one fragment, you may add an optional +sequence number (delimited with another period) between the type +and the suffix. + +In general the name will follow ``..rst`` pattern, +where the categories are: + +- ``feature``: Any new feature +- ``bugfix``: A bug fix +- ``improvement``: An improvement +- ``doc``: A change to the documentation +- ``dependency``: Dependency-related changes +- ``misc``: Changes internal to the repo like CI, test and build changes + +A pull request may have more than one of these components, for example +a code change may introduce a new feature that deprecates an old +feature, in which case two fragments should be added. It is not +necessary to make a separate documentation fragment for documentation +changes accompanying the relevant code changes. + +Examples for adding changelog entries to your Pull Requests +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: rst + :caption: docs/changelog/next_release/1234.doc.1.rst + + Added a ``:github:user:`` role to Sphinx config -- by :github:user:`someuser` + +.. code-block:: rst + :caption: docs/changelog/next_release/2345.bugfix.rst + + Fixed behavior of ``WebDAV`` connector -- by :github:user:`someuser` + +.. code-block:: rst + :caption: docs/changelog/next_release/3456.feature.rst + + Added support of ``timeout`` in ``S3`` connector + -- by :github:user:`someuser`, :github:user:`anotheruser` and :github:user:`otheruser` + +.. tip:: + + See `pyproject.toml `_ for all available categories + (``tool.towncrier.type``). + +.. _Towncrier philosophy: + https://towncrier.readthedocs.io/en/stable/#philosophy + +How to skip change notes check? +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Just add ``ci:skip-changelog`` label to pull request. + +Release Process +^^^^^^^^^^^^^^^ + +Before making a release from the ``develop`` branch, follow these steps: + +0. Checkout to ``develop`` branch and update it to the actual state + +.. code:: bash + + git checkout develop + git pull -p + +1. Backup ``NEXT_RELEASE.rst`` + +.. code:: bash + + cp "docs/changelog/NEXT_RELEASE.rst" "docs/changelog/temp_NEXT_RELEASE.rst" + +2. Build the Release notes with Towncrier + +.. code:: bash + + VERSION=$(cat evacuator/VERSION) + towncrier build "--version=${VERSION}" --yes + +3. Change file with changelog to release version number + +.. code:: bash + + mv docs/changelog/NEXT_RELEASE.rst "docs/changelog/${VERSION}.rst" + +4. Remove content above the version number heading in the ``${VERSION}.rst`` file + +.. code:: bash + + awk '!/^.*towncrier release notes start/' "docs/changelog/${VERSION}.rst" > temp && mv temp "docs/changelog/${VERSION}.rst" + +5. Update Changelog Index + +.. code:: bash + + awk -v version=${VERSION} '/DRAFT/{print;print " " version;next}1' docs/changelog/index.rst > temp && mv temp docs/changelog/index.rst + +6. Restore ``NEXT_RELEASE.rst`` file from backup + +.. code:: bash + + mv "docs/changelog/temp_NEXT_RELEASE.rst" "docs/changelog/NEXT_RELEASE.rst" + +7. Commit and push changes to ``develop`` branch + +.. code:: bash + + git add . + git commit -m "Prepare for release ${VERSION}" + git push + +8. Merge ``develop`` branch to ``master``, **WITHOUT** squashing + +.. code:: bash + + git checkout master + git pull + git merge develop + git push + +9. Add git tag to the latest commit in ``master`` branch + +.. code:: bash + + git tag "$VERSION" + git push origin "$VERSION" + +10. Update version in ``develop`` branch **after release**: + +.. code:: bash + + git checkout develop -We keep pull requests open for a few days for multiple people to have -the chance to review/comment. + NEXT_VERSION=$(echo "$VERSION" | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.) + echo "$NEXT_VERSION" > evacuator/VERSION -After feedback has been given, we expect responses within two weeks. -After two weeks, we may close the pull request if it isn't showing any -activity. + git add . + git commit -m "Bump version" + git push diff --git a/LICENSE.txt b/LICENSE.txt index 67c4288..4c5708d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2023 MTS (Mobile Telesystems). All rights reserved. +Copyright 2022-2024 MTS (Mobile Telesystems). All rights reserved. Apache License Version 2.0, January 2004 diff --git a/README.rst b/README.rst index 892932e..3a2879e 100644 --- a/README.rst +++ b/README.rst @@ -3,13 +3,11 @@ Evacuator ========= -|Repo Status| |PyPI| |PyPI License| |PyPI Python Version| -|Documentation| |Build Status| |Coverage| +|Repo Status| |PyPI License| |PyPI Python Version| +|Documentation| |Build Status| |Coverage| |pre-commit.ci| .. |Repo Status| image:: https://www.repostatus.org/badges/latest/active.svg :target: https://github.com/MobileTeleSystems/evacuator -.. |PyPI| image:: https://img.shields.io/pypi/v/evacuator - :target: https://pypi.org/project/evacuator/ .. |PyPI License| image:: https://img.shields.io/pypi/l/evacuator.svg :target: https://github.com/MobileTeleSystems/evacuator/blob/develop/LICENSE.txt .. |PyPI Python Version| image:: https://img.shields.io/pypi/pyversions/evacuator.svg @@ -20,6 +18,8 @@ Evacuator :target: https://evacuator.readthedocs.io/en/stable/ .. |Coverage| image:: https://codecov.io/gh/MobileTeleSystems/evacuator/branch/develop/graph/badge.svg?token=CM6AQWY65P :target: https://codecov.io/gh/MobileTeleSystems/evacuator +.. |pre-commit.ci| image:: https://results.pre-commit.ci/badge/github/MobileTeleSystems/evacuator/develop.svg + :target: https://results.pre-commit.ci/latest/github/MobileTeleSystems/evacuator/develop What is Evacuator? ------------------ @@ -27,11 +27,13 @@ What is Evacuator? Decorator/context manager designed to catch a certain exception and exit with specific exit code. Designed to be used in `Apache Airflow `__ with: - * ``BashOperator`` - * ``SSHOperator`` - * ``DockerOperator`` - * ``KubernetesPodOperator`` - * any other operator which can handle process exit codes. + * `BashOperator `_ (`airflow>2.1`) + * `PythonVirtualenvOperator `_ (`airflow>=2.6`) + * `ExternalPythonOperator `_ (`airflow>=2.6`) + * `DockerOperator `_ (`apache-airflow-providers-docker>=3.5`) + * `KubernetesPodOperator `_ (`apache-airflow-providers-cncf-kubernetes>=6.1`) + * `SSHOperator `_ (`apache-airflow-providers-ssh>=3.10`) + * any other operator support skipping task when process is exited with some specific exit code (``skip_on_exit_code`` option) .. installation @@ -48,93 +50,3 @@ Documentation ------------- See https://evacuator.readthedocs.io/ - -.. contribution - -Contribution guide -------------------- - -See ``__ - -.. security - -Security -------------------- - -See ``__ - -.. develops - -Develop -------- - -Clone repo -~~~~~~~~~~ - -Clone repo: - -.. code:: bash - - git clone git@github.com:MobileTeleSystems/evacuator.git -b develop - - cd evacuator - -Setup environment -~~~~~~~~~~~~~~~~~ - -Create virtualenv: - -.. code:: bash - - python -m venv venv - source venv/bin/activate - pip install -U wheel - pip install -U pip setuptools - -Install dependencies for development: - -.. code:: bash - - # install linters, formatters, etc - pip install -U -r requirements-dev.txt - -Enable pre-commit hooks -~~~~~~~~~~~~~~~~~~~~~~~ - -Install pre-commit hooks: - -.. code:: bash - - pre-commit install --install-hooks - -Test pre-commit hooks run: - -.. code:: bash - - pre-commit run - -Run tests -~~~~~~~~~ - -.. code:: bash - - # install requirements for testing - pip install -U -r requirements-test.txt - - # run tests - pytest - -Build documentation -~~~~~~~~~~~~~~~~~~~ - -.. code:: bash - - # install requirements for documentation - pip install -U -r requirements-docs.txt - - cd docs - - # generate html documentation - make html - -Then open ``docs/_build/html/index.html`` file in browser. diff --git a/docs/changelog.rst b/docs/changelog.rst new file mode 100644 index 0000000..4d895f9 --- /dev/null +++ b/docs/changelog.rst @@ -0,0 +1,9 @@ +========= +Changelog +========= + +.. toctree:: + :maxdepth: 1 + :caption: Changelog + + changelog/index diff --git a/docs/changelog/1.0.1.rst b/docs/changelog/1.0.1.rst new file mode 100644 index 0000000..1c8a89b --- /dev/null +++ b/docs/changelog/1.0.1.rst @@ -0,0 +1,7 @@ +1.0.1 (2022-07-18) +------------------ + +Bug Fixes +^^^^^^^^^ + +- Fix flake8 warnings diff --git a/docs/changelog/1.0.2.rst b/docs/changelog/1.0.2.rst new file mode 100644 index 0000000..3f532cb --- /dev/null +++ b/docs/changelog/1.0.2.rst @@ -0,0 +1,7 @@ +1.0.2 (2023-02-27) +------------------ + +🎉 Evacuator is now open source 🎉 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +That was long road, but we finally did it! diff --git a/docs/changelog/1.0.3.rst b/docs/changelog/1.0.3.rst new file mode 100644 index 0000000..97e23df --- /dev/null +++ b/docs/changelog/1.0.3.rst @@ -0,0 +1,8 @@ +1.0.2 (2023-05-15) +------------------ + +Improvements +^^^^^^^^^^^^ + +- Change docs there to Furo +- Sync project structure and CI with onetl diff --git a/docs/changelog/1.0.4.rst b/docs/changelog/1.0.4.rst new file mode 100644 index 0000000..36e74a0 --- /dev/null +++ b/docs/changelog/1.0.4.rst @@ -0,0 +1,9 @@ +1.0.4 (2024-03-20) +================== + +Improvements +------------ + +- Added changelog. + + Changelog is generated from separated news files using `towncrier `_. diff --git a/docs/changelog/DRAFT.rst b/docs/changelog/DRAFT.rst new file mode 100644 index 0000000..d396f60 --- /dev/null +++ b/docs/changelog/DRAFT.rst @@ -0,0 +1 @@ +.. towncrier-draft-entries:: |release| [UNRELEASED] diff --git a/docs/changelog/NEXT_RELEASE.rst b/docs/changelog/NEXT_RELEASE.rst new file mode 100644 index 0000000..28a2621 --- /dev/null +++ b/docs/changelog/NEXT_RELEASE.rst @@ -0,0 +1 @@ +.. towncrier release notes start diff --git a/docs/changelog/index.rst b/docs/changelog/index.rst new file mode 100644 index 0000000..775814a --- /dev/null +++ b/docs/changelog/index.rst @@ -0,0 +1,9 @@ +.. toctree:: + :maxdepth: 1 + :caption: Changelog + + DRAFT + 1.0.4 + 1.0.3 + 1.0.2 + 1.0.1 diff --git a/docs/changelog/next_release/.keep b/docs/changelog/next_release/.keep new file mode 100644 index 0000000..e69de29 diff --git a/docs/conf.py b/docs/conf.py index 72bfc44..7ba4ecc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,13 +19,15 @@ from packaging import version as Version -sys.path.insert(0, os.fspath(Path(__file__).parent.parent.absolute())) +PROJECT_ROOT_DIR = Path(__file__).parent.parent.resolve() + +sys.path.insert(0, os.fspath(PROJECT_ROOT_DIR)) # -- Project information ----------------------------------------------------- project = "Evacuator" -copyright = "2023, ONEtools Team" -author = "ONEtools Team" +copyright = "2022-2024 MTS (Mobile Telesystems)" +author = "DataOps.ETL" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -48,11 +50,14 @@ "sphinx_copybutton", "sphinx.ext.autodoc", "sphinx.ext.autosummary", + "sphinx_toolbox.github", + "sphinxcontrib.towncrier", # provides `towncrier-draft-entries` directive ] numpydoc_show_class_members = False # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] +html_extra_path = ["robots.txt"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -91,3 +96,10 @@ # Output file base name for HTML help builder. htmlhelp_basename = "evacuator-doc" + +towncrier_draft_autoversion_mode = "draft" +towncrier_draft_include_empty = False +towncrier_draft_working_directory = PROJECT_ROOT_DIR + +github_username = "MobileTeleSystems" +github_repository = "evacuator" diff --git a/docs/develop.rst b/docs/develop.rst deleted file mode 100644 index d9ae1a8..0000000 --- a/docs/develop.rst +++ /dev/null @@ -1,2 +0,0 @@ -.. include:: ../README.rst - :start-after: develops diff --git a/docs/index.rst b/docs/index.rst index df8cc46..027dd95 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -22,6 +22,6 @@ :name: develop :hidden: - develop + changelog contributing security diff --git a/docs/make.bat b/docs/make.bat index 8084272..53ad1e8 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -5,7 +5,7 @@ pushd %~dp0 REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build + set SPHINXBUILD=sphinx-build ) set SOURCEDIR=. set BUILDDIR=_build @@ -14,15 +14,15 @@ if "%1" == "" goto help %SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.https://www.sphinx-doc.org/ - exit /b 1 + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 ) %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% diff --git a/docs/robots.txt b/docs/robots.txt new file mode 100644 index 0000000..dda0be5 --- /dev/null +++ b/docs/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Allow: /*/stable/ +Allow: /en/stable/ # Fallback for bots that don't understand wildcards +Disallow: / diff --git a/evacuator/VERSION b/evacuator/VERSION index e4c0d46..a6a3a43 100644 --- a/evacuator/VERSION +++ b/evacuator/VERSION @@ -1 +1 @@ -1.0.3 \ No newline at end of file +1.0.4 \ No newline at end of file diff --git a/evacuator/__init__.py b/evacuator/__init__.py index 1b61b81..ecaba91 100644 --- a/evacuator/__init__.py +++ b/evacuator/__init__.py @@ -1,17 +1,7 @@ -# Copyright 2023 MTS (Mobile Telesystems) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# SPDX-FileCopyrightText: 2022-2024 MTS (Mobile Telesystems) +# SPDX-License-Identifier: Apache-2.0 from evacuator.core import evacuator from evacuator.exception import NeedEvacuation from evacuator.version import __version__ + +__all__ = ["evacuator", "NeedEvacuation", "__version__"] diff --git a/evacuator/core.py b/evacuator/core.py index 2cac9ac..381fcc6 100644 --- a/evacuator/core.py +++ b/evacuator/core.py @@ -1,37 +1,27 @@ -# Copyright 2023 MTS (Mobile Telesystems) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# SPDX-FileCopyrightText: 2022-2024 MTS (Mobile Telesystems) +# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import logging import sys from dataclasses import dataclass from functools import wraps -from typing import Callable, NoReturn, Type +from typing import Callable, NoReturn, Type, TypeVar from evacuator.exception import NeedEvacuation logger = logging.getLogger(__name__) +T = TypeVar("T", bound=Callable) + ECANCELED = 125 def evacuator( - func: Callable | None = None, + func: T | None = None, exception: Type[Exception] | tuple[Type[Exception], ...] = NeedEvacuation, exit_code: int = ECANCELED, -): +) -> T | Callable[[T], T]: """Catch specific exception and exit with exit code. Can be used as either decorator or context manager diff --git a/evacuator/exception.py b/evacuator/exception.py index 3b31cee..47f9e1b 100644 --- a/evacuator/exception.py +++ b/evacuator/exception.py @@ -1,17 +1,4 @@ -# Copyright 2023 MTS (Mobile Telesystems) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - +# SPDX-FileCopyrightText: 2022-2024 MTS (Mobile Telesystems) +# SPDX-License-Identifier: Apache-2.0 class NeedEvacuation(RuntimeError): pass diff --git a/evacuator/version.py b/evacuator/version.py index ee0661f..c87df4d 100644 --- a/evacuator/version.py +++ b/evacuator/version.py @@ -1,17 +1,5 @@ -# Copyright 2023 MTS (Mobile Telesystems) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# SPDX-FileCopyrightText: 2022-2024 MTS (Mobile Telesystems) +# SPDX-License-Identifier: Apache-2.0 """ __version__ parameter required to be able to output to the console """ diff --git a/pyproject.toml b/pyproject.toml index 7e56421..080ac12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,3 +15,51 @@ ignore_missing_imports = true pretty = true show_error_codes = true strict_optional = true + +[tool.towncrier] +name = "Evacuator" +package = "evacuator" +filename = "docs/changelog/NEXT_RELEASE.rst" +directory = "docs/changelog/next_release/" +title_format = "{version} ({project_date})" +issue_format = ":github:pull:`{issue}`" + +[[tool.towncrier.type]] +directory = "breaking" +name = "Breaking Changes" +showcontent = true + +[[tool.towncrier.type]] +directory = "significant" +name = "Significant Changes" +showcontent = true + +[[tool.towncrier.type]] +directory = "feature" +name = "Features" +showcontent = true + +[[tool.towncrier.type]] +directory = "improvement" +name = "Improvements" +showcontent = true + +[[tool.towncrier.type]] +directory = "bugfix" +name = "Bug Fixes" +showcontent = true + +[[tool.towncrier.type]] +directory = "dependency" +name = "Dependencies" +showcontent = true + +[[tool.towncrier.type]] +directory = "doc" +name = "Doc only Changes" +showcontent = true + +[[tool.towncrier.type]] +directory = "misc" +name = "Misc" +showcontent = true diff --git a/requirements-docs.txt b/requirements-docs.txt index 2e1f6f1..4a64feb 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -1,8 +1,10 @@ furo +importlib-resources<6 numpydoc packaging sphinx sphinx-copybutton -# ReadTheDocs uses old OpenSSL version -# https://github.com/urllib3/urllib3/issues/2168 -urllib3<2.0 +sphinx-toolbox +sphinxcontrib-towncrier +towncrier +urllib3 diff --git a/setup.cfg b/setup.cfg index 33ad7bf..fb2bf7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -251,6 +251,8 @@ ignore = WPS601, # WPS604 Found incorrect node inside `class` body: pass WPS604, +# WPS410 Found wrong metadata variable: __all__ + WPS410 # http://flake8.pycqa.org/en/latest/user/options.html?highlight=per-file-ignores#cmdoption-flake8-per-file-ignores diff --git a/setup.py b/setup.py index 5942a77..8dc9168 100644 --- a/setup.py +++ b/setup.py @@ -29,24 +29,28 @@ def get_version(): description="Catch an exception and exit with an exit code", long_description=long_description, long_description_content_type="text/x-rst", - license="Apache License 2.0", + license="Apache-2.0", license_files=("LICENSE.txt",), url="https://github.com/MobileTeleSystems/evacuator", packages=find_packages(exclude=["docs", "docs.*", "tests", "tests.*"]), - author="ONEtools Team", + author="DataOps.ETL", author_email="onetools@mts.ru", python_requires=">=3.7", include_package_data=True, zip_safe=False, classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", - "Operating System :: OS Independent", + "Programming Language :: Python :: 3.12", + "Typing :: Typed", ], project_urls={ "Documentation": "https://evacuator.readthedocs.io", @@ -54,4 +58,5 @@ def get_version(): "CI/CD": "https://github.com/MobileTeleSystems/evacuator/actions", "Tracker": "https://github.com/MobileTeleSystems/evacuator/issues", }, + entry_points={"tricoder_package_spy.register": ["evacuator=evacuator"]}, )