ZeroIntensity / view.py

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

Removing conditional installs in favor of optional dependencies #122

Closed ZeroIntensity closed 6 months ago

ZeroIntensity commented 6 months ago

Have you searched for this discussion already?

Content

After some thinking about the conditional installs API, I think it's a good idea to remove it before it gets merged and simply use optional dependencies. This was mentioned in the very issue for conditional installs (#114), and the main problems are outlined here.

For those that don't know, optional dependencies are selected via the pip install foo[bar] syntax.

The biggest issue is mainly that taking pip's job is just going to cause more problems than it fixes. For example, if someone were to run view.py in a stricter environment, all sorts of headaches might be caused by trying to access system packages or using subprocess to call pip. The ideal solution is to create optional dependencies for different features. For example, if you wanted to install all the template engines, it would be like pip install view.py[templates].

This does introduce an issue when it comes to having user defined dependencies. Ideally, they would set up a virtual environment and install things themselves, but that might drive people away from the project if they have to run on separate environments (which would require setting up a module). I'm thinking that the best solution would be to optimize the pyproject.toml creation in view init, but that might violate the "batteries-detachable" philosophy. I'm guessing eventually view init will have to support Poetry and my personal favorite, Hatch.

I think optional dependencies can really shine with #120, especially with the shell_hint utility. For example, if you forget to install pymongo for a MongoDB driver:

$ pip install view.py[databases]
// OR
$ pip install pymongo

This would need a tiny remnant of the conditional dependencies API, but most of it should be scrapped.

Additional Info

No response