-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add windows support and refactor setup (#11)
* ci: add win * feat: add setup.py download and build * style: fix with black and isort and ruff * ci: fix windows commands * ci: add win to package build * ci: add `shell: bash` for commands to execute on win * fix: use str(lang_so_file) * docs: add windows mentioned
- Loading branch information
Showing
11 changed files
with
105 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
[build-system] | ||
requires = ["setuptools>=61.0.0", "wheel", "tree-sitter>=0.20.0,<1.0.0"] | ||
requires = ["setuptools>=61.0.0", "wheel", "tree-sitter>=0.20.0,<1.0.0", "requests>=2.0.0,<3.0.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
|
||
[project] | ||
name = "codebleu" | ||
description = "Unofficial CodeBLEU implementation that supports Linux and MacOS available on PyPI." | ||
description = "Unofficial CodeBLEU implementation that supports Linux, MacOS and Windows available on PyPI." | ||
readme = "README.md" | ||
license = {text = "MIT License"} | ||
authors = [ | ||
{name = "Konstantin Chernyshev", email = "[email protected]"}, | ||
] | ||
keywords = ["codebleu", "code", "bleu", "nlp", "natural language processing", "programming", "evaluate", "evaluation", "code generation", "matrics"] | ||
keywords = ["codebleu", "code", "bleu", "nlp", "natural language processing", "programming", "evaluate", "evaluation", "code generation", "metrics"] | ||
dynamic = ["version"] | ||
|
||
requires-python = ">=3.8" | ||
|
@@ -77,7 +77,7 @@ warn_redundant_casts = true | |
warn_unused_ignores = true | ||
warn_unreachable = true | ||
allow_untyped_decorators = true | ||
exclude = ["codebleu/parser/tree-sitter", "codebleu/parser/tree-sitter/python"] | ||
exclude = ["codebleu/parser/tree-sitter", "codebleu/parser/tree-sitter/python", "tree_sitter"] | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "6.0" | ||
|
@@ -86,7 +86,7 @@ python_files = "test_*.py" | |
addopts = "--cov=codebleu/ --cov-report term-missing" | ||
|
||
[tool.coverage.run] | ||
omit = ["tests/*", "codebleu/parser/tree-sitter/*"] | ||
omit = ["tests/*", "codebleu/parser/tree-sitter/*", "tree_sitter"] | ||
|
||
|
||
[tool.isort] | ||
|
@@ -95,7 +95,7 @@ src_paths = ["codebleu", "tests"] | |
known_first_party = ["codebleu", "tests"] | ||
line_length = 120 | ||
combine_as_imports = true | ||
skip = ["build", "dist", ".venv", ".eggs", ".mypy_cache", ".pytest_cache", ".git", ".tox", ".nox", "codebleu/parser"] | ||
skip = ["build", "dist", ".venv", ".eggs", ".mypy_cache", ".pytest_cache", ".git", ".tox", ".nox", "codebleu/parser", "tree_sitter"] | ||
|
||
[tool.black] | ||
line_length=120 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,87 @@ | ||
import subprocess | ||
from __future__ import annotations | ||
|
||
import io | ||
import shutil | ||
import zipfile | ||
from pathlib import Path | ||
|
||
import requests | ||
from setuptools import setup | ||
from setuptools.dist import Distribution | ||
|
||
from tree_sitter import Language | ||
|
||
ROOT = Path(__file__).parent | ||
|
||
|
||
subprocess.run( | ||
["bash", "build.sh"], | ||
cwd=ROOT / "codebleu" / "parser", | ||
check=True, | ||
tree_sitter_languages = { | ||
"go": "https://github.com/tree-sitter/tree-sitter-go/archive/refs/tags/v0.20.0.zip", | ||
"javascript": "https://github.com/tree-sitter/tree-sitter-javascript/archive/refs/tags/v0.20.1.zip", | ||
"python": "https://github.com/tree-sitter/tree-sitter-python/archive/refs/tags/v0.20.4.zip", | ||
"ruby": "https://github.com/tree-sitter/tree-sitter-ruby/archive/refs/tags/v0.19.0.zip", | ||
"php": "https://github.com/tree-sitter/tree-sitter-php/archive/refs/tags/v0.19.0.zip", | ||
"java": "https://github.com/tree-sitter/tree-sitter-java/archive/refs/tags/v0.20.2.zip", | ||
"c-sharp": "https://github.com/tree-sitter/tree-sitter-c-sharp/archive/refs/tags/v0.20.0.zip", | ||
"c": "https://github.com/tree-sitter/tree-sitter-c/archive/refs/tags/v0.20.6.zip", | ||
"cpp": "https://github.com/tree-sitter/tree-sitter-cpp/archive/refs/tags/v0.20.3.zip", | ||
} | ||
|
||
|
||
def download_tree_sitter_languages(languages: dict[str, str], languages_folder: Path) -> list[str]: | ||
if languages_folder.exists(): | ||
shutil.rmtree(languages_folder) | ||
languages_folder.mkdir(parents=True) | ||
|
||
extracted_folders: list[str] = [] | ||
for lang, url in languages.items(): | ||
# Download the ZIP file | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
|
||
# Extract the ZIP file | ||
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_f: | ||
zip_f.extractall(languages_folder) | ||
extracted_folders.append(zip_f.namelist()[0]) # get the name of the extracted folder | ||
|
||
return extracted_folders | ||
|
||
|
||
def build_tree_sitter_languages(languages: dict[str, str], languages_folder: Path, target_lib_file: Path) -> str: | ||
extracted_folders = download_tree_sitter_languages(languages, languages_folder) | ||
|
||
Language.build_library( | ||
str(target_lib_file), | ||
[str(languages_folder / lang_folder) for lang_folder in extracted_folders], | ||
) | ||
|
||
return str(target_lib_file) | ||
|
||
|
||
build_tree_sitter_languages( | ||
tree_sitter_languages, | ||
ROOT / "tree_sitter", | ||
ROOT / "codebleu" / "my-languages.so", | ||
) | ||
|
||
|
||
# tree_sitter_extension = Extension( | ||
# 'codebleu.tree_sitter', | ||
# sources=[], | ||
# include_dirs=[], | ||
# libraries=[], | ||
# extra_objects=[ | ||
# | ||
# ], | ||
# ) | ||
|
||
|
||
class PlatformSpecificDistribution(Distribution): | ||
"""Distribution which always forces a binary package with platform name""" | ||
|
||
def has_ext_modules(self): | ||
return True | ||
|
||
|
||
setup(distclass=PlatformSpecificDistribution) | ||
setup( | ||
distclass=PlatformSpecificDistribution, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters