Merge pull request 'feat: use uv instead of pip' (#28) from change_to_uv_ into main
Reviewed-on: #28
This commit was merged in pull request #28.
This commit is contained in:
+47
-62
@@ -5,23 +5,33 @@
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import tomllib
|
||||
import urllib.request as url_lib
|
||||
from typing import List
|
||||
|
||||
import nox # pylint: disable=import-error
|
||||
|
||||
|
||||
def _read_dependencies() -> List[str]:
|
||||
"""Read project dependencies from pyproject.toml."""
|
||||
pyproject = tomllib.loads(pathlib.Path("pyproject.toml").read_text())
|
||||
return list(pyproject.get("project", {}).get("dependencies", []))
|
||||
|
||||
|
||||
def _install_bundle(session: nox.Session) -> None:
|
||||
session.install(
|
||||
"-t",
|
||||
deps = _read_dependencies()
|
||||
session.run(
|
||||
"uv",
|
||||
"pip",
|
||||
"install",
|
||||
"--target",
|
||||
"./libs",
|
||||
"--no-cache-dir",
|
||||
"--implementation",
|
||||
"py",
|
||||
"--no-deps",
|
||||
"--upgrade",
|
||||
"-r",
|
||||
"./requirements.txt",
|
||||
*deps,
|
||||
external=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -34,24 +44,6 @@ def _check_files(names: List[str]) -> None:
|
||||
raise Exception(f"Please update {os.fspath(file_path)}.")
|
||||
|
||||
|
||||
def _update_pip_packages(session: nox.Session) -> None:
|
||||
session.install("wheel", "pip-tools==7.3.0")
|
||||
session.run(
|
||||
"pip-compile",
|
||||
"--generate-hashes",
|
||||
"--resolver=backtracking",
|
||||
"--upgrade",
|
||||
"./requirements.in",
|
||||
)
|
||||
session.run(
|
||||
"pip-compile",
|
||||
"--generate-hashes",
|
||||
"--resolver=backtracking",
|
||||
"--upgrade",
|
||||
"./src/test/python_tests/requirements.in",
|
||||
)
|
||||
|
||||
|
||||
def _get_package_data(package):
|
||||
json_uri = f"https://registry.npmjs.org/{package}"
|
||||
with url_lib.urlopen(json_uri) as response:
|
||||
@@ -80,13 +72,8 @@ def _update_npm_packages(session: nox.Session) -> None:
|
||||
package_json["devDependencies"][package] = latest
|
||||
|
||||
# Ensure engine matches the package
|
||||
if (
|
||||
package_json["engines"]["vscode"]
|
||||
!= package_json["devDependencies"]["@types/vscode"]
|
||||
):
|
||||
print(
|
||||
"Please check VS Code engine version and @types/vscode version in package.json."
|
||||
)
|
||||
if package_json["engines"]["vscode"] != package_json["devDependencies"]["@types/vscode"]:
|
||||
print("Please check VS Code engine version and @types/vscode version in package.json.")
|
||||
|
||||
new_package_json = json.dumps(package_json, indent=4)
|
||||
# JSON dumps uses \n for line ending on all platforms by default
|
||||
@@ -97,65 +84,60 @@ def _update_npm_packages(session: nox.Session) -> None:
|
||||
|
||||
|
||||
def _setup_template_environment(session: nox.Session) -> None:
|
||||
session.install("wheel", "pip-tools")
|
||||
session.run(
|
||||
"pip-compile",
|
||||
"--generate-hashes",
|
||||
"--resolver=backtracking",
|
||||
"--upgrade",
|
||||
"./requirements.in",
|
||||
)
|
||||
# session.run(
|
||||
# "pip-compile",
|
||||
# "--generate-hashes",
|
||||
# "--resolver=backtracking",
|
||||
# "--upgrade",
|
||||
# "./src/test/python_tests/requirements.in",
|
||||
# )
|
||||
"""Install project dependencies into the bundled libs directory."""
|
||||
_install_bundle(session)
|
||||
|
||||
|
||||
@nox.session()
|
||||
def setup(session: nox.Session) -> None:
|
||||
"""Sets up the template for development."""
|
||||
session.install("pip<24")
|
||||
_setup_template_environment(session)
|
||||
|
||||
|
||||
@nox.session()
|
||||
def tests(session: nox.Session) -> None:
|
||||
"""Runs all the tests for the extension."""
|
||||
session.install("-r", "src/test/python_tests/requirements.txt")
|
||||
session.run("pytest", "src/test/python_tests")
|
||||
deps = _read_dependencies()
|
||||
session.run("uv", "pip", "install", "--python", sys.executable, *deps, external=True)
|
||||
session.run("uv", "pip", "install", "--python", sys.executable, "pytest", external=True)
|
||||
session.run("pytest", "tests/python_tests")
|
||||
|
||||
|
||||
@nox.session()
|
||||
def lint(session: nox.Session) -> None:
|
||||
"""Runs linter and formatter checks on python files."""
|
||||
session.install("-r", "./requirements.txt")
|
||||
session.install("-r", "src/test/python_tests/requirements.txt")
|
||||
|
||||
session.install("pylint")
|
||||
deps = _read_dependencies()
|
||||
session.run("uv", "pip", "install", "--python", sys.executable, *deps, external=True)
|
||||
session.run(
|
||||
"uv",
|
||||
"pip",
|
||||
"install",
|
||||
"--python",
|
||||
sys.executable,
|
||||
"pytest",
|
||||
"pylint",
|
||||
"black",
|
||||
"isort",
|
||||
external=True,
|
||||
)
|
||||
session.run("pylint", "-d", "W0511", "./bundled/tool")
|
||||
session.run(
|
||||
"pylint",
|
||||
"-d",
|
||||
"W0511",
|
||||
"--ignore=./src/test/python_tests/test_data",
|
||||
"./src/test/python_tests",
|
||||
"--ignore=./tests/python_tests/test_data",
|
||||
"./tests/python_tests",
|
||||
)
|
||||
session.run("pylint", "-d", "W0511", "noxfile.py")
|
||||
|
||||
# check formatting using black
|
||||
session.install("black")
|
||||
session.run("black", "--check", "./bundled/tool")
|
||||
session.run("black", "--check", "./src/test/python_tests")
|
||||
session.run("black", "--check", "./tests/python_tests")
|
||||
session.run("black", "--check", "noxfile.py")
|
||||
|
||||
# check import sorting using isort
|
||||
session.install("isort")
|
||||
session.run("isort", "--check", "./bundled/tool")
|
||||
session.run("isort", "--check", "./src/test/python_tests")
|
||||
session.run("isort", "--check", "./tests/python_tests")
|
||||
session.run("isort", "--check", "noxfile.py")
|
||||
|
||||
# check typescript code
|
||||
@@ -171,9 +153,12 @@ def build_package(session: nox.Session) -> None:
|
||||
session.run("npm", "run", "vsce-package", external=True)
|
||||
|
||||
|
||||
def _update_uv_lock(session: nox.Session) -> None:
|
||||
session.run("uv", "lock", "--upgrade", external=True)
|
||||
|
||||
|
||||
@nox.session()
|
||||
def update_packages(session: nox.Session) -> None:
|
||||
"""Update pip and npm packages."""
|
||||
session.install("wheel", "pip-tools")
|
||||
_update_pip_packages(session)
|
||||
"""Update Python and npm packages."""
|
||||
_update_uv_lock(session)
|
||||
_update_npm_packages(session)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
[project]
|
||||
name = "nx-post-support-server"
|
||||
version = "0.1.0"
|
||||
description = "Python language server for NX Postprocessor Support"
|
||||
requires-python = ">=3.8"
|
||||
dependencies = [
|
||||
"pygls",
|
||||
"packaging",
|
||||
"tclint",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
@@ -1,16 +0,0 @@
|
||||
# This file is used to generate requirements.txt.
|
||||
# NOTE:
|
||||
# Use Python 3.8 or greater which ever is the minimum version of the python
|
||||
# you plan on supporting when creating the environment or using pip-tools.
|
||||
# Only run the commands below to manully upgrade packages in requirements.txt:
|
||||
# 1) python -m pip install pip-tools
|
||||
# 2) pip-compile --generate-hashes --resolver=backtracking --upgrade ./requirements.in
|
||||
# If you are using nox commands to setup or build package you don't need to
|
||||
# run the above commands manually.
|
||||
|
||||
# Required packages
|
||||
pygls
|
||||
packaging
|
||||
|
||||
# TODO: Add your tool here
|
||||
tclint
|
||||
@@ -1,60 +0,0 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with Python 3.11
|
||||
# by the following command:
|
||||
#
|
||||
# pip-compile --generate-hashes ./requirements.in
|
||||
#
|
||||
attrs==25.3.0 \
|
||||
--hash=sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3 \
|
||||
--hash=sha256:75d7cefc7fb576747b2c81b4442d4d4a1ce0900973527c011d1030fd3bf4af1b
|
||||
# via
|
||||
# cattrs
|
||||
# lsprotocol
|
||||
cattrs==25.1.1 \
|
||||
--hash=sha256:1b40b2d3402af7be79a7e7e097a9b4cd16d4c06e6d526644b0b26a063a1cc064 \
|
||||
--hash=sha256:c914b734e0f2d59e5b720d145ee010f1fd9a13ee93900922a2f3f9d593b8382c
|
||||
# via
|
||||
# lsprotocol
|
||||
# pygls
|
||||
importlib-metadata==6.8.0 \
|
||||
--hash=sha256:3ebb78df84a805d7698245025b975d9d67053cd94c79245ba4b3eb694abe68bb \
|
||||
--hash=sha256:dbace7892d8c0c4ac1ad096662232f831d4e64f4c4545bd53016a3e9d4654743
|
||||
# via tclint
|
||||
lsprotocol==2023.0.1 \
|
||||
--hash=sha256:c75223c9e4af2f24272b14c6375787438279369236cd568f596d4951052a60f2 \
|
||||
--hash=sha256:cc5c15130d2403c18b734304339e51242d3018a05c4f7d0f198ad6e0cd21861d
|
||||
# via pygls
|
||||
packaging==25.0 \
|
||||
--hash=sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484 \
|
||||
--hash=sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f
|
||||
# via -r ./requirements.in
|
||||
pathspec==0.11.2 \
|
||||
--hash=sha256:1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20 \
|
||||
--hash=sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3
|
||||
# via tclint
|
||||
ply==3.11 \
|
||||
--hash=sha256:00c7c1aaa88358b9c765b6d3000c6eec0ba42abca5351b095321aef446081da3 \
|
||||
--hash=sha256:096f9b8350b65ebd2fd1346b12452efe5b9607f7482813ffca50c22722a807ce
|
||||
# via tclint
|
||||
pygls==1.3.1 \
|
||||
--hash=sha256:140edceefa0da0e9b3c533547c892a42a7d2fd9217ae848c330c53d266a55018 \
|
||||
--hash=sha256:6e00f11efc56321bdeb6eac04f6d86131f654c7d49124344a9ebb968da3dd91e
|
||||
# via
|
||||
# -r ./requirements.in
|
||||
# tclint
|
||||
tclint==0.6.0 \
|
||||
--hash=sha256:8dd4d7b519e040c164615df8072cc4c28def4bfdc9d2a8672a280b0984b45fc3 \
|
||||
--hash=sha256:f60d2378dd203c0ee1268e9f9138f17cb6106b8824b727e584f054c5932a87db
|
||||
# via -r ./requirements.in
|
||||
typing-extensions==4.14.1 \
|
||||
--hash=sha256:38b39f4aeeab64884ce9f74c94263ef78f3c22467c8724005483154c26648d36 \
|
||||
--hash=sha256:d1e1e3b58374dc93031d6eda2420a48ea44a36c2b4766a4fdeb3710755731d76
|
||||
# via cattrs
|
||||
voluptuous==0.15.2 \
|
||||
--hash=sha256:016348bc7788a9af9520b1764ebd4de0df41fe2138ebe9e06fa036bf86a65566 \
|
||||
--hash=sha256:6ffcab32c4d3230b4d2af3a577c87e1908a714a11f6f95570456b1849b0279aa
|
||||
# via tclint
|
||||
zipp==3.23.0 \
|
||||
--hash=sha256:071652d6115ed432f5ce1d34c336c0adfd6a884660d1e9712a256d3d3bd4b14e \
|
||||
--hash=sha256:a07157588a12518c9d4034df3fbbee09c814741a33ff63c05fa29d26a2404166
|
||||
# via importlib-metadata
|
||||
Reference in New Issue
Block a user