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/tests.yml b/.github/workflows/tests.yml index 4c0843d..76e33eb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,8 +1,15 @@ name: Tests on: - - push - - pull_request + push: + branches: + - main + - master + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: pytest: @@ -12,15 +19,8 @@ jobs: shell: bash -el {0} # setup-miniconda requires bash 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 - - uses: conda-incubator/setup-miniconda@v3 - with: - miniforge-version: latest - activate-environment: test - python-version: ${{ steps.get-python-version.outputs.python_version }} + - name: Setup conda + uses: deargen/workflows/actions/setup-conda-and-uv@master - name: Cache Conda environment id: cache-conda uses: actions/cache@v4 @@ -28,7 +28,7 @@ jobs: cache-name: cache-conda with: path: ~/miniconda3/envs/test - key: ${{ runner.os }}-conda-${{ env.cache-name }}-${{ hashFiles('deps/x86_64-unknown-linux-gnu/requirements_dev.txt', '.github/workflows/tests.yml') }} + 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- @@ -43,34 +43,10 @@ jobs: if: steps.cache-conda.outputs.cache-hit != 'true' run: | # python -m pip install --upgrade pip - uv pip install -r deps/x86_64-unknown-linux-gnu/requirements_dev.txt + uv pip install -r deps/lock/x86_64-manylinux_2_28/requirements_dev.txt uv pip install -e . - name: Run pytest - run: | - set +e # Do not exit shell on pytest failure - out=$(pytest 2> stderr.txt) - exit_code=$? - err=$(> $GITHUB_STEP_SUMMARY - echo "${out}" >> $GITHUB_STEP_SUMMARY - echo "${err}" >> $GITHUB_STEP_SUMMARY - if [[ $exit_code -eq 5 ]] - then - echo - echo 'WARNING: No tests were run and it is considered as success' >> $GITHUB_STEP_SUMMARY - echo "\`\`\`" >> $GITHUB_STEP_SUMMARY - exit 0 - else - echo "\`\`\`" >> $GITHUB_STEP_SUMMARY - # Exit with the exit-code returned by pytest - exit ${exit_code} - fi + uses: deargen/workflows/actions/run-pytest@master doctest: runs-on: ubuntu-latest @@ -79,24 +55,16 @@ jobs: shell: bash -el {0} # setup-miniconda requires bash 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 - - uses: conda-incubator/setup-miniconda@v3 - with: - miniforge-version: latest - activate-environment: test - python-version: ${{ steps.get-python-version.outputs.python_version }} + - 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: - # npm cache files are stored in `~/.npm` on Linux/macOS path: ~/miniconda3/envs/test - key: ${{ runner.os }}-conda-${{ env.cache-name }}-${{ hashFiles('deps/x86_64-unknown-linux-gnu/requirements_dev.txt', '.github/workflows/tests.yml') }} + 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- @@ -107,24 +75,7 @@ jobs: if: steps.cache-conda.outputs.cache-hit != 'true' run: | # python -m pip install --upgrade pip - uv pip install -r deps/x86_64-unknown-linux-gnu/requirements_dev.txt + uv pip install -r deps/lock/x86_64-manylinux_2_28/requirements_dev.txt uv pip install -e . - name: Run doctest - run: | - set +e # Do not exit shell on pytest failure - out=$(python scripts/run_doctest.py 2> stderr.txt) - exit_code=$? - err=$(> $GITHUB_STEP_SUMMARY - echo "${out}" >> $GITHUB_STEP_SUMMARY - echo "${err}" >> $GITHUB_STEP_SUMMARY - echo "\`\`\`" >> $GITHUB_STEP_SUMMARY - # Exit with the exit-code returned by pytest - - exit ${exit_code} + uses: deargen/workflows/actions/run-doctest@master diff --git a/README.md b/README.md index f5f8546..74b0324 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@ | | | |--|--| -|[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![StyLua](https://img.shields.io/badge/StyLua-teal)](https://github.com/JohnnyMorganz/StyLua)|[![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Style%20checking/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions)| -| [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) | [![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Linting/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions) | -| [![pytest](https://img.shields.io/badge/pytest-black)](https://github.com/pytest-dev/pytest) [![doctest](https://img.shields.io/badge/doctest-black)](https://docs.python.org/3/library/doctest.html) | [![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Tests/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions) | +|[![Ruff](https://img.shields.io/badge/Ruff-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)](https://github.com/astral-sh/ruff) |[![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Style%20checking/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions)| +| [![Ruff](https://img.shields.io/badge/Ruff-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)](https://github.com/astral-sh/ruff) | [![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Linting/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions) | +| [![pytest](https://img.shields.io/badge/pytest-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)](https://github.com/pytest-dev/pytest) [![doctest](https://img.shields.io/badge/doctest-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)](https://docs.python.org/3/library/doctest.html) | [![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Tests/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions) | +| [![uv](https://img.shields.io/badge/uv-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)](https://github.com/astral-sh/uv) | [![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Check%20pip%20compile%20sync/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions) | +|[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![StyLua](https://img.shields.io/badge/lua-%232C2D72.svg?style=for-the-badge&logo=lua&logoColor=white)](https://github.com/JohnnyMorganz/StyLua) | [![Actions status](https://github.com/kiyoon/python-import.nvim/workflows/Style%20checking/badge.svg)](https://github.com/kiyoon/python-import.nvim/actions) | A simple tool that auto-inserts import statements. diff --git a/deps/aarch64-apple-darwin/.requirements.in.sha256 b/deps/aarch64-apple-darwin/.requirements.in.sha256 deleted file mode 100644 index e7f926e..0000000 --- a/deps/aarch64-apple-darwin/.requirements.in.sha256 +++ /dev/null @@ -1 +0,0 @@ -a942f8fc23e62a010e18007759c189bfbe54126115e82cf02080302b990beea9 requirements.in diff --git a/deps/lock/aarch64-apple-darwin/.requirements.in.sha256 b/deps/lock/aarch64-apple-darwin/.requirements.in.sha256 new file mode 100644 index 0000000..8aa0d77 --- /dev/null +++ b/deps/lock/aarch64-apple-darwin/.requirements.in.sha256 @@ -0,0 +1 @@ +ce5df27a7f9aee6b8dbf816662d1ca8063af622e0ab6a9332cff1ec478a11c06 requirements.in diff --git a/deps/aarch64-apple-darwin/.requirements_dev.in.sha256 b/deps/lock/aarch64-apple-darwin/.requirements_dev.in.sha256 similarity index 100% rename from deps/aarch64-apple-darwin/.requirements_dev.in.sha256 rename to deps/lock/aarch64-apple-darwin/.requirements_dev.in.sha256 diff --git a/deps/aarch64-apple-darwin/requirements.txt b/deps/lock/aarch64-apple-darwin/requirements.txt similarity index 72% rename from deps/aarch64-apple-darwin/requirements.txt rename to deps/lock/aarch64-apple-darwin/requirements.txt index 94fe78a..38998df 100644 --- a/deps/aarch64-apple-darwin/requirements.txt +++ b/deps/lock/aarch64-apple-darwin/requirements.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements.in -o aarch64-apple-darwin/requirements.txt --python-platform aarch64-apple-darwin --python-version 3.9 +# uv pip compile requirements.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/aarch64-apple-darwin/requirements.txt --python-platform aarch64-apple-darwin --python-version 3.9 click==8.1.7 # via typer markdown-it-py==3.0.0 @@ -16,7 +16,7 @@ tree-sitter==0.22.3 # via -r requirements.in 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 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer diff --git a/deps/aarch64-apple-darwin/requirements_dev.txt b/deps/lock/aarch64-apple-darwin/requirements_dev.txt similarity index 80% rename from deps/aarch64-apple-darwin/requirements_dev.txt rename to deps/lock/aarch64-apple-darwin/requirements_dev.txt index 0ab9699..0d52c21 100644 --- a/deps/aarch64-apple-darwin/requirements_dev.txt +++ b/deps/lock/aarch64-apple-darwin/requirements_dev.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements_dev.in -o aarch64-apple-darwin/requirements_dev.txt --python-platform aarch64-apple-darwin --python-version 3.9 +# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/aarch64-apple-darwin/requirements_dev.txt --python-platform aarch64-apple-darwin --python-version 3.9 click==8.1.7 # via typer coverage==7.5.3 @@ -38,7 +38,7 @@ tree-sitter==0.22.3 # via -r requirements.in 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 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer diff --git a/deps/lock/x86_64-apple-darwin/.requirements.in.sha256 b/deps/lock/x86_64-apple-darwin/.requirements.in.sha256 new file mode 100644 index 0000000..8aa0d77 --- /dev/null +++ b/deps/lock/x86_64-apple-darwin/.requirements.in.sha256 @@ -0,0 +1 @@ +ce5df27a7f9aee6b8dbf816662d1ca8063af622e0ab6a9332cff1ec478a11c06 requirements.in diff --git a/deps/x86_64-apple-darwin/.requirements_dev.in.sha256 b/deps/lock/x86_64-apple-darwin/.requirements_dev.in.sha256 similarity index 100% rename from deps/x86_64-apple-darwin/.requirements_dev.in.sha256 rename to deps/lock/x86_64-apple-darwin/.requirements_dev.in.sha256 diff --git a/deps/x86_64-apple-darwin/requirements.txt b/deps/lock/x86_64-apple-darwin/requirements.txt similarity index 67% rename from deps/x86_64-apple-darwin/requirements.txt rename to deps/lock/x86_64-apple-darwin/requirements.txt index 7c68c43..4991058 100644 --- a/deps/x86_64-apple-darwin/requirements.txt +++ b/deps/lock/x86_64-apple-darwin/requirements.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements.in -o x86_64-apple-darwin/requirements.txt --python-platform x86_64-apple-darwin --python-version 3.9 +# uv pip compile requirements.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-apple-darwin/requirements.txt --python-platform x86_64-apple-darwin --python-version 3.9 click==8.1.7 # via typer markdown-it-py==3.0.0 @@ -16,7 +16,7 @@ tree-sitter==0.22.3 # via -r requirements.in tree-sitter-python==0.21.0 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer diff --git a/deps/x86_64-unknown-linux-gnu/requirements_dev.txt b/deps/lock/x86_64-apple-darwin/requirements_dev.txt similarity index 78% rename from deps/x86_64-unknown-linux-gnu/requirements_dev.txt rename to deps/lock/x86_64-apple-darwin/requirements_dev.txt index ccdd024..0339687 100644 --- a/deps/x86_64-unknown-linux-gnu/requirements_dev.txt +++ b/deps/lock/x86_64-apple-darwin/requirements_dev.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements_dev.in -o x86_64-unknown-linux-gnu/requirements_dev.txt --python-platform x86_64-unknown-linux-gnu --python-version 3.9 +# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-apple-darwin/requirements_dev.txt --python-platform x86_64-apple-darwin --python-version 3.9 click==8.1.7 # via typer coverage==7.5.3 @@ -38,7 +38,7 @@ tree-sitter==0.22.3 # via -r requirements.in tree-sitter-python==0.21.0 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer diff --git a/deps/lock/x86_64-manylinux_2_28/.requirements.in.sha256 b/deps/lock/x86_64-manylinux_2_28/.requirements.in.sha256 new file mode 100644 index 0000000..8aa0d77 --- /dev/null +++ b/deps/lock/x86_64-manylinux_2_28/.requirements.in.sha256 @@ -0,0 +1 @@ +ce5df27a7f9aee6b8dbf816662d1ca8063af622e0ab6a9332cff1ec478a11c06 requirements.in diff --git a/deps/x86_64-pc-windows-msvc/.requirements_dev.in.sha256 b/deps/lock/x86_64-manylinux_2_28/.requirements_dev.in.sha256 similarity index 100% rename from deps/x86_64-pc-windows-msvc/.requirements_dev.in.sha256 rename to deps/lock/x86_64-manylinux_2_28/.requirements_dev.in.sha256 diff --git a/deps/x86_64-pc-windows-msvc/requirements.txt b/deps/lock/x86_64-manylinux_2_28/requirements.txt similarity index 68% rename from deps/x86_64-pc-windows-msvc/requirements.txt rename to deps/lock/x86_64-manylinux_2_28/requirements.txt index 982a286..6287dd1 100644 --- a/deps/x86_64-pc-windows-msvc/requirements.txt +++ b/deps/lock/x86_64-manylinux_2_28/requirements.txt @@ -1,9 +1,7 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements.in -o x86_64-pc-windows-msvc/requirements.txt --python-platform x86_64-pc-windows-msvc --python-version 3.9 +# uv pip compile requirements.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-manylinux_2_28/requirements.txt --python-platform x86_64-manylinux_2_28 --python-version 3.9 click==8.1.7 # via typer -colorama==0.4.6 - # via click markdown-it-py==3.0.0 # via rich mdurl==0.1.2 @@ -18,7 +16,7 @@ tree-sitter==0.22.3 # via -r requirements.in tree-sitter-python==0.21.0 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer diff --git a/deps/x86_64-pc-windows-msvc/requirements_dev.txt b/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt similarity index 80% rename from deps/x86_64-pc-windows-msvc/requirements_dev.txt rename to deps/lock/x86_64-manylinux_2_28/requirements_dev.txt index 942ff98..04d56ae 100644 --- a/deps/x86_64-pc-windows-msvc/requirements_dev.txt +++ b/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt @@ -1,11 +1,7 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements_dev.in -o x86_64-pc-windows-msvc/requirements_dev.txt --python-platform x86_64-pc-windows-msvc --python-version 3.9 +# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt --python-platform x86_64-manylinux_2_28 --python-version 3.9 click==8.1.7 # via typer -colorama==0.4.6 - # via - # click - # pytest coverage==7.5.3 # via pytest-cov exceptiongroup==1.2.1 @@ -42,7 +38,7 @@ tree-sitter==0.22.3 # via -r requirements.in tree-sitter-python==0.21.0 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer diff --git a/deps/lock/x86_64-pc-windows-msvc/.requirements.in.sha256 b/deps/lock/x86_64-pc-windows-msvc/.requirements.in.sha256 new file mode 100644 index 0000000..8aa0d77 --- /dev/null +++ b/deps/lock/x86_64-pc-windows-msvc/.requirements.in.sha256 @@ -0,0 +1 @@ +ce5df27a7f9aee6b8dbf816662d1ca8063af622e0ab6a9332cff1ec478a11c06 requirements.in diff --git a/deps/x86_64-unknown-linux-gnu/.requirements_dev.in.sha256 b/deps/lock/x86_64-pc-windows-msvc/.requirements_dev.in.sha256 similarity index 100% rename from deps/x86_64-unknown-linux-gnu/.requirements_dev.in.sha256 rename to deps/lock/x86_64-pc-windows-msvc/.requirements_dev.in.sha256 diff --git a/deps/x86_64-unknown-linux-gnu/requirements.txt b/deps/lock/x86_64-pc-windows-msvc/requirements.txt similarity index 63% rename from deps/x86_64-unknown-linux-gnu/requirements.txt rename to deps/lock/x86_64-pc-windows-msvc/requirements.txt index 164a22b..15334f3 100644 --- a/deps/x86_64-unknown-linux-gnu/requirements.txt +++ b/deps/lock/x86_64-pc-windows-msvc/requirements.txt @@ -1,7 +1,9 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements.in -o x86_64-unknown-linux-gnu/requirements.txt --python-platform x86_64-unknown-linux-gnu --python-version 3.9 +# uv pip compile requirements.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-pc-windows-msvc/requirements.txt --python-platform x86_64-pc-windows-msvc --python-version 3.9 click==8.1.7 # via typer +colorama==0.4.6 + # via click markdown-it-py==3.0.0 # via rich mdurl==0.1.2 @@ -16,7 +18,7 @@ tree-sitter==0.22.3 # via -r requirements.in tree-sitter-python==0.21.0 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer diff --git a/deps/x86_64-apple-darwin/requirements_dev.txt b/deps/lock/x86_64-pc-windows-msvc/requirements_dev.txt similarity index 74% rename from deps/x86_64-apple-darwin/requirements_dev.txt rename to deps/lock/x86_64-pc-windows-msvc/requirements_dev.txt index 4961831..5ac0166 100644 --- a/deps/x86_64-apple-darwin/requirements_dev.txt +++ b/deps/lock/x86_64-pc-windows-msvc/requirements_dev.txt @@ -1,7 +1,11 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements_dev.in -o x86_64-apple-darwin/requirements_dev.txt --python-platform x86_64-apple-darwin --python-version 3.9 +# uv pip compile requirements_dev.in -o /home/runner/work/python-import.nvim/python-import.nvim/deps/lock/x86_64-pc-windows-msvc/requirements_dev.txt --python-platform x86_64-pc-windows-msvc --python-version 3.9 click==8.1.7 # via typer +colorama==0.4.6 + # via + # click + # pytest coverage==7.5.3 # via pytest-cov exceptiongroup==1.2.1 @@ -38,7 +42,7 @@ tree-sitter==0.22.3 # via -r requirements.in tree-sitter-python==0.21.0 # via -r requirements.in -typer==0.12.3 +typer==0.12.4 # via -r requirements.in typing-extensions==4.12.2 # via typer 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/deps/x86_64-apple-darwin/.requirements.in.sha256 b/deps/x86_64-apple-darwin/.requirements.in.sha256 deleted file mode 100644 index e7f926e..0000000 --- a/deps/x86_64-apple-darwin/.requirements.in.sha256 +++ /dev/null @@ -1 +0,0 @@ -a942f8fc23e62a010e18007759c189bfbe54126115e82cf02080302b990beea9 requirements.in diff --git a/deps/x86_64-pc-windows-msvc/.requirements.in.sha256 b/deps/x86_64-pc-windows-msvc/.requirements.in.sha256 deleted file mode 100644 index e7f926e..0000000 --- a/deps/x86_64-pc-windows-msvc/.requirements.in.sha256 +++ /dev/null @@ -1 +0,0 @@ -a942f8fc23e62a010e18007759c189bfbe54126115e82cf02080302b990beea9 requirements.in diff --git a/deps/x86_64-unknown-linux-gnu/.requirements.in.sha256 b/deps/x86_64-unknown-linux-gnu/.requirements.in.sha256 deleted file mode 100644 index e7f926e..0000000 --- a/deps/x86_64-unknown-linux-gnu/.requirements.in.sha256 +++ /dev/null @@ -1 +0,0 @@ -a942f8fc23e62a010e18007759c189bfbe54126115e82cf02080302b990beea9 requirements.in diff --git a/lua/python_import/api.lua b/lua/python_import/api.lua index 206ff73..23ef17c 100644 --- a/lua/python_import/api.lua +++ b/lua/python_import/api.lua @@ -130,7 +130,7 @@ local function get_import(winnr, word, ts_node) local prev_buf_str = utils.notify_diff_pre(bufnr) local import_status = pyright.import(winnr) if import_status == pyright.ImportStatus.RESOLVED_IMPORT then - utils.notify_diff(bufnr, prev_buf_str) + utils.notify_diff(bufnr, prev_buf_str, "python-import: pyright") return {} -- no further adding lines to buffer needed elseif import_status == pyright.ImportStatus.USER_ABORT then return {} -- no further adding lines to buffer needed diff --git a/lua/python_import/lookup_table.lua b/lua/python_import/lookup_table.lua index e4a03b6..3c30cb1 100644 --- a/lua/python_import/lookup_table.lua +++ b/lua/python_import/lookup_table.lua @@ -31,6 +31,7 @@ M.default_import = { "typing", "typing_extensions", "setuptools", + "xml", -- third-party "PIL", @@ -83,6 +84,7 @@ M.default_import_from = { namedtuple = "collections", defaultdict = "collections", + Callable = "collections.abc", Iterable = "collections.abc", Sequence = "collections.abc", @@ -185,7 +187,6 @@ M.default_import_from = { Annotation = "typing", Any = "typing", -- when you don't know the type Incomplete = "typing", -- alias for Any, but indicates that the type hint should be completed later - Callable = "typing", ClassVar = "typing", Concatenate = "typing", Final = "typing", @@ -254,9 +255,9 @@ M.default_import_from = { Text = "typing", TypeAlias = "typing", TypeGuard = "typing", - override = "typing", overload = "typing", + override = "typing_extensions", deprecated = "typing_extensions", setup = "setuptools", @@ -275,6 +276,8 @@ M.default_import_from = { Traceback = "rich.traceback", Theme = "rich.theme", WebDriver = "selenium.webdriver.remote.webdriver", + ic = "icecream", + sql = "psycopg", NDArray = "numpy.typing", ArrayLike = "numpy.typing", diff --git a/lua/python_import/utils.lua b/lua/python_import/utils.lua index 42a1079..acd3639 100644 --- a/lua/python_import/utils.lua +++ b/lua/python_import/utils.lua @@ -172,7 +172,7 @@ function M.notify_diff_pre(bufnr) return prev_buf_str end -function M.notify_diff(bufnr, prev_buf_str) +function M.notify_diff(bufnr, prev_buf_str, title) local new_buf = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) local new_buf_str = table.concat(new_buf, "\n") local diff = vim.diff(prev_buf_str, new_buf_str, { ctxlen = 3 }) @@ -183,7 +183,7 @@ function M.notify_diff(bufnr, prev_buf_str) diff = diff:gsub("\n$", "") notify(diff, "info", { - title = "python-import", + title = title, on_open = function(win) local buf = vim.api.nvim_win_get_buf(win) vim.bo[buf].filetype = "diff" diff --git a/scripts/compile_requirements.sh b/scripts/compile_requirements.sh deleted file mode 100644 index 6677190..0000000 --- a/scripts/compile_requirements.sh +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/env bash - -# This script compiles all requirements.in files to requirements.txt files -# This means that all dependencies are locked to a specific version -# Plus, it checks if the requirements.in file has changed since the last time it was compiled -# If not, it skips the file rather than recompiling it (which may change version unnecessarily often) - -TARGET_PLATFORMS=(x86_64-unknown-linux-gnu aarch64-apple-darwin x86_64-apple-darwin x86_64-pc-windows-msvc) - -if ! command -v uv &> /dev/null; then - echo "uv is not installed. Please run 'pip3 install --user uv'" >&2 - exit 1 -fi - -if ! command -v sha256sum &> /dev/null; then - echo "sha256sum is not installed." >&2 - echo "If you're on Mac, run 'brew install coreutils'" >&2 - exit 1 -fi - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -# NOTE: sha256sum will put the file path in the hash file. -# To simplify the directory (using relative paths), we change the working directory. -cd "$SCRIPT_DIR/../deps" || { echo "Failure"; exit 1; } - -PYTHON_VERSION=$(python3 "$SCRIPT_DIR/get_python_version.py") - -for platform in "${TARGET_PLATFORMS[@]}"; do - mkdir -p "$platform" -done - -shopt -s globstar - -function get_shafile() { - local file=$1 - local target_platform=$2 - # .requirements.in.sha256 - echo "$target_platform/.$file.sha256" -} - -function get_lockfile() { - local file=$1 - local target_platform=$2 - # requirements.txt - echo "$target_platform/${file%.in}.txt" -} - -function file_content_changed() { - # Check if the file has changed since the last time it was compiled, using the hash file. - # NOTE: returns 0 if the file has changed - local file=$1 - local target_platform=$2 - local shafile - shafile=$(get_shafile "$file" "$target_platform") - if [[ -f "$shafile" ]] && sha256sum -c "$shafile" &> /dev/null; then - return 1 - fi - return 0 -} - - -function deps_changed() { - # Check if the requirements*.in file has changed since the last time it was compiled, including its dependencies (-r another_requirements.in). - # - # When the requirements have dependencies on other requirements files, we need to check if those have changed as well - # e.g. requirements_dev.in has a dependency on requirements.in (-r requirements.in) - # Note that we also need to recursively check if the dependencies of the dependencies have changed. - # We need to recompile requirements_dev.txt if requirements.in has changed. - # NOTE: returns 0 if the deps have changed - local file=$1 - local target_platform=$2 - - if file_content_changed "$file" "$target_platform"; then - return 0 - fi - - - local file_deps - file_deps=$(grep -Eo -- '-r [^ ]+' "$file") - file_deps=${file_deps//"-r "/} # remove -r - for dep in $file_deps; do - echo "ℹī¸ $file depends on $dep" - dep=${dep#-r } # requirements.in - if deps_changed "$dep" "$target_platform"; then - return 0 - fi - done - return 1 -} - -num_files=0 -num_up_to_date=0 -files_changed=() - -# First, collect all files that need to be compiled. -# We don't compile them yet, because it will mess up the hash comparison. -for file in requirements*.in; do - for target_platform in "${TARGET_PLATFORMS[@]}"; do - # $file: requirements.in - ((num_files++)) - - lockfile=$(get_lockfile "$file" "$target_platform") - shafile=$(get_shafile "$file" "$target_platform") - # Process only changed files by comparing hash - if [[ -f "$lockfile" ]]; then - if ! deps_changed "$file" "$target_platform"; then - echo "⚡ Skipping $file due to no changes" - ((num_up_to_date++)) - continue - fi - fi - files_changed+=("$file") - done -done - -for file in "${files_changed[@]}"; do - for target_platform in "${TARGET_PLATFORMS[@]}"; do - lockfile=$(get_lockfile "$file" "$target_platform") - shafile=$(get_shafile "$file" "$target_platform") - echo "🔒 Generating lockfile $lockfile from $file" - uv pip compile "$file" -o "$lockfile" --python-platform "$target_platform" --python-version "$PYTHON_VERSION" > /dev/null - sha256sum "$file" > "$shafile" # update hash - done -done - -# exit code 2 when all files are up to date -if [[ $num_files -eq $num_up_to_date ]]; then - echo "💖 All files are up to date!" - exit 2 -fi - diff --git a/scripts/get_python_version.py b/scripts/get_python_version.py deleted file mode 100644 index 26a2f33..0000000 --- a/scripts/get_python_version.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -Get minimum python version from pyproject.toml. - -Note: - It only works if the format is like this: ">=3.11", ">=3.11,<3.12" -""" - -from __future__ import annotations - -from pathlib import Path - -pyproject_toml_path = Path(__file__).parent.parent / "pyproject.toml" - -try: - import toml - - pyproject = toml.load(pyproject_toml_path) - version_range = pyproject["project"]["requires-python"] -except ImportError: - # alternatively, search for requires-python in pyproject.toml - with open(pyproject_toml_path) as f: - for line in f: - if line.startswith("requires-python"): - version_range = line.replace("requires-python", "").strip(" ='\"") - break - else: - raise ValueError("requires-python not found in pyproject.toml") - - -# get minimum python version -# it has a format like this: ">=3.6", ">=3.7,<3.8" -min_version = version_range.split(",")[0].replace(">=", "") -print(min_version) # noqa: T201 diff --git a/scripts/run_doctest.py b/scripts/run_doctest.py deleted file mode 100644 index 7956ace..0000000 --- a/scripts/run_doctest.py +++ /dev/null @@ -1,54 +0,0 @@ -""" -Run doctest for all modules in `src/` directory. - -It will run all modules in `src/` directory and print the result of doctest. - -It also has to load all modules in `src/` directory, so it will run all modules and test if they can be imported. -So if any module doesn't run (e.g. syntax error, import error, etc.), it will also fail. -""" - -# flake8: noqa: T201 -from __future__ import annotations - -import doctest -import importlib -import os -from pathlib import Path - -if __name__ == "__main__": - # find all modules in src/ - modules = [] - for root, _dirs, files in os.walk("src"): - for file in files: - if file.endswith(".py"): - # convert path to module name - root = root.replace("src/", "") - root = root.replace("/", ".") - modules.append(root + "." + Path(file).stem) - - # run doctest for all modules - failed_modules = [] - num_failed = 0 - num_attempted = 0 - num_modules_with_doctest = 0 - for module_name in modules: - module = importlib.import_module(module_name) - result = doctest.testmod(module, verbose=True) - if result.failed > 0: - print(f"🚨 doctest failed for module: {module_name}") - print(f"🚨 {result.failed} failed out of {result.attempted} tests") - num_failed += result.failed - - if result.attempted > 0: - num_modules_with_doctest += 1 - num_attempted += result.attempted - - if num_failed == 0: - print( - f"✅ All {num_attempted} tests passed in {num_modules_with_doctest} modules." - ) - else: - print( - f"🚨 {num_failed} failed out of {num_attempted} tests in {num_modules_with_doctest} modules." - ) - exit(1) 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