Skip to content

Commit 2dc2076

Browse files
committed
issue2551167 roundup issues when using pip install
Running pip install generates a wheel install. This places locale, template and man pages under site-packages/usr/share/.... These changes make roundup look there for templates (affecting admin.py) and locale (affecting i18n.py) files. This also makes it work better in virtual environment and containers (docker). There is also a commented out bit of code in setup.py that prevents it from making a bdist_wheel forcing a regular install with files put under /usr/locale etc. This can be re-enabled if needed for 2.2 if there are still issues with roundup that aren't solved by then.
1 parent 585a9b5 commit 2dc2076

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Fixed:
3535
length. All other paths with a . in then will be passed through
3636
without change. This allows items like a JWT to be passed as a path
3737
element. (John Rouillard)
38+
- issue2551167 - pip install in containerized environments puts
39+
template and locale files under site-packages where roundup can't find
40+
them. Change code to find them under site-packages.
3841

3942
Features:
4043

roundup/admin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ def listTemplates(self):
324324
templates = init.listTemplates(tdir)
325325
break
326326

327+
# search for data files parallel to the roundup
328+
# install dir. E.G. a wheel install
329+
# use roundup.__path__ and go up a level then use sys.prefix
330+
# to create a base path for searching.
331+
332+
import roundup, sys
333+
# roundup.__path__ should be something like:
334+
# /usr/local/lib/python3.10/site-packages/roundup
335+
# os.prefix should be /usr, /usr/local or root of virtualenv
336+
# strip leading / to make os.path.join work right.
337+
tdir = os.path.join(os.path.dirname(roundup.__path__[0]),
338+
sys.prefix[1:], 'share', 'roundup', 'templates')
339+
if os.path.isdir(tdir):
340+
templates.update(init.listTemplates(tdir))
341+
327342
# OK, now try as if we're in the roundup source distribution
328343
# directory, so this module will be in .../roundup-*/roundup/admin.py
329344
# and we're interested in the .../roundup-*/ part.

roundup/i18n.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@
5858
LOCALE_DIRS.append(_mo_path)
5959
del _mo_path
6060

61+
# find path when locale files are installed as part of a wheel
62+
# roundup.__path__ should be something like:
63+
# /usr/local/lib/python3.10/site-packages/roundup
64+
# os.prefix should be /usr, /usr/local or root of virtualenv
65+
# strip leading / to make os.path.join work right.
66+
import roundup, sys
67+
_ldir = os.path.join(
68+
os.path.dirname(roundup.__path__[0]),
69+
sys.prefix[1:], 'share', 'locale')
70+
if os.path.isdir(_ldir):
71+
LOCALE_DIRS.append(_ldir)
72+
del _ldir
73+
6174
# Roundup text domain
6275
DOMAIN = "roundup"
6376

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ def main():
216216
data_files=data_files)
217217

218218
if __name__ == '__main__':
219+
220+
# Prevent `pip install roundup` from building bdist_wheel.
221+
# Man pages, templates, locales installed under site-packages not
222+
# in normal system locations.
223+
# https://stackoverflow.com/questions/36846260/can-python-setuptools-install-files-outside-dist-packages
224+
'''
225+
if 'bdist_wheel' in sys.argv:
226+
raise RuntimeError("This setup.py does not support wheels")
227+
'''
228+
219229
os.chdir(os.path.dirname(__file__) or '.')
220230
main()
221231

0 commit comments

Comments
 (0)