Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Nov 15, 2023
1 parent a661707 commit aaef64c
Show file tree
Hide file tree
Showing 77 changed files with 783 additions and 37 deletions.
44 changes: 33 additions & 11 deletions src/fake_bpy_module/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def _parse_module(self, file: IO[Any], level: int) -> str:
"3.0", "3.1", "3.2", "3.3", "3.4", "latest"]:
if module_name == "bpy.data":
module_name = "bpy"
elif self.target == "upbge":
if self.target_version in ("latest", ):
if module_name == "bpy.data":
module_name = "bpy"

return module_name

Expand Down Expand Up @@ -452,6 +456,16 @@ def _split_string_by_comma(self, line: str) -> List[str]:
params = []
current = ""
line_to_parse = line

# Handle case "arg1[, arg2]" -> "arg1, arg2"
m = re.match(r"^([a-zA-Z0-9_]+[^=]+?)\[,(.*)\]$", line_to_parse)
if m:
line_to_parse = f"{m.group(1)},{m.group(2)}"
# Handle case "[arg1]"
m = re.match(r"^\[([a-zA-Z0-9_]+)\]$", line_to_parse)
if m:
line_to_parse = f"{m.group(1)}"

for c in line_to_parse:
if c in ("(", "{", "["):
level += 1
Expand Down Expand Up @@ -603,8 +617,8 @@ def _parse_type(file: IO[Any], level: 'RstLevel') -> str:
self._cleanup_string(_parse_type(
file,
level=level.make_next_level(next_level_spaces)))))
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|literalinclude)::", line): # noqa # pylint: disable=C0301
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|literalinclude)::", line).group(1) # noqa # pylint: disable=C0301
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|literalinclude|deprecated)::", line): # noqa # pylint: disable=C0301
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|literalinclude|deprecated)::", line).group(1) # noqa # pylint: disable=C0301
self._skip_until_next_le_level(
file, level=level.make_next_level(next_level_spaces))
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (to do)", line): # noqa # pylint: disable=C0301
Expand Down Expand Up @@ -669,7 +683,7 @@ def _parse_type(file: IO[Any], level: 'RstLevel') -> str:
return type_str

