Skip to content

Commit

Permalink
➕ Add dependencies: tree-sitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Oct 22, 2023
1 parent 3d5eed3 commit 8ce9768
Show file tree
Hide file tree
Showing 18 changed files with 1,447 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
line_width: 120
1 change: 1 addition & 0 deletions .cmakelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
filter=-whitespace/indent,-linelength,-readability/wonkycase
59 changes: 26 additions & 33 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,35 @@ permissions:
contents: write

env:
CMAKE_GENERATOR: Ninja
PYTHONUTF8: "1"
python-version: 3.x
cache: pip

jobs:
test:
build-wheels-and-test:
strategy:
fail-fast: false
matrix:
runs-on:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{matrix.runs-on}}
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: docker/setup-qemu-action@v2.2.0
if: runner.os == 'Linux'
- uses: pypa/cibuildwheel@v2.14.1
- uses: actions/upload-artifact@v3
with:
python-version: ${{env.python-version}}
cache: ${{env.cache}}
cache-dependency-path: |-
requirements.txt
requirements/dev.txt
- name: Install dependencies
run: |
pip install -e '.[dev]'
- name: Test
run: |
pytest --cov
- uses: codecov/codecov-action@v3
path: |
wheelhouse/*.whl
build:
needs: test
strategy:
fail-fast: false
matrix:
runs-on:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{matrix.runs-on}}
needs:
- build-wheels-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -67,24 +56,28 @@ jobs:
- name: Install dependencies
run: |
pip install build
- name: Build
- name: Build sdist
run: |
pyproject-build
- uses: pypa/gh-action-pypi-publish@release/v1
if: runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/')
with:
password: ${{secrets.PYPI_API_TOKEN}}
pyproject-build -s
- uses: actions/upload-artifact@v3
if: runner.os == 'Linux' && ! startsWith(github.ref, 'refs/tags/')
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
with:
path: |
dist/*
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: softprops/action-gh-release@v1
if: runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/')
with:
# body_path: build/CHANGELOG.md
files: |
dist/*
- uses: pypa/gh-action-pypi-publish@release/v1
if: startsWith(github.ref, 'refs/tags/')
with:
password: ${{ secrets.PYPI_API_TOKEN }}

deploy-aur:
needs: build
Expand All @@ -93,7 +86,7 @@ jobs:
steps:
- uses: Freed-Wu/update-aur-package@v1.0.11
with:
package_name: pkgbuild-language-server
package_name: autotools-language-server
ssh_private_key: ${{secrets.AUR_SSH_PRIVATE_KEY}}

deploy-nur:
Expand Down
15 changes: 12 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ repos:
- -cpyproject.toml
additional_dependencies:
- tomli
- repo: https://github.com/nix-community/nixpkgs-fmt
rev: v1.3.0
- repo: https://github.com/cmake-lint/cmake-lint
rev: 1.4.2
hooks:
- id: nixpkgs-fmt
- id: cmakelint
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies:
- pyyaml
- id: cmake-lint
additional_dependencies:
- pyyaml

ci:
skip:
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://github.com/tree-sitter/tree-sitter-bash/issues/227
cmake_minimum_required(VERSION 3.10)
include(FetchContent)
FetchContent_Declare(tree-sitter-bash GIT_REPOSITORY "https://github.com/tree-sitter/tree-sitter-bash")
FetchContent_MakeAvailable(tree-sitter-bash)
include_directories(${tree-sitter-bash_SOURCE_DIR}/src)
add_library(parser SHARED ${tree-sitter-bash_SOURCE_DIR}/src/parser.c)
if(NOT DEFINED SKBUILD_PLATLIB_DIR)
set(SKBUILD_PLATLIB_DIR ${CMAKE_SOURCE_DIR}/src)
endif()
set(CMAKE_INSTALL_LIBDIR ${SKBUILD_PLATLIB_DIR}/termux_language_server/data/lib)
install(TARGETS parser RUNTIME)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ doesn't support:
- [ ] [cpan2aur](https://metacpan.org/release/CPANPLUS-Dist-Arch)
- [ ] [gem2arch](https://github.com/anatol/gem2arch)
- [ ] [arch-hs](https://github.com/berberman/arch-hs)
- [ ] update `.SRCINFO` by `makepkg --printsrcinfo > .SRCINFO`
- [ ] update `pkgsums` by [`updpkgsums`](https://gitlab.archlinux.org/pacman/pacman-contrib)
- [ ] update version by a `nvcheck.toml` to tell this
program where to search new version:
Expand Down
58 changes: 37 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
[build-system]
requires = [
"setuptools_scm[toml] >= 6.2",
"setuptools-generate >= 0.0.6",
"platformdirs",
]
build-backend = "setuptools.build_meta"
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
[project]
name = "pkgbuild-language-server"
description = "pkgbuild language server"
readme = "README.md"
requires-python = ">= 3.7"
# type_a | type_b
requires-python = ">= 3.10"
keywords = ["pkgbuild", "language server"]
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -24,15 +21,22 @@ classifiers = [
"Operating System :: MacOS",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version", "dependencies", "optional-dependencies"]
# dynamic = ["version", "dependencies", "optional-dependencies"]
# https://github.com/pypa/twine/issues/753
dynamic = ["version"]
dependencies = ["colorama", "jinja2", "platformdirs", "pygls", "tree-sitter"]

[project.optional-dependencies]
cache = ["markdown-it-py", "pypandoc"]
dev = ["pytest-cov"]
diagnostic = ["namcap"]
package = ["pyalpm"]

[[project.authors]]
name = "Wu Zhenyu"
Expand All @@ -50,28 +54,39 @@ Source = "https://github.com/Freed-Wu/pkgbuild-language-server"
[project.scripts]
pkgbuild-language-server = "pkgbuild_language_server.__main__:main"

[tool.setuptools.package-data]
pkgbuild_language_server = ["py.typed", "assets/**"]
[tool.scikit-build]
experimental = true

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.setuptools_scm"

[tool.scikit-build.sdist]
include = ["src/pkgbuild_language_server/_version.py"]

[tool.setuptools.data-files]
"share/man/man1" = ["sdist/pkgbuild-language-server.1"]
"share/bash-completion/completions" = ["sdist/pkgbuild-language-server"]
"share/zsh/site-functions" = ["sdist/_pkgbuild-language-server"]
[[tool.scikit-build.generate]]
path = "pkgbuild_language_server/_metainfo.py"
template-path = "templates/metainfo.py"

[tool.setuptools.dynamic.dependencies]
file = "requirements.txt"

# begin: scripts/update-pyproject.toml.pl
[tool.setuptools.dynamic.optional-dependencies.cache]
file = "requirements/cache.txt"

[tool.setuptools.dynamic.optional-dependencies.dev]
file = "requirements/dev.txt"

[tool.setuptools.dynamic.optional-dependencies.diagnostic]
file = "requirements/diagnostic.txt"

[tool.setuptools.dynamic.optional-dependencies.package]
file = "requirements/package.txt"
# end: scripts/update-pyproject.toml.pl

[tool.setuptools_scm]
write_to = "src/pkgbuild_language_server/_version.py"

[tool.setuptools-generate]
write-to = "src/pkgbuild_language_server/_metainfo.py"

[tool.mdformat]
number = true

Expand Down Expand Up @@ -101,5 +116,6 @@ skips = ["*_test.py", "*/test_*.py"]

