From 142db00ce2b2e8b6479859e33815ca1361c9294a Mon Sep 17 00:00:00 2001 From: Viktor Hangya Date: Wed, 15 Nov 2023 15:16:08 +0100 Subject: [PATCH] setting exact python, dependency and tree-sitter grammar versions --- .github/workflows/publish-to-pypi.yml | 2 +- setup.py | 26 ++++++++++++++++---------- textLSP/documents/document.py | 17 +++++++++-------- textLSP/documents/latex/latex.py | 1 + textLSP/documents/markdown/markdown.py | 1 + textLSP/documents/org/org.py | 1 + textLSP/utils.py | 7 +++++-- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 296ad80..d03aa7e 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.x" + python-version: "3.10" - name: Install pypa/setuptools run: >- python -m diff --git a/setup.py b/setup.py index 44432ca..bd00815 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,12 @@ import os +import sys from setuptools import setup, find_packages +if sys.version_info >= (3, 11, 0): + # due to current pytorch limitations + print('Required python version <= 3.11.0') + sys.exit(-1) + # Utility function to read the README file. def read(fname): @@ -9,7 +15,7 @@ def read(fname): setup( name="textLSP", - version="0.2.0", + version="0.2.1", author="Viktor Hangya", author_email="hangyav@gmail.com", description=("Language server for text spell and grammar check with various tools."), @@ -27,15 +33,15 @@ def read(fname): 'console_scripts': ['textlsp=textLSP.cli:main'], }, install_requires=[ - 'pygls>=1.0.0', - 'lsprotocol>=2022.0.0a9', - 'language-tool-python>=2.7.1', - 'tree_sitter>=0.20.1', - 'gitpython>=3.1.29', - 'appdirs>=1.4.4', - 'torch>=1.13.1', - 'openai>=0.26.4', - 'transformers>=4.25.1', + 'pygls==1.0.0', + 'lsprotocol==2022.0.0a9', + 'language-tool-python==2.7.1', + 'tree_sitter==0.20.1', + 'gitpython==3.1.29', + 'appdirs==1.4.4', + 'torch==1.13.1', + 'openai==0.26.4', + 'transformers==4.25.1', ], extras_require={ 'dev': [ diff --git a/textLSP/documents/document.py b/textLSP/documents/document.py index 007c5cf..f238d89 100644 --- a/textLSP/documents/document.py +++ b/textLSP/documents/document.py @@ -327,46 +327,47 @@ def __len__(self): class TreeSitterDocument(CleanableDocument): LIB_PATH_TEMPLATE = '{}/treesitter/{}.so'.format(get_user_cache(), '{}') - def __init__(self, language_name, grammar_url, *args, **kwargs): + def __init__(self, language_name, grammar_url, branch, *args, **kwargs): super().__init__(*args, **kwargs) - self._language = self.get_language(language_name, grammar_url) + self._language = self.get_language(language_name, grammar_url, branch) self._parser = self.get_parser( language_name, grammar_url, + branch, self._language ) self._text_intervals = None @classmethod - def build_library(cls, name, url) -> None: + def build_library(cls, name, url, branch=None) -> None: with tempfile.TemporaryDirectory() as tmpdir: - git_clone(url, tmpdir) + git_clone(url, tmpdir, branch) Language.build_library( cls.LIB_PATH_TEMPLATE.format(name), [tmpdir] ) @classmethod - def get_language(cls, name, url) -> Language: + def get_language(cls, name, url, branch=None) -> Language: try: return Language( cls.LIB_PATH_TEMPLATE.format(name), name, ) except Exception: - cls.build_library(name, url) + cls.build_library(name, url, branch) return Language( cls.LIB_PATH_TEMPLATE.format(name), name, ) @classmethod - def get_parser(cls, name=None, url=None, language=None) -> Parser: + def get_parser(cls, name=None, url=None, branch=None, language=None) -> Parser: parser = Parser() if language is None: assert name is not None assert url is not None - language = cls.get_language(name, url) + language = cls.get_language(name, url, branch) parser.set_language(language) return parser diff --git a/textLSP/documents/latex/latex.py b/textLSP/documents/latex/latex.py index ab13c90..ecca371 100644 --- a/textLSP/documents/latex/latex.py +++ b/textLSP/documents/latex/latex.py @@ -40,6 +40,7 @@ def __init__(self, *args, **kwargs): super().__init__( 'latex', 'https://github.com/latex-lsp/tree-sitter-latex', + 'v0.3.0', *args, **kwargs, ) diff --git a/textLSP/documents/markdown/markdown.py b/textLSP/documents/markdown/markdown.py index baf8c17..a029174 100644 --- a/textLSP/documents/markdown/markdown.py +++ b/textLSP/documents/markdown/markdown.py @@ -51,6 +51,7 @@ def __init__(self, *args, **kwargs): super().__init__( 'markdown', 'https://github.com/ikatyang/tree-sitter-markdown', + 'v0.7.1', *args, **kwargs, ) diff --git a/textLSP/documents/org/org.py b/textLSP/documents/org/org.py index 865c3c3..957562c 100644 --- a/textLSP/documents/org/org.py +++ b/textLSP/documents/org/org.py @@ -41,6 +41,7 @@ def __init__(self, *args, **kwargs): super().__init__( 'org', 'https://github.com/milisims/tree-sitter-org', + 'v1.3.1', *args, **kwargs, ) diff --git a/textLSP/utils.py b/textLSP/utils.py index ab17eb2..bca0186 100644 --- a/textLSP/utils.py +++ b/textLSP/utils.py @@ -59,8 +59,11 @@ def _wrapper(*args, **kwargs): return _wrapper -def git_clone(url, dir): - return Repo.clone_from(url=url, to_path=dir) +def git_clone(url, dir, branch=None): + repo = Repo.clone_from(url=url, to_path=dir) + if branch is not None: + repo.git.checkout(branch) + return repo def get_textlsp_name():