astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.6k stars 466 forks source link

'rye build' with maturin produces the wheel using the bootstrap Python interpreter #1152

Closed mvaled closed 2 months ago

mvaled commented 3 months ago

Steps to Reproduce

  1. rye init --build-system maturin -p 3.8 rusty; cd rusty
  2. rye pin --relaxed 3.8
  3. rye sync
  4. rye build

Expected Result

The binary wheel should be for Python 3.8.

Actual Result

The binary wheel is for Python 3.12 (rusty-0.1.0-cp312-cp312-linux_x86_64.whl).

Version Info

rye 0.34.0
commit: 0.34.0 (d31340178 2024-05-20)
platform: linux (x86_64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true

Stacktrace

No response

phi-friday commented 3 months ago

same on macos(arm)

log

❯ rye init --build-system maturin -p 3.8 rusty; cd rusty
success: Initialized project in /Users/***/git/python/test/qwe/rusty
  Run `rye sync` to get started
❯ rye pin --relaxed 3.8

pinned 3.8 in /Users/***/git/python/test/qwe/rusty/.python-version
❯ rye sync

Initializing new virtualenv in /Users/***/git/python/test/qwe/rusty/.venv
Python version: cpython@3.8.18
Generating production lockfile: /Users/***/git/python/test/qwe/rusty/requirements.lock
Generating dev lockfile: /Users/***/git/python/test/qwe/rusty/requirements-dev.lock
Installing dependencies
   Built file:///Users/***/git/python/test/qwe/rusty                                                        Built 1 editable in 3.97s
Installed 1 package in 1ms
 + rusty==0.1.0 (from file:///Users/***/git/python/test/qwe/rusty)
Done!
❯ rye build

building rusty
* Creating isolated environment: venv+uv...
* Using external uv from /Users/***/.rye/uv/0.1.44/uv
* Installing packages in isolated environment:
  - maturin>=1.2,<2.0
* Getting build dependencies for sdist...
* Building sdist...
Running `maturin pep517 write-sdist --sdist-directory /Users/***/git/python/test/qwe/rusty/dist`
🍹 Building a mixed python/rust project
🔗 Found pyo3 bindings
🐍 Found CPython 3.12 at /private/var/folders/27/xcyb5y7j5ql7sklfygs11m940000gn/T/build-env-3u6gfgo3/bin/python3
📡 Using build options features from pyproject.toml
📦 Built source distribution to /Users/***/git/python/test/qwe/rusty/dist/rusty-0.1.0.tar.gz
rusty-0.1.0.tar.gz
* Building wheel from sdist
* Creating isolated environment: venv+uv...
* Using external uv from /Users/***/.rye/uv/0.1.44/uv
* Installing packages in isolated environment:
  - maturin>=1.2,<2.0
* Getting build dependencies for wheel...
* Building wheel...
Running `maturin pep517 build-wheel -i /Users/***/.rye/py/cpython@3.12.3/bin/python3.12 --compatibility off`
🍹 Building a mixed python/rust project
🔗 Found pyo3 bindings
🐍 Found CPython 3.12 at /Users/***/.rye/py/cpython@3.12.3/bin/python3.12
📡 Using build options features from pyproject.toml
💻 Using `MACOSX_DEPLOYMENT_TARGET=11.0` for aarch64-apple-darwin by default
   Compiling target-lexicon v0.12.14
   Compiling autocfg v1.3.0
   Compiling proc-macro2 v1.0.85
   Compiling once_cell v1.19.0
   Compiling unicode-ident v1.0.12
   Compiling libc v0.2.155
   Compiling syn v1.0.109
   Compiling parking_lot_core v0.9.10
   Compiling cfg-if v1.0.0
   Compiling scopeguard v1.2.0
   Compiling smallvec v1.13.2             ] 0/43: proc-macro2(build.rs), scopeguard, parking_lot_core(buil...
   Compiling unindent v0.1.11             ] 1/43: proc-macro2(build.rs), scopeguard, parking_lot_core(buil...
   Compiling indoc v1.0.9                 ] 2/43: proc-macro2(build.rs), parking_lot_core(build.rs), syn(b...
   Compiling lock_api v0.4.12             ] 7/43: indoc, proc-macro2(build), parking_lot_core(build), syn(...
   Compiling memoffset v0.9.1             ] 8/43: indoc, proc-macro2(build), parking_lot_core(build), syn(...
   Compiling quote v1.0.36               ] 17/43: syn(build), memoffset(build), libc(build), target-lexico...
   Compiling pyo3-build-config v0.19.2   ] 24/43: memoffset(build), target-lexicon, syn, lock_api(build)     
   Compiling pyo3-macros-backend v0.19.2 ] 28/43: pyo3-build-config(build), syn, lock_api(build)             
   Compiling parking_lot v0.12.3         ] 29/43: pyo3-build-config(build), lock_api, syn, pyo3-macros-bac...
   Compiling pyo3-ffi v0.19.2====>       ] 33/43: pyo3-build-config, pyo3-macros-backend                     
   Compiling pyo3 v0.19.2
   Compiling pyo3-macros v0.19.2===>     ] 36/43: pyo3-ffi(build), pyo3-macros-backend                       
   Compiling rusty v0.1.0 (/private/var/folders/27/xcyb5y7j5ql7sklfygs11m940000gn/T/build-via-sdist-varl957f/rusty-0.1.0)
    Finished `release` profile [optimized] target(s) in 6.16s                                                
📦 Built wheel for CPython 3.12 to /private/var/folders/27/xcyb5y7j5ql7sklfygs11m940000gn/T/build-via-sdist-varl957f/rusty-0.1.0/target/wheels/rusty-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
/private/var/folders/27/xcyb5y7j5ql7sklfygs11m940000gn/T/build-via-sdist-varl957f/rusty-0.1.0/target/wheels/rusty-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Successfully built rusty-0.1.0.tar.gz and rusty-0.1.0-cp312-cp312-macosx_11_0_arm64.whl

version

❯ rye --version
rye 0.34.0
commit: 0.34.0 (d31340178 2024-05-20)
platform: macos (aarch64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true
b0o commented 2 months ago

Same issue here on Arch Linux, but I'm not using maturin. I'm using the hatch-mypyc build hook. Trying to build for 3.11, but getting a 3.12 wheel out.

[tool.hatch.build.targets.wheel.hooks.mypyc]
dependencies = ["hatch-mypyc"]
mypy-args = [
  "--disable-error-code=name-defined",
  "--disable-error-code=attr-defined",
]
$ rye --version
rye 0.36.0
commit: 0.36.0 (12c024c7c 2024-07-07)
platform: linux (x86_64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true

$ cat .python-version
3.11

$ python  --version
Python 3.11.9

$ rye build --wheel -v
building myproject-py
* Creating isolated environment: venv+uv...
* Using external uv from /home/myname/.rye/uv/0.2.22/uv
* Installing packages in isolated environment:
  - hatchling
> /home/myname/.rye/uv/0.2.22/uv pip install hatchling
< Resolved 5 packages in 65ms
< Installed 5 packages in 4ms
<  + hatchling==1.25.0
<  + packaging==24.1
<  + pathspec==0.12.1
<  + pluggy==1.5.0
<  + trove-classifiers==2024.7.2
* Getting build dependencies for wheel...
* Installing packages in isolated environment:
  - hatch-mypyc
> /home/myname/.rye/uv/0.2.22/uv pip install hatch-mypyc
< Resolved 10 packages in 69ms
< Installed 5 packages in 66ms
<  + hatch-mypyc==0.16.0
<  + mypy==1.11.0
<  + mypy-extensions==1.0.0
<  + setuptools==71.0.4
<  + typing-extensions==4.12.2
* Building wheel...
Successfully built myproject_py-0.0.1-cp312-cp312-linux_x86_64.whl

When building with hatch, it uses the python version from the default env or the build env. I think rye should follow suit and use the python version specified in .python-version.

charliermarsh commented 2 months ago

I believe I have a fix here: https://github.com/astral-sh/rye/pull/1250

charliermarsh commented 2 months ago

Success:

❯ ../rye/target/debug/rye build
Python version: cpython@3.8.19
building rusty
* Creating isolated environment: venv+uv...
* Using external uv from /Users/crmarsh/.rye/uv/0.2.24/uv
* Installing packages in isolated environment:
  - maturin>=1.2,<2.0
* Getting build dependencies for sdist...
* Building sdist...
Running `maturin pep517 write-sdist --sdist-directory /Users/crmarsh/workspace/rusty/dist`
    Updating crates.io index
  Downloaded redox_syscall v0.5.3
  Downloaded 1 crate (23.8 KB) in 0.16s
🍹 Building a mixed python/rust project
🔗 Found pyo3 bindings
🐍 Found CPython 3.8 at /private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/build-env-r1j7m8yr/bin/python3
📡 Using build options features from pyproject.toml
📦 Built source distribution to /Users/crmarsh/workspace/rusty/dist/rusty-0.1.0.tar.gz
rusty-0.1.0.tar.gz
* Building wheel from sdist
* Creating isolated environment: venv+uv...
* Using external uv from /Users/crmarsh/.rye/uv/0.2.24/uv
* Installing packages in isolated environment:
  - maturin>=1.2,<2.0
* Getting build dependencies for wheel...
* Building wheel...
Running `maturin pep517 build-wheel -i /private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/build-env-cy75lkxx/bin/python --compatibility off`
🍹 Building a mixed python/rust project
🔗 Found pyo3 bindings
🐍 Found CPython 3.8 at /private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/build-env-cy75lkxx/bin/python
📡 Using build options features from pyproject.toml
💻 Using `MACOSX_DEPLOYMENT_TARGET=11.0` for aarch64-apple-darwin by default
   Compiling target-lexicon v0.12.15
   Compiling autocfg v1.3.0
   Compiling once_cell v1.19.0
   Compiling proc-macro2 v1.0.86
   Compiling unicode-ident v1.0.12
   Compiling libc v0.2.155
   Compiling syn v1.0.109
   Compiling parking_lot_core v0.9.10
   Compiling cfg-if v1.0.0
   Compiling smallvec v1.13.2
   Compiling scopeguard v1.2.0
   Compiling indoc v1.0.9
   Compiling unindent v0.1.11
   Compiling lock_api v0.4.12             ] 7/43: parking_lot_core(build), target-lexicon(build.rs), unindent, indoc,...
   Compiling memoffset v0.9.1
   Compiling quote v1.0.36               ] 19/43: target-lexicon(build), proc-macro2, memoffset(build), lock_api(buil...
   Compiling pyo3-build-config v0.19.2   ] 23/43: parking_lot_core, syn, target-lexicon, memoffset(build), lock_api(b...
   Compiling parking_lot v0.12.3         ] 26/43: lock_api, syn, pyo3-build-config(build.rs), memoffset(build)
   Compiling pyo3-ffi v0.19.2====>       ] 32/43: syn, pyo3-build-config
   Compiling pyo3 v0.19.2
   Compiling pyo3-macros-backend v0.19.2 ] 36/43: pyo3-ffi, syn, pyo3(build)
   Compiling pyo3-macros v0.19.2=====>   ] 39/43: pyo3-macros-backend
   Compiling rusty v0.1.0 (/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/build-via-sdist-l3xd2jfr/rusty-0.1.0)
    Finished release [optimized] target(s) in 4.24susty
📦 Built wheel for CPython 3.8 to /private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/build-via-sdist-l3xd2jfr/rusty-0.1.0/target/wheels/rusty-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/build-via-sdist-l3xd2jfr/rusty-0.1.0/target/wheels/rusty-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Successfully built rusty-0.1.0.tar.gz and rusty-0.1.0-cp38-cp38-macosx_11_0_arm64.whl