Skip to content

Commit

Permalink
Showing parser versions #453
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Beloborodov committed Apr 25, 2021
1 parent 052bda6 commit 0e3c7fd
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 20 deletions.
53 changes: 50 additions & 3 deletions lingvodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os.path
import re
import subprocess

try:
import git
Expand All @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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=[]):

Expand Down
4 changes: 4 additions & 0 deletions lingvodoc/schema/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ class Query(graphene.ObjectType):
debug_flag = graphene.Boolean()))

version = graphene.String()
version_uniparser = ObjectVal()

client_list = (
graphene.Field(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lingvodoc/version.py
Original file line number Diff line number Diff line change
@@ -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

10 changes: 5 additions & 5 deletions server-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 23 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -77,40 +79,48 @@ 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(

'''\
# 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.

Expand All @@ -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
Expand Down

0 comments on commit 0e3c7fd

Please sign in to comment.