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

Migration to pyproject.toml #3338

Open
wants to merge 42 commits into
base: master
Choose a base branch
from

Conversation

hirosassa
Copy link
Contributor

@hirosassa hirosassa commented Jan 19, 2025

Description

In this PR, I migrated from setup.py to pyproject.toml using uv.
Fixes #3327.

In detail I did followings:

  • migrate setup.py features to equivalent pyproject.toml
  • introduce uv as a package manager
  • move dependency configurations for test from tox.ini to pyproject.toml
  • update tox version to use new features of tox and pyproject.toml
  • drop Python 3.7 support. see: Migration to pyproject.toml #3338 (comment)

A part of codes are burrowed from @dlstadther 's branch.
ref master...dlstadther:luigi:migrate-setup-to-pyproject

Motivation and Context

python setup.py install is deprecated.

Have you tested this? If so, how?

CI worked.

@hirosassa hirosassa requested review from dlstadther and a team as code owners January 19, 2025 07:11
@hirosassa hirosassa changed the title Migration to uv Migration to pyproject.toml Jan 19, 2025
@hirosassa hirosassa marked this pull request as draft January 19, 2025 07:15
Copy link
Collaborator

@dlstadther dlstadther left a comment

Choose a reason for hiding this comment

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

Awesome start on this! I really appreciate your active involvement. My time is too unpredictable to spend significant dedicated time to this project.

