Skip to content

Commit 876e4d4

Browse files
SK-3118: Make flowvault sdist self-contained (bundle common/)
The custom build_py vendors the sibling common/ tree into the wheel, but the sdist never included it, so a source build (pip --no-binary, some mirrors) produced a package that fails to import common. Add a custom sdist command that vendors common/ into the tarball (MANIFEST grafts it) and clean it up after, and resolve COMMON_SRC from that vendored copy when the sibling checkout is absent (i.e. when building from the sdist). Exclude common from find_packages so the vendored copy is bundled only through the build_py mechanism. Wheel builds are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 872fefe commit 876e4d4

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎flowvault/MANIFEST.in‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
graft common
12
prune samples
3+
global-exclude *.pyc
4+
global-exclude __pycache__

‎flowvault/setup.py‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from setuptools import setup, find_packages
99
from setuptools.command.build_py import build_py as _build_py
10+
from setuptools.command.sdist import sdist as _sdist
1011

1112

1213
if sys.version_info < (3, 9):
@@ -15,12 +16,15 @@
1516

1617
HERE = os.path.abspath(os.path.dirname(__file__))
1718
REPO_ROOT = os.path.dirname(HERE)
19+
VENDORED_COMMON = os.path.join(HERE, 'common')
1820
COMMON_SRC = os.path.join(REPO_ROOT, 'common')
21+
if not os.path.isdir(COMMON_SRC):
22+
COMMON_SRC = VENDORED_COMMON
1923

2024
with open(os.path.join(HERE, 'README.md'), 'r', encoding='utf-8') as f:
2125
long_description = f.read()
2226

23-
_COMMON_EXCLUDE_DIRS = {'__pycache__', '.pytest_cache', 'tests', '.mypy_cache'}
27+
_COMMON_EXCLUDE_DIRS = {'__pycache__', '.pytest_cache', 'tests', '.mypy_cache', 'build', 'dist'}
2428
_COMMON_EXCLUDE_FILES = {'setup.py', 'pyproject.toml', 'requirements.txt', '.gitignore'}
2529
_COMMON_EXCLUDE_SUFFIXES = ('.egg-info',)
2630

@@ -37,7 +41,8 @@ def _ignore_common_files(_directory, names):
3741

3842
class CustomBuildPy(_build_py):
3943
"""SK-2938 Option C bundling mechanism -- see skyvault/setup.py for full rationale. Bundles the
40-
sibling common/ source tree into this variant's wheel; wheel builds only, not sdist."""
44+
common/ source tree into this variant's wheel, from the sibling checkout or, when building from
45+
an sdist, from the copy vendored into the tarball by CustomSdist."""
4146

4247
def run(self):
4348
super().run()
@@ -47,17 +52,32 @@ def run(self):
4752
shutil.copytree(COMMON_SRC, dest, ignore=_ignore_common_files)
4853

4954

55+
class CustomSdist(_sdist):
56+
def run(self):
57+
copied = False
58+
if os.path.isdir(COMMON_SRC) and os.path.abspath(COMMON_SRC) != os.path.abspath(VENDORED_COMMON):
59+
if os.path.exists(VENDORED_COMMON):
60+
shutil.rmtree(VENDORED_COMMON)
61+
shutil.copytree(COMMON_SRC, VENDORED_COMMON, ignore=_ignore_common_files)
62+
copied = True
63+
try:
64+
super().run()
65+
finally:
66+
if copied:
67+
shutil.rmtree(VENDORED_COMMON)
68+
69+
5070
setup(
5171
name='skyflow-flowvault-python',
5272
version=current_version,
5373
author='Skyflow',
5474
author_email='service-ops@skyflow.com',
55-
packages=find_packages(where='.', exclude=['test*', 'samples*']),
75+
packages=find_packages(where='.', exclude=['test*', 'samples*', 'common', 'common.*']),
5676
package_data={
5777
'skyflow': ['py.typed'],
5878
'skyflow.generated.rest': ['py.typed'],
5979
},
60-
cmdclass={'build_py': CustomBuildPy},
80+
cmdclass={'build_py': CustomBuildPy, 'sdist': CustomSdist},
6181
url='https://github.com/skyflowapi/skyflow-python/',
6282
license='LICENSE',
6383
description='Skyflow SDK for the Python programming language (v3 / flowservice API)',

0 commit comments

Comments
 (0)