Skip to content

Commit f5558c7

Browse files
authored
Add requirements.txt, .gitignore, setup.py and github actions. (#5)
1 parent a30ed37 commit f5558c7

File tree

8 files changed

+233
-0
lines changed

8 files changed

+233
-0
lines changed

.github/workflows/actions.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_call:
7+
release:
8+
types: [created]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
run_tests:
15+
name: Test the code
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
backend: [tensorflow, jax, torch]
20+
runs-on: ubuntu-latest
21+
env:
22+
KERAS_BACKEND: ${{ matrix.backend }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python 3.9
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: 3.9
29+
- name: Get pip cache dir
30+
id: pip-cache
31+
run: |
32+
python -m pip install --upgrade pip setuptools
33+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
34+
- name: pip cache
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ steps.pip-cache.outputs.dir }}
38+
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
39+
restore-keys: |
40+
${{ runner.os }}-pip-
41+
- name: Install dependencies
42+
run: |
43+
pip install -r requirements.txt --progress-bar off
44+
pip install --no-deps -e "." --progress-bar off
45+
- name: Test with pytest
46+
run: |
47+
pytest keras_rs/
48+
check_format:
49+
name: Check the code format
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Set up Python 3.9
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: 3.9
57+
- name: Get pip cache dir
58+
id: pip-cache
59+
run: |
60+
python -m pip install --upgrade pip setuptools
61+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
62+
- name: pip cache
63+
uses: actions/cache@v4
64+
with:
65+
path: ${{ steps.pip-cache.outputs.dir }}
66+
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
67+
restore-keys: |
68+
${{ runner.os }}-pip-
69+
- name: Install dependencies
70+
run: |
71+
pip install -r requirements.txt --progress-bar off
72+
pip install --no-deps -e "." --progress-bar off
73+
- name: Lint
74+
run: bash shell/lint.sh
75+
- name: Check for API changes
76+
run: |
77+
bash shell/api_gen.sh
78+
git status
79+
clean=$(git status | grep "nothing to commit")
80+
if [ -z "$clean" ]; then
81+
echo "Please run shell/api_gen.sh to generate API."
82+
exit 1
83+
fi

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Python temp files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Vim temp files
7+
*.swp
8+
*.swo
9+
10+
*.egg-info/
11+
dist/
12+
13+
.coverage
14+
.coverage.*
15+
16+
# Windows-specific build files
17+
build/
18+
19+
# Pycharm files
20+
.idea/
21+
22+
venv/

requirements-common.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# api generation
2+
namex>=0.0.8
3+
4+
# formatting and linting
5+
black>=22
6+
flake8
7+
isort
8+
mypy
9+
10+
# testing
11+
absl-py
12+
pytest
13+
pytest-cov
14+
numpy
15+
16+
# pip build
17+
build
18+
19+
# keras
20+
keras

requirements-jax-cuda.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tensorflow cpu-only version.
2+
tensorflow-cpu
3+
4+
# Torch cpu-only version.
5+
--extra-index-url https://download.pytorch.org/whl/cpu
6+
torch>=2.1.0
7+
torchvision>=0.16.0
8+
9+
# Jax with cuda support.
10+
# Keep same version as Keras repo.
11+
--find-links https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
12+
jax[cuda12_pip]==0.4.28
13+
14+
-r requirements-common.txt

requirements-tensorflow-cuda.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Tensorflow with cuda support.
2+
tensorflow[and-cuda]~=2.17.0
3+
4+
# Torch cpu-only version.
5+
--extra-index-url https://download.pytorch.org/whl/cpu
6+
torch>=2.1.0
7+
torchvision>=0.16.0
8+
9+
# Jax cpu-only version.
10+
jax[cpu]
11+
12+
-r requirements-common.txt

requirements-torch-cuda.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Tensorflow cpu-only version.
2+
tensorflow-cpu~=2.17
3+
4+
# Torch with cuda support.
5+
--extra-index-url https://download.pytorch.org/whl/cu121
6+
torch==2.4.1+cu121
7+
torchvision==0.19.1+cu121
8+
9+
# Jax cpu-only version.
10+
jax[cpu]
11+
12+
-r requirements-common.txt

requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Tensorflow.
2+
tensorflow-cpu~=2.17
3+
4+
# Torch.
5+
--extra-index-url https://download.pytorch.org/whl/cpu
6+
torch>=2.1.0
7+
torchvision>=0.16.0
8+
9+
# Jax.
10+
jax[cpu]
11+
12+
-r requirements-common.txt

setup.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Setup script."""
2+
3+
import os
4+
import pathlib
5+
6+
from setuptools import find_packages
7+
from setuptools import setup
8+
9+
10+
def read(rel_path: str) -> str:
11+
here = os.path.abspath(os.path.dirname(__file__))
12+
with open(os.path.join(here, rel_path)) as fp:
13+
return fp.read()
14+
15+
16+
def get_version(rel_path: str) -> str:
17+
for line in read(rel_path).splitlines():
18+
if line.startswith("__version__"):
19+
delim = '"' if '"' in line else "'"
20+
return line.split(delim)[1]
21+
raise RuntimeError("Unable to find version string.")
22+
23+
24+
HERE = pathlib.Path(__file__).parent
25+
README = (HERE / "README.md").read_text()
26+
VERSION = get_version("keras_rs/src/version_utils.py")
27+
28+
setup(
29+
name="keras-rs",
30+
description=("Multi-backend recommender systems with Keras 3."),
31+
long_description=README,
32+
long_description_content_type="text/markdown",
33+
version=VERSION,
34+
url="https://github.com/keras-team/keras-rs",
35+
author="Keras team",
36+
author_email="[email protected]",
37+
license="Apache License 2.0",
38+
install_requires=[
39+
"keras",
40+
],
41+
# Supported Python versions
42+
python_requires=">=3.9",
43+
classifiers=[
44+
"Development Status :: 3 - Alpha",
45+
"Programming Language :: Python :: 3",
46+
"Programming Language :: Python :: 3.9",
47+
"Programming Language :: Python :: 3.10",
48+
"Programming Language :: Python :: 3.11",
49+
"Programming Language :: Python :: 3 :: Only",
50+
"Operating System :: Unix",
51+
"Operating System :: Microsoft :: Windows",
52+
"Operating System :: MacOS",
53+
"Intended Audience :: Science/Research",
54+
"Topic :: Scientific/Engineering",
55+
"Topic :: Software Development",
56+
],
57+
packages=find_packages(), # exclude=("keras_rs.src.testing",)),
58+
)

0 commit comments

Comments
 (0)