mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-09 12:58:31 +02:00
Snipets tooling update
- update README - generate-md.py: ignore trailing newlines when complaining about diffs - all langs: add more dependencies to templates - all langs: support @hide-start and @hide-end for multi-line hiding - go: also allow one-line imports - java: allow declarations other than `main` method - python, typescript: implement `unshorten` for implicit imports and client initialization - python: add mypy config as `datasets` lacks type py.typed - python: hide `# mypy:` annotations - typescript: add tsconfig that allows top-level `await`s - typescript: depend on @types/node to fix `import ... from "crypto"`
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from .base import CompileResult, Language, copy_template, trim_commonpath
|
||||
from .base import (
|
||||
CompileResult,
|
||||
Language,
|
||||
copy_template,
|
||||
generic_shorten,
|
||||
trim_commonpath,
|
||||
)
|
||||
|
||||
RE_IMPORTS = re.compile(
|
||||
r"^from qdrant_client import (.*)$",
|
||||
re.MULTILINE,
|
||||
)
|
||||
|
||||
|
||||
class LanguagePython(Language):
|
||||
@@ -28,7 +40,57 @@ class LanguagePython(Language):
|
||||
target_path,
|
||||
]
|
||||
|
||||
p = subprocess.run(["uv", "--project=templates/python", "run", "mypy", tmpdir])
|
||||
p = subprocess.run(
|
||||
[
|
||||
"uv",
|
||||
"--project=templates/python",
|
||||
"run",
|
||||
"mypy",
|
||||
"--config-file=templates/python/pyproject.toml",
|
||||
tmpdir,
|
||||
]
|
||||
)
|
||||
result.has_issues = p.returncode != 0
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def shorten(cls, contents: str) -> str:
|
||||
lines = [
|
||||
line
|
||||
for line in contents.splitlines(keepends=True)
|
||||
if not line.lstrip().startswith("# mypy:")
|
||||
]
|
||||
return generic_shorten("".join(lines))
|
||||
|
||||
@classmethod
|
||||
def unshorten(cls, contents: str) -> str:
|
||||
if "client." in contents and "QdrantClient" not in contents:
|
||||
contents = (
|
||||
'client = QdrantClient(url="http://localhost:6333") # @hide\n\n'
|
||||
+ contents.lstrip()
|
||||
)
|
||||
|
||||
has_imports = set()
|
||||
if m := RE_IMPORTS.search(contents):
|
||||
has_imports = set(i.strip() for i in m[1].split(","))
|
||||
|
||||
need_imports = set()
|
||||
if "QdrantClient" in contents:
|
||||
need_imports.add("QdrantClient")
|
||||
if "models." in contents:
|
||||
need_imports.add("models")
|
||||
|
||||
if need_imports - has_imports:
|
||||
if m is not None:
|
||||
contents = RE_IMPORTS.sub(
|
||||
f"from qdrant_client import {', '.join(sorted(need_imports | has_imports))}",
|
||||
contents,
|
||||
)
|
||||
else:
|
||||
contents = (
|
||||
f"from qdrant_client import {', '.join(sorted(need_imports))} # @hide\n\n"
|
||||
+ contents.lstrip()
|
||||
)
|
||||
|
||||
return contents
|
||||
|
||||
Reference in New Issue
Block a user