Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bfbe572
add pyproject.toml
davidhabboosh1 Aug 10, 2025
7f8e864
replace setup.py with pyproject.toml
davidhabboosh1 Aug 10, 2025
ec6db1d
update license line
davidhabboosh1 Aug 10, 2025
d2db4dc
typo
davidhabboosh1 Aug 10, 2025
4db731b
remove sh file
davidhabboosh1 Aug 10, 2025
1c84b57
move BUILD
davidhabboosh1 Aug 10, 2025
e676a5a
put back build_pip_package.sh
davidhabboosh1 Aug 10, 2025
0673d33
add back setup.py at root
davidhabboosh1 Aug 10, 2025
4241e12
move build stuff to root
davidhabboosh1 Aug 10, 2025
d089412
put back build pip package
davidhabboosh1 Aug 10, 2025
6364e46
move packages back and rename build
davidhabboosh1 Aug 11, 2025
2e109a5
use bzl instead of bazel
davidhabboosh1 Aug 11, 2025
60d4bd8
put BUILD back
davidhabboosh1 Aug 11, 2025
db2c475
add custom build folder
davidhabboosh1 Aug 11, 2025
a14fcf9
made executable again?
davidhabboosh1 Aug 11, 2025
08d45fe
use pip-compile rather than bazel
davidhabboosh1 Aug 13, 2025
6403229
fix path
davidhabboosh1 Aug 13, 2025
9683a1d
syntax
davidhabboosh1 Aug 13, 2025
428ac16
debug
davidhabboosh1 Aug 13, 2025
3f99992
more debug
davidhabboosh1 Aug 13, 2025
3819637
syntax
davidhabboosh1 Aug 13, 2025
3e10d48
revamp TF_ABIFLAG
davidhabboosh1 Aug 13, 2025
c4e5eea
syntax
davidhabboosh1 Aug 13, 2025
2683b2e
remove bazel references from prepare_tf_dep.sh
davidhabboosh1 Aug 13, 2025
876145a
debug
davidhabboosh1 Aug 13, 2025
63b45f2
debug removing -e
davidhabboosh1 Aug 13, 2025
eb8932b
add python version of building
davidhabboosh1 Aug 13, 2025
2010645
revert sh files to original and create build_pip_package.py
davidhabboosh1 Aug 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions build_pip_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
import shutil
import subprocess
import sys
import tempfile

def is_nightly():
return os.environ.get("IS_NIGHTLY") == "nightly"

def abspath(path):
return os.path.abspath(path)

def main(output_dir=None):
if output_dir is None:
output_dir = "/tmp/tensorflow_text_pkg"
os.makedirs(output_dir, exist_ok=True)
output_dir = abspath(output_dir)

print(f"=== Destination directory: {output_dir}")
print(f"=== Current directory: {os.getcwd()}")

# Source directories/files in your repo (relative to repo root)
src_tensorflow_text = os.path.join("tensorflow_text")
src_setup_py = os.path.join("oss_scripts", "pip_package", "setup.nightly.py" if is_nightly() else "setup.py")
src_manifest = os.path.join("oss_scripts", "pip_package", "MANIFEST.in")
src_license = os.path.join("oss_scripts", "pip_package", "LICENSE")

# Check if source exists
if not os.path.isdir(src_tensorflow_text):
print(f"Error: directory '{src_tensorflow_text}' not found.", file=sys.stderr)
sys.exit(1)
for f in [src_setup_py, src_manifest, src_license]:
if not os.path.isfile(f):
print(f"Error: file '{f}' not found.", file=sys.stderr)
sys.exit(1)

temp_dir = tempfile.mkdtemp()
print(f"=== Using tmpdir {temp_dir}")

# Copy tensorflow_text directory
dest_tf_text = os.path.join(temp_dir, "tensorflow_text")
shutil.copytree(src_tensorflow_text, dest_tf_text)

# Copy setup.py or setup.nightly.py
shutil.copy(src_setup_py, temp_dir)
setup_script = os.path.basename(src_setup_py)

# Copy MANIFEST.in and LICENSE
shutil.copy(src_manifest, temp_dir)
shutil.copy(src_license, temp_dir)

# Run setup.py bdist_wheel --universal
old_cwd = os.getcwd()
os.chdir(temp_dir)
try:
if shutil.which('python3'):
python_cmd = 'python3'
elif shutil.which('python'):
python_cmd = 'python'
else:
print("Python not found in PATH.", file=sys.stderr)
sys.exit(1)

print(python_cmd, setup_script, "bdist_wheel", "--universal")
subprocess.run([python_cmd, setup_script, "bdist_wheel", "--universal"], check=True)
# Copy generated wheel(s) to output directory
dist_dir = os.path.join(temp_dir, "dist")
for filename in os.listdir(dist_dir):
if filename.endswith(".whl"):
shutil.copy(os.path.join(dist_dir, filename), output_dir)
finally:
os.chdir(old_cwd)
shutil.rmtree(temp_dir)

if __name__ == "__main__":
output_dir_arg = sys.argv[1] if len(sys.argv) > 1 else None
main(output_dir_arg)
9 changes: 8 additions & 1 deletion oss_scripts/pip_package/setup.nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from setuptools import setup
from setuptools.command.install import install
from setuptools.dist import Distribution
from setuptools.command.build import build

project_name = 'tensorflow-text-nightly'
project_version = 'REPLACE_ME'
Expand All @@ -70,6 +71,12 @@ def finalize_options(self):
self.install_lib = os.path.join(self.install_lib, self.extra_dirs)


class BuildToBuildSetuptools(build):
def initialize_options(self):
super().initialize_options()
self.build_base = 'build_setuptools'


DOCLINES = __doc__.split('\n')

setup(
Expand All @@ -84,7 +91,7 @@ def finalize_options(self):
packages=find_packages(),
include_package_data=True,
zip_safe=False,
cmdclass={'install': InstallPlatlib},
cmdclass={'install': InstallPlatlib, 'build': BuildToBuildSetuptools},
distclass=BinaryDistribution,
install_requires=[
],
Expand Down
9 changes: 8 additions & 1 deletion oss_scripts/pip_package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from setuptools import setup
from setuptools.command.install import install
from setuptools.dist import Distribution
from setuptools.command.build import build

project_name = 'tensorflow-text'
project_version = '2.18.0'
Expand All @@ -70,6 +71,12 @@ def finalize_options(self):
self.install_lib = os.path.join(self.install_lib, self.extra_dirs)


class BuildToBuildSetuptools(build):
def initialize_options(self):
super().initialize_options()
self.build_base = 'build_setuptools'


DOCLINES = __doc__.split('\n')

setup(
Expand All @@ -84,7 +91,7 @@ def finalize_options(self):
packages=find_packages(),
include_package_data=True,
zip_safe=False,
cmdclass={'install': InstallPlatlib},
cmdclass={'install': InstallPlatlib, 'build': BuildToBuildSetuptools},
distclass=BinaryDistribution,
install_requires=[
(
Expand Down