mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 08:35:14 +00:00
typing
This commit is contained in:
@@ -207,6 +207,7 @@ if __name__ == "__main__":
|
|||||||
print("""
|
print("""
|
||||||
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import pickle
|
import pickle
|
||||||
@@ -217,7 +218,7 @@ import mapping
|
|||||||
from pyparsing import *
|
from pyparsing import *
|
||||||
from nodes import *
|
from nodes import *
|
||||||
|
|
||||||
def parse(fn):
|
def parse(fn: str) -> mapping.Mapping:
|
||||||
cache_file = fn + ".cache.dat"
|
cache_file = fn + ".cache.dat"
|
||||||
if os.path.exists(cache_file) and os.path.getmtime(cache_file) >= os.path.getmtime(fn):
|
if os.path.exists(cache_file) and os.path.getmtime(cache_file) >= os.path.getmtime(fn):
|
||||||
with open(cache_file, "rb") as f:
|
with open(cache_file, "rb") as f:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import pickle
|
import pickle
|
||||||
@@ -11,7 +12,7 @@ import mapping
|
|||||||
from pyparsing import *
|
from pyparsing import *
|
||||||
from nodes import *
|
from nodes import *
|
||||||
|
|
||||||
def parse(fn):
|
def parse(fn: str) -> mapping.Mapping:
|
||||||
cache_file = fn + ".cache.dat"
|
cache_file = fn + ".cache.dat"
|
||||||
if os.path.exists(cache_file) and os.path.getmtime(cache_file) >= os.path.getmtime(fn):
|
if os.path.exists(cache_file) and os.path.getmtime(cache_file) >= os.path.getmtime(fn):
|
||||||
with open(cache_file, "rb") as f:
|
with open(cache_file, "rb") as f:
|
||||||
|
|||||||
@@ -17,9 +17,11 @@
|
|||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
import sys
|
import sys
|
||||||
import nodes
|
import nodes
|
||||||
import templates
|
import templates
|
||||||
|
import schema
|
||||||
|
|
||||||
|
|
||||||
class Mapping:
|
class Mapping:
|
||||||
@@ -55,7 +57,7 @@ class Mapping:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, schema):
|
def __init__(self, schema: schema.Schema):
|
||||||
self.schema = schema
|
self.schema = schema
|
||||||
|
|
||||||
def flatten_type_string(self, type):
|
def flatten_type_string(self, type):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import re
|
|||||||
import ast
|
import ast
|
||||||
import collections
|
import collections
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
from logging import Logger
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from codegen import indent
|
from codegen import indent
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ def fix_type(v):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
def run(f, logger):
|
def run(f: ifcopenshell.file, logger: Logger) -> None:
|
||||||
from _pytest import assertion
|
from _pytest import assertion
|
||||||
|
|
||||||
if hasattr(logger, "set_instance"):
|
if hasattr(logger, "set_instance"):
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
import nodes
|
import nodes
|
||||||
import platform
|
import platform
|
||||||
import collections
|
import collections
|
||||||
|
import pyparsing
|
||||||
|
|
||||||
if tuple(map(int, platform.python_version_tuple())) < (2, 7):
|
if tuple(map(int, platform.python_version_tuple())) < (2, 7):
|
||||||
import ordereddict
|
import ordereddict
|
||||||
@@ -83,7 +84,7 @@ class Schema:
|
|||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self.all_declarations[OrderedCaseInsensitiveDict_KeyObject(key)]
|
return self.all_declarations[OrderedCaseInsensitiveDict_KeyObject(key)]
|
||||||
|
|
||||||
def __init__(self, parsetree):
|
def __init__(self, parsetree: pyparsing.ParseResults):
|
||||||
self.tree = parsetree
|
self.tree = parsetree
|
||||||
schema = next(iter(parsetree.syntax[0]))
|
schema = next(iter(parsetree.syntax[0]))
|
||||||
self.name = schema.simple_id
|
self.name = schema.simple_id
|
||||||
|
|||||||
@@ -17,12 +17,14 @@
|
|||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
import operator
|
import operator
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import nodes
|
import nodes
|
||||||
import codegen
|
import codegen
|
||||||
import templates
|
import templates
|
||||||
|
import mapping
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
@@ -363,7 +365,7 @@ const std::string strings[] = {%s};
|
|||||||
|
|
||||||
|
|
||||||
class SchemaClass(codegen.Base):
|
class SchemaClass(codegen.Base):
|
||||||
def __init__(self, mapping, code=EarlyBoundCodeWriter):
|
def __init__(self, mapping: mapping.Mapping, code=EarlyBoundCodeWriter):
|
||||||
class UnmetDependenciesException(Exception):
|
class UnmetDependenciesException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -25,16 +25,17 @@ except ModuleNotFoundError as e:
|
|||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
from collections import Counter
|
|
||||||
import itertools
|
import itertools
|
||||||
import operator
|
import operator
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
import json
|
import json
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
from collections import Counter
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
# Hacky modified functions from server.py to make parser work
|
# Hacky modified functions from server.py to make parser work
|
||||||
def get_definition_from_md(resource, mdc):
|
def get_definition_from_md(resource: str, mdc: str) -> str:
|
||||||
# Only match up to the first h2
|
# Only match up to the first h2
|
||||||
lines = []
|
lines = []
|
||||||
for line in mdc.split("\n"):
|
for line in mdc.split("\n"):
|
||||||
@@ -49,7 +50,7 @@ def get_definition_from_md(resource, mdc):
|
|||||||
return mdc_splitted[1] if len(mdc_splitted) > 1 else ""
|
return mdc_splitted[1] if len(mdc_splitted) > 1 else ""
|
||||||
|
|
||||||
|
|
||||||
def get_type_values(resource, mdc):
|
def get_type_values(resource: str, mdc: str) -> dict[str, Any]:
|
||||||
values = R.type_values.get(resource)
|
values = R.type_values.get(resource)
|
||||||
if not values:
|
if not values:
|
||||||
return
|
return
|
||||||
@@ -128,7 +129,7 @@ def get_attributes_keep_md(resource, builder):
|
|||||||
# -------------------------
|
# -------------------------
|
||||||
|
|
||||||
|
|
||||||
def get_description_json(resource):
|
def get_description_json(resource: str) -> str:
|
||||||
md = get_resource_path(resource, abort_on_error=False)
|
md = get_resource_path(resource, abort_on_error=False)
|
||||||
mdc = open(md, "r", encoding="utf-8").read()
|
mdc = open(md, "r", encoding="utf-8").read()
|
||||||
description = get_definition_from_md(resource, mdc)
|
description = get_definition_from_md(resource, mdc)
|
||||||
@@ -153,7 +154,7 @@ def get_predefined_type_values_json(resource):
|
|||||||
return get_type_values(resource, mdc)["schema_values"]
|
return get_type_values(resource, mdc)["schema_values"]
|
||||||
|
|
||||||
|
|
||||||
def save_entities_data(entities):
|
def save_entities_data(entities: list[str]) -> None:
|
||||||
entities_description = dict()
|
entities_description = dict()
|
||||||
for entity in entities:
|
for entity in entities:
|
||||||
entity_data = dict()
|
entity_data = dict()
|
||||||
@@ -198,6 +199,6 @@ def save_entities_data(entities):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name("IFC4X3")
|
schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name("IFC4X3_ADD2")
|
||||||
entities = [e.name() for e in schema.declarations()]
|
entities: list[str] = [e.name() for e in schema.declarations()]
|
||||||
save_entities_data(entities)
|
save_entities_data(entities)
|
||||||
|
|||||||
Reference in New Issue
Block a user