-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
133 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ authors = [ | |
{email = "[email protected]"}, | ||
{name = "Christoph Reiter"} | ||
] | ||
dependencies = [ | ||
# for @deprecated decorator | ||
'typing_extensions>="4.5.0"; python_version<"3.13"', | ||
] | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"Intended Audience :: Developers", | ||
|
@@ -50,7 +54,8 @@ include = '\.pyi?$' | |
skip = "*__pycache__*,.mypy_cache,.git,test,*.pyi" | ||
ignore-words-list = """ | ||
astroid, | ||
inout""" | ||
inout, | ||
gir""" | ||
|
||
[tool.isort] | ||
force_alphabetical_sort_within_sections = true | ||
|
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from typing import cast | ||
|
||
import os | ||
import re | ||
import sys | ||
import xml.etree.ElementTree as ET | ||
|
||
import gi | ||
from gi.repository import GLib | ||
|
||
|
||
def _get_gir_path(girname: str) -> str: | ||
searchdirs: list[str] = [] | ||
|
||
from_env = os.getenv("GI_GIR_PATH", "") | ||
if from_env: | ||
searchdirs.extend(from_env.split(os.pathsep)) | ||
|
||
user_data_dir = GLib.get_user_data_dir() | ||
if user_data_dir is not None: | ||
searchdirs.append(os.path.join(user_data_dir, "gir-1.0")) | ||
|
||
for path in GLib.get_system_data_dirs(): | ||
searchdirs.append(os.path.join(path, "gir-1.0")) | ||
|
||
if os.name != "nt": | ||
# For backwards compatibility, was always unconditionally added to the list. | ||
searchdirs.append("/usr/share/gir-1.0") | ||
|
||
for d in searchdirs: | ||
path = os.path.join(d, girname) | ||
if os.path.exists(path): | ||
return path | ||
|
||
sys.stderr.write(f"Couldn't find '{girname}' (search path: '{searchdirs}')\n") | ||
sys.exit(1) | ||
|
||
|
||
def load_gir(module: str, version: str) -> dict[str, str]: | ||
deprecation_docs: dict[str, str] = {} | ||
ns = { | ||
"core": "http://www.gtk.org/introspection/core/1.0", | ||
"c": "http://www.gtk.org/introspection/c/1.0", | ||
"glib": "http://www.gtk.org/introspection/glib/1.0", | ||
} | ||
gir_tree = ET.parse(_get_gir_path(f"{module}-{version}.gir")) | ||
gir_root = gir_tree.getroot() | ||
gir_parent_map = {c: p for p in gir_tree.iter() for c in p} | ||
|
||
for child in gir_root.iterfind(".//core:doc-deprecated", ns): | ||
parents: list[str] = [] | ||
parent = gir_parent_map[child] | ||
while True: | ||
try: | ||
parents.insert(0, parent.attrib["name"]) | ||
except KeyError: | ||
break | ||
parent = gir_parent_map[parent] | ||
deprecation_docs[".".join(parents[1:])] = re.sub( | ||
" +", " ", cast(str, child.text).replace("\n", " ").replace('"', '\\"') | ||
) | ||
|
||
return deprecation_docs |