# HG changeset patch # User RhodeCode Admin # Date 2023-12-27 12:29:56 # Node ID dc28b3979afa4f18dd79b19f590a33319f542ef9 # Parent 6a73d87eda94e6f6a5b54a6e9f183ea27926d5e8 fix(core): don't rely on pkgutil to extract the version info of project diff --git a/vcsserver/__init__.py b/vcsserver/__init__.py --- a/vcsserver/__init__.py +++ b/vcsserver/__init__.py @@ -15,10 +15,16 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import pkgutil +import os -__version__ = pkgutil.get_data('vcsserver', 'VERSION').strip().decode() +def get_version(): + here = os.path.abspath(os.path.dirname(__file__)) + ver_file = os.path.join(here, "VERSION") + with open(ver_file, "rt") as f: + version = f.read().strip() + + return version # link to config for pyramid CONFIG = {} diff --git a/vcsserver/hook_utils/__init__.py b/vcsserver/hook_utils/__init__.py --- a/vcsserver/hook_utils/__init__.py +++ b/vcsserver/hook_utils/__init__.py @@ -87,7 +87,7 @@ def install_git_hooks(repo_path, bare, e log.debug('writing git %s hook file at %s !', h_type, _hook_file) try: with open(_hook_file, 'wb') as f: - template = template.replace(b'_TMPL_', safe_bytes(vcsserver.__version__)) + template = template.replace(b'_TMPL_', safe_bytes(vcsserver.get_version())) template = template.replace(b'_DATE_', safe_bytes(timestamp)) template = template.replace(b'_ENV_', safe_bytes(executable)) template = template.replace(b'_PATH_', safe_bytes(path)) @@ -140,7 +140,7 @@ def install_svn_hooks(repo_path, executa try: with open(_hook_file, 'wb') as f: - template = template.replace(b'_TMPL_', safe_bytes(vcsserver.__version__)) + template = template.replace(b'_TMPL_', safe_bytes(vcsserver.get_version())) template = template.replace(b'_DATE_', safe_bytes(timestamp)) template = template.replace(b'_ENV_', safe_bytes(executable)) template = template.replace(b'_PATH_', safe_bytes(path)) diff --git a/vcsserver/http_main.py b/vcsserver/http_main.py --- a/vcsserver/http_main.py +++ b/vcsserver/http_main.py @@ -465,7 +465,7 @@ class HTTPApplication: return { "status": "OK", - "vcsserver_version": vcsserver.__version__, + "vcsserver_version": vcsserver.get_version(), "platform": _platform_id, "pid": os.getpid(), } @@ -495,7 +495,7 @@ class HTTPApplication: resp = { 'id': payload.get('id'), 'result': dict( - version=vcsserver.__version__, + version=vcsserver.get_version(), config=server_config, app_config=app_config, environ=environ, diff --git a/vcsserver/remote/hg_remote.py b/vcsserver/remote/hg_remote.py --- a/vcsserver/remote/hg_remote.py +++ b/vcsserver/remote/hg_remote.py @@ -1178,8 +1178,8 @@ class HgRemote(RemoteBase): @reraise_safe_exceptions def get_hooks_info(self, wire): return { - 'pre_version': vcsserver.__version__, - 'post_version': vcsserver.__version__, + 'pre_version': vcsserver.get_version(), + 'post_version': vcsserver.get_version(), } @reraise_safe_exceptions diff --git a/vcsserver/tests/test_install_hooks.py b/vcsserver/tests/test_install_hooks.py --- a/vcsserver/tests/test_install_hooks.py +++ b/vcsserver/tests/test_install_hooks.py @@ -82,7 +82,7 @@ class BaseInstallHooks: content = hook_file.read() expected_env = '#!{}'.format(executable) - expected_rc_version = "\nRC_HOOK_VER = '{}'\n".format(vcsserver.__version__) + expected_rc_version = "\nRC_HOOK_VER = '{}'\n".format(vcsserver.get_version()) assert content.strip().startswith(expected_env) assert expected_rc_version in content diff --git a/vcsserver/tweens/request_wrapper.py b/vcsserver/tweens/request_wrapper.py --- a/vcsserver/tweens/request_wrapper.py +++ b/vcsserver/tweens/request_wrapper.py @@ -76,7 +76,7 @@ class RequestWrapperTween: repo_name = call_context.get('X-RC-Repo-Name', '') count = request.request_count() - _ver_ = vcsserver.__version__ + _ver_ = vcsserver.get_version() _path = safe_str(get_access_path(request.environ)) ip = '127.0.0.1'