From 2a9f1ee926ae6ed4f27cff704a70a517c3c65ab7 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Wed, 30 Oct 2024 23:04:52 +1300 Subject: [PATCH 1/5] Move project metadata from setup.py to pyproject.toml --- .github/workflows/actions.yml | 4 +-- .github/workflows/nightly.yml | 4 +-- pip_build.py | 19 +++++----- pyproject.toml | 39 ++++++++++++++++++++ setup.py | 67 ----------------------------------- 5 files changed, 52 insertions(+), 81 deletions(-) delete mode 100644 setup.py diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 81c7e4f5ea5..88c5ce49893 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 5bf954f4891..0a6ae5cb7a6 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 66e7578eee2..5c9b996a409 100644 --- a/pip_build.py +++ b/pip_build.py @@ -22,6 +22,7 @@ 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 @@ -29,22 +30,20 @@ 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"] 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) diff --git a/pyproject.toml b/pyproject.toml index e7dfee5fa76..c5fd32cbc37 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,42 @@ +[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"} + +[tool.setuptools.packages.find] +include = ["keras", "keras.*"] + [tool.black] line-length = 80 diff --git a/setup.py b/setup.py deleted file mode 100644 index 6d8096a0b85..00000000000 --- 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"), - ), -) From 5c182ed127e059aed6cd3c00e94928c5b3a2a3b4 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Wed, 30 Oct 2024 23:52:59 +1300 Subject: [PATCH 2/5] Override black target version (for now) to avoid other changes --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index c5fd32cbc37..44516c80d35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ include = ["keras", "keras.*"] [tool.black] line-length = 80 +target-version = [] # black needs this to be a regex # to add more exclude expressions From 8a37452839999eb690820abfad57255a71eb6353 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Thu, 31 Oct 2024 08:05:37 +1300 Subject: [PATCH 3/5] PR feedback --- pip_build.py | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pip_build.py b/pip_build.py index 5c9b996a409..1c82a7db434 100644 --- a/pip_build.py +++ b/pip_build.py @@ -30,7 +30,7 @@ package = "keras" build_directory = "tmp_build_dir" dist_directory = "dist" -to_copy = ["pyproject.toml", "README.md", "requirements-common.txt"] +to_copy = ["pyproject.toml", "README.md"] def export_version_string(version, is_nightly=False, rc_index=None): diff --git a/pyproject.toml b/pyproject.toml index 44516c80d35..387369468cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ Repository = "https://github.com/keras-team/keras" [tool.setuptools.dynamic] version = {attr = "keras.src.version.__version__"} dependencies = {file = "requirements-common.txt"} +# Run also: pip install -r requirements.txt [tool.setuptools.packages.find] include = ["keras", "keras.*"] From 197f44291d9a49d2ac2f9c326b84899bddc215d5 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Fri, 1 Nov 2024 09:40:57 +1300 Subject: [PATCH 4/5] Move explicit list of dependencies from setup.py to pyproject.toml --- pyproject.toml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 387369468cf..12c2de3353a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ 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", @@ -24,7 +25,17 @@ classifiers = [ "Topic :: Scientific/Engineering", "Topic :: Software Development", ] -dynamic = ["version", "dependencies"] +dependencies = [ + "absl-py", + "numpy", + "rich", + "namex", + "h5py", + "optree", + "ml-dtypes", + "packaging", +] +# Run also: pip install -r requirements.txt [project.urls] Home = "https://keras.io/" @@ -32,8 +43,6 @@ Repository = "https://github.com/keras-team/keras" [tool.setuptools.dynamic] version = {attr = "keras.src.version.__version__"} -dependencies = {file = "requirements-common.txt"} -# Run also: pip install -r requirements.txt [tool.setuptools.packages.find] include = ["keras", "keras.*"] From 44456bf400e631af47afdac55763c2dc1b77b797 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Fri, 1 Nov 2024 09:44:31 +1300 Subject: [PATCH 5/5] pathlib was already imported --- pip_build.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pip_build.py b/pip_build.py index 1c82a7db434..f0022e415cd 100644 --- a/pip_build.py +++ b/pip_build.py @@ -22,7 +22,6 @@ 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 @@ -39,7 +38,7 @@ def export_version_string(version, is_nightly=False, rc_index=None): date = datetime.datetime.now() version += f".dev{date:%Y%m%d%H}" # Update `name = "keras"` with "keras-nightly" - pyproj_pth = Path("pyproject.toml") + pyproj_pth = pathlib.Path("pyproject.toml") pyproj_str = pyproj_pth.read_text().replace( 'name = "keras"', 'name = "keras-nightly"' )