line = file.readline()
pattern = r"^\s{" + str(level.num_spaces()) + r"}\.\. (data|attribute):: ([a-zA-Z0-9_]+)$" # noqa # pylint: disable=C0301
pattern = r"^\s{" + str(level.num_spaces()) + r"}\.\. (data|attribute|property):: ([a-zA-Z0-9_]+)$" # noqa # pylint: disable=C0301
m = re.match(pattern, line)
if m is None:
self._invalid_line(line, level)
Expand Down Expand Up @@ -769,8 +783,8 @@ def _parse_function(
info.add_parameter_details(detail["parameters"])
if detail["return"] is not None:
info.set_return(detail["return"])
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (seealso|note|warning|code-block)::", line): # noqa # pylint: disable=C0301
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (seealso|note|warning|code-block)::", line).group(1) # noqa # pylint: disable=C0301
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (seealso|note|warning|code-block|deprecated)::", line): # noqa # pylint: disable=C0301
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (seealso|note|warning|code-block|deprecated)::", line).group(1) # noqa # pylint: disable=C0301
self._skip_until_next_le_level(
file, level=level.make_next_level(next_level_spaces))
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (warning):", line): # noqa # pylint: disable=C0301
Expand All @@ -796,7 +810,7 @@ def _parse_function(
def _parse_class(self, file: IO[Any], level: 'RstLevel') -> 'ClassInfo':
def _parse_method(file: IO[Any], level: 'RstLevel') -> 'FunctionInfo':
line = self._get_multiline_string(file, level)
pattern = r"^\s{" + str(level.num_spaces()) + r"}\.\. method:: ([a-zA-Z0-9_]+)\((.*)\):*$" # noqa # pylint: disable=C0301
pattern = r"^\s{" + str(level.num_spaces()) + r"}\.\. method:: ([a-zA-Z0-9_]+)\s*\((.*)\):*$" # noqa # pylint: disable=C0301
m = re.match(pattern, line)
if m is None:
self._invalid_line(line, level)
Expand Down Expand Up @@ -984,10 +998,10 @@ def _parse_static_method(
elif self._has_le_level_string(line, level):
file.seek(last_pos)
return info
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. data::", line): # noqa # pylint: disable=C0301
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (data|property)::", line): # noqa # pylint: disable=C0301
# TODO: Should use assignment expression introduced
# in Python 3.8
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. data::", line).group(1) # noqa # pylint: disable=C0301
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (data|property)::", line).group(1) # noqa # pylint: disable=C0301
file.seek(last_pos)
attr = self._parse_attribute(
file, level=level.make_next_level(next_level_spaces))
Expand Down Expand Up @@ -1033,8 +1047,8 @@ def _parse_static_method(
file, level=level.make_next_level(next_level_spaces))
method.set_class(class_name)
info.add_method(method)
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|warning|literalinclude|seealso)::", line): # noqa # pylint: disable=C0301
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|warning|literalinclude|seealso)::", line).group(1) # noqa # pylint: disable=C0301
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|warning|literalinclude|seealso|deprecated)::", line): # noqa # pylint: disable=C0301
next_level_spaces = re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\. (note|code-block|warning|literalinclude|seealso|deprecated)::", line).group(1) # noqa # pylint: disable=C0301
self._skip_until_next_le_level(
file, level=level.make_next_level(next_level_spaces))
elif re.match(r"^\s{" + str(level.num_spaces()) + r"}(\s+)\.\.", line): # noqa # pylint: disable=C0301
Expand Down Expand Up @@ -1078,7 +1092,11 @@ def _analyze_by_file(self, filename: str) -> 'SectionInfo':
file, level=RstLevel())
elif re.match(r"^\.\. (currentmodule|module)::", line):
if self.current_module is not None:
self._invalid_line(line, 0)
m = re.match(
r"^\.\. (currentmodule|module)::\s*(.*)", line)
if (len(m.groups()) != 2 or
m.group(2) != self.current_module):
self._invalid_line(line, 0)
file.seek(last_pos)
self.current_module = self._cleanup_string(
self._parse_module(file, level=RstLevel()))
Expand Down Expand Up @@ -1124,6 +1142,10 @@ def _analyze_by_file(self, filename: str) -> 'SectionInfo':
re.match(r"^\.\. code-block::", line) or
re.match(r"^\.\. seealso::", line) or
re.match(r"^\.\. note:", line) or
re.match(r"^ \.\. _mat4_cam_to_world:", line) or
re.match(r"^ \.\. code-block:", line) or
re.match(r"^ \.\. _armatureactuator-constants-type",
line) or
re.match(r"^\.\. note,", line) or
re.match(r"^\.\.$", line) or
re.match(r"^\.\. _[a-zA-Z0-9-_]+:", line) or
Expand Down
13 changes: 11 additions & 2 deletions src/fake_bpy_module/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,9 @@ def add_base_classes(self, classes: List['DataType']):
for c in classes:
self.add_base_class(c)

def remove_base_class(self, class_: 'DataType'):
self._base_classes.remove(class_)

def set_base_class(self, index: int, class_: 'DataType'):
self._base_classes[index] = class_

Expand Down Expand Up @@ -1767,7 +1770,8 @@ def _get_refined_data_type_fast(
return None

def _get_refined_data_type_slow(
self, data_type: 'DataType', module_name: str) -> 'DataType':
self, data_type: 'DataType', module_name: str,
variable_kind: str) -> 'DataType':
# convert to aliased data type string
dtype_str = data_type.to_string()
for (key, value) in REPLACE_DATA_TYPE.items():
Expand Down Expand Up @@ -2017,6 +2021,10 @@ def parse_modifier(string_to_parse: str) -> Tuple[List[str], str]:
return dtype_list[0]
if len(dtype_list) >= 2:
return MixinDataType(dtype_list)

if variable_kind == 'CLS_BASE':
return UnknownDataType()

return ModifierDataType("typing.Any")

def _tweak_metadata(self, data_type: 'DataType', variable_kind: str):
Expand Down Expand Up @@ -2170,7 +2178,8 @@ def _get_refined_data_type_internal(
LOG_LEVEL_DEBUG,
f"Slow data type refining: {data_type.to_string()}")

result = self._get_refined_data_type_slow(data_type, module_name)
result = self._get_refined_data_type_slow(
data_type, module_name, variable_kind)
result.set_is_optional(is_optional)
result.set_metadata(metadata)
return result
Expand Down
25 changes: 18 additions & 7 deletions src/fake_bpy_module/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,25 @@ def _sorted_generation_info(
if base_class.type() == 'UNKNOWN':
continue

if base_class.data_type() == class_.name():
dtype = None
if base_class.type() == 'MODIFIER':
dtype = base_class.modifier_data_type()
else:
dtype = base_class.data_type()

if dtype == class_.name():
output_log(
LOG_LEVEL_DEBUG,
f"Self dependency {base_class.data_type()} is found.")
continue

base_class_node = class_name_to_nodes.get(
base_class.data_type())
base_class_node = class_name_to_nodes.get(dtype)
if base_class_node:
graph.make_edge(base_class_node, class_node)
else:
output_log(
LOG_LEVEL_WARN,
f"Base class node (type={base_class.data_type()}) is "
"not found")
f"Base class node (type={dtype}) is not found")
sorted_nodes = topological_sort(graph)
sorted_class_data = [node.data() for node in sorted_nodes]

Expand All @@ -354,7 +358,7 @@ def _sorted_generation_info(
order[class_.name()] = i
for class_ in sorted_class_data:
def sort_func(x):
if x.type() == 'UNKNOWN':
if x.type() in ('UNKNOWN', 'MODIFIER'):
return 0
if x.data_type() not in order:
return 0
Expand Down Expand Up @@ -924,13 +928,20 @@ def get_parameter_from_parameter_detail(
"self_class": f"{info.module()}.{info.name()}"
})
return_.set_data_type(refined_type)

remove_classes = []
for i, c in enumerate(info.base_classes()):
refined_type = refiner.get_refined_data_type(
c, info.module(), 'CLS_BASE',
additional_info={
"self_class": f"{info.module()}.{info.name()}"
})
info.set_base_class(i, refined_type)
if refined_type.type() == 'UNKNOWN':
remove_classes.append(c)
else:
info.set_base_class(i, refined_type)
for c in remove_classes:
info.remove_base_class(c)

def _remove_duplicate(
self,
Expand Down
42 changes: 28 additions & 14 deletions src/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def make_mathutils_rule(
f"{MOD_FILES_DIR}/mods/common/analyzer/mathutils.json"
.replace("\\", "/"),
]
if config.mod_version in ["2.78", "2.79"]:
if config.target == "blender" and config.mod_version in ["2.78", "2.79"]:
mod_files.append(
f"{MOD_FILES_DIR}/mods/{config.mod_version}/analyzer/"
"mathutils.json".replace("\\", "/"))
Expand All @@ -77,10 +77,16 @@ def make_gpu_extras_rule(
config: 'fbm.PackageGeneratorConfig') -> 'fbm.PackageGenerationRule':
files = glob.glob(INPUT_DIR + "/gpu_extras*.rst")
mod_files = []
if config.mod_version not in ["2.78", "2.79"]:
mod_files.append(
f"{MOD_FILES_DIR}/mods/generated_mods/gen_modules_modfile/"
"gpu_extras.json".replace("\\", "/"))
if config.target == "blender":
if config.mod_version not in ["2.78", "2.79"]:
mod_files.append(
f"{MOD_FILES_DIR}/mods/generated_mods/gen_modules_modfile/"
"gpu_extras.json".replace("\\", "/"))
elif config.target == "upbge":
if config.mod_version not in ["0.2.5"]:
mod_files.append(
f"{MOD_FILES_DIR}/mods/generated_mods/gen_modules_modfile/"
"gpu_extras.json".replace("\\", "/"))
return fbm.PackageGenerationRule(
"gpu_extras", files, fbm.AnalyzerWithModFile(mod_files),
fbm.BaseGenerator())
Expand Down Expand Up @@ -146,10 +152,11 @@ def make_bl_math_rule(
config: 'fbm.PackageGeneratorConfig') -> 'fbm.PackageGenerationRule':
files = glob.glob(INPUT_DIR + "/bl_math*.rst")
mod_files = []
if config.mod_version in ["2.90", "2.91", "2.92", "2.93"]:
mod_files.append(
f"{MOD_FILES_DIR}/mods/{config.mod_version}/analyzer/bl_math.json"
.replace("\\", "/"))
if config.target == "blender":
if config.mod_version in ["2.90", "2.91", "2.92", "2.93"]:
mod_files.append(
f"{MOD_FILES_DIR}/mods/{config.mod_version}/"
"analyzer/bl_math.json".replace("\\", "/"))
return fbm.PackageGenerationRule(
"bl_math", files, fbm.AnalyzerWithModFile(mod_files),
fbm.BaseGenerator())
Expand Down Expand Up @@ -179,11 +186,18 @@ def make_other_rules(config: 'fbm.PackageGeneratorConfig') -> List['fbm.PackageG
.replace("\\", "/"),
}

if config.mod_version not in ["2.78", "2.79"]:
mod_files -= {
f"{MOD_FILES_DIR}/mods/generated_mods/gen_modules_modfile/"
"gpu_extras.json".replace("\\", "/"),
}
if config.target == "blender":
if config.mod_version not in ["2.78", "2.79"]:
mod_files -= {
f"{MOD_FILES_DIR}/mods/generated_mods/gen_modules_modfile/"
"gpu_extras.json".replace("\\", "/"),
}
elif config.target == "upbge":
if config.mod_version not in ["0.2.5"]:
mod_files -= {
f"{MOD_FILES_DIR}/mods/generated_mods/gen_modules_modfile/"
"gpu_extras.json".replace("\\", "/"),
}

rules = []
for mod_file in mod_files:
Expand Down
1 change: 1 addition & 0 deletions src/gen_modfile/gen_external_modules_modfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"bl_app_templates_system.Sculpting",
"bl_app_templates_system.VFX",
"bl_app_templates_system.Video_Editing",
"bgui.bgui_utils",
}


Expand Down
2 changes: 1 addition & 1 deletion src/gen_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ cp -r "${tmp_dir}/sphinx-in" "${tmp_dir}/sphinx-in.orig"
if [ "${mod_version}" != "not-specified" ]; then
echo "Applying patches ..."
# shellcheck disable=SC2044
for patch_file in $(find "${SCRIPT_DIR}/patches/${mod_version}/sphinx-in" -name "*.patch"); do
for patch_file in $(find "${SCRIPT_DIR}/patches/${target}/${mod_version}/sphinx-in" -name "*.patch"); do
patch -u -p2 -d "${tmp_dir}/sphinx-in" < "${patch_file}"
done
fi
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- gen_module-tmp/sphinx-in.orig/bge.types.KX_ConstraintWrapper.rst 2020-07-07 11:14:46.128093707 +0000
+++ gen_module-tmp/sphinx-in/bge.types.KX_ConstraintWrapper.rst 2020-07-07 12:55:51.760077104 +0000
@@ -112,14 +112,6 @@ base class --- :class:`EXP_PyObjectPlus`
:return: position
:rtype: float

- axis = 3..5 are relative constraint (Euler) angles in radians
- * 3: X axis angle
- * 4: Y axis angle
- * 5: Z axis angle
-
- :return: angle
- :rtype: float
-
.. attribute:: constraint_id

Returns the contraint ID (read only)
Loading

0 comments on commit aaef64c

Please sign in to comment.