changeset 6739:00fe67eb8a91

Update locations templates and locale files are stored Installing on a new ubuntu 22.04 venv at /tmp/roundup, I found the locale and template files installed under /tmp/roundup2/lib/python3.10/site-packages/usr/local/share which was unexpected. /tmp/roundup2/lib/python3.10/site-packages/tmp/roundup2/share would be expected. Why sys.prefix (/tmp/roundup2) was not being used but sys.base_prefix (/usr) and 'local' were added in I have no idea. In any case, updated admin and i18n code to find the files in this location. Suggested building a venv for installation with commands in installation.txt. Removed search for templates top level directory. Was used for the old location of the tracker templates pre-2009 when they were moved under share/roundup/templates. left print statemts for debugging directory search in admin templates. They are disabled by a variable set to False. At some point will add pragma's to admin to set debugging and other options see issue 2551103.
author John Rouillard <rouilj@ieee.org>
date Tue, 28 Jun 2022 23:16:47 -0400
parents 966263ad45ea
children 2fdb00ab6277
files doc/installation.txt doc/tracker_templates.txt roundup/admin.py roundup/i18n.py
diffstat 4 files changed, 67 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/doc/installation.txt	Tue Jun 28 21:09:55 2022 -0400
+++ b/doc/installation.txt	Tue Jun 28 23:16:47 2022 -0400
@@ -198,10 +198,25 @@
 Basic Installation Steps
 ------------------------
 
-To install the Roundup support code into your Python tree and
-Roundup scripts into /usr/bin (substitute that path for whatever is
-appropriate on your system). You need to have write permissions
-for these locations, eg. being root on unix::
+Installation of Roundup using Python3 in a virtual environment is
+probably the path of least resistance. Use::
+
+   python3 -m venv /path/to/environment/roundup
+
+then proceed as below after activating (assuming a Bourne like shell)
+the Python environment using::
+
+   . /path/to/environment/roundup/bin/activate
+
+then use the alias ``deactivate`` to return to the normal Python
+environment. If you create the virtual envirnment as a non-root user,
+you can install below using the same user.
+
+To install the Roundup support code into your Python tree and Roundup
+scripts into /usr/bin (substitute that path for whatever is
+appropriate on your system). You need to have write permissions for
+these locations, so you may need to run wthese commands with ``sudo``
+if root permission is required::
 
     python setup.py install
 
--- a/doc/tracker_templates.txt	Tue Jun 28 21:09:55 2022 -0400
+++ b/doc/tracker_templates.txt	Tue Jun 28 23:16:47 2022 -0400
@@ -13,13 +13,14 @@
    This should be the standard place to find them when Roundup is
    installed running setup.py from source.
 2. ``install_dir``/../<prefix>/share/....``, where prefix is the
