diff --git a/.efrocachemap b/.efrocachemap index d8d3bcac..365841f5 100644 --- a/.efrocachemap +++ b/.efrocachemap @@ -4140,8 +4140,8 @@ "build/prefab/mac-server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/e2/ab/b22ebe07c4342beb4dba33d5f7a5", "build/prefab/mac/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/80/24/b24a5a26ce61719456479f0c452d", "build/prefab/mac/release/ballisticacore": "https://files.ballistica.net/cache/ba1/13/5f/7dff6b239258c1a1151df24eec19", - "build/prefab/windows-server/debug/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/9b/9e/4db687b4f06579dafe4f1f9cf389", - "build/prefab/windows-server/release/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/16/16/ac342d48eb3964472eabb6854bd8", - "build/prefab/windows/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/c3/5e/42852af8d746f60999139e7069cd", - "build/prefab/windows/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/34/d3/a51b67800857a8271d6f1d947f5a" + "build/prefab/windows-server/debug/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/50/8b/8d342ad7bc729c5e536367df1b5e", + "build/prefab/windows-server/release/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/5c/c2/f9f81aa79da92bcc424727c45027", + "build/prefab/windows/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/4f/f9/a2f9a45c36a8355da03fd744f1c1", + "build/prefab/windows/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/90/4c/627bead0b20e019539fb906cb772" } \ No newline at end of file diff --git a/tools/efrotools/snippets.py b/tools/efrotools/snippets.py index 6f9e8513..71d931c7 100644 --- a/tools/efrotools/snippets.py +++ b/tools/efrotools/snippets.py @@ -26,14 +26,12 @@ be imported into projects' snippets script for easy reuse. """ from __future__ import annotations -import os +# Note: import as little as possible here at the module level to keep +# launch times fast for small snippets. import sys from pathlib import Path from typing import TYPE_CHECKING -from efro.error import CleanError -from efro.terminal import Clr - if TYPE_CHECKING: from typing import Dict, Any, List @@ -48,6 +46,8 @@ def snippets_main(globs: Dict[str, Any]) -> None: the one corresponding to the first passed arg. """ import types + from efro.error import CleanError + from efro.terminal import Clr funcs = dict(((name, obj) for name, obj in globs.items() if not name.startswith('_') and name != 'snippets_main' and isinstance(obj, types.FunctionType))) @@ -174,6 +174,7 @@ def check_clean_safety() -> None: Use to avoid losing work if we accidentally do a clean without adding something. """ + import os import subprocess if len(sys.argv) != 2: raise Exception('invalid arguments') @@ -357,8 +358,11 @@ def sync_all() -> None: This assumes that there is a 'sync-full' and 'sync-list' Makefile target under each project. """ + import os import subprocess import concurrent.futures + from efro.error import CleanError + from efro.terminal import Clr print(f'{Clr.SBLU}Updating formatting for all projects...{Clr.RST}') projects_str = os.environ.get('EFROTOOLS_SYNC_PROJECTS') if projects_str is None: @@ -427,6 +431,7 @@ def compile_python_files() -> None: the built-in scripts directly (or go through the asset build system which properly recreates the .pyc files). """ + import os import py_compile for arg in sys.argv[2:]: mode = py_compile.PycInvalidationMode.UNCHECKED_HASH @@ -439,9 +444,11 @@ def compile_python_files() -> None: def pytest() -> None: """Run pytest with project environment set up properly.""" + import os import platform import subprocess from efrotools import get_config, PYTHON_BIN + from efro.error import CleanError # Grab our python paths for the project and stuff them in PYTHONPATH. pypaths = get_config(PROJROOT).get('python_paths') @@ -468,6 +475,7 @@ def makefile_target_list() -> None: Takes a single argument: a path to a Makefile. """ from dataclasses import dataclass + from efro.terminal import Clr @dataclass class _Entry: diff --git a/tools/snippets b/tools/snippets index e9fe7bdd..ed32b564 100755 --- a/tools/snippets +++ b/tools/snippets @@ -30,19 +30,18 @@ to functionality contained in efrotools or other standalone tool modules. """ from __future__ import annotations -import os +# Note: import as little as possible here at the module level to +# keep launch times fast for small snippets. import sys from typing import TYPE_CHECKING -import efrotools - # Pull in some standard snippets we want to expose. # noinspection PyUnresolvedReferences from efrotools.snippets import ( # pylint: disable=unused-import - PROJROOT, CleanError, snippets_main, formatcode, formatscripts, - 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) + PROJROOT, snippets_main, formatcode, formatscripts, 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 @@ -103,6 +102,8 @@ def resize_image() -> None: args: xres, yres, src, dst """ + import os + import efrotools if len(sys.argv) != 6: raise Exception('expected 5 args') width = int(sys.argv[2]) @@ -114,8 +115,7 @@ def resize_image() -> None: if not src.endswith('.png'): raise Exception('src must be a png') print('Creating: ' + os.path.basename(dst), file=sys.stderr) - efrotools.run('convert "' + src + '" -resize ' + str(width) + 'x' + - str(height) + ' "' + dst + '"') + efrotools.run(f'convert "{src}" -resize {width}x{height} "{dst}"') def check_clean_safety() -> None: @@ -124,6 +124,7 @@ def check_clean_safety() -> None: Use to avoid losing work if we accidentally do a clean without adding something. """ + import os from efrotools.snippets import check_clean_safety as std_snippet # First do standard checks. @@ -166,6 +167,7 @@ def androidaddr() -> None: command line args: archive_dir architecture addr """ import batools.android + from efro.error import CleanError if len(sys.argv) != 5: raise CleanError(f'ERROR: expected 3 args; got {len(sys.argv) - 2}\n' f'Usage: "tools/snippets android_addr' @@ -188,6 +190,7 @@ def python_build_apple_debug() -> None: def _python_build_apple(debug: bool) -> None: """Build an embeddable python for macOS/iOS/tvOS.""" + import os from efrotools import pybuild os.chdir(PROJROOT) archs = ('mac', 'ios', 'tvos') @@ -212,6 +215,7 @@ def python_build_android_debug() -> None: def _python_build_android(debug: bool) -> None: + import os from efrotools import pybuild os.chdir(PROJROOT) archs = ('arm', 'arm64', 'x86', 'x86_64') @@ -227,6 +231,7 @@ def _python_build_android(debug: bool) -> None: def python_android_patch() -> None: """Patches Python to prep for building for Android.""" + import os from efrotools import pybuild os.chdir(sys.argv[2]) pybuild.android_patch() @@ -237,6 +242,7 @@ def python_gather() -> None: This assumes all embeddable py builds have been run successfully. """ + import os from efrotools import pybuild os.chdir(PROJROOT) pybuild.gather() @@ -244,7 +250,9 @@ def python_gather() -> None: def clean_orphaned_assets() -> None: """Remove asset files that are no longer part of the build.""" + import os import json + import efrotools # Operate from dist root.. os.chdir(PROJROOT) @@ -268,7 +276,9 @@ def clean_orphaned_assets() -> None: def py_examine() -> None: """Run a python examination at a given point in a given file.""" + import os from pathlib import Path + import efrotools if len(sys.argv) != 7: print('ERROR: expected 7 args') sys.exit(255) @@ -297,12 +307,12 @@ def py_examine() -> None: def push_ipa() -> None: """Construct and push ios IPA for testing.""" from pathlib import Path - from efrotools import ios + import efrotools.ios root = Path(sys.argv[0], '../..').resolve() if len(sys.argv) != 3: raise Exception('expected 1 arg (debug or release)') modename = sys.argv[2] - ios.push_ipa(root, modename) + efrotools.ios.push_ipa(root, modename) def fix_mac_ssh() -> None: @@ -383,6 +393,7 @@ def get_modern_make() -> None: def warm_start_asset_build() -> None: """Prep asset builds to run faster.""" + import os import subprocess from pathlib import Path from efrotools import get_config @@ -426,6 +437,7 @@ def install_pip_reqs() -> None: def checkenv() -> None: """Check for tools necessary to build and run the app.""" import batools.build + from efro.error import CleanError try: batools.build.checkenv() except RuntimeError as exc: @@ -435,6 +447,7 @@ def checkenv() -> None: def ensure_prefab_platform() -> None: """Ensure we are running on a particular prefab platform.""" import batools.build + from efro.error import CleanError if len(sys.argv) != 3: raise CleanError('Expected 1 platform name arg.') needed = sys.argv[2] @@ -487,6 +500,7 @@ def lazybuild() -> None: """Run a build command only if an input has changed.""" import subprocess import batools.build + from efro.error import CleanError if len(sys.argv) < 5: raise CleanError('Expected at least 3 args') try: @@ -504,6 +518,7 @@ def lazybuild() -> None: def filter_server_config() -> None: """Add commented-out config options to a server config.""" import batools.build + from efro.error import CleanError if len(sys.argv) != 4: raise CleanError('Expected 2 args (infile and outfile).') batools.build.filter_server_config(str(PROJROOT), sys.argv[2], sys.argv[3])