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

Move project metadata from setup.py to pyproject.toml #20427

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('requirements.txt') }}
- name: Install dependencies
run: |
pip install -r requirements.txt --progress-bar off --upgrade
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('requirements.txt') }}
- name: Install dependencies
run: |
pip install -r requirements.txt --progress-bar off --upgrade
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('requirements.txt') }}
- name: Install dependencies
run: |
pip install -r requirements.txt --progress-bar off --upgrade
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('requirements.txt') }}
- name: Install dependencies
run: |
pip install -r requirements.txt --progress-bar off --upgrade
Expand Down
19 changes: 9 additions & 10 deletions pip_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,28 @@
import pathlib
import re
import shutil
from pathlib import Path

# Needed because importing torch after TF causes the runtime to crash
import torch # noqa: F401

package = "keras"
build_directory = "tmp_build_dir"
dist_directory = "dist"
to_copy = ["setup.py", "README.md"]
to_copy = ["pyproject.toml", "README.md", "requirements-common.txt"]
mwtoews marked this conversation as resolved.
Show resolved Hide resolved


def export_version_string(version, is_nightly=False, rc_index=None):
"""Export Version and Package Name."""
if is_nightly:
date = datetime.datetime.now()
version += f".dev{date.strftime('%Y%m%d%H')}"
# Replaces `name="keras"` string in `setup.py` with `keras-nightly`
with open("setup.py") as f:
setup_contents = f.read()
with open("setup.py", "w") as f:
setup_contents = setup_contents.replace(
'name="keras"', 'name="keras-nightly"'
)
f.write(setup_contents)
version += f".dev{date:%Y%m%d%H}"
# Update `name = "keras"` with "keras-nightly"
pyproj_pth = Path("pyproject.toml")
pyproj_str = pyproj_pth.read_text().replace(
'name = "keras"', 'name = "keras-nightly"'
)
pyproj_pth.write_text(pyproj_str)
elif rc_index is not None:
version += "rc" + str(rc_index)

Expand Down
40 changes: 40 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
[build-system]
requires = ["setuptools >=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "keras"
authors = [
{name = "Keras team", email = "keras-users@googlegroups.com"},
]
description = "Multi-backend Keras"
readme = "README.md"
requires-python = ">=3.9"
license = {text = "Apache License 2.0"}
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Operating System :: Unix",
"Operating System :: MacOS",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
]
dynamic = ["version", "dependencies"]

[project.urls]
Home = "https://keras.io/"
Repository = "https://github.com/keras-team/keras"

[tool.setuptools.dynamic]
version = {attr = "keras.src.version.__version__"}
dependencies = {file = "requirements-common.txt"}
mwtoews marked this conversation as resolved.
Show resolved Hide resolved

[tool.setuptools.packages.find]
include = ["keras", "keras.*"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

No excludes?

Copy link
Contributor Author

@mwtoews mwtoews Oct 30, 2024

Choose a reason for hiding this comment

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

setup.py had exclude=("*_test.py", "benchmarks"), but this didn't do anything, so was dropped with the transition. The reason why it didn't do anything is that only Python modules under "keras" are found (thus "benchmarks" was already excluded), and individual Python files cannot be excluded -- only modules can be excluded. But I see that pip_build.py has logic to ignore the "_test.py" files.


[tool.black]
line-length = 80
target-version = []
mwtoews marked this conversation as resolved.
Show resolved Hide resolved

# black needs this to be a regex
# to add more exclude expressions
Expand Down
67 changes: 0 additions & 67 deletions setup.py

This file was deleted.