-   Python's ``sys.prefix``. This finds templates (and locales)
+   Python's ``sys.prefix``. ``sys.base_prefix`` or 
+   `sys.base_prefix/local``. This finds templates (and locales)
    installed by pip. E.G. in a virtualenv located at (``sys.prefix``):
    ``/tools/roundup``, roundup would be at:
    ``/tools/roundup/lib/python3.6/site-packages/roundup``. The
    templates would be at:
    ``/tools/roundup/lib/python3.6/site-packages/tools/roundup/share/roundup/templates/``.
-3. ``<roundup.admin.__file__>/../templates/*``.
+3. ``<roundup.admin.__file__>/../../share/roundup/templates/*``.
    This will be used if Roundup's run in the distro (aka. source)
    directory.
 4. ``<current working dir>/*``.
--- a/roundup/admin.py	Tue Jun 28 21:09:55 2022 -0400
+++ b/roundup/admin.py	Tue Jun 28 23:16:47 2022 -0400
@@ -296,18 +296,16 @@
 
          1. <roundup.admin.__file__>/../../share/roundup/templates/*
             this is where they will be if we installed an egg via easy_install
+            or we are in the source tree.
          2. <prefix>/share/roundup/templates/*
             this should be the standard place to find them when Roundup is
-            installed
+            installed using setup.py without a prefix
          3. <roundup.admin.__file__>/../../<sys.prefix>/share/\
                  roundup/templates/* which is where they will be found if
             roundup is installed as a wheel using pip install
-         4. <roundup.admin.__file__>/../templates/*
-            this will be used if Roundup's run in the distro (aka. source)
-            directory
-         5. <current working dir>/*
+         4. <current working dir>/*
             this is for when someone unpacks a 3rd-party template
-         6. <current working dir>
+         5. <current working dir>
             this is for someone who "cd"s to the 3rd-party template dir
         """
         # OK, try <prefix>/share/roundup/templates
@@ -320,15 +318,19 @@
         #    (2 dirs up)
         #
         # we're interested in where the directory containing "share" is
+        debug = False
         templates = {}
+        if debug: print(__file__)
         for N in 2, 4, 5, 6:
             path = __file__
             # move up N elements in the path
             for _i in range(N):
                 path = os.path.dirname(path)
             tdir = os.path.join(path, 'share', 'roundup', 'templates')
+            if debug: print(tdir)
             if os.path.isdir(tdir):
                 templates = init.listTemplates(tdir)
+                if debug: print("  Found templates breaking loop")
                 break
 
         # search for data files parallel to the roundup
@@ -347,25 +349,39 @@
         # path is /usr/local/lib/python3.10/site-packages
         tdir = os.path.join(path, sys.prefix[1:], 'share',
                             'roundup', 'templates')
+        if debug: print(tdir)
         if os.path.isdir(tdir):
             templates.update(init.listTemplates(tdir))
 
-        # OK, now try as if we're in the roundup source distribution
-        # directory, so this module will be in .../roundup-*/roundup/admin.py
-        # and we're interested in the .../roundup-*/ part.
-        path = __file__
-        for _i in range(2):
-            path = os.path.dirname(path)
-        tdir = os.path.join(path, 'templates')
-        if os.path.isdir(tdir):
-            templates.update(init.listTemplates(tdir))
+        try:
+            # sigh pip 3.10 in virtual env finds another place to bury them.
+            # why local and sys.base_prefix are in path I do not know.
+            # path is /usr/local/lib/python3.10/site-packages
+            tdir = os.path.join(path, sys.base_prefix[1:], 'local', 'share',
+                                'roundup', 'templates')
+            if debug: print(tdir)
+            if os.path.isdir(tdir):
+                templates.update(init.listTemplates(tdir))
+                            # path is /usr/local/lib/python3.10/site-packages
+
+
+            tdir = os.path.join(path, sys.base_prefix[1:], 'share',
+                                'roundup', 'templates')
+            if debug: print(tdir)
+            if os.path.isdir(tdir):
+                templates.update(init.listTemplates(tdir))
+        except AttributeError:
+            pass  # sys.base_prefix doesn't work under python2
 
         # Try subdirs of the current dir
         templates.update(init.listTemplates(os.getcwd()))
-
+        if debug: print(os.getcwd() + '/*')
+            
         # Finally, try the current directory as a template
         template = init.loadTemplateInfo(os.getcwd())
+        if debug: print(os.getcwd() + '/*')
         if template:
+            if debug: print("  Found template %s"%template['name'])
             templates[template['name']] = template
 
         return templates
--- a/roundup/i18n.py	Tue Jun 28 21:09:55 2022 -0400
+++ b/roundup/i18n.py	Tue Jun 28 23:16:47 2022 -0400
@@ -70,6 +70,19 @@
 _ldir = os.path.join(path, sys.prefix[1:], 'share', 'locale')
 if os.path.isdir(_ldir):
     LOCALE_DIRS.append(_ldir)
+# try other places locale files are hidden on install
+_ldir = os.path.join(path, sys.prefix[1:], 'local', 'share', 'locale')
+if os.path.isdir(_ldir):
+    LOCALE_DIRS.append(_ldir)
+try:
+    _ldir = os.path.join(path, sys.base_prefix[1:], 'local', 'share', 'locale')
+    if os.path.isdir(_ldir):
+        LOCALE_DIRS.append(_ldir)
+    _ldir = os.path.join(path, sys.base_prefix[1:], 'share', 'locale')
+    if os.path.isdir(_ldir):
+        LOCALE_DIRS.append(_ldir)
+except AttributeError:
+    pass # no base_prefix on 2.7
 del _ldir
 
 # Roundup text domain

Roundup Issue Tracker: http://roundup-tracker.org/