diff --git a/.idea/MypyConfig.xml b/.idea/MypyConfig.xml
index c5bc1e62..c9ac4ea5 100644
--- a/.idea/MypyConfig.xml
+++ b/.idea/MypyConfig.xml
@@ -1,7 +1,7 @@
-
+
-
+
\ No newline at end of file
diff --git a/.idea/dictionaries/ericf.xml b/.idea/dictionaries/ericf.xml
index 879b3457..130b2d3d 100644
--- a/.idea/dictionaries/ericf.xml
+++ b/.idea/dictionaries/ericf.xml
@@ -87,6 +87,7 @@
assetcacheassetdataassetfiles
+ assetmanagerassetpackassetpackageassetpackput
@@ -414,6 +415,7 @@
dlinedllsdmodule
+ dmypydnamednamesdnode
@@ -1863,6 +1865,7 @@
workdirworkflowswpath
+ wrefwriteclasseswritefuncswtcolor
diff --git a/Makefile b/Makefile
index 661caf9c..59dd7fc5 100644
--- a/Makefile
+++ b/Makefile
@@ -310,6 +310,14 @@ mypy: prereqs
mypy-full: prereqs
@tools/snippets mypy -full
+# Run Mypy checks on all Python code using daemon mode.
+dmypy: prereqs
+ @tools/snippets dmypy
+
+# Stop the mypy daemon
+dmypy-stop: prereqs
+ @tools/snippets dmypy -stop
+
# Run PyCharm checks on all Python code.
pycharm: prereqs
@tools/snippets pycharm
@@ -339,6 +347,11 @@ test: prereqs
# Run tests with any caching disabled.
test-full: test
+# Some individual tests for iterating.
+test-assetmanager:
+ @tools/snippets pytest \
+ -s -v tests/test_ba/test_assetmanager.py::test_assetmanager
+
# Tell make which of these targets don't represent files.
.PHONY: test test-full
diff --git a/assets/.asset_manifest_1.json b/assets/.asset_manifest_1.json
index 48529787..462ef824 100644
--- a/assets/.asset_manifest_1.json
+++ b/assets/.asset_manifest_1.json
@@ -10,6 +10,7 @@
"ba_data/python/ba/__pycache__/_appconfig.cpython-37.opt-1.pyc",
"ba_data/python/ba/__pycache__/_appdelegate.cpython-37.opt-1.pyc",
"ba_data/python/ba/__pycache__/_apputils.cpython-37.opt-1.pyc",
+ "ba_data/python/ba/__pycache__/_assetmanager.cpython-37.opt-1.pyc",
"ba_data/python/ba/__pycache__/_benchmark.cpython-37.opt-1.pyc",
"ba_data/python/ba/__pycache__/_campaign.cpython-37.opt-1.pyc",
"ba_data/python/ba/__pycache__/_coopgame.cpython-37.opt-1.pyc",
@@ -58,6 +59,7 @@
"ba_data/python/ba/_appconfig.py",
"ba_data/python/ba/_appdelegate.py",
"ba_data/python/ba/_apputils.py",
+ "ba_data/python/ba/_assetmanager.py",
"ba_data/python/ba/_benchmark.py",
"ba_data/python/ba/_campaign.py",
"ba_data/python/ba/_coopgame.py",
diff --git a/assets/Makefile b/assets/Makefile
index 38e847ec..f458de9e 100644
--- a/assets/Makefile
+++ b/assets/Makefile
@@ -181,6 +181,7 @@ SCRIPT_TARGETS_PY_1 = \
build/ba_data/python/ba/_store.py \
build/ba_data/python/ba/_activitytypes.py \
build/ba_data/python/ba/__init__.py \
+ build/ba_data/python/ba/_assetmanager.py \
build/ba_data/python/ba/_session.py \
build/ba_data/python/ba/_hooks.py \
build/ba_data/python/ba/_enums.py \
@@ -417,6 +418,7 @@ SCRIPT_TARGETS_PYC_1 = \
build/ba_data/python/ba/__pycache__/_store.cpython-37.opt-1.pyc \
build/ba_data/python/ba/__pycache__/_activitytypes.cpython-37.opt-1.pyc \
build/ba_data/python/ba/__pycache__/__init__.cpython-37.opt-1.pyc \
+ build/ba_data/python/ba/__pycache__/_assetmanager.cpython-37.opt-1.pyc \
build/ba_data/python/ba/__pycache__/_session.cpython-37.opt-1.pyc \
build/ba_data/python/ba/__pycache__/_hooks.cpython-37.opt-1.pyc \
build/ba_data/python/ba/__pycache__/_enums.cpython-37.opt-1.pyc \
@@ -821,6 +823,11 @@ build/ba_data/python/ba/__pycache__/__init__.cpython-37.opt-1.pyc: \
@echo Compiling script: $^
@rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
+build/ba_data/python/ba/__pycache__/_assetmanager.cpython-37.opt-1.pyc: \
+ build/ba_data/python/ba/_assetmanager.py
+ @echo Compiling script: $^
+ @rm -rf $@ && $(TOOLS_DIR)/snippets compile_python_files $^ && chmod 444 $@
+
build/ba_data/python/ba/__pycache__/_session.cpython-37.opt-1.pyc: \
build/ba_data/python/ba/_session.py
@echo Compiling script: $^
diff --git a/assets/src/ba_data/python/ba/_assetmanager.py b/assets/src/ba_data/python/ba/_assetmanager.py
new file mode 100644
index 00000000..c933747f
--- /dev/null
+++ b/assets/src/ba_data/python/ba/_assetmanager.py
@@ -0,0 +1,31 @@
+# Copyright (c) 2011-2020 Eric Froemling
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+# -----------------------------------------------------------------------------
+"""Functionality related to managing cloud based assets."""
+
+
+class AssetManager:
+ """Wrangles all assets."""
+
+ def __init__(self) -> None:
+ print('AssetManager()')
+
+ def __del__(self) -> None:
+ print('~AssetManager()')
diff --git a/assets/src/ba_data/python/efro/util.py b/assets/src/ba_data/python/efro/util.py
index da424513..8f607758 100644
--- a/assets/src/ba_data/python/efro/util.py
+++ b/assets/src/ba_data/python/efro/util.py
@@ -288,6 +288,9 @@ def make_hash(obj: Any) -> int:
Note that this uses Python's hash() function internally so collisions/etc.
may be more common than with fancy cryptographic hashes.
+
+ Also be aware that Python's hash() output varies across processes, so
+ this should only be used for values that will remain in a single process.
"""
import copy
diff --git a/docs/ba_module.md b/docs/ba_module.md
index bbc1cb10..f7290b6a 100644
--- a/docs/ba_module.md
+++ b/docs/ba_module.md
@@ -1,6 +1,6 @@
-
-
last updated on 2020-02-19 for Ballistica version 1.5.0 build 20001
+
+
last updated on 2020-03-05 for Ballistica version 1.5.0 build 20001
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 let me know. Happy modding!
diff --git a/tests/test_ba/__init__.py b/tests/test_ba/__init__.py
new file mode 100644
index 00000000..32622553
--- /dev/null
+++ b/tests/test_ba/__init__.py
@@ -0,0 +1,20 @@
+# Copyright (c) 2011-2020 Eric Froemling
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+# -----------------------------------------------------------------------------
diff --git a/tests/test_ba/test_assetmanager.py b/tests/test_ba/test_assetmanager.py
new file mode 100644
index 00000000..b65915b3
--- /dev/null
+++ b/tests/test_ba/test_assetmanager.py
@@ -0,0 +1,44 @@
+# Copyright (c) 2011-2020 Eric Froemling
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+# -----------------------------------------------------------------------------
+"""Testing asset manager functionality."""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+import weakref
+# noinspection PyProtectedMember
+from ba._assetmanager import AssetManager
+
+# import pytest
+
+if TYPE_CHECKING:
+ pass
+
+
+def test_assetmanager() -> None:
+ """Testing."""
+
+ manager = AssetManager()
+ wref = weakref.ref(manager)
+
+ # Make sure it's not keeping itself alive.
+ del manager
+ assert wref() is None
diff --git a/tools/efrotools/code.py b/tools/efrotools/code.py
index a004a4d2..d5a7f773 100644
--- a/tools/efrotools/code.py
+++ b/tools/efrotools/code.py
@@ -524,7 +524,7 @@ def runmypy(filenames: List[str],
def mypy(projroot: Path, full: bool) -> None:
- """Run mypy on all of our scripts."""
+ """Type check all of our scripts using mypy."""
import time
filenames = get_script_filenames(projroot)
print('Running Mypy ' + ('(full)' if full else '(incremental)') + '...',
@@ -539,6 +539,31 @@ def mypy(projroot: Path, full: bool) -> None:
print(f'Mypy passed in {duration:.1f} seconds.', flush=True)
+def dmypy(projroot: Path) -> None:
+ """Type check all of our scripts using mypy in daemon mode."""
+ import time
+ filenames = get_script_filenames(projroot)
+
+ # Special case; explicitly kill the daemon.
+ if '-stop' in sys.argv:
+ subprocess.run(['dmypy', 'stop'], check=False)
+ return
+
+ print('Running Mypy (daemon)...', flush=True)
+ starttime = time.time()
+ try:
+ args = [
+ 'dmypy', 'run', '--timeout', '3600', '--', '--config-file',
+ '.mypy.ini', '--follow-imports=error', '--pretty'
+ ] + filenames
+ subprocess.run(args, check=True)
+ except Exception:
+ print('Mypy: fail.')
+ sys.exit(255)
+ duration = time.time() - starttime
+ print(f'Mypy daemon passed in {duration:.1f} seconds.', flush=True)
+
+
def _parse_idea_results(path: Path) -> int:
"""Print errors found in an idea inspection xml file.
diff --git a/tools/efrotools/snippets.py b/tools/efrotools/snippets.py
index 406f0a49..da236c00 100644
--- a/tools/efrotools/snippets.py
+++ b/tools/efrotools/snippets.py
@@ -262,6 +262,12 @@ def mypy() -> None:
code.mypy(PROJROOT, full)
+def dmypy() -> None:
+ """Run mypy checks on our scripts using the mypy daemon."""
+ from efrotools import code
+ code.dmypy(PROJROOT)
+
+
def pycharm() -> None:
"""Run PyCharm checks on our scripts."""
from efrotools import code
diff --git a/tools/snippets b/tools/snippets
index 8425a048..f3a9c9e6 100755
--- a/tools/snippets
+++ b/tools/snippets
@@ -43,9 +43,9 @@ import efrotools
# noinspection PyUnresolvedReferences
from efrotools.snippets import ( # pylint: disable=unused-import
PROJROOT, CleanError, snippets_main, formatcode, formatscripts,
- formatmakefile, cpplint, pylint, mypy, tool_config_install, sync, sync_all,
- scriptfiles, pycharm, clioncode, androidstudiocode, makefile_target_list,
- spelling, spelling_all, compile_python_files, pytest)
+ formatmakefile, cpplint, pylint, mypy, dmypy, tool_config_install, sync,
+ sync_all, scriptfiles, pycharm, clioncode, androidstudiocode,
+ makefile_target_list, spelling, spelling_all, compile_python_files, pytest)
if TYPE_CHECKING:
from typing import Optional, List, Sequence