Repository: keras-team/keras-nlp

Issue:
Tests included with release
Seems the test files are not excluded for release?

https://github.com/keras-team/keras-nlp/blob/2c8e915859ffcb3ba2d19e7707cce542d92c6b96/pip_build.py#L58C27-L58C27

By copying the code to KerasTuner, the tests were included with the release.
So I made this change:

https://github.com/keras-team/keras-tuner/blob/3c3cce890d21f4c59ecb72ef203008966eb6e357/pip_build.py#L32

@mattdangerw 


Discussion:

Resolving patch:
diff --git a/pip_build.py b/pip_build.py
--- a/pip_build.py
+++ b/pip_build.py
@@ -46,6 +46,10 @@
 ]
 
 
+def ignore_files(_, filenames):
+    return [f for f in filenames if "_test" in f]
+
+
 def export_version_string(version, is_nightly=False):
     """Export Version and Package Name."""
     if is_nightly:
@@ -80,52 +84,66 @@ def export_version_string(version, is_nightly=False):
         f.write("from keras_nlp.src.version_utils import __version__\n")
 
 
-def build(root_path, is_nightly=False):
-    if os.path.exists(build_directory):
-        raise ValueError(f"Directory already exists: {build_directory}")
+def copy_source_to_build_directory(root_path):
+    # Copy sources (`keras_nlp/` directory and setup files) to build dir
+    os.chdir(root_path)
+    os.mkdir(build_directory)
+    shutil.copytree(
+        package, os.path.join(build_directory, package), ignore=ignore_files
+    )
+    for fname in to_copy:
+        shutil.copy(fname, os.path.join(f"{build_directory}", fname))
+    os.chdir(build_directory)
+
+
+def run_namex_conversion():
+    # Restructure the codebase so that source files live in `keras_nlp/src`
+    namex.convert_codebase(package, code_directory="src")
+
+    # Generate API __init__.py files in `keras_nlp/`
+    namex.generate_api_files(package, code_directory="src", verbose=True)
+
+
+def build_and_save_output(root_path, __version__):
+    """Build the package."""
+    os.system("python3 -m build")
 
+    # Save the dist files generated by the build process
+    os.chdir(root_path)
+    if not os.path.exists(dist_directory):
+        os.mkdir(dist_directory)
+    for fpath in glob.glob(
+        os.path.join(build_directory, dist_directory, "*.*")
+    ):
+        shutil.copy(fpath, dist_directory)
+
+    # Find the .whl file path
     whl_path = None
-    try:
-        # Copy sources (`keras_nlp/` directory and setup files) to build directory
-        os.chdir(root_path)
-        os.mkdir(build_directory)
-        shutil.copytree(package, os.path.join(build_directory, package))
-        for fname in to_copy:
-            shutil.copy(fname, os.path.join(f"{build_directory}", fname))
-        os.chdir(build_directory)
+    for fname in os.listdir(dist_directory):
+        if __version__ in fname and fname.endswith(".whl"):
+            whl_path = os.path.abspath(os.path.join(dist_directory, fname))
+    if whl_path:
+        print(f"Build successful. Wheel file available at {whl_path}")
+    else:
+        print("Build failed.")
+    return whl_path
 
-        # Restructure the codebase so that source files live in `keras_nlp/src`
-        namex.convert_codebase(package, code_directory="src")
 
-        # Generate API __init__.py files in `keras_nlp/`
-        namex.generate_api_files(package, code_directory="src", verbose=True)
+def build(root_path, is_nightly=False):
+    if os.path.exists(build_directory):
+        raise ValueError(f"Directory already exists: {build_directory}")
 
+    try:
+        copy_source_to_build_directory(root_path)
+        run_namex_conversion()
         # Make sure to export the __version__ string
         from keras_nlp.src import __version__  # noqa: E402
 
         export_version_string(__version__, is_nightly)
-
-        # Build the package
-        os.system("python3 -m build")
-
-        # Save the dist files generated by the build process
-        os.chdir(root_path)
-        if not os.path.exists(dist_directory):
-            os.mkdir(dist_directory)
-        for fpath in glob.glob(
-            os.path.join(build_directory, dist_directory, "*.*")
-        ):
-            shutil.copy(fpath, dist_directory)
-
-        # Find the .whl file path
-        for fname in os.listdir(dist_directory):
-            if __version__ in fname and fname.endswith(".whl"):
-                whl_path = os.path.abspath(os.path.join(dist_directory, fname))
-        print(f"Build successful. Wheel file available at {whl_path}")
+        return build_and_save_output(root_path, __version__)
     finally:
         # Clean up: remove the build directory (no longer needed)
         shutil.rmtree(build_directory)
-    return whl_path
 
 
 def install_whl(whl_fpath):


Test patch: