ZeroIntensity / view.py

The Batteries-Detachable Web Framework
https://view.zintensity.dev
MIT License
206 stars 15 forks source link

Conditional Dependencies #93

Closed ZeroIntensity closed 6 months ago

ZeroIntensity commented 7 months ago

Improvement Description

View has several dependencies that are only used for niche features. View could install these conditionally based on the configuration. For example, if the database (unfinished but see #10) is postgres, view.py will then leverage pip and install the driver. If not, it remains uninstalled, as it seems silly to have dependencies that not all users need. Originally, attempt_import addressed this issue but that proved to be buggy and a headache.

This may also introduce a dependencies and auto_install setting in the configuration.

Improvement Request Example API

dependencies = ["pymongo"]
auto_install = false  # true by default

Anything else?

No response

ZeroIntensity commented 6 months ago

Notice about this API

As this API comes near to being on the master branch, it should be noted that preinstalling dependencies (i.e., putting view's dependencies in the pyproject.toml) should be preferred over leveraging the conditional installation API at runtime.

This feature is meant generally to help with the batteries-detachable philosophy. For example, in #118, if something from ReactPy were to be needed, it would be installed via this API, but some sort of parser library (in the context of view.py, ujson would be a good example) for use in parsing requests, would be listed as a dependency in pyproject.toml and not something to be used via this API.

There is a chance that this will be deprecated in the future. It's not exactly View's place to start taking pip's job, so possibly just something like pip install view.py[react] would be a better solution.

However, before this has any chance of being marked for removal, a better system for managing dependencies should be created in View. Possibly something like a view dep command that messes with the pyproject.toml?

ZeroIntensity commented 6 months ago

See RFC 1 #122