-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Moo-Ack-Productions/api-addition
Addition of BpyBuild API
- Loading branch information
Showing
34 changed files
with
1,441 additions
and
361 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist | ||
__pycache__ | ||
build | ||
test/deps/polib.py |
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 |
---|---|---|
@@ -1,18 +1,24 @@ | ||
repos: | ||
- repo: local | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v1.9.0 | ||
hooks: | ||
- id: mypy | ||
name: mypy | ||
entry: poetry run mypy --pretty | ||
require_serial: true | ||
language: system | ||
types: [ python ] | ||
- repo: https://github.com/psf/black | ||
rev: 23.7.0 | ||
args: [--pretty] | ||
additional_dependencies: [ | ||
"attrs==23.1.0", | ||
"pyyaml==6.0.1", | ||
"cattrs==23.2.3", | ||
"rich==13.7.0", | ||
"typeguard==4.1.5", | ||
"types-pyyaml==6.0.12.11", | ||
"GitPython==3.1.43" | ||
] | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.3.4 | ||
hooks: | ||
- id: black | ||
# It is recommended to specify the latest version of Python | ||
# supported by your project here, or alternatively use | ||
# pre-commit's default_language_version, see | ||
# https://pre-commit.com/#top_level-default_language_version | ||
language_version: python3.11 | ||
# Run the linter. | ||
- id: ruff | ||
# Run the formatter. | ||
- id: ruff-format |
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
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
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,84 @@ | ||
from types import ModuleType | ||
from typing import Dict, Optional | ||
from pathlib import Path | ||
from bpy_addon_build.config import Config | ||
from dataclasses import dataclass | ||
import sys | ||
|
||
|
||
@dataclass | ||
class BpyError: | ||
msg: str | ||
|
||
|
||
@dataclass | ||
class BpyWarning: | ||
msg: str | ||
|
||
|
||
@dataclass | ||
class BabContext: | ||
# Path where the action is being | ||
# executed in. This should be | ||
# the intended cwd | ||
current_path: Path | ||
|
||
|
||
class Api: | ||
""" | ||
API object; this holds all scripts used as modules | ||
Attributes | ||
---------- | ||
build_actions: Dict[str, str] | ||
Action name to script file | ||
action_mods: Dict[str, ModuleType] | ||
Action name to module | ||
""" | ||
|
||
def __init__(self, conf: Config, config_path: Path, debug_mode: bool) -> None: | ||
if conf.build_actions is not None: | ||
self.build_actions = conf.build_actions | ||
self.action_mods: Dict[str, ModuleType] = {} | ||
|
||
for action in self.build_actions: | ||
mod = self.add_modules(config_path, action, debug_mode) | ||
if mod is None: | ||
continue | ||
self.action_mods[action] = mod | ||
|
||
def add_modules( | ||
self, config_path: Path, action: str, debug_mode: bool | ||
) -> Optional[ModuleType]: | ||
import importlib.util | ||
|
||
path = config_path.parent.resolve().joinpath( | ||
Path(self.build_actions[action].script) | ||
) | ||
|
||
# Add the parent folder of the script to the sys path | ||
# so that we don't get module errors | ||
# | ||
# While we could argue that developers should at least | ||
# opt in by calling this themselves, I think automatically | ||
# doing this isn't a problem for now | ||
sys.path.append(str(path.expanduser().parent)) | ||
action_spec = importlib.util.spec_from_file_location(action, path) | ||
if action_spec is None: | ||
if debug_mode: | ||
print("Can not generate action spec for", action) | ||
print("Path:", path) | ||
return None | ||
action_mod = importlib.util.module_from_spec(action_spec) | ||
if action_mod is None: | ||
if debug_mode: | ||
print("Can not generate module from spec for", action) | ||
print("Path:", path) | ||
return None | ||
|
||
sys.modules[action] = action_mod | ||
if action_spec.loader is not None: | ||
action_spec.loader.exec_module(action_mod) | ||
|
||
return action_mod |
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
Oops, something went wrong.