moving functionality to efro and bacommon modules

This commit is contained in:
Eric Froemling 2020-02-03 11:47:44 -08:00
parent 1a56dde622
commit 5180f3b563
28 changed files with 163 additions and 175 deletions

View File

@ -34,6 +34,7 @@
<excludeFolder url="file://$MODULE_DIR$/src/generated" />
<excludeFolder url="file://$MODULE_DIR$/src/tools" />
<excludeFolder url="file://$MODULE_DIR$/submodules" />
<excludeFolder url="file://$MODULE_DIR$/tools/efro" />
<excludePattern pattern=".assetcache" />
<excludePattern pattern=".cache*" />
<excludePattern pattern=".clang-format" />

View File

@ -125,6 +125,7 @@
<w>backgrounding</w>
<w>bacloud</w>
<w>bacloudcmd</w>
<w>bacommon</w>
<w>badguy</w>
<w>bafoundation</w>
<w>ballistica</w>
@ -325,6 +326,7 @@
<w>coords</w>
<w>copyreg</w>
<w>copyrightline</w>
<w>copyrule</w>
<w>cornerpin</w>
<w>coroutines</w>
<w>countdownsounds</w>
@ -342,6 +344,7 @@
<w>csum</w>
<w>ctest</w>
<w>ctex</w>
<w>ctuple</w>
<w>ctype</w>
<w>curdir</w>
<w>curhash</w>
@ -718,6 +721,7 @@
<w>goles</w>
<w>goodlist</w>
<w>googlevr</w>
<w>goosey</w>
<w>gotresponse</w>
<w>gpio</w>
<w>gprev</w>
@ -950,6 +954,7 @@
<w>logitech</w>
<w>logput</w>
<w>loofa</w>
<w>loosey</w>
<w>losecount</w>
<w>lpos</w>
<w>lprop</w>

View File

@ -1,5 +1,5 @@
### 1.5.0 (20001)
- Ported the entire scripting layer from Python 2 to to Python 3 (currently 3.5 to 3.7 depending on platform). There's some significant changes going from python 2 to 3 (new print statement, string behavior, etc), but these are well documented online, so please read up as needed. This should provide us some nice benefits and future-proofs everything. (my janky 2.7 custom Python builds were getting a little long in the tooth)
- Ported the entire scripting layer from Python 2 to to Python 3 (currently 3.5 to 3.7 depending on platform). There's some significant changes going from python 2 to 3 (new print statement, string behavior, etc), but these are well documented online, so please read up as needed. This should provide us some nice benefits and future-proofs everything. (my janky 2.7 custom Python builds were getting a little long in the tooth)..
- Refactored all script code to be PEP8 compliant (python coding standards). Basically, this means that stuff that was camel-case (fooBar) is now a single word or underscores (foobar / foo_bar). There are a few minor exceptions such as existing resource and media filenames, but in general old code can be ported by taking a pass through and killing the camel-case. I know this is a bit of a pain in the ass, but it'll let us use things like pylint and just be more consistent with the rest of the Python world.
- On a related note, I'm now using 'yapf' to keep my Python code formatted nicely (using pep8 style); I'd recommend checking it out if you're doing a lot of scripting as its a great time-saver.
- On another related note, I'm trying to confirm to Google's recommendations for Python code (search 'Google Python Style Guide'). There are some good bits of wisdom in there so I recommend at least skimming through it.

View File

