[config] Avoid relying on shared_dir method when possible
From 3.26, some "data" directories (like web/data and i18n or wdoc) are
installed along with CubicWeb in site packages. So we can retrieve them
relatively to the module that needs them (namely "cubicweb" for "i18n"
and "cubicweb.web" for "web/data" and "wdoc"). Reason for doing this is
that "share_dir()" is not working when cubicweb is installed in
"develop" mode and we are about to drop this method.
Related to #17132990.
--- a/cubicweb/cwconfig.py Thu Feb 15 14:11:18 2018 +0100
+++ b/cubicweb/cwconfig.py Thu Feb 15 13:45:06 2018 +0100
@@ -493,7 +493,7 @@
@classmethod
def i18n_lib_dir(cls):
"""return instance's i18n directory"""
- return join(cls.shared_dir(), 'i18n')
+ return join(dirname(__file__), 'i18n')
@classmethod
def cw_languages(cls):
--- a/cubicweb/web/test/unittest_webconfig.py Thu Feb 15 14:11:18 2018 +0100
+++ b/cubicweb/web/test/unittest_webconfig.py Thu Feb 15 13:45:06 2018 +0100
@@ -58,7 +58,7 @@
for fpath in wdocfiles:
self.assertTrue(path.exists(fpath), fpath)
for expected in [path.join('cubes', 'file', 'wdoc', 'toc.xml'),
- path.join('cubes', 'shared', 'wdoc', 'toc.xml')]:
+ path.join('cubicweb', 'web', 'wdoc', 'toc.xml')]:
for fpath in wdocfiles:
if fpath.endswith(expected):
break
--- a/cubicweb/web/webconfig.py Thu Feb 15 14:11:18 2018 +0100
+++ b/cubicweb/web/webconfig.py Thu Feb 15 13:45:06 2018 +0100
@@ -23,7 +23,7 @@
import os
import hmac
from uuid import uuid4
-from os.path import join, exists, split, isdir
+from os.path import dirname, join, exists, split, isdir
from warnings import warn
from six import text_type
@@ -37,6 +37,9 @@
from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options
+_DATA_DIR = join(dirname(__file__), 'data')
+
+
register_persistent_options( (
# site-wide only web ui configuration
('site-title',
@@ -204,7 +207,7 @@
('captcha-font-file',
{'type' : 'string',
- 'default': join(CubicWebConfiguration.shared_dir(), 'data', 'porkys.ttf'),
+ 'default': join(_DATA_DIR, 'porkys.ttf'),
'help': 'True type font to use for captcha image generation (you \
must have the python imaging library installed to use captcha)',
'group': 'web', 'level': 3,
@@ -327,7 +330,7 @@
@cached
def _fs_path_locate(self, rid, rdirectory):
"""return the directory where the given resource may be found"""
- path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())]
+ path = [self.apphome] + self.cubes_path() + [dirname(__file__)]
for directory in path:
if exists(join(directory, rdirectory, rid)):
return directory
@@ -352,7 +355,7 @@
def locate_all_files(self, rid, rdirectory='wdoc'):
"""return all files corresponding to the given resource"""
- path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())]
+ path = [self.apphome] + self.cubes_path() + [dirname(__file__)]
for directory in path:
fpath = join(directory, rdirectory, rid)
if exists(fpath):
@@ -399,7 +402,7 @@
self._init_uiprops(self.uiprops)
def _init_uiprops(self, uiprops):
- libuiprops = join(self.shared_dir(), 'data', 'uiprops.py')
+ libuiprops = join(_DATA_DIR, 'uiprops.py')
uiprops.load(libuiprops)
for path in reversed([self.apphome] + self.cubes_path()):
self._load_ui_properties_file(uiprops, path)
--- a/cubicweb/web/webctl.py Thu Feb 15 14:11:18 2018 +0100
+++ b/cubicweb/web/webctl.py Thu Feb 15 13:45:06 2018 +0100
@@ -115,7 +115,7 @@
cube_datadir = osp.join(cwcfg.cube_dir(cube), 'data')
if osp.isdir(cube_datadir):
yield cube_datadir
- yield osp.join(config.shared_dir(), 'data')
+ yield _DATA_DIR
class WebUpgradeHandler(CommandHandler, GenStaticDataDirMixIn):