diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 81c7e4f5ea57..88c5ce49893c 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -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 @@ -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 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 5bf954f48913..0a6ae5cb7a60 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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 @@ -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 diff --git a/pip_build.py b/pip_build.py index 66e7578eee25..f0022e415cd6 100644 --- a/pip_build.py +++ b/pip_build.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index e7dfee5fa761..12c2de3353a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,55 @@ +[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"} +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 diff --git a/setup.py b/setup.py deleted file mode 100644 index 6d8096a0b856..000000000000 --- a/setup.py +++ /dev/null @@ -1,67 +0,0 @@ -"""Setup script.""" - -import os -import pathlib - -from setuptools import find_packages -from setuptools import setup - - -def read(rel_path): - here = os.path.abspath(os.path.dirname(__file__)) - with open(os.path.join(here, rel_path)) as fp: - return fp.read() - - -def get_version(rel_path): - for line in read(rel_path).splitlines(): - if line.startswith("__version__"): - delim = '"' if '"' in line else "'" - return line.split(delim)[1] - raise RuntimeError("Unable to find version string.") - - -HERE = pathlib.Path(__file__).parent -README = (HERE / "README.md").read_text() -VERSION = get_version("keras/src/version.py") - -setup( - name="keras", - description="Multi-backend Keras.", - long_description_content_type="text/markdown", - long_description=README, - version=VERSION, - url="https://github.com/keras-team/keras", - author="Keras team", - author_email="keras-users@googlegroups.com", - license="Apache License 2.0", - install_requires=[ - "absl-py", - "numpy", - "rich", - "namex", - "h5py", - "optree", - "ml-dtypes", - "packaging", - ], - # Supported Python versions - python_requires=">=3.9", - 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", - ], - packages=find_packages( - include=("keras", "keras.*"), - exclude=("*_test.py", "benchmarks"), - ), -)