@ -99,34 +99,12 @@
"data/scripts/ba/internal.py",
"data/scripts/ba/ui/__init__.py",
"data/scripts/ba/ui/__pycache__/__init__.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/__init__.py",
"data/scripts/bafoundation/__pycache__/__init__.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/__pycache__/assets.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/__pycache__/dataclassutils.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/__pycache__/err.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/__pycache__/executils.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/__pycache__/jsonutils.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/__pycache__/util.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/assets.py",
"data/scripts/bafoundation/dataclassutils.py",
"data/scripts/bafoundation/entity/__init__.py",
"data/scripts/bafoundation/entity/__pycache__/__init__.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/entity/__pycache__/_base.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/entity/__pycache__/_entity.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/entity/__pycache__/_field.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/entity/__pycache__/_support.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/entity/__pycache__/_value.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/entity/__pycache__/util.cpython-37.opt-1.pyc",
"data/scripts/bafoundation/entity/_base.py",
"data/scripts/bafoundation/entity/_entity.py",
"data/scripts/bafoundation/entity/_field.py",
"data/scripts/bafoundation/entity/_support.py",
"data/scripts/bafoundation/entity/_value.py",
"data/scripts/bafoundation/entity/util.py",
"data/scripts/bafoundation/err.py",
"data/scripts/bafoundation/executils.py",
"data/scripts/bafoundation/jsonutils.py",
"data/scripts/bafoundation/util.py",
"data/scripts/bacommon/__init__.py",
"data/scripts/bacommon/__pycache__/__init__.cpython-37.opt-1.pyc",
"data/scripts/bacommon/__pycache__/assets.cpython-37.opt-1.pyc",
"data/scripts/bacommon/__pycache__/err.cpython-37.opt-1.pyc",
"data/scripts/bacommon/assets.py",
"data/scripts/bacommon/err.py",
"data/scripts/bastd/__init__.py",
"data/scripts/bastd/__pycache__/__init__.cpython-37.opt-1.pyc",
"data/scripts/bastd/__pycache__/appdelegate.cpython-37.opt-1.pyc",
@ -463,6 +441,28 @@
"data/scripts/bastd/ui/trophies.py",
"data/scripts/bastd/ui/url.py",
"data/scripts/bastd/ui/watch.py",
"data/scripts/efro/__init__.py",
"data/scripts/efro/__pycache__/__init__.cpython-37.opt-1.pyc",
"data/scripts/efro/__pycache__/executils.cpython-37.opt-1.pyc",
"data/scripts/efro/__pycache__/jsonutils.cpython-37.opt-1.pyc",
"data/scripts/efro/__pycache__/util.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/__init__.py",
"data/scripts/efro/entity/__pycache__/__init__.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/__pycache__/_base.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/__pycache__/_entity.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/__pycache__/_field.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/__pycache__/_support.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/__pycache__/_value.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/__pycache__/util.cpython-37.opt-1.pyc",
"data/scripts/efro/entity/_base.py",
"data/scripts/efro/entity/_entity.py",
"data/scripts/efro/entity/_field.py",
"data/scripts/efro/entity/_support.py",
"data/scripts/efro/entity/_value.py",
"data/scripts/efro/entity/util.py",
"data/scripts/efro/executils.py",
"data/scripts/efro/jsonutils.py",
"data/scripts/efro/util.py",
"server/__pycache__/config.cpython-37.opt-1.pyc",
"server/__pycache__/server.cpython-37.opt-1.pyc",
"server/config.py",

View File

@ -144,20 +144,20 @@ ASSET_TARGETS_WIN_X64 += $(EXTRAS_TARGETS_WIN_X64)
SCRIPT_TARGETS_PY_1 = \
build/server/server.py \
build/server/config.py \
build/data/scripts/bafoundation/executils.py \
build/data/scripts/bafoundation/dataclassutils.py \
build/data/scripts/bafoundation/util.py \
build/data/scripts/bafoundation/__init__.py \
build/data/scripts/bafoundation/assets.py \
build/data/scripts/bafoundation/jsonutils.py \
build/data/scripts/bafoundation/err.py \
build/data/scripts/bafoundation/entity/_base.py \
build/data/scripts/bafoundation/entity/_support.py \
build/data/scripts/bafoundation/entity/util.py \
build/data/scripts/bafoundation/entity/_entity.py \
build/data/scripts/bafoundation/entity/_field.py \
build/data/scripts/bafoundation/entity/__init__.py \
build/data/scripts/bafoundation/entity/_value.py \
build/data/scripts/efro/executils.py \
build/data/scripts/efro/util.py \
build/data/scripts/efro/__init__.py \
build/data/scripts/efro/jsonutils.py \
build/data/scripts/efro/entity/_base.py \
build/data/scripts/efro/entity/_support.py \
build/data/scripts/efro/entity/util.py \
build/data/scripts/efro/entity/_entity.py \
build/data/scripts/efro/entity/_field.py \
build/data/scripts/efro/entity/__init__.py \
build/data/scripts/efro/entity/_value.py \
build/data/scripts/bacommon/__init__.py \
build/data/scripts/bacommon/assets.py \
build/data/scripts/bacommon/err.py \
build/data/scripts/ba/_gameactivity.py \
build/data/scripts/ba/_apputils.py \
build/data/scripts/ba/_coopsession.py \
@ -380,20 +380,20 @@ SCRIPT_TARGETS_PY_1 = \
SCRIPT_TARGETS_PYC_1 = \
build/server/__pycache__/server.cpython-37.opt-1.pyc \
build/server/__pycache__/config.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/__pycache__/executils.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/__pycache__/dataclassutils.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/__pycache__/util.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/__pycache__/__init__.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/__pycache__/assets.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/__pycache__/jsonutils.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/__pycache__/err.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/entity/__pycache__/_base.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/entity/__pycache__/_support.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/entity/__pycache__/util.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/entity/__pycache__/_entity.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/entity/__pycache__/_field.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/entity/__pycache__/__init__.cpython-37.opt-1.pyc \
build/data/scripts/bafoundation/entity/__pycache__/_value.cpython-37.opt-1.pyc \
build/data/scripts/efro/__pycache__/executils.cpython-37.opt-1.pyc \
build/data/scripts/efro/__pycache__/util.cpython-37.opt-1.pyc \
build/data/scripts/efro/__pycache__/__init__.cpython-37.opt-1.pyc \
build/data/scripts/efro/__pycache__/jsonutils.cpython-37.opt-1.pyc \
build/data/scripts/efro/entity/__pycache__/_base.cpython-37.opt-1.pyc \
build/data/scripts/efro/entity/__pycache__/_support.cpython-37.opt-1.pyc \
build/data/scripts/efro/entity/__pycache__/util.cpython-37.opt-1.pyc \
build/data/scripts/efro/entity/__pycache__/_entity.cpython-37.opt-1.pyc \
build/data/scripts/efro/entity/__pycache__/_field.cpython-37.opt-1.pyc \
build/data/scripts/efro/entity/__pycache__/__init__.cpython-37.opt-1.pyc \
build/data/scripts/efro/entity/__pycache__/_value.cpython-37.opt-1.pyc \
build/data/scripts/bacommon/__pycache__/__init__.cpython-37.opt-1.pyc \
build/data/scripts/bacommon/__pycache__/assets.cpython-37.opt-1.pyc \
build/data/scripts/bacommon/__pycache__/err.cpython-37.opt-1.pyc \
build/data/scripts/ba/__pycache__/_gameactivity.cpython-37.opt-1.pyc \
build/data/scripts/ba/__pycache__/_apputils.cpython-37.opt-1.pyc \
build/data/scripts/ba/__pycache__/_coopsession.cpython-37.opt-1.pyc \
@ -624,7 +624,7 @@ $(SCRIPT_TARGETS_PY_1) : build/%.py : src/%.py
# Looks like path mangling from py to pyc is too complex for pattern rules so
# just generating explicit targets for each. Could perhaps look into using a
# fancy for-loop instead.
# fancy for-loop instead, but perhaps listing these explicitly isn't so bad.
build/server/__pycache__/server.cpython-37.opt-1.pyc: \
build/server/server.py
@ -636,73 +636,73 @@ build/server/__pycache__/config.cpython-37.opt-1.pyc: \
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/__pycache__/executils.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/executils.py
build/data/scripts/efro/__pycache__/executils.cpython-37.opt-1.pyc: \
build/data/scripts/efro/executils.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/__pycache__/dataclassutils.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/dataclassutils.py
build/data/scripts/efro/__pycache__/util.cpython-37.opt-1.pyc: \
build/data/scripts/efro/util.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/__pycache__/util.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/util.py
build/data/scripts/efro/__pycache__/__init__.cpython-37.opt-1.pyc: \
build/data/scripts/efro/__init__.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/__pycache__/__init__.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/__init__.py
build/data/scripts/efro/__pycache__/jsonutils.cpython-37.opt-1.pyc: \
build/data/scripts/efro/jsonutils.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/__pycache__/assets.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/assets.py
build/data/scripts/efro/entity/__pycache__/_base.cpython-37.opt-1.pyc: \
build/data/scripts/efro/entity/_base.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/__pycache__/jsonutils.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/jsonutils.py
build/data/scripts/efro/entity/__pycache__/_support.cpython-37.opt-1.pyc: \
build/data/scripts/efro/entity/_support.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/__pycache__/err.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/err.py
build/data/scripts/efro/entity/__pycache__/util.cpython-37.opt-1.pyc: \
build/data/scripts/efro/entity/util.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/entity/__pycache__/_base.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/entity/_base.py
build/data/scripts/efro/entity/__pycache__/_entity.cpython-37.opt-1.pyc: \
build/data/scripts/efro/entity/_entity.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/entity/__pycache__/_support.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/entity/_support.py
build/data/scripts/efro/entity/__pycache__/_field.cpython-37.opt-1.pyc: \
build/data/scripts/efro/entity/_field.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/entity/__pycache__/util.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/entity/util.py
build/data/scripts/efro/entity/__pycache__/__init__.cpython-37.opt-1.pyc: \
build/data/scripts/efro/entity/__init__.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/entity/__pycache__/_entity.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/entity/_entity.py
build/data/scripts/efro/entity/__pycache__/_value.cpython-37.opt-1.pyc: \
build/data/scripts/efro/entity/_value.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/entity/__pycache__/_field.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/entity/_field.py
build/data/scripts/bacommon/__pycache__/__init__.cpython-37.opt-1.pyc: \
build/data/scripts/bacommon/__init__.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/entity/__pycache__/__init__.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/entity/__init__.py
build/data/scripts/bacommon/__pycache__/assets.cpython-37.opt-1.pyc: \
build/data/scripts/bacommon/assets.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
build/data/scripts/bafoundation/entity/__pycache__/_value.cpython-37.opt-1.pyc: \
build/data/scripts/bafoundation/entity/_value.py
build/data/scripts/bacommon/__pycache__/err.cpython-37.opt-1.pyc: \
build/data/scripts/bacommon/err.py
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
@ -2665,7 +2665,7 @@ $(SCRIPT_TARGETS_PY_2_APPLE) : ../.efrocachemap
# Looks like path mangling from py to pyc is too complex for pattern rules so
# just generating explicit targets for each. Could perhaps look into using a
# fancy for-loop instead.
# fancy for-loop instead, but perhaps listing these explicitly isn't so bad.
build/pylib-apple/__pycache__/zipfile.cpython-37.opt-1.pyc: \
build/pylib-apple/zipfile.py
@ -5668,7 +5668,7 @@ $(SCRIPT_TARGETS_PY_2_ANDROID) : ../.efrocachemap
# Looks like path mangling from py to pyc is too complex for pattern rules so
# just generating explicit targets for each. Could perhaps look into using a
# fancy for-loop instead.
# fancy for-loop instead, but perhaps listing these explicitly isn't so bad.
build/pylib-android/__pycache__/zipfile.cpython-37.opt-1.pyc: \
build/pylib-android/zipfile.py
@ -7819,7 +7819,7 @@ $(SCRIPT_TARGETS_PY_2_COMMON) : ../.efrocachemap
# Looks like path mangling from py to pyc is too complex for pattern rules so
# just generating explicit targets for each. Could perhaps look into using a
# fancy for-loop instead.
# fancy for-loop instead, but perhaps listing these explicitly isn't so bad.
build/pylib-site-packages/__pycache__/typing_extensions.cpython-37.opt-1.pyc: \
build/pylib-site-packages/typing_extensions.py
@ -9174,7 +9174,7 @@ $(SCRIPT_TARGETS_PY_2_WIN_WIN32) : ../.efrocachemap
# Looks like path mangling from py to pyc is too complex for pattern rules so
# just generating explicit targets for each. Could perhaps look into using a
# fancy for-loop instead.
# fancy for-loop instead, but perhaps listing these explicitly isn't so bad.
build/windows/Win32/Lib/__pycache__/zipfile.cpython-37.opt-1.pyc: \
build/windows/Win32/Lib/zipfile.py
@ -13864,7 +13864,7 @@ $(SCRIPT_TARGETS_PY_2_WIN_X64) : ../.efrocachemap
# Looks like path mangling from py to pyc is too complex for pattern rules so
# just generating explicit targets for each. Could perhaps look into using a
# fancy for-loop instead.
# fancy for-loop instead, but perhaps listing these explicitly isn't so bad.
build/windows/x64/Lib/__pycache__/zipfile.cpython-37.opt-1.pyc: \
build/windows/x64/Lib/zipfile.py