[tool.cibuildwheel]
archs = ["all"]
before-test = "pip install pytest"
skip = "*37-* *38-* *39-*"
before-test = "pip install -rrequirements.txt -rrequirements/dev.txt"
test-command = "pytest {project}"
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env -S pip install -r

colorama
jinja2
platformdirs
pygls
tree-sitter
4 changes: 2 additions & 2 deletions src/pkgbuild_language_server/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from .. import CACHE


def check_extension(uri: str) -> Literal["install", "PKGBUILD", ""]:
r"""Check extension.
def get_filetype(uri: str) -> Literal["install", "PKGBUILD", ""]:
r"""Get filetype.
:param uri:
:type uri: str
Expand Down
43 changes: 43 additions & 0 deletions src/pkgbuild_language_server/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
r"""Parser
==========
"""
import os
from glob import glob

from platformdirs import user_data_path
from tree_sitter import Language, Parser, Tree

LIBS = glob(
os.path.join(
os.path.join(os.path.join(os.path.dirname(__file__), "data"), "lib"),
"*",
)
)
if len(LIBS) > 0:
LIB = LIBS[0]
else:
# https://github.com/nvim-treesitter/nvim-treesitter/issues/5493
LIB = str(
next(
(
user_data_path("nvim")
/ "repos"
/ "github.com"
/ "nvim-treesitter"
/ "nvim-treesitter"
/ "parser"
).glob("bash.*")
)
)
PARSER = Parser()
PARSER.set_language(Language(LIB, "bash"))


def parse(source: bytes) -> Tree:
r"""Parse.
:param source:
:type source: bytes
:rtype: Tree
"""
return PARSER.parse(source)
Loading

0 comments on commit 8ce9768

Please sign in to comment.