Skip to content

Feat: Override dependencies at lib/ #4718

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
wants to merge 2 commits into from

Conversation

evnchn
Copy link
Collaborator

@evnchn evnchn commented May 8, 2025

This PR allows the user to set NICEGUI_LIB_OVERRIDE_DIRECTORY in env to a directory, for which it contains what would have been in NiceGUI's lib/ folder.

This way, the user can override NiceGUI's dependencies with newer ones, skipping forward in the release cycle.

Combined with a beta feedback system, we can collect information on whether a new version of JS dependency will work with NiceGUI or not, potentially easin upcoming releases, and empowering us to move faster 🚀

Demo code:

from nicegui import ui
import os
from pathlib import Path
os.environ['NICEGUI_LIB_OVERRIDE_DIRECTORY'] = str(Path(__file__).parent / 'lib_override')

grid = ui.aggrid({
    'defaultColDef': {'flex': 1},
    'columnDefs': [
        {'headerName': 'Name', 'field': 'name'},
        {'headerName': 'Age', 'field': 'age'},
    ],
    'rowData': [
        {'name': 'Alice', 'age': 18},
        {'name': 'Bob', 'age': 21},
        {'name': 'Carol', 'age': 42},
    ],
    'rowSelection': 'multiple',
}).classes('max-h-40')

ui.run(reload=True)

Ensure in same folder as your test script, lib_override/lib/aggrid/ag-grid-community.min.js is accessible.

Without override:

{A4504147-9A07-487E-8D34-3A899EDBEBE7}

With override:

{BD7CE54B-AA7E-4C59-8181-D49892436680}

Notice the new styling.

Remaining tasks:

  • Should we add this?
  • Where should we place the option? Is environment variables a good idea?
  • Why it doesn't work when I try and shove the option into core.app.config?
  • Why the environment variable is ignored when I do reload=False?
  • Documentation?
  • Underlying framework to receive beta feedback?

@evnchn evnchn added feature Type/scope: New feature or enhancement dependencies Type/scope: Third party libraries in progress Status: Someone is working on it labels May 8, 2025
@evnchn
Copy link
Collaborator Author

evnchn commented May 8, 2025

If implemented, would help with #3854, and possibly #4468

@evnchn evnchn self-assigned this May 9, 2025
Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quickly reviewed this pull request, which could be useful in certain situations. But I'm undecided about the details yet.

@evnchn
Copy link
Collaborator Author

evnchn commented May 11, 2025

Me too.

I think setting via environment variable is a bit jank and unreliable, especially since it doesn't work if you:

from dotenv import load_dotenv
load_dotenv()

Or

import os
os.environ['NICEGUI_LIB_OVERRIDE_DIRECTORY'] = 'blahblahblah'

You seem to MUST set it via command line before even launching the Python script for it to work.


However, overriding lib is still desirable. While we're at it, maybe even allow overriding the Tailwind to V4. Those beta testers (i.e. me and a few brave people) can speed things up when we roll around to implementing Tailwind V4 in NiceGUI for real.

@falkoschindler falkoschindler added analysis Status: Requires team/community input and removed in progress Status: Someone is working on it labels May 13, 2025
@rodja
Copy link
Member

rodja commented May 13, 2025

I'm not sure an env variable is very handy. One would need to have all the NiceGUI JS code in that dir. Why not simply copy the lib you want to test/update in the pip installed location. With venv, Docker etc this stays well encapsulated.

@evnchn
Copy link
Collaborator Author

evnchn commented May 13, 2025

Fair point.

I think for alpha-level testing, overriding the JS files directly at Lib/site-packages/nicegui/elements/lib provided the use of an isolated environment like venv or Docker makes sense.

Besides a slightly better way to keep track of the old copy, and being able to do this in non-venv situations, this PR doesn't seem to add much to the table. Alpha-testers should be able to back their files up and handle a venv anyways.

So, I'm more inclined to closing this PR in favor of a documentation update somewhere in CONTRIBUTING.md or somewhere in the NiceGUI website (though former seems more plausible since this is alpha-level thing, and I don't feel comfortable endorsing writing to Lib/site-packages/nicegui/elements/lib out loud)


However, for beta-level testing, perhaps a more streamlined experience is still desirable, which this PR does not provide so far.

Wishful programming:

from nicegui.beta import dependency_override 
# put in nicegui.beta, and we declare we may have breaking changes in minor versions, so that we move quickly
# could be an optional package, or external package

dependency_override('aggrid': '33.3.0')
dependency_override('leaflet': 'latest')
dependency_override('plotly': '/path/to/plotly/js')

It is best, if the function can be called after ui.run is called, such that we can live-swap dependencies in-and-out.

ui.input('Enter AG Grid version or path to test', lambda e: dependency_override('aggrid', e.args['value'])

To avoid shifting the topic of the conversation here, whoever thinks this is useful, if there isn't a thread already, please open a thread in https://github.com/zauberzeug/nicegui/discussions/categories/ideas-feature-requests and comment the link to the new thread below to restart the conversation.

@evnchn evnchn closed this May 13, 2025
@evnchn evnchn mentioned this pull request May 14, 2025
3 tasks
@evnchn
Copy link
Collaborator Author

evnchn commented May 16, 2025

Apparently swapping dependencies is as easy as #4739 (reply in thread)

So there's no need for this override lib functionality for elements.

Only though remaining is if we can let user swap out Vue, Quasar and Tailwind (<- This one most tricky since v4 has breaking changes)

@evnchn evnchn deleted the override-dependencies branch May 16, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Status: Requires team/community input dependencies Type/scope: Third party libraries feature Type/scope: New feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants