Skip to content

Conversation

@manzt
Copy link
Owner

@manzt manzt commented May 2, 2023

Right now, we raise an exception if one starts developing a widget locally but doesn't have watchfiles installed.

Requiring developers to remember to install optional dev dependencies (i.e.,pip install "anywidget[dev]") is kind of annoying, and it's a pretty minimal dependency. This PR adds watchfiles as a direct dependency so developers can use pip install anywidget and get started without any hiccups.

As an alternative, we could add a warning rather rather than raising an exception, notifying the developer that "watchfiles" must be installed to enable anywidget's live development features, but still load the file the first time. I think adding the dependency is more simple solution, but am open to alternatives.

@netlify
Copy link

netlify bot commented May 2, 2023

Deploy Preview for anywidget canceled.

Name Link
🔨 Latest commit 6b0624e
🔍 Latest deploy log https://app.netlify.com/sites/anywidget/deploys/645105d606ba8f000857442e

@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Merging #116 (aa8f901) into main (148d21e) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #116   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files           7        7           
  Lines         392      392           
=======================================
  Hits          386      386           
  Misses          6        6           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@manzt manzt merged commit 7398426 into main May 2, 2023
@manzt manzt deleted the manzt/watchfiles branch May 2, 2023 12:45
@github-actions github-actions bot mentioned this pull request May 2, 2023
@kolibril13
Copy link
Collaborator

Hey @manzt,
I have a few projects with JupyterLite demos that are based on ipyreact, which itself is based on anywidget.
Unfortunately, watchfiles is not available in JupyterLite, therefore all JupyterLite examples are not working anymore with the latest ipyreact version which @maartenbreddels just released.

when I try to run
%pip install watchfiles
in JupyterLite, I get:

ValueError: Can't find a pure Python 3 wheel for 'watchfiles'.
See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel

A quick workaround fix for now is
%pip install -q ipyreact anywidget<0.2.4

Here are two ideas to approach this issue:

  1. Remove the watchfiles dependency again
  2. Writing an issue in the JupyterLite repo and asking if there is a way to support watchfiles.

And another question in this regard:

When I use the live-reload behavior with watchfiles during development, do I have to add the read_text() method before shipping a package to pypi?
E.g.
_esm = pathlib.Path("index.js").read_text()
Or would I add the watchfiles package to the dependencies for my anywidget project?

@manzt
Copy link
Owner Author

manzt commented May 9, 2023

Thanks for opening this issue. I’d made the change since you (#94) and others had some friction with developing using anywidget initially. I wasn’t aware of the JupyterLite incompatibility.

I wonder if rather than raising an error like before, we could just have a warning if watchfiles isn’t installed, notifying the developer they need to install it if they want the file to reload automatically.

When I use the live-reload behavior with watchfiles during development, do I have to add the read_text() method before shipping a package to pypi?

no, watchfiles is only for reloading the file if the contents change. it triggers anywidget to call read_text() again internally. Reloading is a development-only feature. When someone pip-installs your widget, the file contents are loaded once.

@tlambert03
Copy link
Collaborator

yeah, I noticed the recent requirement addition :) Even if it feels like a minor thing, I feel like if it can be optional, it should be optional. And since watchfiles is only necessary for development, I think you should remove it and just solve things like #94 using documentation, or an inline comment somewhere.

@kolibril13
Copy link
Collaborator

no, watchfiles is only for reloading the file if the contents change.

Amazing!
As users don't need it, I also think watchfiles should not be shipped by default.
This is also the easiest solution for the JupyterLite issue.

could just have a warning if watchfiles isn’t installed, notifying the developer they need to install it if they want the file to reload automatically

That sounds great!

@tlambert03
Copy link
Collaborator

we could just have a warning if watchfiles isn’t installed, notifying the developer they need to install it if they want the file to reload automatically.

yeah I like that too!

@nvictus
Copy link
Collaborator

nvictus commented May 9, 2023

I suppose it could also be shipped via optional-dependencies with something like pip install anywidget[complete] or anywidget[developer]

@manzt
Copy link
Owner Author

manzt commented May 9, 2023

@nvictus, that's what we did before 🫣

pip install "anywidget[dev]"

@nvictus
Copy link
Collaborator

nvictus commented May 9, 2023

Ah, right. I noticed it but wasn't sure if dev was intended for development on anywidget, or developers of AnyWidgets... Some ambiguity there.

@manzt
Copy link
Owner Author

manzt commented May 9, 2023

Reverted in v0.3! Anywidget now warns developers that live-reloading is disabled if it cannot find watchfiles, but it no longer fails with a import error.

@kolibril13
Copy link
Collaborator

Thanks for this super quick fix!
I just tested the JupyterLite ipyreact example (https://widgetti.github.io/ipyreact/lab/index.html) and it works, no error message anymore.

@maartenbreddels
Copy link

awesome, great that you responded so quickly @manzt !

@psychemedia
Copy link

I am currently trying to test this with the xeus-python jupyter kernel, and with anywidget=0.9.13 in the environment.yml file used to build that kernel, I am getting the watchfiles error?

Channels:
 - https://repo.mamba.pm/emscripten-forge
 - conda-forge
 - defaults
Platform: emscripten-wasm32
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... failed
LibMambaUnsatisfiableError: Encountered problems while solving:
  - nothing provides requested watchfiles
  - nothing provides watchfiles needed by anywidget-0.9.13-pyhd8ed1ab_0
Could not solve for environment specs
The following packages are incompatible
├─ anywidget 0.9.13  is not installable because it requires
│  └─ watchfiles, which does not exist (perhaps a missing channel);
└─ watchfiles does not exist (perhaps a typo or a missing channel).

@cclauss
Copy link

cclauss commented Jan 22, 2026

https://pypi.org/project/watchfiles is currently at v1.1.1, but the version used in this project fails on Python 3.14.

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 this pull request may close these issues.

7 participants