View File

@ -62,7 +62,7 @@ class Dependency(Generic[T]):
def get_hash(self) -> int:
"""Return the dependency's hash, calculating it if necessary."""
from bafoundation.util import make_hash
from efro.util import make_hash
if self._hash is None:
self._hash = make_hash((self.cls, self.config))
return self._hash

View File

@ -29,7 +29,7 @@ import _ba
if TYPE_CHECKING:
from typing import Any, Type
from bafoundation import executils
from efro import executils
T = TypeVar('T')

View File

@ -18,4 +18,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
"""Functionality shared between all Ballistica clients, servers, and tools."""
"""Bits of functionality common to ballistica client and server components."""

View File

@ -25,7 +25,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from enum import Enum
from bafoundation import entity
from efro import entity
if TYPE_CHECKING:
pass

View File

@ -18,13 +18,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
"""Error related functionality shared between all ba components."""
"""Error related functionality."""
# Hmmmm - need to give this exception structure some thought...
from __future__ import annotations
from typing import TYPE_CHECKING
class CommunicationError(Exception):
"""A communication-related error occurred."""
if TYPE_CHECKING:
pass
class RemoteError(Exception):

View File

@ -18,34 +18,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
"""Utilities for working with dataclasses."""
"""Common bits of functionality shared between all efro projects.
from __future__ import annotations
# import dataclasses
# def dataclass_from_dict(cls, data):
# print("Creating dataclass from dict", cls, data, type(cls))
# try:
# print("FLDTYPES", [field.type for field in dataclasses.fields(cls)])
# fieldtypes = {
# field.name: field.type
# for field in dataclasses.fields(cls)
# }
# print("GOT FIELDTYPES", fieldtypes)
# # print("GOT", cls.__name__, fieldtypes, data)
# args = {
# field: dataclass_from_dict(fieldtypes[field], data[field])
# for field in data
# }
# print("CALCED ARGS", args)
# val = cls(
# **{
# field: dataclass_from_dict(fieldtypes[field], data[field])
# for field in data
# })
# print("CREATED", val)
# return val
# except Exception as exc:
# print("GOT EXC", exc)
# return data # Not a dataclass field
Things in here should be hardened, highly type-safe, and well-covered by unit
tests since they are widely used in live client and server code.
"""

View File

@ -28,14 +28,13 @@ certain use cases.
"""
# pylint: disable=unused-import
from bafoundation.entity._entity import EntityMixin, Entity
from bafoundation.entity._field import (Field, CompoundField, ListField,
DictField, CompoundListField,
CompoundDictField)
from bafoundation.entity._value import (
from efro.entity._entity import EntityMixin, Entity
from efro.entity._field import (Field, CompoundField, ListField, DictField,
CompoundListField, CompoundDictField)
from efro.entity._value import (
EnumValue, OptionalEnumValue, IntValue, OptionalIntValue, StringValue,
OptionalStringValue, BoolValue, OptionalBoolValue, FloatValue,
OptionalFloatValue, DateTimeValue, OptionalDateTimeValue, Float3Value,
CompoundValue)
from bafoundation.entity._support import FieldInspector
from efro.entity._support import FieldInspector

View File

@ -25,9 +25,9 @@ from __future__ import annotations
import json
from typing import TYPE_CHECKING, TypeVar
from bafoundation.entity._support import FieldInspector, BoundCompoundValue
from bafoundation.entity._value import CompoundValue
from bafoundation.jsonutils import ExtendedJSONEncoder, ExtendedJSONDecoder
from efro.entity._support import FieldInspector, BoundCompoundValue
from efro.entity._value import CompoundValue
from efro.jsonutils import ExtendedJSONEncoder, ExtendedJSONDecoder
if TYPE_CHECKING:
from typing import Dict, Any, Type, Union
@ -79,7 +79,7 @@ class EntityMixin:
compound field, the assignment operator can be used.
"""
import copy
from bafoundation.entity.util import have_matching_fields
from efro.entity.util import have_matching_fields
tvalue: CompoundValue
if isinstance(target, CompoundValue):
tvalue = target
@ -108,7 +108,7 @@ class EntityMixin:
with the result of a database transaction (which generally return
fresh entities).
"""
from bafoundation.entity.util import have_matching_fields
from efro.entity.util import have_matching_fields
if not isinstance(target, EntityMixin):
raise TypeError('EntityMixin is required.')
assert isinstance(target, CompoundValue)
@ -136,7 +136,7 @@ class EntityMixin:
def to_json_str(self, prune: bool = True, pretty: bool = False) -> str:
"""Convert the entity to a json string.
This uses bafoundation.jsontools.ExtendedJSONEncoder/Decoder
This uses efro.jsontools.ExtendedJSONEncoder/Decoder
to support data types not natively storable in json.
Be sure to use the corresponding loading functions here for
this same reason.

View File

@ -26,15 +26,15 @@ import copy
import logging
from typing import TYPE_CHECKING, Generic, TypeVar, overload
from bafoundation.entity._support import (BaseField, BoundCompoundValue,
BoundListField, BoundDictField,
BoundCompoundListField,
BoundCompoundDictField)
from bafoundation.entity.util import have_matching_fields
from efro.entity._support import (BaseField, BoundCompoundValue,
BoundListField, BoundDictField,
BoundCompoundListField,
BoundCompoundDictField)
from efro.entity.util import have_matching_fields
if TYPE_CHECKING:
from typing import Dict, Type, List, Any
from bafoundation.entity._value import TypedValue, CompoundValue
from efro.entity._value import TypedValue, CompoundValue
T = TypeVar('T')
TK = TypeVar('TK')
@ -97,7 +97,7 @@ class CompoundField(BaseField, Generic[TC]):
store_default: bool = True) -> None:
super().__init__(d_key)
if __debug__ is True:
from bafoundation.entity._value import CompoundValue
from efro.entity._value import CompoundValue
assert isinstance(value, CompoundValue)
assert not hasattr(value, 'd_data')
self.d_value = value
@ -138,7 +138,7 @@ class CompoundField(BaseField, Generic[TC]):
return BoundCompoundValue(self.d_value, data[self.d_key])
def set_with_data(self, data: Any, value: Any, error: bool) -> Any:
from bafoundation.entity._value import CompoundValue
from efro.entity._value import CompoundValue
# Ok here's the deal: our type checking above allows any subtype
# of our CompoundValue in here, but we want to be more picky than

View File

@ -24,14 +24,13 @@ from __future__ import annotations
from typing import TYPE_CHECKING, TypeVar, Generic, overload
from bafoundation.entity._base import BaseField
from efro.entity._base import BaseField
if TYPE_CHECKING:
from typing import (Optional, Tuple, Type, Any, Dict, List, Union)
from bafoundation.entity._value import CompoundValue
from bafoundation.entity._field import (ListField, DictField,
CompoundListField,
CompoundDictField)
from efro.entity._value import CompoundValue
from efro.entity._field import (ListField, DictField, CompoundListField,
CompoundDictField)
T = TypeVar('T')
TKey = TypeVar('TKey')
@ -56,7 +55,7 @@ class BoundCompoundValue:
def __eq__(self, other: Any) -> Any:
# Allow comparing to compound and bound-compound objects.
from bafoundation.entity.util import compound_eq
from efro.entity.util import compound_eq
return compound_eq(self, other)
def __getattr__(self, name: str, default: Any = None) -> Any:
@ -119,7 +118,7 @@ class FieldInspector:
def __getattr__(self, name: str, default: Any = None) -> Any:
# pylint: disable=cyclic-import
from bafoundation.entity._field import CompoundField
from efro.entity._field import CompoundField
# If this attribute corresponds to a field on our obj's
# unbound type, return a new inspector for it.
@ -296,7 +295,7 @@ class BoundCompoundListField(Generic[TCompound]):
self._i = 0
def __eq__(self, other: Any) -> Any:
from bafoundation.entity.util import have_matching_fields
from efro.entity.util import have_matching_fields
# We can only be compared to other bound-compound-fields
if not isinstance(other, BoundCompoundListField):
@ -383,7 +382,7 @@ class BoundCompoundDictField(Generic[TKey, TCompound]):
self.d_data = d_data
def __eq__(self, other: Any) -> Any:
from bafoundation.entity.util import have_matching_fields
from efro.entity.util import have_matching_fields
# We can only be compared to other bound-compound-fields
if not isinstance(other, BoundCompoundDictField):

View File

@ -29,8 +29,8 @@ from collections import abc
from enum import Enum
from typing import TYPE_CHECKING, TypeVar, Tuple, Optional, Generic
from bafoundation.entity._base import DataHandler, BaseField
from bafoundation.entity.util import compound_eq
from efro.entity._base import DataHandler, BaseField
from efro.entity.util import compound_eq
if TYPE_CHECKING:
from typing import Optional, Set, List, Dict, Any, Type

View File

@ -26,8 +26,8 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any, Union, Tuple, List
from bafoundation.entity._value import CompoundValue
from bafoundation.entity._support import BoundCompoundValue
from efro.entity._value import CompoundValue
from efro.entity._support import BoundCompoundValue
def diff_compound_values(
@ -73,7 +73,7 @@ class CompoundValueDiff:
def _diff(obj1: Union[BoundCompoundValue, CompoundValue],
obj2: Union[BoundCompoundValue, CompoundValue], indent: int) -> str:
from bafoundation.entity._support import BoundCompoundValue
from efro.entity._support import BoundCompoundValue
bits: List[str] = []
indentstr = ' ' * indent
vobj1, _data1 = get_compound_value_and_data(obj1)
@ -113,8 +113,8 @@ def get_compound_value_and_data(
) -> Tuple[CompoundValue, Any]:
"""Return value and data for bound or unbound compound values."""
# pylint: disable=cyclic-import
from bafoundation.entity._support import BoundCompoundValue
from bafoundation.entity._value import CompoundValue
from efro.entity._support import BoundCompoundValue
from efro.entity._value import CompoundValue
if isinstance(obj, BoundCompoundValue):
value = obj.d_value
data = obj.d_data

View File

@ -69,9 +69,10 @@ class CallbackSet(Generic[CT]):
# similarly to functools.partial (in that they take a callable and some
# positional arguments to be passed to it)
# We define several different _CallXArg classes corresponding to different
# argument counts and define Call() as an overloaded function which returns
# one of them based on how many args are passed.
# In type-checking land, We define several different _CallXArg classes
# corresponding to different argument counts and define Call() as an
# overloaded function which returns one of them based on how many args are
# passed.
# To use this, simply assign your call type to this Call for type checking:
# example:

View File

@ -1,6 +1,6 @@
<!-- THIS FILE IS AUTO GENERATED; DO NOT EDIT BY HAND -->
<!--DOCSHASH=b0f526616eda4f3458fe72fdcd3b29e2-->
<h4><em>last updated on 2020-01-23 for Ballistica version 1.5.0 build 20001</em></h4>
<!--DOCSHASH=b79ca84fb2cba7f2cc11b3d3169b6c29-->
<h4><em>last updated on 2020-02-03 for Ballistica version 1.5.0 build 20001</em></h4>
<p>This page documents the Python classes and functions in the 'ba' module,
which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please <a href="mailto:support@froemling.net">let me know</a>. Happy modding!</p>
<hr>

View File

@ -27,7 +27,7 @@ from enum import Enum, unique
import pytest
from bafoundation import entity
from efro import entity
from efrotools.statictest import static_type_equals
if TYPE_CHECKING:
@ -277,7 +277,7 @@ def test_field_access_from_type() -> None:
# instead of values.
assert static_type_equals(ent.ival, int)
assert isinstance(ent.ival, int)
mypytype = 'bafoundation.entity._field.Field[builtins.int*]'
mypytype = 'efro.entity._field.Field[builtins.int*]'
assert static_type_equals(type(ent).ival, mypytype)
assert isinstance(type(ent).ival, entity.Field)

1
tools/efro Symbolic link
View File

@ -0,0 +1 @@
../assets/src/data/scripts/efro

View File

@ -18,7 +18,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
"""EfroTools: Various build related functionality for use in my projects."""
"""Build/tool functionality shared between all efro projects.
This stuff can be a bit more sloppy/loosey-goosey since it is not used in
live client or server code.
"""
from __future__ import annotations

View File

@ -671,7 +671,8 @@ def update_docs_md() -> None:
exts = ['.cc', '.c', '.h', '.py']
for basedir in [
'src/ballistica/python',
'assets/src/data/scripts/bafoundation',
'assets/src/data/scripts/efro',
'assets/src/data/scripts/bacommon',
'assets/src/data/scripts/ba',
]:
assert os.path.isdir(basedir)

View File

@ -45,6 +45,8 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Optional, Tuple, List, Dict, Set
# Minimal legal notice line required in our private files.
# (Though public ones also start with this line too)
LEGAL_NOTICE_PRIVATE = 'Copyright (c) 2011-2019 Eric Froemling'
CLRHDR = '\033[95m' # Header.
@ -442,7 +444,7 @@ class App:
# Check our packages and make sure all subdirs contain and __init__.py
# (I tend to forget this sometimes)
packagedirs = ['tools/efrotools']
packagedirs = ['tools/efrotools', 'tools/efro']
# (Assume all dirs under these dirs are packages)
dirs_of_packages = ['assets/src/data/scripts', 'tests']