mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-07-18 01:45:02 +00:00
add djls-django crate (#6)
* add djls-django crate * rework * oops * add check for GDAL and GeoDjango * lots of things * remove unused scripts * move scripts to dedicated mod and make static consts * inline gdal check * rename mod * rename mod * move server info to consts * adjust pyproject * hide rustfmt config * simplify django setup * adjust printing
This commit is contained in:
parent
b7a1de98dd
commit
fce343f44d
32 changed files with 1139 additions and 291 deletions
0
python/README.md
Normal file
0
python/README.md
Normal file
0
python/djls/__init__.py
Normal file
0
python/djls/__init__.py
Normal file
31
python/djls/django_setup.py
Normal file
31
python/djls/django_setup.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.engine import Engine
|
||||
|
||||
|
||||
def get_django_setup_info():
|
||||
return {
|
||||
"installed_apps": list(settings.INSTALLED_APPS),
|
||||
"templatetags": [
|
||||
{
|
||||
"name": tag_name,
|
||||
"library": module_name.split(".")[-1],
|
||||
"doc": tag_func.__doc__ if hasattr(tag_func, "__doc__") else None,
|
||||
}
|
||||
for module_name, library in (
|
||||
[("", lib) for lib in Engine.get_default().template_builtins]
|
||||
+ sorted(Engine.get_default().template_libraries.items())
|
||||
)
|
||||
for tag_name, tag_func in library.tags.items()
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import django
|
||||
|
||||
django.setup()
|
||||
print(json.dumps(get_django_setup_info()))
|
21
python/djls/has_import.py
Normal file
21
python/djls/has_import.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# has_import.py
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def check_import(module: str) -> bool:
|
||||
try:
|
||||
module_parts = module.split(".")
|
||||
current = __import__(module_parts[0])
|
||||
for part in module_parts[1:]:
|
||||
current = getattr(current, part)
|
||||
return True
|
||||
except (ImportError, AttributeError):
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = {"can_import": check_import(sys.argv[1])}
|
||||
print(json.dumps(result))
|
9
python/djls/installed_apps_check.py
Normal file
9
python/djls/installed_apps_check.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(json.dumps({"has_app": sys.argv[1] in settings.INSTALLED_APPS}))
|
0
python/djls/py.typed
Normal file
0
python/djls/py.typed
Normal file
78
python/djls/python_setup.py
Normal file
78
python/djls/python_setup.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib.metadata
|
||||
import json
|
||||
import sys
|
||||
import sysconfig
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
def get_version_info():
|
||||
version_parts = sys.version.split()[0].split(".")
|
||||
patch_and_suffix = version_parts[2]
|
||||
for i, c in enumerate(patch_and_suffix):
|
||||
if not c.isdigit():
|
||||
patch = patch_and_suffix[:i]
|
||||
suffix = patch_and_suffix[i:]
|
||||
break
|
||||
else:
|
||||
patch = patch_and_suffix
|
||||
suffix = None
|
||||
|
||||
return {
|
||||
"major": int(version_parts[0]),
|
||||
"minor": int(version_parts[1]),
|
||||
"patch": int(patch),
|
||||
"suffix": suffix,
|
||||
}
|
||||
|
||||
|
||||
class Package(TypedDict):
|
||||
name: str
|
||||
version: str
|
||||
location: Optional[str]
|
||||
|
||||
|
||||
def get_installed_packages() -> Dict[str, Package]:
|
||||
packages: Dict[str, Package] = {}
|
||||
for dist in importlib.metadata.distributions():
|
||||
try:
|
||||
location_path = dist.locate_file("")
|
||||
location = location_path.parent.as_posix() if location_path else None
|
||||
|
||||
packages[dist.metadata["Name"]] = {
|
||||
"name": dist.metadata["Name"],
|
||||
"version": dist.version,
|
||||
"location": location,
|
||||
}
|
||||
except Exception:
|
||||
continue
|
||||
return packages
|
||||
|
||||
|
||||
def get_python_info() -> (
|
||||
Dict[
|
||||
str,
|
||||
str
|
||||
| Dict[str, str]
|
||||
| List[str]
|
||||
| Dict[str, Package]
|
||||
| Dict[str, int | str | None],
|
||||
]
|
||||
):
|
||||
return {
|
||||
"version_info": get_version_info(),
|
||||
"sysconfig_paths": sysconfig.get_paths(),
|
||||
"sys_prefix": sys.prefix,
|
||||
"sys_base_prefix": sys.base_prefix,
|
||||
"sys_executable": sys.executable,
|
||||
"sys_path": [p for p in sys.path if p],
|
||||
"packages": get_installed_packages(),
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(json.dumps(get_python_info()))
|
Loading…
Add table
Add a link
Reference in a new issue