Skip to content

Commit

Permalink
refactor(python): replace deprecated api
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Feb 24, 2024
1 parent 22cf359 commit d43b6ec
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-requirements"
description = "requirements grammar for the tree-sitter parsing library"
version = "0.3.0"
version = "0.3.1"
keywords = ["incremental", "parsing", "requirements"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter-grammars/tree-sitter-requirements"
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Editors
Changelog
---------

v0.3.1
^^^^^^

* Replace deprecated resource API

v0.3.0
^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/tree_sitter_requirements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ._core import parse, query, highlights

__author__ = 'ObserverOfTime'
__version__ = '0.1.0'
__version__ = '0.3.1'
__license__ = 'MIT'

__all__ = ['parse', 'query', 'highlights']
12 changes: 8 additions & 4 deletions bindings/python/tree_sitter_requirements/_core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from pathlib import PurePath
from pkg_resources import resource_filename
from sys import platform

from tree_sitter import Language, Parser

try:
from importlib.resources import files
_highlights = (files(__package__) / 'queries' / 'highlights.scm').read_text()
except ImportError:
from importlib.resources import read_text
_highlights = read_text(__package__ + '.queries', 'highlights.scm')

_language = Language(
PurePath(__file__).with_name('requirements').with_suffix(
{'win32': '.dll', 'darwin': '.dylib'}.get(platform, '.so')
Expand All @@ -26,6 +32,4 @@ def query(query, node):

def highlights(tree):
"""Return the highlight groups for the given source tree"""
res = resource_filename(__package__, 'queries/highlights.scm')
with open(res, 'r') as hl:
return query(hl.read(), tree.root_node)
return query(_highlights, tree.root_node)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tree-sitter-requirements",
"version": "0.3.0",
"version": "0.3.1",
"license": "MIT",
"description": "pip requirements grammar for tree-sitter",
"repository": "tree-sitter-grammars/tree-sitter-requirements",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tree-sitter-requirements"
version = "0.3.0"
version = "0.3.1"
description = "A tree-sitter parser for requirements.txt files"
keywords = ["tree-sitter", "parser", "lexer"]
classifiers = [
Expand Down

0 comments on commit d43b6ec

Please sign in to comment.