Skip to content

separate node and python build steps in dash-generate-components #1256

@python273

Description

@python273

Links for building custom components for reference:
https://dash.plotly.com/plugins
https://github.com/plotly/dash-component-boilerplate

Is your feature request related to a problem? Please describe.
Building custom dash components requires nodejs + python at the same time. It complicates CI pipeline, since it's not possible to use docker's node and python images separately, but you have to make a custom docker image with both

my Dockerfile for reference
FROM ubuntu:latest

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install nodejs npm python3 python3-pip -y && \
    node --version && \
    python3 --version && \
    python3 -m pip install "dash[dev]>=1.3.1"

COPY ./custom_dash_components/package.json /src/custom_dash_components/
COPY ./custom_dash_components/package-lock.json /src/custom_dash_components/
WORKDIR /src/custom_dash_components/
RUN npm i

COPY ./custom_dash_components/ /src/custom_dash_components/

RUN npm run build:js && npm run build:py

build:py is dash-generate-components ./src/lib/components custom_dash_components -p package-info.json

Describe the solution you'd like

I think it's possible to separate nodejs and python build steps, so

  1. nodejs step would build js code and generate metadata file
  2. python step would take metadata file as a cmd arg and generate python code
Related code

extract_path = pkg_resources.resource_filename("dash", "extract-meta.js")
reserved_patterns = "|".join("^{}$".format(p) for p in reserved_words)
os.environ["NODE_PATH"] = "node_modules"
cmd = shlex.split(
'node {} "{}" "{}" {}'.format(
extract_path, ignore, reserved_patterns, components_source
),
posix=not is_windows,
)
shutil.copyfile(
"package.json", os.path.join(project_shortname, package_info_filename)
)
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=is_windows
)
out, err = proc.communicate()
status = proc.poll()
if err:
print(err.decode(), file=sys.stderr)
if not out:
print(
"Error generating metadata in {} (status={})".format(
project_shortname, status
),
file=sys.stderr,
)
sys.exit(1)
metadata = safe_json_loads(out.decode("utf-8"))

Describe alternatives you've considered
Another option is to generate python code in nodejs, so python is not required, but I'd guess that's harder to implement

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogfeaturesomething new

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions