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