Skip to content

Commit

Permalink
Switch from poetry to uv (#105)
Browse files Browse the repository at this point in the history
* Switch from `poetry` to `uv`

* Use Python 3.12

* Some more adjustments for `uv`

* Polish

* uv in workflows (#107)

* Fix openrewrite-remote package name

* Disable tests for now

* Polish

* Try to disable `comment-pr.yml`

* Polish

* Disable `receive-pr` workflow again

* Update `README.md` a bit

---------

Co-authored-by: Kyle Scully <[email protected]>
  • Loading branch information
knutwannheden and zieka authored Dec 17, 2024
1 parent 8ec4473 commit 27c6407
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 496 deletions.
37 changes: 18 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,31 @@ jobs:
- name: check-java
run: java --version

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Uv
uses: astral-sh/setup-uv@v4

- name: Install Poetry
uses: snok/install-poetry@v1
- name: "Set up Python"
uses: actions/setup-python@v5
with:
version: 1.8.1
plugins: poetry-plugin-export
python-version-file: "rewrite/.python-version"

- name: build-java
run: ./gradlew ${{ env.GRADLE_SWITCHES }} build

- name: build-python
- name: Install dependencies
working-directory: rewrite
run: |
uv python install
uv sync --all-extras
# - name: Run tests
# run: |
# poe test

- name: Run build
working-directory: rewrite
run: |
for directory in rewrite/rewrite-*/; do
if [ -f "$directory/pyproject.toml" ]; then
echo "Building project in $directory"
cd "$directory"
poetry install --no-interaction --no-ansi
poetry build
poetry run pytest
cd - > /dev/null
fi
done
uv build
- name: publish-snapshots
if: github.event_name != 'pull_request'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/comment-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_run:
workflows: ["receive-pr"]
types:
- completed
# - completed

# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code.
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: "3.12"

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v4

- name: publish-candidate
if: contains(github.ref, '-rc.')
Expand Down Expand Up @@ -78,15 +78,18 @@ jobs:
echo "Extracted version: $version"
echo "::set-output name=VERSION::$version"
- name: Set project version with Poetry
- name: Set project version
working-directory: rewrite
run: poetry version ${{ steps.extract_version.outputs.VERSION }}
run: |
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version ${{ steps.extract_version.outputs.VERSION }}
- name: publish-python
working-directory: rewrite
if: (!contains(github.ref, '-rc.'))
run: |
poetry install --no-interaction --no-ansi
poetry build
poetry publish --username __token__ --password ${{ secrets.PYPI_TOKEN }}
rm -rf .venv
uv python install
uv sync --all-extras
uv build
uv publish --token ${{ secrets.PYPI_TOKEN }}
git restore --staged --worktree . && git clean -fd
5 changes: 3 additions & 2 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: receive-pr

on:
pull_request:
types: []
# pull_request:
# types: []
workflow_dispatch:

# pull_request:
# types: [opened, synchronize]
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ build/
out/
bin/
example-data/
.idea/
.idea/

.DS_Store
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ In the setup described here it is at the time of writing important that the GitH
mkdir -p ~/git/moderneinc && gh repo clone moderneinc/rewrite-remote ~/git/moderneinc/rewrite-remote
mkdir -p ~/git/openrewrite && gh repo clone openrewrite/rewrite-python ~/git/openrewrite/rewrite-python
```
2. Make sure Python 3.8 and Poetry are installed
2. Make sure Python 3.12 and Uv are installed
```shell
brew install [email protected]
brew install poetry
brew install uv
uv install python
```
3. Create a Python virtual environment (here we are going to use `~/.venv` but any directory works) and activate it
```shell
python3.8 -m venv ~/.venv
un sync --all-extras
source ~/.venv/bin/activate
```
4. Switch to `moderneinc/rewrite-remote/python` and install all dependencies using Poetry
4. Switch to `moderneinc/rewrite-remote/python` and install all dependencies using Uv
```shell
cd ~/git/moderneinc/rewrite-remote/python/rewrite-remote-test
poetry install
uv build
```
5. Open `~/git/openrewrite/rewrite-python/rewrite` in IDEA (or PyCharm)
```shell
Expand Down
11 changes: 5 additions & 6 deletions rewrite-python/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
testImplementation("org.junit-pioneer:junit-pioneer:latest.release")
}

val poetryProjectDir = file("../rewrite")
val pythonProjectDir = file("../rewrite")
val outputDir = layout.buildDirectory.dir("resources/main/META-INF")
val requirementsFile = outputDir.map { it.file("python-requirements.txt") }

Expand All @@ -40,19 +40,18 @@ tasks.register("prepareOutputDir") {
}
}

tasks.register<Exec>("exportPoetryRequirements") {
tasks.register<Exec>("exportPythonRequirements") {
dependsOn("prepareOutputDir")
workingDir = poetryProjectDir
commandLine("sh", "-c", "poetry export --without-hashes -o ${requirementsFile.get().asFile.absolutePath}")
workingDir = pythonProjectDir
commandLine("sh", "-c", "uv export --no-header --frozen --no-hashes --no-emit-project --no-dev --no-emit-package openrewrite-remote -o ${requirementsFile.get().asFile.absolutePath}")
standardOutput = System.out
errorOutput = System.err
}

tasks.register("appendOpenRewriteRequirements") {
dependsOn("exportPoetryRequirements")
dependsOn("exportPythonRequirements")
doLast {
val file = requirementsFile.get().asFile
file.appendText("cbor2\n")
file.appendText("openrewrite${generatePipVersionConstraint(project.version.toString(), false)}\n")
file.appendText("openrewrite-remote${generatePipVersionConstraint(getDirectDependencyVersion("org.openrewrite:rewrite-remote-java"), true)}\n")
}
Expand Down
2 changes: 1 addition & 1 deletion rewrite/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.12
3.12
Loading

0 comments on commit 27c6407

Please sign in to comment.