Skip to content

Commit

Permalink
chore: fix missing client bundle in Python wheels
Browse files Browse the repository at this point in the history
Fixes google#542.
  • Loading branch information
jbms committed Mar 18, 2024
1 parent 64e3809 commit 121c82d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ exclude .prettierrc.yml
exclude .prettierignore
exclude .eslintrc.yml
exclude index.html
exclude webpack.config.js
exclude firebase.json
exclude .firebaserc
5 changes: 4 additions & 1 deletion build_tools/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function getWebpackConfig(
webpackEnv = { ...webpackEnv, NEUROGLANCER_CLI: true };
const conditions = argv.conditions;
if (argv.python) conditions.push("neuroglancer/python");
const outDir =
let outDir =
(argv.output as string | undefined) ??
(argv.python
? path.resolve(
Expand All @@ -105,6 +105,9 @@ async function getWebpackConfig(
"client",
)
: undefined);
if (outDir !== undefined) {
outDir = path.resolve(outDir);
}
const plugins = [];
if (argv.typecheck || argv.lint) {
plugins.push(
Expand Down
2 changes: 1 addition & 1 deletion firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hosting": {
"target": "app",
"public": "dist/min"
"public": "dist/client"
}
}
6 changes: 4 additions & 2 deletions python/build_tools/cibuildwheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export CIBW_SKIP="cp27-* cp36-* cp37-* cp38-* pp* *_i686 *-win32 *-musllinux*"
export CIBW_TEST_REQUIRES="-r python/requirements-test.txt"
export CIBW_TEST_COMMAND="python -m pytest {project}/python/tests -vv -s --skip-browser-tests"
export CIBW_MANYLINUX_X86_64_IMAGE=manylinux2014
export CIBW_ENVIRONMENT_PASS_LINUX="NEUROGLANCER_BUILD_BUNDLE_INPLACE"

export NEUROGLANCER_BUILD_BUNDLE_INPLACE=1
# Assume the client bundle was already built. The github actions workflow builds
# the client with specific defines to include the build stamp, and that would be
# lost if setup.py rebuilds the client.
export CIBW_ENVIRONMENT="NEUROGLANCER_PREBUILT_CLIENT=1"

script_dir="$(dirname "$0")"
root_dir="${script_dir}/../.."
Expand Down
22 changes: 15 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ class BundleClientCommand(
None,
'The nodejs bundle type. "production" (default) creates condensed static files for production, "development" creates human-readable files.',
),
(
"prebuilt-bundle",
None,
"Assume the client bundle already exists within the source tree, and don't build it again.",
),
("build-bundle-inplace", None, "Build the client bundle inplace."),
(
"skip-npm-reinstall",
Expand All @@ -154,7 +159,8 @@ def initialize_options(self):
self.client_bundle_type = "production"
self.skip_npm_reinstall = None
self.skip_rebuild = None
self.build_bundle_inplace = None
self.build_bundle_inplace = False
self.prebuilt_bundle = None

def finalize_options(self):
self.set_undefined_options("build_py", ("build_lib", "build_lib"))
Expand All @@ -167,10 +173,8 @@ def finalize_options(self):
if self.skip_npm_reinstall is None:
self.skip_npm_reinstall = False

if self.build_bundle_inplace is None:
self.build_bundle_inplace = (
os.getenv("NEUROGLANCER_BUILD_BUNDLE_INPLACE") == "1"
)
if self.prebuilt_bundle is None:
self.prebuilt_bundle = os.getenv("NEUROGLANCER_PREBUILT_CLIENT") == "1"

if self.skip_rebuild is None:
self.skip_rebuild = self.build_bundle_inplace
Expand Down Expand Up @@ -209,8 +213,12 @@ def run(self):

# If building from an sdist, `package.json` won't be present but the
# bundled files will.
if not _PACKAGE_JSON_EXISTS:
print("Skipping build of client bundle because package.json does not exist")
if not _PACKAGE_JSON_EXISTS or self.prebuilt_bundle:
if not _PACKAGE_JSON_EXISTS:
reason = "package.json does not exist"
else:
reason = "it was prebuilt"
print(f"Skipping build of client bundle because {reason}")
if not self.build_bundle_inplace:
shutil.copytree(
self._get_inplace_client_dir(), self._get_client_output_dir()
Expand Down

0 comments on commit 121c82d

Please sign in to comment.