Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: migrate to uv #29566

Merged
merged 134 commits into from
Feb 6, 2025
Merged

infra: migrate to uv #29566

merged 134 commits into from
Feb 6, 2025

Conversation

ccurme
Copy link
Collaborator

@ccurme ccurme commented Feb 3, 2025

No description provided.

@ccurme ccurme temporarily deployed to Scheduled testing February 5, 2025 23:24 — with GitHub Actions Inactive
@ccurme ccurme temporarily deployed to Scheduled testing February 5, 2025 23:25 — with GitHub Actions Inactive
@ccurme ccurme temporarily deployed to Scheduled testing February 5, 2025 23:25 — with GitHub Actions Inactive
# Conflicts:
#	libs/community/extended_testing_deps.txt
@ccurme ccurme merged commit d172984 into master Feb 6, 2025
284 of 285 checks passed
@ccurme ccurme deleted the cc/migrate_uv branch February 6, 2025 18:36
Comment on lines -237 to +240
poetry run pip install dist/*.whl
VIRTUAL_ENV=.venv uv pip install dist/*.whl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a minor note, we should detect .venv as the target automatically here

e.g.

❯ uv venv
Using CPython 3.12.6
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
❯ uv pip install anyio
Resolved 4 packages in 85ms
Installed 4 packages in 4ms
 + anyio==4.8.0
 + idna==3.10
 + sniffio==1.3.1
 + typing-extensions==4.12.2
❯ ls .venv/lib/python3.12/site-packages
__pycache__				anyio-4.8.0.dist-info			sniffio-1.3.1.dist-info
_virtualenv.pth				idna					typing_extensions-4.12.2.dist-info
_virtualenv.py				idna-3.10.dist-info			typing_extensions.py
anyio					sniffio

Not that it's bad to be explicit — otherwise another VIRTUAL_ENV could overlap.

The following is also valid, if you prefer

uv pip install -p .venv ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccurme weren't you running into some issues here where it was using some global context instead of the local install here, requiring the added environment variable specification?

I might be remembering wrong

Copy link

@zanieb zanieb Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think astral-sh/setup-uv may activate a virtual environment by default, which would cause that behavior and be a bit annoying in this context — if that's the case I can look into changing that.

ref https://github.com/astral-sh/setup-uv/blob/f95cd8710c5064b4546350da1950efde82c26d24/src/setup-uv.ts#L148-L167

Copy link
Contributor

@efriis efriis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ didn't hit submit yesterday - will go through and resolve things we talked about async

@@ -0,0 +1,23 @@
# TODO: https://docs.astral.sh/uv/guides/integration/github/#caching
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this interacts ok with python-version but that would be main suspect if things go wrong with enable-cache: true

@@ -304,7 +307,7 @@ def _get_configs_for_multi_dirs(
f"Unknown lib: {file}. check_diff.py likely needs "
"an update for this new library!"
)
elif file.startswith("docs/") or file in ["pyproject.toml", "poetry.lock"]: # docs or root poetry files
elif file.startswith("docs/") or file in ["pyproject.toml", "uv.lock"]: # docs or root uv files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth adding a lint case that confirms there are no poetry.lock files in the tree

Comment on lines +18 to +19
dependencies = toml_data["project"]["dependencies"]
for dep_version in dependencies:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what changed here? why isn't it iterating over the keys anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependencies is no longer a dict matching dependency names to version constraints / markers etc. It is a list of dependency specifier strings.

@@ -87,21 +63,12 @@ jobs:
if: ${{ ! startsWith(inputs.working-directory, 'libs/partners/') }}
working-directory: ${{ inputs.working-directory }}
run: |
poetry install --with test
uv sync --group test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically I think this is a functional change because this will remove lint/typing deps, whereas poetry install (without --sync) would only add deps, and not remove anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 06b99bd

@@ -184,13 +188,11 @@ jobs:
# - The package is published, and it breaks on the missing dependency when
# used in the real world.

- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
- name: Set up Python + uv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv versioning maybe worth declaring - but assume different based on frozen thing


- name: Import test dependencies
run: poetry install --with test --no-root
run: uv sync --group test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might reinstall the "current project" which we don't want - we want to install the built wheel we're testing. That's what --no-root was handling

happy to discuss this one

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, you probably want uv sync --inexact --only-group test

Copy link

@zanieb zanieb Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the subsequent step does say

Overwrite the local version of the package with the built version

which would replace it.

You probably want to skip the project dependencies regardless to ensure the wheel isn't missing declaration of any dependencies?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow has

uv pip install dist/*.whl
make tests <-- basically uv run --group test pytest ...

As I understand it the problem is that make tests will replace the wheel install with the local project.

In 8b8678f I set UV_NO_SYNC=true. Let me know if this isn't sufficient.

>>> uv pip install dist/*.whl
>>> uv pip freeze | grep langchain
langchain @ file:///.../libs/langchain/dist/langchain-0.3.18-py3-none-any.whl
>>> make tests
>>> uv pip freeze | grep langchain
-e file:///Users/chestercurme/repos/langchain/libs/langchain

^ If I set UV_NO_SYNC=true, I get the wheel install in the second pip freeze.

Comment on lines -237 to +240
poetry run pip install dist/*.whl
VIRTUAL_ENV=.venv uv pip install dist/*.whl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccurme weren't you running into some issues here where it was using some global context instead of the local install here, requiring the added environment variable specification?

I might be remembering wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants