Skip to content

Commit

Permalink
Make common between fake-bpy-module and fake-bge-module
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Aug 13, 2023
1 parent 832ecef commit 0b7efc7
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 147 deletions.
4 changes: 2 additions & 2 deletions src/fake_bpy_module/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ def __init__(self):
self.os: str = "Linux"
self.style_format: str = "pep8"
self.dump: bool = False
self.blender_version: str = None
self.target: str = "blender"
self.target_version: str = None
self.mod_version: str = None
self.support_bge: bool = False


class PackageGenerationRule:
Expand Down
77 changes: 62 additions & 15 deletions src/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import fake_bpy_module as fbm

INPUT_DIR: str = "."
SUPPORTED_TARGET: List[str] = ["pycharm"]
SUPPORTED_TARGET: List[str] = ["blender", "upbge"]
SUPPORTED_STYLE_FORMAT: List[str] = ["none", "pep8"]
SUPPORTED_MOD_BLENDER_VERSION: List[str] = [
"2.78", "2.79",
Expand All @@ -17,13 +17,21 @@
"3.0", "3.1", "3.2", "3.3", "3.4",
"latest"
]
SUPPORTED_MOD_UPBGE_VERSION: List[str] = [
"0.2.5",
"latest"
]
SUPPORTED_BLENDER_VERSION: List[str] = [
"2.78", "2.79",
"2.80", "2.81", "2.82", "2.83",
"2.90", "2.91", "2.92", "2.93",
"3.0", "3.1", "3.2", "3.3", "3.4",
"latest"
]
SUPPORTED_UPBGE_VERSION: List[str] = [
"0.2.5",
"latest"
]
MOD_FILES_DIR: str = os.path.dirname(os.path.abspath(__file__))


Expand Down Expand Up @@ -167,6 +175,14 @@ def make_bl_math_rule(
fbm.BaseGenerator())


def make_bge_rule(
_: 'fbm.PackageGeneratorConfig') -> 'fbm.PackageGenerationRule':
files = glob.glob(INPUT_DIR + "/bge*.rst")
files.extend(glob.glob(INPUT_DIR + "/bge_types/bge*.rst"))
return fbm.PackageGenerationRule(
"bge", files, fbm.BaseAnalyzer(), fbm.BaseGenerator())


def make_other_rules(config: 'fbm.PackageGeneratorConfig') -> List['fbm.PackageGenerationRule']: # noqa # pylint: disable=C0301
mod_files = glob.glob(
f"{MOD_FILES_DIR}/mods/generated_mods/gen_modules_modfile/*.json"
Expand Down Expand Up @@ -200,9 +216,10 @@ def make_other_rules(config: 'fbm.PackageGeneratorConfig') -> List['fbm.PackageG

def parse_options(config: 'fbm.PackageGeneratorConfig'):
# pylint: disable=W0603
global INPUT_DIR, SUPPORTED_TARGET # pylint: disable=W0602
global INPUT_DIR # pylint: disable=W0602
usage = f"Usage: python {__file__} [-i <input_dir>] [-o <output_dir>] " \
"[-d] [-f <style_format>] [-m <mod_version>]"
"[-T <target>] [-t <target_version>] [-d] [-f <style_format>] " \
"[-m <mod_version>]"
parser = argparse.ArgumentParser(usage)
parser.add_argument(
"-i", dest="input_dir", type=str, help="Input directory"
Expand All @@ -223,8 +240,12 @@ def parse_options(config: 'fbm.PackageGeneratorConfig'):
"(ex. 2.79, 2.80)"
)
parser.add_argument(
"-b", dest="blender_version", type=str,
help="Blender version (ex. 2.79, 2.80)"
"-T", dest="target", type=str,
help="Target (blender, upbge)"
)
parser.add_argument(
"-t", dest="target_version", type=str,
help="Target version (ex. 2.79, 2.80)"
)
parser.add_argument(
"-l", dest="output_log_level", type=str,
Expand All @@ -242,21 +263,45 @@ def parse_options(config: 'fbm.PackageGeneratorConfig'):
raise RuntimeError(
f"Not supported style format {args.style_format}. "
f"(Supported Style Format: {SUPPORTED_STYLE_FORMAT})")
if args.mod_version:
if args.mod_version in SUPPORTED_MOD_BLENDER_VERSION:
config.mod_version = args.mod_version

if args.target in SUPPORTED_TARGET:
config.target = args.target
else:
raise RuntimeError(
f"Not supported target {args.target}."
f"(Supported Target: {SUPPORTED_TARGET})")

if args.target == "blender":
if args.target_version in SUPPORTED_BLENDER_VERSION:
config.target_version = args.target_version
else:
raise RuntimeError(
f"Not supported mod version {args.mod_version}. "
f"(Supported Version: {SUPPORTED_MOD_BLENDER_VERSION})")
f"Not supported blender version {args.target_version}. "
f"(Supported Version: {SUPPORTED_BLENDER_VERSION})")

if args.blender_version:
if args.blender_version in SUPPORTED_BLENDER_VERSION:
config.blender_version = args.blender_version
if args.target == "upbge":
if args.target_version in SUPPORTED_UPBGE_VERSION:
config.target_version = args.target_version
else:
raise RuntimeError(
f"Not supported blender version {args.blender_version}. "
f"(Supported Version: {SUPPORTED_BLENDER_VERSION})")
f"Not supported upbge version {args.target_version}. "
f"(Supported Version: {SUPPORTED_UPBGE_VERSION})")

if args.mod_version:
if config.target == "blender":
if args.mod_version in SUPPORTED_MOD_BLENDER_VERSION:
config.mod_version = args.mod_version
else:
raise RuntimeError(
f"Not supported mod version {args.mod_version}. "
f"(Supported Version: {SUPPORTED_MOD_BLENDER_VERSION})")
elif config.target == "upbge":
if args.mod_version in SUPPORTED_MOD_UPBGE_VERSION:
config.mod_version = args.mod_version
else:
raise RuntimeError(
f"Not supported mod version {args.mod_version}. "
f"(Supported Version: {SUPPORTED_MOD_UPBGE_VERSION})")

if args.output_log_level:
ARG_TO_LOG_LEVEL = {
Expand Down Expand Up @@ -291,6 +336,8 @@ def main():
pkg_generator.add_rule(make_idprop_rule(config))
pkg_generator.add_rule(make_imbuf_rule(config))
pkg_generator.add_rule(make_bl_math_rule(config))
if config.target == "upbge":
pkg_generator.add_rule(make_bge_rule(config))
for rule in make_other_rules(config):
pkg_generator.add_rule(rule)
pkg_generator.generate()
Expand Down
49 changes: 27 additions & 22 deletions src/gen_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ SCRIPT_DIR=$(cd $(dirname "$0"); pwd)
PYTHON_BIN=${PYTHON_BIN:-python}

if [ $# -ne 5 ] && [ $# -ne 6 ]; then
echo "Usage: bash gen_module.sh <source-dir> <blender-dir> <branch/tag/commit> <blender-version> <output-dir> [<mod-version>]"
echo "Usage: bash gen_module.sh <source-dir> <blender-dir> <target> <branch/tag/commit> <target-version> <output-dir> [<mod-version>]"
exit 1
fi

source_dir=${1}
blender_dir=${2}
git_ref=${3}
blender_version=${4}
output_dir=${5}
mod_version=${6:-not-specified}
target=${3}
git_ref=${4}
target_version=${5}
output_dir=${6}
mod_version=${7:-not-specified}
current_dir=$(pwd)
tmp_dir=${current_dir}/${TMP_DIR_NAME}
format="pep8"
Expand Down Expand Up @@ -87,29 +88,33 @@ git checkout -f "${remote_git_ref}"

function apply_workaround() {
local ref=${git_ref}
local blender_source=${source_dir}
local project_source=${source_dir}

if [ "${ref}" = "v2.90.0" ] || [ "${ref}" = "v2.91.0" ]; then
pushd "${blender_source}" > /dev/null
if [ "${target}" = "blender" ]; then
if [ "${ref}" = "v2.90.0" ] || [ "${ref}" = "v2.91.0" ]; then
pushd "${project_source}" > /dev/null

# Workaround for an error of rst document generation.
# See https://developer.blender.org/T80364 for detail.
cp doc/python_api/sphinx_doc_gen.py doc/python_api/sphinx_doc_gen.py.orig
sed -i -e "/Hair/s/^/#/" doc/python_api/sphinx_doc_gen.py
sed -i -e "/PointCloud/s/^/#/" doc/python_api/sphinx_doc_gen.py
# Workaround for an error of rst document generation.
# See https://developer.blender.org/T80364 for detail.
cp doc/python_api/sphinx_doc_gen.py doc/python_api/sphinx_doc_gen.py.orig
sed -i -e "/Hair/s/^/#/" doc/python_api/sphinx_doc_gen.py
sed -i -e "/PointCloud/s/^/#/" doc/python_api/sphinx_doc_gen.py

popd > /dev/null
popd > /dev/null
fi
fi
}

function revert_workaround() {
local ref=${git_ref}
local blender_source=${source_dir}

if [ "${ref}" = "v2.90.0" ] || [ "${ref}" = "v2.91.0" ]; then
pushd "${blender_source}" > /dev/null
git checkout doc/python_api/sphinx_doc_gen.py
popd > /dev/null
local project_source=${source_dir}

if [ "${target}" = "blender" ]; then
if [ "${ref}" = "v2.90.0" ] || [ "${ref}" = "v2.91.0" ]; then
pushd "${project_source}" > /dev/null
git checkout doc/python_api/sphinx_doc_gen.py
popd > /dev/null
fi
fi
}

Expand Down Expand Up @@ -149,9 +154,9 @@ ${python_bin} "${SCRIPT_DIR}/gen_modfile/gen_bgl_modfile.py" -i "${bgl_c_file}"

echo "Generating fake bpy modules ..."
if [ "${mod_version}" = "not-specified" ]; then
${python_bin} "${SCRIPT_DIR}/gen.py" -i "${tmp_dir}/sphinx-in" -o "${output_dir}" -f ${format} -b "${blender_version}" -l "${output_log_level}"
${python_bin} "${SCRIPT_DIR}/gen.py" -i "${tmp_dir}/sphinx-in" -o "${output_dir}" -f "${format}" -T "${target}" -t "${target_version}" -l "${output_log_level}"
else
${python_bin} "${SCRIPT_DIR}/gen.py" -i "${tmp_dir}/sphinx-in" -o "${output_dir}" -f ${format} -b "${blender_version}" -l "${output_log_level}" -m "${mod_version}"
${python_bin} "${SCRIPT_DIR}/gen.py" -i "${tmp_dir}/sphinx-in" -o "${output_dir}" -f "${format}" -T "${target}" -t "${target_version}" -l "${output_log_level}" -m "${mod_version}"
fi

echo "Cleaning up ..."
Expand Down
Loading

0 comments on commit 0b7efc7

Please sign in to comment.