From 0e3c7fd0b424ceeb5556bdaf1d3b179c000201e6 Mon Sep 17 00:00:00 2001 From: Ivan Beloborodov Date: Sun, 25 Apr 2021 14:09:55 +0300 Subject: [PATCH] Showing parser versions #453 --- lingvodoc/__init__.py | 53 ++++++++++++++++++++++++++++++++++++--- lingvodoc/schema/query.py | 4 +++ lingvodoc/version.py | 4 +++ server-requirements.txt | 10 ++++---- setup.py | 35 +++++++++++++++++--------- 5 files changed, 86 insertions(+), 20 deletions(-) diff --git a/lingvodoc/__init__.py b/lingvodoc/__init__.py index 7aa941a13..3f34ec51c 100755 --- a/lingvodoc/__init__.py +++ b/lingvodoc/__init__.py @@ -8,6 +8,7 @@ import logging import os.path import re +import subprocess try: import git @@ -34,6 +35,10 @@ import multiprocess +# Setting up logging. +log = logging.getLogger(__name__) + + def get_git_version(repository_dir): """ Determines version from the Git repository state. @@ -115,7 +120,7 @@ def get_git_version(repository_dir): else: - # No tagged version, using just the fallback commit hash/ + # No tagged version, using just the fallback commit hash. assert ( head_commit.hexsha.startswith( @@ -198,19 +203,61 @@ def get_git_version(repository_dir): return version_str +def get_uniparser_version(): + """ + Gets versions of some uniparser-* packages. + """ + + try: + + result = ( + + subprocess.check_output([ + 'pip', + 'show', + 'uniparser-erzya', + 'uniparser-komi-zyrian', + 'uniparser-meadow-mari', + 'uniparser-moksha', + 'uniparser-udmurt'])) + + except: + + return None + + version_str_list = ( + + re.findall( + r'Name: (.*)(\n\r?|\r\n?)Version: (.*)', + result.decode('utf-8'))) + + version_str_dict = { + name_str: version_str + for name_str, _, version_str in version_str_list} + + log.debug( + f'\nversion_str_dict: {version_str_dict}') + + return version_str_dict or None + + # Updating version with current Git repository info, if we have any, setting up package version. import lingvodoc.version version_str = ( get_git_version(os.path.join( - os.path.dirname(__file__), '..'))) + os.path.dirname(__file__), '..'))) if version_str is not None: - lingvodoc.version.__version__ = version_str + lingvodoc.version.__version__ = version_str __version__ = lingvodoc.version.__version__ +# Getting version of some uniparser-* packages. + +lingvodoc.version.uniparser_version_dict = get_uniparser_version() + # def add_route_custom(config, name, pattern, api_version=[]): diff --git a/lingvodoc/schema/query.py b/lingvodoc/schema/query.py index 5dc684402..bec4d6aae 100644 --- a/lingvodoc/schema/query.py +++ b/lingvodoc/schema/query.py @@ -543,6 +543,7 @@ class Query(graphene.ObjectType): debug_flag = graphene.Boolean())) version = graphene.String() + version_uniparser = ObjectVal() client_list = ( graphene.Field( @@ -585,6 +586,9 @@ def resolve_client_list( def resolve_version(self, info): return lingvodoc.version.__version__ + def resolve_version_uniparser(self, info): + return lingvodoc.version.uniparser_version_dict + def resolve_eaf_search( self, info, diff --git a/lingvodoc/version.py b/lingvodoc/version.py index 4cd577a80..3330ec4c8 100644 --- a/lingvodoc/version.py +++ b/lingvodoc/version.py @@ -1,5 +1,9 @@ # This file is overwritten on setup. +# # Please do not modify it and ignore its changes in version control. + __version__ = None +uniparser_version_dict = None + diff --git a/server-requirements.txt b/server-requirements.txt index 6e60f4444..1a7035a2d 100644 --- a/server-requirements.txt +++ b/server-requirements.txt @@ -98,11 +98,11 @@ transaction==1.6.1 translationstring==1.3 typepy==0.6.6 typing==3.6.2 -uniparser-erzya==1.1.0 -uniparser-komi-zyrian==1.1.1 -uniparser-meadow-mari==1.1.3 -uniparser-moksha==1.1.0 -uniparser-udmurt==2.1.0 +uniparser-erzya<1.2 +uniparser-komi-zyrian<1.2 +uniparser-meadow-mari<1.2 +uniparser-moksha<1.2 +uniparser-udmurt<2.2 urllib3==1.25.10 venusian==1.0 waitress==0.9.0 diff --git a/setup.py b/setup.py index 149b5acc6..ecb54f432 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,9 @@ from setuptools.command.develop import develop from setuptools.command.install import install -from lingvodoc import get_git_version +from lingvodoc import ( + get_git_version, + get_uniparser_version) here = os.path.abspath(os.path.dirname(__file__)) @@ -77,11 +79,9 @@ def setup_react_interface(self, lingvodoc_dir): lingvodoc_dir, 'assets')) -class Git_Version_Mixin(object): +class Version_Mixin(object): """ - Tries to determine version from the Git repository state. - - Absense of Git repository is silently ignored. + Tries to determine version from the Git repository state and pip installation state. """ version_py_template = textwrap.dedent( @@ -89,28 +89,38 @@ class Git_Version_Mixin(object): '''\ # This file is overwritten on setup. + # # Please do not modify it and ignore its changes in version control. - __version__ = '{}' + + __version__ = {} + + uniparser_version_dict = {} ''') def run(self): """ - Tries to determine version from the Git repository state, saves it to 'lingvodoc/version.py' if - successful. + Tries to determine version info from the Git repository and pip installation state, saves it to + 'lingvodoc/version.py' if required. """ version_str = ( get_git_version(here)) - if version_str is not None: + version_uniparser_dict = ( + get_uniparser_version()) + + if (version_str is not None or + version_uniparser_dict is not None): with open( os.path.join(here, 'lingvodoc', 'version.py'), 'w', encoding = 'utf-8') as version_py_file: version_py_file.write( - self.version_py_template.format(version_str)) + self.version_py_template.format( + repr(version_str), + repr(version_uniparser_dict))) # Continuing with setup. @@ -127,12 +137,13 @@ class develop_with_interface( __react_path_attr__ = 'egg_path' user_options = ( - develop.user_options + React_Interface_Mixin.user_options) + develop.user_options + + React_Interface_Mixin.user_options) class install_with_interface( React_Interface_Mixin, - Git_Version_Mixin, + Version_Mixin, install): """ Extends 'install' setup.py command with ability to install React-based interface and update version from