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

Introduce uv for Project Management #547

Merged
merged 13 commits into from
Mar 7, 2025
Merged

Conversation

KanchiShimono
Copy link
Contributor

This Pull Request introduces uv to improve project management. The key reasons for adopting uv are as follows:

  1. Unified Environment Management
    uv allows managing Python versions, virtual environments, and dependencies with a single tool, reducing the overhead of environment setup.

  2. Strict Dependency Management
    uv precisely manages dependencies based on OS, CPU architecture, and Python versions. In contrast, the current approach using pip-compile generates lock files tied to the developer's Python version, which can lead to unexpected issues (e.g., failing to resolve dependencies for libraries that have dropped support for older Python versions).

  3. High Performance
    With optimized dependency resolution and caching mechanisms, uv provides a fast and efficient package management experience.

  4. Consistency Across the Organization
    Since Pydantic has already adopted uv, standardizing project management tools within the same organization reduces cognitive load for developers.

@KanchiShimono
Copy link
Contributor Author

The test failures are caused by changes introduced in Pydantic 2.10 and are unrelated to the changes in this PR.

However, it was found that in Python 3.9 or earlier combined with Pydantic 2.10, CliSettingsSource does not correctly generate metavar.

elif isinstance(obj, WithArgsTypes):
return self._metavar_format_choices(
list(map(self._metavar_format_recurse, self._get_modified_args(obj))),
obj_qualname=obj.__qualname__ if hasattr(obj, '__qualname__') else str(obj),
)

As a workaround, applying the following change allows the tests to pass, but I am unsure if this is the appropriate solution.

        elif isinstance(obj, WithArgsTypes) and sys.version_info >= (3, 9):

I believe it would be best to handle the test failures separately from this PR. What do you think?

@hramezani
Copy link
Member

The test failures are caused by changes introduced in Pydantic 2.10 and are unrelated to the changes in this PR.

However, it was found that in Python 3.9 or earlier combined with Pydantic 2.10, CliSettingsSource does not correctly generate metavar.

elif isinstance(obj, WithArgsTypes):
return self._metavar_format_choices(
list(map(self._metavar_format_recurse, self._get_modified_args(obj))),
obj_qualname=obj.__qualname__ if hasattr(obj, '__qualname__') else str(obj),
)

As a workaround, applying the following change allows the tests to pass, but I am unsure if this is the appropriate solution.

        elif isinstance(obj, WithArgsTypes) and sys.version_info >= (3, 9):

I believe it would be best to handle the test failures separately from this PR. What do you think?

Thanks @KanchiShimono for this PR.

Yes, it is better to handle the test failure in separate PR.

I think @kschwab can fix the problem because he wrote most of the code there and he is the CLI expert

@KanchiShimono
Copy link
Contributor Author

@hramezani @kschwab
Thank you for your reply.

  1. I have created a new issue Incorrect metavar generation in CliSettingsSource with Python 3.9 or earlier and Pydantic 2.10 #551 regarding the incorrect generation of metavar.
  2. As a workaround, I added a constraint on the Pydantic version used during development with Python 3.9 or earlier. This constraint is applied only when managing the development environment with uv and does not affect installations from PyPI as a library.
  3. Tests for Python 3.9 and earlier use an older version of Pydantic, causing some print tests using pytest-examples to fail. To address this, I modified the tests to skip test_docs.py when an older version of Pydantic is detected.

@hramezani
Copy link
Member

@KanchiShimono you need to rebase.

we removed support for Python 3.8 and fixed the bug

@KanchiShimono
Copy link
Contributor Author

@hramezani

I have rebased the branch to incorporate the latest changes from main.
All tests are now passing.

Comment on lines 101 to 119
- name: set up python
uses: actions/setup-python@v5
- name: set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: '3.10'

- name: install
run: pip install -U build

- name: check GITHUB_REF matches package version
uses: samuelcolvin/check-python-version@v3.1
uses: samuelcolvin/check-python-version@v4.1
with:
version_file_path: pydantic_settings/version.py

- name: build
run: python -m build
run: uv build
Copy link
Member

Choose a reason for hiding this comment

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

Let's not change the release part. as we are using the same thing in pydantic.

@hramezani
Copy link
Member

@KanchiShimono I requested a small change, other than that LGTM.

@KanchiShimono
Copy link
Contributor Author

@hramezani
Thank you for your review.

I have borrowed the release part from the latest version of Pydantic. Additionally, I have upgraded the default Python version used in GitHub Actions to 3.12.

@hramezani hramezani merged commit a1710b2 into pydantic:main Mar 7, 2025
20 checks passed
@hramezani
Copy link
Member

Thanks @KanchiShimono

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants