Skip to content

Remove the reading of the package.json file in the Python package #276

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

Closed
martinRenou opened this issue Oct 28, 2020 · 7 comments · Fixed by #272
Closed

Remove the reading of the package.json file in the Python package #276

martinRenou opened this issue Oct 28, 2020 · 7 comments · Fixed by #272

Comments

@martinRenou
Copy link
Member

Seeing the issue that appears here: jupyter-book/thebe#294 I wonder if we should not get rid of this line. We should maybe hard-code the supported front-end version instead of reading the front-end version that is installed alongside the Python package.

@celine168
Copy link

I'll copy what I wrote in the Thebe issue:
I've tried to spin up the image of this in Binder w/ https://github.com/matplotlib/ipympl.
When creating a notebook in the root of the https://github.com/matplotlib/ipympl repository, I run into the error. When creating a notebook in the examples directory, the code executes fine.

Part of the error is this:

~/ipympl/backend_nbagg.py in <module>
     25 
     26 here = os.path.dirname(__file__)
---> 27 with open(os.path.join(here, 'static', 'package.json')) as fid:
     28     js_semver = '^%s' % json.load(fid)['version']
     29 

I'm not sure where this file is executing but maybe it's dependent on where the current notebook is?

@martinRenou
Copy link
Member Author

The package.json file is included as package_data in the setup.py, this means that this file should be next to the installed Python files. Depending on how you installed ipympl, this logic might break.

@moorepants
Copy link

You could move your js folder into the python package as a subdirectory. Then it would be present in the source repo and would also be in the installed version if the package data flag is used.

@celine168
Copy link

In setup.py, it seems that NPM uses the relative paths to build ipympl, so I don't know if moving the js folder would be a solution.

class NPM(Command):
    description = 'install package.json dependencies using npm'

    user_options = []

    node_modules = pjoin(node_root, 'node_modules')

    targets = [
        pjoin(here, 'ipympl', 'static', 'extension.js'),
        pjoin(here, 'ipympl', 'static', 'index.js'),
        pjoin(here, 'ipympl', 'static', 'package.json')
    ]

Running Binder with this repository seems like a very specific use case for the error so I'm hesitant to make any big changes to the codebase.

I find that renaming the ipympl folder to another does allow the code to run though. One solution could be to rename the folder in postBuild, but would it be too confusing for users?

@moorepants
Copy link

I find that renaming the ipympl folder to another does allow the code to run though. One solution could be to rename the folder in postBuild, but would it be too confusing for users?

I don't think that is a solution for this repository. But you can do things like that in thebe. For example, you can add a rm -r ipympl as the first line in your thebe documentation as a simple workaround.

@martinRenou
Copy link
Member Author

You could move your js folder into the python package as a subdirectory

I wouldn't really like this, ideally, both packages would be in separate repos.

The best approach IMO is to not depend on the package.json in the Python code, it's no big deal to remove this dependency and will fix your issue. I am quite busy with other things this week though.

@moorepants
Copy link

I wouldn't really like this, ideally, both packages would be in separate repos.

Yeh, it seems Jupyter 3.0 has new mechanisms for supporting extensions installed from pypi. So there are probably new better ways to set things up.

The best approach IMO is to not depend on the package.json in the Python code, it's no big deal to remove this dependency and will fix your issue. I am quite busy with other things this week though.

That's fine, we just don't quite know what exactly we can remove, because we aren't familiar with this source code.

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

Successfully merging a pull request may close this issue.

3 participants