Migrating from Poetry to Rye and fully supporting Netlify builds#

I migrated the Python project that was managed with Poetry to Rye, which has been attracting a lot of attention recently, and also completed the configuration by deploying it with Netlify. In this article, I will record the steps and key points.

During the transition, we kept the following points in mind:

  • Safe migration from existing Poetry projects

  • Review of Ruff settings using pre-commit

  • Installing and running Rye binaries on Netlify

  • Causes and countermeasures for dependency resolution failure depending on Python version

  • Separating from pip (avoiding requirements.txt method)


Status before migration#

  • Managed by Poetry (pyproject.toml, poetry.lock included)

  • There are also .venv/, setup.py, poetry.toml, etc.

  • In Netlify, build operation is done using requirements.txt and pip install.


Steps to migrate to Rye#

  1. Back up the current status with tags:

    git tag before-rye
    
  2. Delete Poetry related files:

    rm poetry.lock poetry.toml setup.py
    rm -rf .venv/
    
  3. Temporarily save setup.py and rye init:

    mv setup.py setup.py.bak
    rye init
    
  4. Installing required packages:

    rye add sphinx pydata-sphinx-theme myst-parser
    
  5. Installing development packages:

    rye add --dev sphinx-autobuild doc8 esbonio rstcheck pre-commit doit ruff
    
  6. Specify Python version:

    echo "3.12.9" > .python-version
    
  7. Manually modify pyproject.toml to Rye format and also normalize Ruff settings:

    [tool.ruff]
    line-length = 120
    extend-select = ["I", "C901"]
    
    [tool.ruff.lint.mccabe]
    max-complexity = 10
    
  8. Modify the condition of requires-python:

    requires-python = ">=3.12"
    

Compatible with Netlify#

Rye’s official installation script is in the curl | bash format, but with Netlify, the curl -sSf https://rye.astral.sh/get | bash method resulted in an error, so I instead adopted the method of downloading and extracting the Rye binary.

[build]
command = """
  wget -q https://github.com/astral-sh/rye/releases/latest/download/rye-x86_64-linux.gz
  gunzip rye-x86_64-linux.gz
  chmod +x rye-x86_64-linux
  ./rye-x86_64-linux self install --yes
  . $HOME/.rye/env
  rye sync
  rye run doit doc
"""
publish = "docs/_build/html"

[build.environment]
PYTHON_VERSION = "3.13"
LANG = "ja_JP.UTF-8"
LANGUAGE = "ja_JP:ja"
LC_ALL = "ja_JP.UTF-8"
TZ = "Asia/Tokyo"

Summary of troubles and countermeasures#

  • rye init fails if pyproject.toml from the poetry era remains → delete it

  • rye init fails if setup.py exists → Temporarily save it and it will be OK

  • If pyproject.toml has requires-python = ">=3.8", Rye uses 3.8 → corrected to ">=3.12"

  • If the max-complexity setting is incorrect, an error will occur in Ruff → Correctly described in [tool.ruff.lint.mccabe]


summary#

While Rye has a very good developer experience, it needed a bit of work in a CI environment like Netlify. The transition has been completed. I was also able to feel the differences and performance benefits compared to poetry. In the future, we would like to shift to development based on rye and accumulate know-how.

Article information

author:

Mr. Takagi

Release date:

2025-05-31