Skip to content

Commit

Permalink
setting exact python, dependency and tree-sitter grammar versions
Browse files Browse the repository at this point in the history
  • Loading branch information
hangyav committed Nov 15, 2023
1 parent 7238085 commit 142db00
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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."),
Expand All @@ -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': [
Expand Down
17 changes: 9 additions & 8 deletions textLSP/documents/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions textLSP/documents/latex/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions textLSP/documents/markdown/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, *args, **kwargs):
super().__init__(
'markdown',
'https://github.com/ikatyang/tree-sitter-markdown',
'v0.7.1',
*args,
**kwargs,
)
Expand Down
1 change: 1 addition & 0 deletions textLSP/documents/org/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, *args, **kwargs):
super().__init__(
'org',
'https://github.com/milisims/tree-sitter-org',
'v1.3.1',
*args,
**kwargs,
)
Expand Down
7 changes: 5 additions & 2 deletions textLSP/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 142db00

Please sign in to comment.