Skip to content

Commit

Permalink
Move project metadata from setup.py to pyproject.toml (keras-team#20427)
Browse files Browse the repository at this point in the history
* Move project metadata from setup.py to pyproject.toml

* Override black target version (for now) to avoid other changes

* PR feedback

* Move explicit list of dependencies from setup.py to pyproject.toml

* pathlib was already imported
  • Loading branch information
mwtoews authored Nov 1, 2024
1 parent 965c4a2 commit cfa32a3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 81 deletions.
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
18 changes: 8 additions & 10 deletions pip_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@
package = "keras"
build_directory = "tmp_build_dir"
dist_directory = "dist"
to_copy = ["setup.py", "README.md"]
to_copy = ["pyproject.toml", "README.md"]


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 = pathlib.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
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
[build-system]
requires = ["setuptools >=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "keras"
authors = [
{name = "Keras team", email = "[email protected]"},
]
description = "Multi-backend Keras"
readme = "README.md"
requires-python = ">=3.9"
license = {text = "Apache License 2.0"}
dynamic = ["version"]
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",
]
dependencies = [
"absl-py",
"numpy",
"rich",
"namex",
"h5py",
"optree",
"ml-dtypes",
"packaging",
]
# Run also: pip install -r requirements.txt

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

[tool.setuptools.dynamic]
version = {attr = "keras.src.version.__version__"}

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

[tool.black]
line-length = 80
target-version = []

# 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.

0 comments on commit cfa32a3

Please sign in to comment.