RELEASE-PROCESS.rst Show resolved Hide resolved
pyproject.toml Outdated
Comment on lines 80 to 81
common = [
"pytest<7.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have 2 preferences here related to sorting:

  1. keep package names in alphabetic order
  2. keep group names in alphabetic order

This makes it easiest for humans to view and also to maintain order where new packages should be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 9616953

pyproject.toml Outdated
Comment on lines 47 to 53
[project.optional-dependencies]
jsonschema = ["jsonschema"]
prometheus = ["prometheus-client>=0.5,<0.15"]
toml = ["toml<2.0.0"]

[dependency-groups]
dropbox = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

(This comment doesn't need to be addressed as part of this PR; mostly just thinking aloud)

Perhaps it makes sense in the future to move some of the dependency-groups content which is used for unit test execution for specific luigi modules (particularly the contrib and optional stuff) out of dependency-groups and into project.optional-dependencies to facilitate luigi installation with "extras". These extras can also easily control the cases where the luigi module may only support up to a max version.

Food for thought if it changes how you design/organize this file.

Comment on lines +2 to +4
requires =
tox>=4.22 # `dependency_groups` needed
tox-uv>=1.19
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you help me understand why these requirements are here and not in pyproject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general case, tox version is not managed in pyproject.toml, requirements.txt, etc.
https://github.com/tox-dev/tox-uv/blob/main/.github/workflows/check.yaml#L40
https://github.com/tox-dev/tox-uv/blob/main/tox.ini#L2-L4
I think this is because tox is not related to actual implementation of tests.

In our CI, we use dependency_groups feature of pyproject.toml and tox, so I added this requirements on tox's configuration.

@@ -67,7 +67,10 @@ def _warn_node(self, msg, node, *args, **kwargs):

sphinx.environment.BuildEnvironment.warn_node = _warn_node

if os.environ.get('READTHEDOCS', None) == 'True':
# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
Copy link
Collaborator

Choose a reason for hiding this comment

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

Before merging, we'll need to identify how to verify the merging of the final version of this branch doesn't break Luigi's readthedocs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hirosassa , how you thought how we can be sure that we don't break RTD when merging this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is a little bit difficult because it depends on webhook of this repo.
I confirmed that a local build of documents using Sphinx is succeeded.

@hirosassa
Copy link
Contributor Author

hirosassa commented Feb 1, 2025

@dlstadther I confirmed CIs are all green without Python 3.7.
see: https://github.com/spotify/luigi/actions/runs/13086373164/job/36517994352

With Python 3.7, test fails in code below:
https://github.com/mysql/mysql-connector-python/blob/8.0.33/lib/mysql/connector/connection_cext.py#L291
https://github.com/spotify/luigi/actions/runs/13086478927/job/36518207022?pr=3338#step:6:166

I think the root cause of this problem is Python 3.7.9 runtime.
The succeeded case runs in 3.7.17.
https://github.com/spotify/luigi/actions/runs/12875540263/job/35897024647#step:7:19

The reason why the CI in this PR for Python 3.7 run in 3.7.9 is uv supports only 3.7.9 for Python 3.7
We cannot use newer Python with uv because uv using python frompython-builds-standalone and it dropped Python 3.7.10+ support.
https://github.com/astral-sh/python-build-standalone/releases/tag/20210103

We might need to consider dropping support for Python 3.7.
Do you have any idea solving this problem?

@RRap0so
Copy link
Contributor

RRap0so commented Feb 1, 2025

@dlstadther I confirmed CIs are all green without Python 3.7.

see: https://github.com/spotify/luigi/actions/runs/13086373164/job/36517994352

With Python 3.7, test fails in code below:

https://github.com/mysql/mysql-connector-python/blob/8.0.33/lib/mysql/connector/connection_cext.py#L291

https://github.com/spotify/luigi/actions/runs/13086478927/job/36518207022?pr=3338#step:6:166

I think the root cause of this problem is Python 3.7.9 runtime.

The succeeded case runs in 3.7.17.

https://github.com/spotify/luigi/actions/runs/12875540263/job/35897024647#step:7:19

The reason why the CI in this PR for Python 3.7 run in 3.7.9 is uv supports only 3.7.9 for Python 3.7

We cannot use newer Python with uv because uv using python frompython-builds-standalone and it dropped Python 3.7.10+ support.

https://github.com/astral-sh/python-build-standalone/releases/tag/20210103

We might need to consider dropping support for Python 3.7.

Do you have any idea solving this problem?

With 3.7 already EOL for awhile I think it's fine dropping support.

@dlstadther
Copy link
Collaborator

Looking at https://pypistats.org/packages/luigi , there are still 3.7 downloads, but fewer than 3.8+. I'm in favor of removing 3.7 support

@hirosassa
Copy link
Contributor Author

@dlstadther @RRap0so Thanks for your comment!
Let's drop Python 3.7.

@hirosassa hirosassa force-pushed the migration-to-uv branch 2 times, most recently from 9d5181b to 99ac166 Compare February 2, 2025 02:15
@hirosassa hirosassa marked this pull request as ready for review February 2, 2025 02:28
@hirosassa
Copy link
Contributor Author

@dlstadther This PR is ready for review!

@RRap0so
Copy link
Contributor

RRap0so commented Feb 3, 2025

We probably need to drop the checks for 3.7 but I'm wondering why there's 3.8,3.9 even 3.10 checks not being reported?

@hirosassa can you take a look at the changes? Something is up, some checks haven't ran.

I can remove the 3.7 checks once this is good to go.

@hirosassa
Copy link
Contributor Author

hirosassa commented Feb 3, 2025

@RRap0so Thank you for your comment!
This is because I changed environment matrixes changes, for example for simplifying environment specification.
So we should follow repository setting of "must pass CI".
You can fix this on settings > branch > master > edit > Require a pull request before merging > Status checks that are required.

@hirosassa hirosassa requested a review from dlstadther February 3, 2025 20:56
Copy link
Collaborator

@dlstadther dlstadther left a comment

Choose a reason for hiding this comment

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

A few comments/questions.

Also, we'll need to have the merge approval settings updated by @RRap0so .

- name: Build
env:
TOXENV: ${{ matrix.tox-env }}
OVERRIDE_SKIP_CI_TESTS: ${{ matrix.OVERRIDE_SKIP_CI_TESTS }}
run: tox
run: uvx --with tox-uv tox run
Copy link
Collaborator

Choose a reason for hiding this comment

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

The step just below this line includes a conditional to not run coverage upload if flake8 or docs. But this "others" matrix only includes flake8 and docs. Could we then remove its Upload coverage to Codecov step entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 48650b7

@@ -1,13 +1,14 @@
For maintainers of Luigi, who have push access to pypi. Here's how you upload
Luigi to pypi.

#. Make sure [twine](https://pypi.org/project/twine/) is installed ``pip install twine``.
#. Update version number in `luigi/__meta__.py`.
#. Make sure [uv](https://github.com/astral-sh/uv) is installed ``curl -LsSf https://astral.sh/uv/install.sh | sh``.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we suggest to install uv with curl+sh, but in contributing.rst, we suggest pipx. We should be consistent between the two docs. Personally, i prefer curl+sh because it doesn't require the installation of another tool to install uv.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 6f8a76f

@@ -67,7 +67,10 @@ def _warn_node(self, msg, node, *args, **kwargs):

sphinx.environment.BuildEnvironment.warn_node = _warn_node

if os.environ.get('READTHEDOCS', None) == 'True':
# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hirosassa , how you thought how we can be sure that we don't break RTD when merging this PR?

- name: Install dependencies
run: |
python -m pip install --upgrade pip 'tox<4.0'
uv tool install --python-preference only-managed --python 3.12 tox --with tox-uv
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused how the CI is working know to use the correct python version for each tox environment. Could you help me understand why we use py 3.12 to install tox, but expect the correct python version to run the specific tox environment tests? Are there details within tox-uv that handle this?

Copy link
Contributor Author

@hirosassa hirosassa Feb 7, 2025

Choose a reason for hiding this comment

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

Are there details within tox-uv that handle this?

Yes, you are right.
ref: https://github.com/tox-dev/tox-uv

if you run uvx --with tox-uv tox -e py311 then we can see the log below:

$ uvx --with tox-uv tox -e py311
py311: uv-sync> uv sync --frozen --python-preference system --no-dev -p cpython3.11
...

At the first line of the log shows constructing process of Python 3.11 environment.

@hirosassa hirosassa requested a review from dlstadther February 7, 2025 05:57
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.

Migrate setup.py to pyproject.toml
3 participants