Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local package build: wizmap.js not found #8

Closed
carschno opened this issue Jul 15, 2023 · 5 comments
Closed

Local package build: wizmap.js not found #8

carschno opened this issue Jul 15, 2023 · 5 comments

Comments

@carschno
Copy link

carschno commented Jul 15, 2023

I am trying to add an option for customized stopwords (#6), but struggling to install a local version of the Python widget.

Here is how I try (after changing wizmap.py):

$ python -m pip install -U -e ../wizmap/notebook-widget
[...]
Successfully built wizmap
Installing collected packages: wizmap
  Attempting uninstall: wizmap
    Found existing installation: wizmap 0.1.2
    Uninstalling wizmap-0.1.2:
      Successfully uninstalled wizmap-0.1.2
Successfully installed wizmap-0.1.2

However, when I try to import wizmap in Python, I get this error:

import wizmap

wizmap.visualize(data_url, grid_url)

File [.../wizmap/notebook-widget/wizmap/wizmap.py:847](.../wizmap/notebook-widget/wizmap/wizmap.py:847), in visualize(data_url, grid_url, height)
    834 def visualize(data_url, grid_url, height=700):
    835     """
    836     Render WizMap in the output cell.
    837 
   (...)
    845         HTML code with deferred JS code in base64 format
    846     """
--> 847     html_str = _make_html(data_url, grid_url)
    849     # Randomly generate an ID for the iframe to avoid collision
    850     iframe_id = "wizmap-iframe-" + str(int(random.random() * 1e8))

File [.../wizmap/notebook-widget/wizmap/wizmap.py:797](.../wizmap/notebook-widget/wizmap/wizmap.py:797), in _make_html(data_url, grid_url)
    794 html_bottom = """</head><body><div id="app"></div></body></html>"""
    796 # Read the bundled JS file
--> 797 js_b = pkgutil.get_data(__name__, "wizmap.js")
    799 # Read local JS file (for development only)
    800 # with open("./wizmap.js", "r") as fp:
    801 #     js_string = fp.read()
    802 # js_b = bytes(js_string, encoding="utf-8")
    803 
    804 # Encode the JS & CSS with base 64
    805 js_base64 = base64.b64encode(js_b).decode("utf-8")

File [/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pkgutil.py:640](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pkgutil.py:640), in get_data(package, resource)
    638 parts.insert(0, os.path.dirname(mod.__file__))
    639 resource_name = os.path.join(*parts)
--> 640 return loader.get_data(resource_name)

File :1130, in get_data(self, path)

FileNotFoundError: [Errno 2] No such file or directory: '.../wizmap/notebook-widget/wizmap/wizmap.js'

Note: I have replaced the full path to my local wizmap repository by ... in the output above for brevity.

This works fine with the wizmap version 0.1.2 installed with pip install wizmap.
Is there anything else I need to run for building the Python package locally?

@carschno
Copy link
Author

From the comments in wizmap.py, I do understand that the JS file needs to be bundled. However, I am not clear how to do that -- possibly due to a lack of JS knowledge.

@Bdl-1989
Copy link

u need to have node.js/npm
check the package.json, build notebook, then wizmap.js can be generated

@carschno
Copy link
Author

I do have node.js and npm, and all JS dependencies installed, but when I build the notebook-widget locally, it still does not include the wizmap.js file. This is what I have done:

$ npm install
npm WARN deprecated @types/sass@1.45.0: This is a stub types definition. sass provides its own type definitions, so you do not need this installed.
npm WARN deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead

added 384 packages, and audited 385 packages in 29s

52 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

So I build the notebook:

$ cd notebook-widget
$ python3 -m build --wheel
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting build dependencies for wheel...
[...]
Successfully built wizmap-0.1.2-py2.py3-none-any.whl

However, the resulting Wheel does not contain the wizmap.js file:

$ unzip -t dist/wizmap-0.1.2-py2.py3-none-any.whl | grep wizmap.js

Consequently, when I install the package, wizmap.js is not there either:

$ pip install .
$ ls .venv/lib/python3.11/site-packages/wizmap | grep wizmap.js

With the pip package that you have provided, on the other hand, wizmap.js is present (as expected):

$ ls .venv/lib/python3.11/site-packages/wizmap | grep wizmap.js
wizmap.js

Would you mind sharing the commands to use for building the Python package?

@Bdl-1989
Copy link

build notebook means
image
image

@carschno
Copy link
Author

That works, thanks!

Now I can also confirm that my changes in PR #11 work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants