1313# limitations under the License.
1414"""Script to create (and optionally install) a `.whl` archive for KerasHub.
1515
16+ By default this will also create a shim package for `keras-nlp` (the old
17+ package name) that provides a backwards compatible namespace.
18+
1619Usage:
1720
18- 1. Create a `.whl` file in `dist/`:
21+ 1. Create `.whl` files in `dist/` and `keras_nlp/ dist/`:
1922
2023```
2124python3 pip_build.py
2225```
2326
24- 2. Also install the new package immediately after:
27+ 2. Also install the new packages immediately after:
2528
2629```
2730python3 pip_build.py --install
2831```
32+
33+ 3. Only build keras-hub:
34+
35+ ```
36+ python3 pip_build.py --install --skip_keras_nlp
37+ ```
2938"""
3039
3140import argparse
@@ -49,14 +58,20 @@ def ignore_files(_, filenames):
4958def update_version (build_path , package , version , is_nightly = False ):
5059 """Export Version and Package Name."""
5160 package_name = package .replace ("_" , "-" )
52- if is_nightly :
53- date = datetime .datetime .now ()
54- version += f".dev{ date .strftime ('%Y%m%d%H' )} "
55- package_name = f"{ package } -nightly"
5661
5762 with open (build_path / "setup.py" ) as f :
5863 setup_contents = f .read ()
5964 with open (build_path / "setup.py" , "w" ) as f :
65+ if is_nightly :
66+ date = datetime .datetime .now ()
67+ version += f".dev{ date .strftime ('%Y%m%d%H%M' )} "
68+ package_name = f"{ package_name } -nightly"
69+ if package == nlp_package :
70+ # keras-nlp-nightly needs to depend on keras-hub-nightly
71+ hub_name = hub_package .replace ("_" , "-" )
72+ setup_contents = setup_contents .replace (
73+ hub_name , f"{ hub_name } -nightly"
74+ )
6075 setup_contents = setup_contents .replace (
6176 "name=" , f'name="{ package_name } ", # '
6277 )
@@ -157,22 +172,19 @@ def install_whl(whls):
157172 "--install" ,
158173 action = "store_true" ,
159174 help = "Whether to install the generated wheel file." ,
160- default = False ,
161175 )
162176 parser .add_argument (
163177 "--nightly" ,
164178 action = "store_true" ,
165179 help = "Whether to generate nightly wheel file." ,
166- default = False ,
167180 )
168181 parser .add_argument (
169- "--keras_nlp " ,
182+ "--skip_keras_nlp " ,
170183 action = "store_true" ,
171184 help = "Whether to build the keras-nlp shim package." ,
172- default = True ,
173185 )
174186 args = parser .parse_args ()
175187 root_path = pathlib .Path (__file__ ).parent .resolve ()
176- whls = build (root_path , args .nightly , args .keras_nlp )
188+ whls = build (root_path , args .nightly , not args .skip_keras_nlp )
177189 if whls and args .install :
178190 install_whl (whls )
0 commit comments