Skip to content
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

Being built from source, gourmet cannot be started #107

Closed
kirienko opened this issue Jun 6, 2020 · 7 comments · Fixed by #172
Closed

Being built from source, gourmet cannot be started #107

kirienko opened this issue Jun 6, 2020 · 7 comments · Fixed by #172
Assignees

Comments

@kirienko
Copy link
Owner

kirienko commented Jun 6, 2020

If we clone gourmet from Github and do python setup.py install [--user], then it cannot be started.

The problem is that the path in uifile is incorrect. It looks like that's because base_dir which is currently set in settings.py as

base_dir = os.path.join(os.path.dirname(__file__), '..')

points one level up, which is correct for development, but it breaks execution for regular users.

It might be the case that this way of installation was not foreseen and had never been tested.

@maweki
Copy link
Collaborator

maweki commented Jun 6, 2020

I think that's not really the issue. During installation the settings.py file is changed (in a strange manner that leaves many newlines) with the following content (newlines removed):

import os.path
import sys
# The following lines are modified at installation time by setup.py so they
# point to the actual data files installation paths.
base_dir = '/usr/local/share'
lib_dir = '/usr/local/lib/python3.8/site-packages/'
data_dir = '/usr/local/share/gourmet'
ui_base = os.path.join(base_dir, 'ui')
doc_base = '/usr/local/share/doc/gourmet'
locale_base = '/usr/local/share/locale'
plugin_base = data_dir
# Apologies for the formatting -- something in the build process is
# getting rid of indentations in this file which throws a syntax error
# on install
base_dir = '/usr/local/share'
icon_base = '/usr/local/share/icons/hicolor'

The original file looks like this:

import os.path
import sys

# The following lines are modified at installation time by setup.py so they
# point to the actual data files installation paths.

base_dir = os.path.join(os.path.dirname(__file__), '..')
lib_dir = os.path.join(base_dir, 'gourmet')
data_dir = os.path.join(base_dir, 'data')
ui_base = os.path.join(base_dir, 'ui')
doc_base = os.path.join(base_dir)
locale_base = os.path.join(base_dir, 'build', 'mo')
plugin_base = os.path.join(base_dir, 'build', 'share', 'gourmet')

# Apologies for the formatting -- something in the build process is
# getting rid of indentations in this file which throws a syntax error
# on install
if getattr(sys, 'frozen', False): base_dir = os.path.dirname(sys.executable); data_dir = base_dir; ui_base = os.path.join(base_dir, 'ui'); doc_base = os.path.join(base_dir, 'doc'); locale_base = os.path.join(base_dir, 'locale'); plugin_base = os.path.join(base_dir)

icon_base = os.path.join(data_dir, 'icons')

So it seems the rewriting process during setup is completely borked.

@maweki
Copy link
Collaborator

maweki commented Jun 6, 2020

Here is the rewriting process which completely changes the relative paths:

https://github.com/kirienko/gourmet/blob/master/setup.py#L264-L291

But the comment mentions bin/gourmet which isn't rewritten by this part of the setup.

