-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add script to build pyright (currently build only 1.1.378 for t…
…esting purpose)
- Loading branch information
1 parent
1b417c7
commit 91e1ec2
Showing
5 changed files
with
153 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,17 @@ description = "Pyright type checker, packaged for Python 🍞 + 🐍 + 🪨 = | |
authors = ["ducdetronquito <[email protected]>"] | ||
license = "The Unlicense" | ||
readme = "README.md" | ||
include = [ | ||
"pyright_alright/**/*", | ||
] | ||
exclude = [ | ||
"pyright_alright/pyright/.gitkeep", | ||
] | ||
|
||
[tool.poetry.scripts] | ||
pyright = 'pyright_alright.main:pyright' | ||
pyright_alright = 'pyright_alright.main:pyright' | ||
pyright-alright = 'pyright_alright.main:pyright' | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.9" | ||
|
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# pyright: strict | ||
import subprocess | ||
import sys | ||
from os import path | ||
|
||
|
||
def pyright(): | ||
pyright_alright_directory = path.dirname(path.realpath(__file__)) | ||
pyright_index = path.join(pyright_alright_directory, "pyright/index.js") | ||
return_code = subprocess.call(["bun", "run", pyright_index, *sys.argv[1:]]) | ||
|
||
sys.exit(return_code) | ||
|
||
|
||
if __name__ == "__main__": | ||
pyright() |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# pyright: basic | ||
import logging | ||
import subprocess | ||
import sys | ||
import zipfile | ||
from contextlib import chdir | ||
from io import BytesIO | ||
from urllib import request | ||
|
||
logger = logging.getLogger("pyright-alright") | ||
|
||
|
||
def clean_existing_pyright_artifacts(): | ||
logger.info( | ||
"Clean existing pyright artifacts in the `pyright_alright/pyright` directory" | ||
) | ||
return_code = subprocess.call( | ||
[ | ||
"rm", | ||
"-rf", | ||
"./pyright_alright/pyright/dist/", | ||
"&&", | ||
"rm", | ||
"-f", | ||
"./pyright_alright/pyright/index.js", | ||
] | ||
) | ||
if return_code != 0: | ||
logger.error(f"Failed with code {return_code}") | ||
return | ||
|
||
|
||
def get_pyright_archive(pyright_version: str) -> bytes: | ||
logger.info(f"Get pyright {pyright_version} archive") | ||
|
||
url = ( | ||
f"https://github.com/microsoft/pyright/archive/refs/tags/{pyright_version}.zip" | ||
) | ||
|
||
with request.urlopen(url) as response: | ||
return response.read() | ||
|
||
|
||
def store_pyright_archive_in_temp_directory( | ||
pyright_version: str, pyright_archive: bytes | ||
): | ||
logger.info( | ||
f"Unzip and store pyright {pyright_version} archive in `temp` directory" | ||
) | ||
with zipfile.ZipFile(BytesIO(pyright_archive), "r") as zip_ref: | ||
zip_ref.extractall("./temp") | ||
|
||
|
||
def install_pyright_dependencies(pyright_version: str): | ||
logger.info(f"Install pyright {pyright_version} dependencies") | ||
|
||
with chdir(f"./temp/pyright-{pyright_version}"): | ||
return_code = subprocess.call([sys.executable, "-m", "pybun", "install"]) | ||
if return_code != 0: | ||
logger.error(f"Failed with code {return_code}") | ||
return | ||
|
||
|
||
def build_pyright(pyright_version: str): | ||
logger.info(f"Build pyright {pyright_version}") | ||
|
||
with chdir(f"./temp/pyright-{pyright_version}/packages/pyright"): | ||
return_code = subprocess.call([sys.executable, "-m", "pybun", "run", "build"]) | ||
if return_code != 0: | ||
logger.error(f"Failed with code {return_code}") | ||
return | ||
|
||
|
||
def move_pyright_artifacts_to_pyright_alright(pyright_version: str): | ||
logger.info("Move built pyright into the pyright_alright directory") | ||
return_code = subprocess.call( | ||
[ | ||
"cp", | ||
"-R", | ||
f"./temp/pyright-{pyright_version}/packages/pyright/dist/", | ||
"./pyright_alright/pyright", | ||
] | ||
) | ||
if return_code != 0: | ||
logger.error(f"Failed with code {return_code}") | ||
return | ||
|
||
return_code = subprocess.call( | ||
[ | ||
"cp", | ||
f"./temp/pyright-{pyright_version}/packages/pyright/index.js", | ||
"./pyright_alright/pyright", | ||
] | ||
) | ||
if return_code != 0: | ||
logger.error(f"Failed with code {return_code}") | ||
return | ||
|
||
|
||
def main(): | ||
clean_existing_pyright_artifacts() | ||
|
||
pyright_version = "1.1.378" | ||
|
||
pyright_archive = get_pyright_archive(pyright_version) | ||
|
||
store_pyright_archive_in_temp_directory(pyright_version, pyright_archive) | ||
|
||
install_pyright_dependencies(pyright_version) | ||
|
||
build_pyright(pyright_version) | ||
|
||
move_pyright_artifacts_to_pyright_alright(pyright_version) | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(handlers=[logging.StreamHandler()], level=logging.INFO) | ||
main() |