diff --git a/.github/workflows/apply-pip-compile.yml b/.github/workflows/apply-pip-compile.yml index 6e21652..658f634 100644 --- a/.github/workflows/apply-pip-compile.yml +++ b/.github/workflows/apply-pip-compile.yml @@ -8,19 +8,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - uses: deargen/workflows/actions/apply-pip-compile@master with: - python-version-file: pyproject.toml - - name: Install uv - run: | - pip3 install uv - - name: Run uv pip compile and push - run: | - set +e # Do not exit shell on failure - bash scripts/compile_requirements.sh - git config user.name github-actions[bot] - git config user.email github-actions[bot]@users.noreply.github.com - git add . - git commit -m "build: update requirements using uv pip compile [skip ci]" - git push + pyproject-toml-file: pyproject.toml + requirements-in-dir: deps + requirements-out-dir: deps/lock + python-platforms: x86_64-manylinux_2_28,aarch64-apple-darwin,x86_64-apple-darwin,x86_64-pc-windows-msvc diff --git a/.github/workflows/apply-styles.yml b/.github/workflows/apply-styles.yml index c7f10f1..7108e5c 100644 --- a/.github/workflows/apply-styles.yml +++ b/.github/workflows/apply-styles.yml @@ -3,33 +3,17 @@ name: Apply ruff format, isort, and fixes on: workflow_dispatch: inputs: - ruff_select: + ruff-select: description: 'ruff select' default: I,D20,D21,UP00,UP032,UP034 - ruff_ignore: + ruff-ignore: description: 'ruff ignore' default: D212 jobs: - apply-ruff: - name: Apply ruff - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version-file: pyproject.toml - - name: Install ruff - run: | - pip3 install -r <(grep '^ruff==' deps/x86_64-unknown-linux-gnu/requirements_dev.txt) - - name: Run ruff and push - run: | - set +e # Do not exit shell on ruff failure - ruff --select=${{ github.event.inputs.ruff_select }} --ignore=${{ github.event.inputs.ruff_ignore }} --fix --unsafe-fixes . - ruff format . - git config user.name github-actions[bot] - git config user.email github-actions[bot]@users.noreply.github.com - git add . - git commit -m "style: ruff format, isort, fixes [skip ci]" - git push + ruff-format: + uses: deargen/workflows/.github/workflows/apply-ruff.yml@master + with: + ruff-select: ${{ github.event.inputs.ruff-select }} + ruff-ignore: ${{ github.event.inputs.ruff-ignore }} + ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt diff --git a/.github/workflows/check-pip-compile.yml b/.github/workflows/check-pip-compile.yml index 10fda1b..97b6e82 100644 --- a/.github/workflows/check-pip-compile.yml +++ b/.github/workflows/check-pip-compile.yml @@ -1,6 +1,15 @@ name: Check pip compile sync -on: [push, pull_request] +on: + push: + branches: + - main + - master + pull_request: + +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true jobs: check-pip-compile: @@ -8,42 +17,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: | - echo "python_version=$(python3 scripts/get_python_version.py)" >> "$GITHUB_OUTPUT" - pip3 install --user uv - id: get-python-version - - name: Set up Python - uses: actions/setup-python@v5 + - uses: deargen/workflows/actions/check-pip-compile@master with: - python-version: ${{ steps.get-python-version.outputs.python_version }} - - name: Install uv - run: | - pip3 install uv - - name: Generate lockfile and print diff - run: | - set +e # Do not exit shell on failure - - out=$(bash scripts/compile_requirements.sh 2> _stderr.txt) - exit_code=$? - err=$(<_stderr.txt) - - if [[ -n "$out" ]]; then - # Display the raw output in the step - echo "${out}" - # Display the Markdown output in the job summary - { echo "\`\`\`"; echo "${out}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY" - fi - if [[ -n "$err" ]]; then - echo "${err}" - { echo "\`\`\`"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY" - fi - - if [[ $exit_code -eq 0 ]]; then - # When the script fails, there are changes in requirements that are not compiled yet. - # Print the suggested changes. - { echo "\`\`\`diff"; git diff; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY" - exit 1 - fi - - # When the script fails, it means it does not have anything to compile. - exit 0 + pyproject-toml-file: pyproject.toml + requirements-in-dir: deps + requirements-out-dir: deps/lock + python-platforms: x86_64-manylinux_2_28,aarch64-apple-darwin,x86_64-apple-darwin,x86_64-pc-windows-msvc diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 52f1d2a..f895864 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,94 +1,37 @@ -name: Deploy a new version +name: Commit CHANGELOG.md, create a Release and deploy MkDocs on: workflow_dispatch: inputs: - version_tag: - description: 'Version tag' + version-tag: + description: Version tag required: true default: v0.1.0 - dry_run: + dry-run: + description: Dry run type: boolean - description: 'Dry run' default: false jobs: - deploy: + commit-changelog-and-release: + uses: deargen/workflows/.github/workflows/commit-changelog-and-release.yml@master + with: + version-tag: ${{ github.event.inputs.version-tag }} + dry-run: ${{ github.event.inputs.dry-run == true }} + changelog-path: docs/CHANGELOG.md + exclude-types: build,docs,style,other + + publish-to-pypi: runs-on: ubuntu-latest - environment: deploy - steps: - - uses: actions/checkout@v4 - - name: Push new version tag temporarily for changelog generation - run: | - git config user.name github-actions[bot] - git config user.email github-actions[bot]@users.noreply.github.com - git tag -a ${{ github.event.inputs.version_tag }} -m ${{ github.event.inputs.version_tag }} - git push --tags - - - name: (dry-run) Get CHANGELOG - if: ${{ github.event.inputs.dry_run == 'true' }} - id: changelog-dry-run - uses: requarks/changelog-action@v1.10.2 - with: - includeInvalidCommits: true - excludeTypes: build,docs,style,other - token: ${{ github.token }} - tag: ${{ github.event.inputs.version_tag }} - - - name: (dry-run) Display CHANGELOG - if: ${{ github.event.inputs.dry_run == 'true' }} - run: | - echo '${{ steps.changelog-dry-run.outputs.changes }}' - echo '${{ steps.changelog-dry-run.outputs.changes }}' > "$GITHUB_STEP_SUMMARY" - - - name: (dry-run) Remove temporary version tag - if: ${{ github.event.inputs.dry_run == 'true' }} - run: | - git tag -d ${{ github.event.inputs.version_tag }} - git push origin --delete ${{ github.event.inputs.version_tag }} - - - name: Update CHANGELOG - if: ${{ github.event.inputs.dry_run == 'false' }} - id: changelog - uses: requarks/changelog-action@v1.10.2 - with: - includeInvalidCommits: true - excludeTypes: build,docs,style,other - token: ${{ github.token }} - tag: ${{ github.event.inputs.version_tag }} - changelogFilePath: docs/CHANGELOG.md - - - name: Commit docs/CHANGELOG.md and update tag - if: ${{ github.event.inputs.dry_run == 'false' }} - run: | - git tag -d ${{ github.event.inputs.version_tag }} - git push origin --delete ${{ github.event.inputs.version_tag }} - git add docs/CHANGELOG.md - git commit -m "docs: update docs/CHANGELOG.md for ${{ github.event.inputs.version_tag }} [skip ci]" - git tag -a ${{ github.event.inputs.version_tag }} -m ${{ github.event.inputs.version_tag }} - git push - git push --tags - - - name: Create Release - if: ${{ github.event.inputs.dry_run == 'false' }} - uses: ncipollo/release-action@v1.14.0 - with: - allowUpdates: true - draft: false - makeLatest: true - name: ${{ github.event.inputs.version_tag }} - tag: ${{ github.event.inputs.version_tag }} - body: ${{ steps.changelog.outputs.changes }} - - name: Set up Python 3.11 - if: ${{ github.event.inputs.dry_run == 'false' }} + if: ${{ github.event.inputs.dry-run == 'false' }} uses: actions/setup-python@v4 with: python-version: 3.11 - name: Build and upload to PyPI - if: ${{ github.event.inputs.dry_run == 'false' }} + if: ${{ github.event.inputs.dry-run == 'false' }} run: | python -m pip install --upgrade pip pip3 install build twine diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 697f5d0..5641932 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,67 +1,19 @@ name: Linting -on: [push, pull_request] +on: + push: + branches: + - main + - master + pull_request: -jobs: - ruff: - name: ruff - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version-file: pyproject.toml - - name: Install ruff and requirements - run: | - pip3 install -r <(grep '^ruff==' deps/x86_64-unknown-linux-gnu/requirements_dev.txt) - - name: Run ruff (code annotation) - run: | - set +e # Do not exit shell on ruff failure - - ruff check --output-format=github - exit 0 - - name: Run ruff (summary) - run: | - set +e # Do not exit shell on ruff failure - - nonzero_exit=0 - files=$(find . -type f -name "*.py" | sort) - while read -r file; do - out=$(ruff check --force-exclude "$file" 2> ruff_stderr.txt) - exit_code=$? - err=$(> "$GITHUB_STEP_SUMMARY" - fi - if [[ -n "$err" ]]; then - echo "${err}" - { echo "\`\`\`python"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY" - fi - - out=$(ruff check --diff --force-exclude "$file" 2> ruff_stderr.txt) - err=$(> "$GITHUB_STEP_SUMMARY" - fi - if [[ -n "$err" ]]; then - echo "${err}" - { echo "\`\`\`python"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY" - fi - done <<< "$files" - - # Exit with the first non-zero exit-code returned by ruff - # or just zero if all passed - exit ${nonzero_exit} +jobs: + ruff-lint: + uses: deargen/workflows/.github/workflows/check-ruff.yml@master + with: + check-type: lint + ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt diff --git a/.github/workflows/styles.yml b/.github/workflows/styles.yml index c0af225..273ab74 100644 --- a/.github/workflows/styles.yml +++ b/.github/workflows/styles.yml @@ -1,74 +1,24 @@ name: Style checking -on: [push, pull_request] +on: + push: + branches: + - main + - master + pull_request: + +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true jobs: ruff-format: - name: ruff-format - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version-file: pyproject.toml - - name: Install ruff - run: | - pip3 install -r <(grep '^ruff==' deps/x86_64-unknown-linux-gnu/requirements_dev.txt) - - name: Run ruff format - run: | - set +e # Do not exit shell on black failure - out=$(ruff format --check --diff . 2> app_stderr.txt) - exit_code=$? - err=$(> "$GITHUB_STEP_SUMMARY" - - # Exit with the exit-code returned by ruff - exit ${exit_code} - + uses: deargen/workflows/.github/workflows/check-ruff.yml@master + with: + check-type: format + ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt ruff-isort: - name: ruff-isort - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version-file: pyproject.toml - - name: Install ruff - run: | - pip3 install -r <(grep '^ruff==' deps/x86_64-unknown-linux-gnu/requirements_dev.txt) - - name: Run ruff isort - run: | - set +e # Do not exit shell on app failure - out=$(ruff --select I --diff . 2> app_stderr.txt) - exit_code=$? - err=$(> "$GITHUB_STEP_SUMMARY" - - # Exit with the exit-code returned by ruff - exit ${exit_code} - - stylua: - name: StyLua - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Lint with stylua - uses: JohnnyMorganz/stylua-action@v2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - version: latest - args: --check . + uses: deargen/workflows/.github/workflows/check-ruff.yml@master + with: + check-type: isort + ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..76e33eb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,81 @@ +name: Tests + +on: + push: + branches: + - main + - master + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + pytest: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -el {0} # setup-miniconda requires bash + steps: + - uses: actions/checkout@v4 + - name: Setup conda + uses: deargen/workflows/actions/setup-conda-and-uv@master + - name: Cache Conda environment + id: cache-conda + uses: actions/cache@v4 + env: + cache-name: cache-conda + with: + path: ~/miniconda3/envs/test + key: ${{ runner.os }}-conda-${{ env.cache-name }}-${{ hashFiles('deps/lock/x86_64-manylinux_2_28/requirements_dev.txt') }} + # restore-keys: | + # ${{ runner.os }}-conda-${{ env.cache-name }}- + # ${{ runner.os }}-conda- + # ${{ runner.os }}- + - if: steps.cache-conda.outputs.cache-hit == 'true' + run: echo 'conda cache hit!' + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: ripgrep + version: 1.0 + - name: Install dependencies + if: steps.cache-conda.outputs.cache-hit != 'true' + run: | + # python -m pip install --upgrade pip + uv pip install -r deps/lock/x86_64-manylinux_2_28/requirements_dev.txt + uv pip install -e . + - name: Run pytest + uses: deargen/workflows/actions/run-pytest@master + + doctest: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -el {0} # setup-miniconda requires bash + steps: + - uses: actions/checkout@v4 + - name: Setup conda + uses: deargen/workflows/actions/setup-conda-and-uv@master + - name: Cache Conda environment + id: cache-conda + uses: actions/cache@v4 + env: + cache-name: cache-conda + with: + path: ~/miniconda3/envs/test + key: ${{ runner.os }}-conda-${{ env.cache-name }}-${{ hashFiles('deps/lock/x86_64-manylinux_2_28/requirements_dev.txt') }} + # restore-keys: | + # ${{ runner.os }}-conda-${{ env.cache-name }}- + # ${{ runner.os }}-conda- + # ${{ runner.os }}- + - if: steps.cache-conda.outputs.cache-hit == 'true' + run: echo 'conda cache hit!' + - name: Install dependencies + if: steps.cache-conda.outputs.cache-hit != 'true' + run: | + # python -m pip install --upgrade pip + uv pip install -r deps/lock/x86_64-manylinux_2_28/requirements_dev.txt + uv pip install -e . + - name: Run doctest + uses: deargen/workflows/actions/run-doctest@master diff --git a/deps/requirements.in b/deps/requirements.in index 363ab1c..9964292 100644 --- a/deps/requirements.in +++ b/deps/requirements.in @@ -1,4 +1,4 @@ -typer +typer>=0.12.4 tree-sitter>=0.22.0 tree-sitter-python; sys_platform != "darwin" or platform_machine != 'arm64' tree-sitter-python @ https://github.com/kiyoon/tree-sitter-python/releases/download/temp/tree_sitter_python-0.21.0-cp38-abi3-macosx_11_0_arm64.whl ; sys_platform == "darwin" and platform_machine == 'arm64' diff --git a/src/python_import/cli/main.py b/src/python_import/cli/main.py index e768e84..c35bb03 100644 --- a/src/python_import/cli/main.py +++ b/src/python_import/cli/main.py @@ -1,4 +1,4 @@ -# ruff: noqa: UP007, T201 +# ruff: noqa: T201 from __future__ import annotations import json