bin/gourmet file is rewritten as well (in https://github.com/kirienko/gourmet/blob/master/setup.py#L304-L323):

#!/usr/bin/python3
# PYTHON_ARGCOMPLETE_OK
# Copyright (c) 2004, 2005, 2006, 2007 Tom Hinkle
# You may use and distribute this software under the terms of the
# GNU General Public License, version 2 or later
import sys
# The following line is modified at installation time by setup.py so it
# points to the actual modules installation path.
lib_dir = '/usr/local/lib/python3.8/site-packages/'
if lib_dir not in sys.path:
    sys.path.insert(0, lib_dir)
from gourmet import GourmetRecipeManager
GourmetRecipeManager.startGUI()

I don't know whether this is correct but I guess not. The original version has lib_dir = '.'

@maweki
Copy link
Collaborator

maweki commented Jun 6, 2020

Okay, I commented out all the rewriting stuff (the lines I referenced), deleted the build directory and gourmet starts from the system install. I got many errors on plugin loading so one of the paths might still be off or it's my dependencies in the container:

$ /usr/local/bin/gourmet
./gourmet/GourmetRecipeManager.py:12: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gtk
elib.intl failed to load.
IF YOU HAVE TROUBLE WITH TRANSLATIONS, MAKE SURE YOU HAVE THIS LIBRARY INSTALLED.
args = Namespace(db_url='', debug=None, debug_file='', gourmetdir='', html_plugin_dir='', thread_debug=False, thread_debug_interval=5.0, threads=False, time=False)
elib.intl failed to load.
IF YOU HAVE TROUBLE WITH TRANSLATIONS, MAKE SURE YOU HAVE THIS LIBRARY INSTALLED.
No pyglet player
No gst player
No windows player
DEBUG:   ./gourmet/GourmetRecipeManager.py: 47 No RTF support

(gourmet:599995): Gtk-WARNING **: 00:47:48.396: Could not load a pixbuf from /org/gtk/libgtk/theme/Adwaita/assets/check-symbolic.svg.
This may indicate that pixbuf loaders or the mime database could not be found.
~~~ readableUnits {'reccard_window_2': {'position': (1100, 181), 'window_size': (700, 600)}, 'reccard_window_3': {'position': (0, 0), 'window_size': (700, 600)}, 'reccard_window_1': {'position': (0, 0), 'window_size': (700, 600)}, 'reccard_window_6': {'position': (0, 0), 'window_size': (1233, 830)}, 'reccard_window_7': {'position': (0, 0), 'window_size': (1132, 720)}, 'rectree_column_order': {}, 'sautTog': {'active': True}, 'reccard_window_9': {'position': (0, 64), 'window_size': (700, 600)}, 'readableUnits': False, 'rec_editor_window': {'position': (0, 0), 'window_size': (1920, 1016)}, 'save_recipes_as': '.xml', 'regexpTog': {'active': False}, 'rec_exp_directory': '/home/maweki/sync', 'rectree_hidden_columns': ['Website', 'Yield', 'Yield Unit', 'Preparation Time', 'Cooking Time'], 'reccard_window_10': {'position': (0, 0), 'window_size': (700, 600)}, 'app_window': {'position': (0, 0), 'window_size': (800, 600)}, 'shopGuiWin': {'position': (0, 0), 'window_size': (800, 600)}, 'shopvpaned1': {'position': 150}, 'shophpaned1': {'position': 400}, 'reccard_window_4': {'window_size': (700, 600), 'position': (0, 0)}}
WARNING: Plugin module import failed
PATH: ['.', '/usr/local/bin', '/usr/lib64/python38.zip', '/usr/lib64/python3.8', '/usr/lib64/python3.8/lib-dynload', '/home/maweki/.local/lib/python3.8/site-packages', '/home/maweki/s/python/gourmet', '/usr/local/lib64/python3.8/site-packages', '/usr/local/lib/python3.8/site-packages', '/usr/lib64/python3.8/site-packages', '/usr/lib/python3.8/site-packages', './gourmet/../build/share/gourmet/plugins', './gourmet/../gourmet/plugins', './gourmet/../gourmet/plugins/import_export']
Traceback (most recent call last):
  File "./gourmet/plugin_loader.py", line 259, in get_module
    self._loaded = __import__(self.module)
  File "./gourmet/../gourmet/plugins/spellcheck/__init__.py", line 1, in <module>
    from . import reccard_spellcheck_plugin
  File "./gourmet/../gourmet/plugins/spellcheck/reccard_spellcheck_plugin.py", line 3, in <module>
    from gtkspellcheck import SpellChecker
ModuleNotFoundError: No module named 'gtkspellcheck'
WARNING: Failed to load plugin spellcheck
ERROR:root:
Traceback (most recent call last):
  File "./gourmet/plugin_loader.py", line 98, in load_active_plugins
    self.active_plugins.extend(self.available_plugin_sets[p].plugins)
  File "./gourmet/plugin_loader.py", line 272, in __getattr__
    if attr == 'plugins': return self.get_plugins()
  File "./gourmet/plugin_loader.py", line 278, in get_plugins
    return self.get_module().plugins
AttributeError: 'NoneType' object has no attribute 'plugins'
WARNING: Plugin module import failed
PATH: ['.', '/usr/local/bin', '/usr/lib64/python38.zip', '/usr/lib64/python3.8', '/usr/lib64/python3.8/lib-dynload', '/home/maweki/.local/lib/python3.8/site-packages', '/home/maweki/s/python/gourmet', '/usr/local/lib64/python3.8/site-packages', '/usr/local/lib/python3.8/site-packages', '/usr/lib64/python3.8/site-packages', '/usr/lib/python3.8/site-packages', './gourmet/../build/share/gourmet/plugins', './gourmet/../gourmet/plugins', './gourmet/../gourmet/plugins/import_export', './gourmet/../build/share/gourmet/plugins/import_export']
Traceback (most recent call last):
  File "./gourmet/plugin_loader.py", line 259, in get_module
    self._loaded = __import__(self.module)
  File "./gourmet/../gourmet/plugins/import_export/pdf_plugin/__init__.py", line 1, in <module>
    from . import pdf_exporter_plugin, print_plugin
  File "./gourmet/../gourmet/plugins/import_export/pdf_plugin/print_plugin.py", line 4, in <module>
    import poppler
ModuleNotFoundError: No module named 'poppler'
WARNING: Failed to load plugin pdf_plugin
ERROR:root:
Traceback (most recent call last):
  File "./gourmet/plugin_loader.py", line 98, in load_active_plugins
    self.active_plugins.extend(self.available_plugin_sets[p].plugins)
  File "./gourmet/plugin_loader.py", line 272, in __getattr__
    if attr == 'plugins': return self.get_plugins()
  File "./gourmet/plugin_loader.py", line 278, in get_plugins
    return self.get_module().plugins
AttributeError: 'NoneType' object has no attribute 'plugins'

I don't really get it though. I tried to print the paths in the settings.py file after I removed the change and it seems like it isn't even loaded anywhere. So where do the wrong paths come from? It seems like somehow the source folder has been added to the path PATH: [..., '/home/maweki/s/python/gourmet' so it actually loads all the stuff from there.

It is completely borked. You can pick it up from here :D

@takluyver
Copy link
Collaborator

Continuing the discussion from #110:

Is there a way we can do it with relative paths? What would we need to do to fix this?

The static data and ui folders would need to go inside the gourmet folder (the package folder, the one that contains all the Python code). Also probably the generated folders for plugins and compiled translations (mo). Then it would be relatively simple to adjust the paths in settings.py (which would probably stay around to be patched by downstream packagers who want to split these things back up).

There is an alternative approach: instead of having one path for each type of file, define a search path of different places to look, and have it keep looking until it finds the files it wants. The sysconfig module can be useful for finding likely installation directories. This makes separating code & data easier, but leaves more room for things to go wrong (e.g. gourmet version X finds data files from version Y).

I tried to print the paths in the settings.py file after I removed the change and it seems like it isn't even loaded anywhere.

It looks like it's imported in gglobals, which is imported from the GourmetRecipeManager module which has the application class. Not sure why printing wouldn't work. :-/

@maweki
Copy link
Collaborator

maweki commented Jun 7, 2020

Not sure why printing wouldn't work.

When I deleted the file there was no error. So it seemed like when removing all the rewriting, the original source directory somehow got added to the path and I was running gourmet from the source directory and not from the install directory (only the bin from the install but not the lib).

@OzarkShepherd
Copy link

I am not sure if it is feasible, since I am a beginner at python still, but can't /gourmet just be added staticly to the end of the base directory? When I modified the installed settings.py at .../lib/python3.7/site-packages/gourmet at line 7 to:
base_dir = '/app/share/gourmet'
then the gourmet GUI opens for the flatpak build.

@OzarkShepherd
Copy link

When this issue is fixed, .github/workflows/flatpak.yaml needs to be edited to remove the workaround in comments at the end of the file.

OzarkShepherd added a commit to OzarkShepherd/gourmet that referenced this issue Jul 16, 2020
Added Pyglet Player to dependencies to get rid of a terminal error, and added Ubuntu 20.04 specific instructions including a workaround for issue kirienko#107.  I also added a note at the beginning that this fork is still under development.
@cydanil cydanil mentioned this issue Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants