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 for packaging #4164

Merged
merged 33 commits into from
Jan 30, 2023

Conversation

himkt
Copy link
Member

@himkt himkt commented Nov 12, 2022

Motivation

This PR migrates from setup.py to pyproject.toml for the packaging configuration file. With this migration, we can easily retrieve the package metadata using TOML parser (it's tricky with setup.py since we need to parse a Python script). The ecosystem of packaging Python project with pyproject.toml is getting practical so I propose to start defining the package metadata with pyproject.toml.

Description of the changes

References

@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2022

Codecov Report

Merging #4164 (fbe44e3) into master (b84022a) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #4164   +/-   ##
=======================================
  Coverage   90.43%   90.43%           
=======================================
  Files         172      172           
  Lines       13660    13660           
=======================================
  Hits        12354    12354           
  Misses       1306     1306           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@c-bata c-bata self-assigned this Nov 14, 2022
@himkt
Copy link
Member Author

himkt commented Nov 14, 2022

I got the feedback (from core-dev team) that we can go ahead for this transition, so let me remove RFC. I will revisit after some dependent PRs are merged.

@himkt himkt changed the title [RFC] Migration to pyproject.toml for packaging Migration to pyproject.toml for packaging Nov 14, 2022
@c-bata c-bata added the other Issue/PR that does not fit into any other label. label Nov 14, 2022
@c-bata c-bata added this to the v3.1.0 milestone Nov 14, 2022
Copy link
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

I understand it's WIP but left a single request change since I noticed while reviewing another PRs.

It's required to fix all actions that uses actions/cache to cache ~/.cache/pip since hashFiles('**/setup.py') is included in the cache key.
https://github.com/optuna/optuna/blob/master/.github/workflows/tests-storage.yml#L69-L77

@himkt
Copy link
Member Author

himkt commented Nov 18, 2022

I updated pyproject.toml based on the changed in setup.py.

It's required to fix all actions that uses actions/cache to cache ~/.cache/pip since hashFiles('**/setup.py') is included in the cache key.

Thank you, I just updated to use pyproject.toml to generate a cache key. 👀

@himkt himkt marked this pull request as ready for review November 18, 2022 06:27
@c-bata
Copy link
Member

c-bata commented Nov 18, 2022

@HideakiImamura Could you review this PR?

Copy link
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

Left some comments while taking a look quickly. Also Could you remove setup.py?

pyproject.toml Outdated Show resolved Hide resolved
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Copy link
Member

Choose a reason for hiding this comment

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

In setup.py, "Programming Language :: Python :: 3.11" is also listed.

https://github.com/optuna/optuna/blob/master/setup.py#L175

himkt and others added 3 commits November 18, 2022 23:27
Co-authored-by: Masashi Shibata <c-bata@users.noreply.github.com>
@himkt
Copy link
Member Author

himkt commented Nov 18, 2022

Also Could you remove setup.py?

Oh, sorry. It restored in syncing the master branch... Removed.

@himkt
Copy link
Member Author

himkt commented Nov 24, 2022

@HideakiImamura @c-bata I merged the master branch and tests passed.
Could you please review the PR again? 🙏

@himkt
Copy link
Member Author

himkt commented Jan 6, 2023

@HideakiImamura @gen740
Sorry for the very late response. 💦 I updated the PR to make asv/pypi-publish work.
PTAL again, especially the package downloaded from (test) PyPI. 🙏

Comment on lines +141 to +142
[tool.setuptools.packages.find]
include = ["optuna*"]
Copy link
Member Author

Choose a reason for hiding this comment

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

Describing package discovery in pyproject.toml is in the beta stage.
https://setuptools.pypa.io/en/latest/userguide/package_discovery.html

If we'd like to avoid the unstable API for building a package, setup.cfg maybe a better place for that.

Copy link
Member

Choose a reason for hiding this comment

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

It would be great to use this simple rule.

Copy link
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

Thanks for the update and investigation! Almost, LGTM!

We have planned to release optuna v3.1.0 in next Monday. Just to be safe, I think this PR, which has a large impact around installation, should be merged after the 3.1.0 release.

pyproject.toml Outdated
"mlflow",
"pandas",
"pillow",
"plotly>=4.0.0", # optuna/visualization.
Copy link
Member

Choose a reason for hiding this comment

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

This version is constrained as plotly>=4.9.0 in the master branch. https://github.com/optuna/optuna/blob/master/setup.py#L74

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, updated in 2379003. 🙇

pyproject.toml Outdated
optional = [
"matplotlib!=3.6.0", # optuna/visualization/matplotlib
"pandas", # optuna/study.py
"plotly>=4.0.0", # optuna/visualization.
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@HideakiImamura
Copy link
Member

And, CI errors will be fixed in #4301.

@himkt
Copy link
Member Author

himkt commented Jan 10, 2023

Thank you for the careful consideration, I agree with you that merge the PR after the next release for safe. 👍

@HideakiImamura @gen740
BTW, I want you to check if you can install Optuna with editable manner.
Editable installation seemingly need pip>=21.3 and setuptools>=64 (but it looks I could do it with pip>=21.3 and setuptools==56). 🤔 I think these requirements can be acceptable to developers, however, any feedback is welcome.
🔗 https://stackoverflow.com/questions/69711606/how-to-install-a-package-using-pip-in-editable-mode-with-pyproject-toml

@gen740
Copy link
Collaborator

gen740 commented Jan 12, 2023

pyproject.toml based project (PEP 621) has supported setuptools >= 61.0.0. So it must not be able to even build the project on setuptools=56. I suspect you are looking different setuptools version.

Copy link
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

Thanks for the update. LGTM. Note that the CI will be fixed by merging the master.

@HideakiImamura
Copy link
Member

Could you merge the master branch?

@HideakiImamura
Copy link
Member

Note that setup.py has been updated, so you need to update pyproject.toml as well.

Copy link
Collaborator

@gen740 gen740 left a comment

Choose a reason for hiding this comment

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

LGTM!

@himkt
Copy link
Member Author

himkt commented Jan 19, 2023

pyproject.toml based project (PEP 621) has supported setuptools >= 61.0.0. So it must not be able to even build the project on setuptools=56. I suspect you are looking different setuptools version.

Hmm..., it seemingly succeeded to install in editable manner with pip==22.0.4 and setuptools==47.1.0. Certainly I'm missing something but I don't have any idea. What am I misunderstanding?

https://gist.github.com/himkt/39a48eff132107b56e125312eb117485


Building the package is done in the isolated environment, which is why we can build the package with old pip/setuptools.

https://gist.github.com/himkt/f441968e9ca9406dabb7c25a5d1a7fe8

@himkt
Copy link
Member Author

himkt commented Jan 19, 2023

Merged the master branch (d104563) and fix dependency degradation (7398c7f). 🙏

Copy link
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

LGTM.

I found a missed todo comment, but it can be added as a follow-up.

"plotly>=4.9.0", # optuna/visualization.
"scikit-learn",
"scikit-optimize",
"sphinx<6",
Copy link
Member

Choose a reason for hiding this comment

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

Missed the todo comment above this line.

# TODO(not522): Remove the constraint after sphinx_rtd_theme supports Sphinx 6

Copy link
Member Author

Choose a reason for hiding this comment

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

🙇 fixed in f81457c.

@HideakiImamura HideakiImamura added installation Installation and dependency. and removed other Issue/PR that does not fit into any other label. labels Jan 20, 2023
@HideakiImamura HideakiImamura added this to the v3.2.0 milestone Jan 20, 2023
@himkt
Copy link
Member Author

himkt commented Jan 25, 2023

a47d580 to reflect #4357.

@c-bata c-bata dismissed their stale review January 30, 2023 01:14

Since I was not reviewer.

@HideakiImamura
Copy link
Member

@himkt I'm so sorry for the delayed response, but could you merge the master to run the Checks CI?

@HideakiImamura HideakiImamura merged commit d3872bd into optuna:master Jan 30, 2023
@himkt himkt deleted the pyproject.toml branch January 30, 2023 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installation Installation and dependency.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants