kivy-garden / graph

Displays plots on a graph.
MIT License
50 stars 18 forks source link

Kivy is imported before it is installed #22

Closed davidkleiven closed 4 years ago

davidkleiven commented 5 years ago

Describe the bug Applications that depend on kivy_garden (and thus kivy) fails when kivy is not installed before the package is installed.

To Reproduce Create a small application that depend on kivy_garden and install it on a system that does not have kivy

Expected behavior Since kivy_garden depends on kivy, I would expect that kivy gets installed before kivy_garden is installed.

Logs/output

Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-7dgkxaju/kivy-garden.graph/setup.py", line 8, in <module>
        from kivy_garden.graph import __version__
      File "/tmp/pip-install-7dgkxaju/kivy-garden.graph/kivy_garden/graph/__init__.py", line 58, in <module>
        from kivy.uix.widget import Widget
    ModuleNotFoundError: No module named 'kivy'

Additional context The reason for the failure is that setup.py import __version__ and hence kivy will be imported. Therefore, it does not matter whether one specify kivy as a dependency of the project one is trying to install or not. @matham Is this intentional? In that case how can one install an app that depend on kivy_garden.graph?

Since it is only to get the version one solution would be to not import the __version__ but extract it with RegEx or something and require apps that depend on kivy_garden to install kivy as a dependency.

AndreMiras commented 5 years ago

Thank you @davidkleiven for the report. I assumed it would have been an issue, here's how I addressed it for some other garden projects. https://github.com/kivy-garden/zbarcam/blob/2019.1020/src/kivy_garden/zbarcam/__init__.py#L14 Basically the idea is to skip the import if we detect pip install. Give this a try and feel free to pull request the same fix

matham commented 5 years ago

I ran into the same issue with cython flowers, here's the fix: https://github.com/kivy-garden/cython_flower/tree/master/kivy_garden/cython_flower. But I didn't implement the fix for normal flowers. Fell free to open a PR to the demo flower as well as this repo separating the version into a new file.

I don't like the detecting pip fix, as that's a but too automatic and doesn't directly solve the issue. Moving version to its own file should properly take care of this.

davidkleiven commented 5 years ago

Ok, thanks. The solution in cython-flower looks good. I opened a PR to the demo flower. I will open a similar fix here, if that PR gets accepted.