Skip to content

Commit 33bf553

Browse files
committed
Move _tf_keras directory to the root of the pip package.
1 parent 99fdbf7 commit 33bf553

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

keras/src/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from keras.src.api_export import keras_export
22

33
# Unique source of truth for the version number.
4-
__version__ = "3.3.0"
4+
__version__ = "3.3.1"
55

66

77
@keras_export("keras.version")

pip_build.py

+51-7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,57 @@ def export_version_string(version, is_nightly=False, rc_index=None):
6060
f.write(init_contents)
6161

6262

63+
def ignore_files(_, filenames):
64+
return [f for f in filenames if f.endswith("_test.py")]
65+
66+
67+
def copy_source_to_build_directory(root_path):
68+
# Copy sources (`keras/` directory and setup files) to build
69+
# directory
70+
os.chdir(root_path)
71+
os.mkdir(build_directory)
72+
shutil.copytree(
73+
package, os.path.join(build_directory, package), ignore=ignore_files
74+
)
75+
for fname in to_copy:
76+
shutil.copy(fname, os.path.join(f"{build_directory}", fname))
77+
os.chdir(build_directory)
78+
79+
80+
def build(root_path, is_nightly=False, rc_index=None):
81+
if os.path.exists(build_directory):
82+
raise ValueError(f"Directory already exists: {build_directory}")
83+
84+
try:
85+
copy_source_to_build_directory(root_path)
86+
create_legacy_directory()
87+
from keras.src.version import __version__ # noqa: E402
88+
89+
export_version_string(__version__, is_nightly, rc_index)
90+
return build_and_save_output(root_path, __version__)
91+
finally:
92+
# Clean up: remove the build directory (no longer needed)
93+
shutil.rmtree(build_directory)
94+
95+
96+
def create_legacy_directory():
97+
shutil.move(os.path.join("keras", "api", "_tf_keras"), "keras")
98+
with open(os.path.join("keras", "api", "__init__.py")) as f:
99+
contents = f.read()
100+
contents = contents.replace("from keras.api import _tf_keras", "")
101+
with open(os.path.join("keras", "api", "__init__.py"), "w") as f:
102+
f.write(contents)
103+
104+
with open(os.path.join("keras", "_tf_keras", "__init__.py")) as f:
105+
contents = f.read()
106+
contents = contents.replace(
107+
"from keras.api._tf_keras import keras",
108+
"from keras._tf_keras import keras",
109+
)
110+
with open(os.path.join("keras", "_tf_keras", "__init__.py"), "w") as f:
111+
f.write(contents)
112+
113+
63114
def build_and_save_output(root_path, __version__):
64115
# Build the package
65116
os.system("python3 -m build")
@@ -85,13 +136,6 @@ def build_and_save_output(root_path, __version__):
85136
return whl_path
86137

87138

88-
def build(root_path, is_nightly=False, rc_index=None):
89-
from keras.src.version import __version__ # noqa: E402
90-
91-
export_version_string(__version__, is_nightly, rc_index)
92-
return build_and_save_output(root_path, __version__)
93-
94-
95139
def install_whl(whl_fpath):
96140
print(f"Installing wheel file: {whl_fpath}")
97141
os.system(f"pip3 install {whl_fpath} --force-reinstall --no-dependencies")

0 commit comments

Comments
 (0)