From 7400414d86fba7f043b05afd8761007ad0dec97e Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 13:51:10 -0400 Subject: [PATCH 01/21] Added freeze.py and controller.spec --- .gitignore | 3 +- Python/controller.spec | 61 ++++++++++++++++++++ Python/freeze.py | 124 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 Python/controller.spec create mode 100644 Python/freeze.py diff --git a/.gitignore b/.gitignore index 53a20f20a..c43fff8c7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ Python/tdw.egg-info/ __pycache__/ */__pycache__/* Python/dist/ -Python/tdw/tdw.egg-info/ \ No newline at end of file +Python/tdw/tdw.egg-info/ +Python/build/ diff --git a/Python/controller.spec b/Python/controller.spec new file mode 100644 index 000000000..798f036f3 --- /dev/null +++ b/Python/controller.spec @@ -0,0 +1,61 @@ +# -*- mode: python -*- +import sys +from pathlib import Path +from PyInstaller.utils.hooks import copy_metadata + + +# Read the config file. +config_file = Path.home().joinpath("tdw_build/freeze.ini") +assert config_file.exists() +config = config_file.read_text(encoding="utf-8") +controller = Path(config.split("controller=")[1]) +root_dir = str(controller.parent.resolve()) +controller = str(controller.resolve()) + +block_cipher = None + +import os + + +if sys.platform == "darwin": + files = [str(config_file.resolve())] + datas = [] + for f in files: + datas.append((f, f.split("/")[0])) +else: + datas = copy_metadata("tdw") + +hiddenimports = [] + +a = Analysis([controller], + pathex=[os.getcwd()], + binaries=[], + datas=datas, + hiddenimports=hiddenimports, + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='tdw_controller', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + console=True) +if sys.platform == "darwin": + app = BUNDLE(exe, + name='tdw_controller.app', + icon=None, + bundle_identifier=None) diff --git a/Python/freeze.py b/Python/freeze.py new file mode 100644 index 000000000..21fee34e9 --- /dev/null +++ b/Python/freeze.py @@ -0,0 +1,124 @@ +from subprocess import call, check_output +import os +from shutil import copyfile +from distutils import dir_util +from pathlib import Path +from argparse import ArgumentParser +from platform import system +from pkg_resources import get_distribution, DistributionNotFound +from sys import argv + + +if __name__ == "__main__": + spec = "controller.spec" + root_dir = Path.home().joinpath("tdw_build") + if not root_dir.exists(): + root_dir.mkdir() + # Remove an existing frozen controller. + output_dir = root_dir.joinpath("tdw_controller") + if output_dir.exists(): + dir_util.remove_tree(str(output_dir.resolve())) + output_dir.mkdir(parents=True) + + parser = ArgumentParser() + parser.add_argument("--args", type=str, help='Arguments for the controller when it launches. ' + 'These will be stored in a text file. ' + 'Encapsulate the arguments in quotes, e.g. "--num_images 100"') + parser.add_argument("--controller", type=str, default="example_controllers/minimal.py", + help="The relative path from this script to your controller. " + "Example: example_controllers/minimal.py") + args = parser.parse_args() + if args.args is None: + arguments = '""' + else: + arguments = args.args + controller = Path(args.controller) + if not controller.exists(): + raise Exception(f"Controller not found: {controller.resolve()}") + # Write the config text. + config_text = f"args={arguments}\ncontroller={str(controller.resolve())}" + root_dir.joinpath("freeze.ini").write_text(config_text, encoding="utf-8") + p = system() + + # Install PyInstaller. + try: + get_distribution("pyinstaller") + except DistributionNotFound: + if p == "Windows": + call(["pip3", "install", "pyinstaller", "--user"]) + else: + call(["pip3", "install", "pyinstaller"]) + + # Create the executable. + if p == "Linux": + call(["python3.6", "-m", "PyInstaller", spec, "--onefile"]) + elif p == "Darwin": + call(["python3.7", "-m", "PyInstaller", spec, "--onefile", "--windowed"]) + else: + call(["py", "-3", "-m", "PyInstaller", spec, "--onefile"]) + exit() + +# Move the executable. +if p == "windows": + azazel_exe = "AZAZEL.exe" +elif p == "linux": + azazel_exe = "AZAZEL" +else: + azazel_exe = "AZAZEL.app" +exe_dest = output_dir.joinpath(azazel_exe) +if exe_dest.exists(): + os.remove(str(exe_dest.resolve())) +os.rename("dist/" + azazel_exe, str(exe_dest.resolve())) + +if p != "osx": + # Create new directories. + for directory in ["data", "sound", "fonts"]: + assert os.path.exists(directory) + dest = str(output_dir.joinpath(directory).resolve()) + # Remove existing directories. + if os.path.exists(dest): + rmtree(dest) + os.makedirs(dest) + + # Copy the data files. + files = ["sound/cool_nidre.ogg", + "sound/tokef_loop.mp3", + "sound/t_bleat1.ogg", + "sound/z_bleat1.ogg", + "data/controls.txt", + "data/leviticus.txt", + "data/splash.txt", + "data/wonders.json", + "data/icon.png" + ] + for font in Path("fonts").glob("azazel_*.png"): + files.append(f"fonts/{font.name}") + + for file in files: + dest = str(output_dir.joinpath(file).resolve()) + copyfile(file, dest) + +# Copy the README file. +readme = "README.html" +readme_dest = str(output_dir.joinpath(readme).resolve()) +if os.path.exists(readme_dest): + os.remove(readme_dest) +copyfile(readme, readme_dest) + +# Go to the correct butler executable. +os.chdir(f"itch/butler/{p}") + +release_path = Path(f"../../../dist/release/{args.version}") +assert release_path.exists() + +for f in release_path.iterdir(): + if f.is_dir(): + if p == "linux": + exe = "./butler" + elif p == "windows": + exe = "./butler.exe" + else: + exe = "./butler" + if not args.dry_run: + call([exe, "push", str(f.resolve()), f"subalterngames/azazel:{f.stem}", "--userversion", str(args.version)]) + From ee0ffcd8d08d5a9c2ddde8eac75f592cd733ccb2 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 14:49:29 -0400 Subject: [PATCH 02/21] cleanup --- Python/controller.spec | 2 +- Python/freeze.py | 110 ++++++++++++++--------------------------- 2 files changed, 38 insertions(+), 74 deletions(-) diff --git a/Python/controller.spec b/Python/controller.spec index 798f036f3..b16691e93 100644 --- a/Python/controller.spec +++ b/Python/controller.spec @@ -5,7 +5,7 @@ from PyInstaller.utils.hooks import copy_metadata # Read the config file. -config_file = Path.home().joinpath("tdw_build/freeze.ini") +config_file = Path.home().joinpath("tdw_build/tdw_controller/freeze.ini") assert config_file.exists() config = config_file.read_text(encoding="utf-8") controller = Path(config.split("controller=")[1]) diff --git a/Python/freeze.py b/Python/freeze.py index 21fee34e9..94adfdc83 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -1,12 +1,9 @@ -from subprocess import call, check_output -import os -from shutil import copyfile +from subprocess import call, check_call from distutils import dir_util from pathlib import Path from argparse import ArgumentParser from platform import system from pkg_resources import get_distribution, DistributionNotFound -from sys import argv if __name__ == "__main__": @@ -19,7 +16,6 @@ if output_dir.exists(): dir_util.remove_tree(str(output_dir.resolve())) output_dir.mkdir(parents=True) - parser = ArgumentParser() parser.add_argument("--args", type=str, help='Arguments for the controller when it launches. ' 'These will be stored in a text file. ' @@ -29,15 +25,16 @@ "Example: example_controllers/minimal.py") args = parser.parse_args() if args.args is None: - arguments = '""' + arguments = '' else: arguments = args.args + arguments = arguments.replace('"', '') controller = Path(args.controller) if not controller.exists(): raise Exception(f"Controller not found: {controller.resolve()}") # Write the config text. config_text = f"args={arguments}\ncontroller={str(controller.resolve())}" - root_dir.joinpath("freeze.ini").write_text(config_text, encoding="utf-8") + output_dir.joinpath("freeze.ini").write_text(config_text, encoding="utf-8") p = system() # Install PyInstaller. @@ -50,75 +47,42 @@ call(["pip3", "install", "pyinstaller"]) # Create the executable. + dist_path = str(output_dir.resolve()).replace("\\", "/") if p == "Linux": - call(["python3.6", "-m", "PyInstaller", spec, "--onefile"]) + call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + exe = "tdw_controller" elif p == "Darwin": - call(["python3.7", "-m", "PyInstaller", spec, "--onefile", "--windowed"]) + call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + exe = "tdw_controller.app" + elif p == "Windows": + q = check_call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + exe = "tdw_controller.exe" else: - call(["py", "-3", "-m", "PyInstaller", spec, "--onefile"]) - exit() - -# Move the executable. -if p == "windows": - azazel_exe = "AZAZEL.exe" -elif p == "linux": - azazel_exe = "AZAZEL" -else: - azazel_exe = "AZAZEL.app" -exe_dest = output_dir.joinpath(azazel_exe) -if exe_dest.exists(): - os.remove(str(exe_dest.resolve())) -os.rename("dist/" + azazel_exe, str(exe_dest.resolve())) - -if p != "osx": - # Create new directories. - for directory in ["data", "sound", "fonts"]: - assert os.path.exists(directory) - dest = str(output_dir.joinpath(directory).resolve()) - # Remove existing directories. - if os.path.exists(dest): - rmtree(dest) - os.makedirs(dest) - - # Copy the data files. - files = ["sound/cool_nidre.ogg", - "sound/tokef_loop.mp3", - "sound/t_bleat1.ogg", - "sound/z_bleat1.ogg", - "data/controls.txt", - "data/leviticus.txt", - "data/splash.txt", - "data/wonders.json", - "data/icon.png" - ] - for font in Path("fonts").glob("azazel_*.png"): - files.append(f"fonts/{font.name}") + raise Exception(f"Platform not supported: {p}") - for file in files: - dest = str(output_dir.joinpath(file).resolve()) - copyfile(file, dest) + exe_path = output_dir.joinpath(exe) + assert exe_path.exists() + print(f"Created: {exe_path.resolve()}") -# Copy the README file. -readme = "README.html" -readme_dest = str(output_dir.joinpath(readme).resolve()) -if os.path.exists(readme_dest): - os.remove(readme_dest) -copyfile(readme, readme_dest) - -# Go to the correct butler executable. -os.chdir(f"itch/butler/{p}") - -release_path = Path(f"../../../dist/release/{args.version}") -assert release_path.exists() - -for f in release_path.iterdir(): - if f.is_dir(): - if p == "linux": - exe = "./butler" - elif p == "windows": - exe = "./butler.exe" - else: - exe = "./butler" - if not args.dry_run: - call([exe, "push", str(f.resolve()), f"subalterngames/azazel:{f.stem}", "--userversion", str(args.version)]) + # Add a shortcut with args. + if p == "Windows": + # Install winshell. + for m in ["pypiwin32", "winshell"]: + try: + get_distribution(m) + except DistributionNotFound: + call(["pip3", "install", m, "--user"]) + import winshell + link_path = str(output_dir.joinpath("tdw_controller.lnk").resolve()) + with winshell.shortcut(link_path) as link: + link.path = str(exe_path.resolve()) + link.description = "TDW controller executable." + # Add arguments. + if arguments != "": + link.arguments = arguments + elif p == "Linux": + sh = f"./{str(exe_path.resolve())} {arguments}" + sh_path = output_dir.joinpath("tdw_controller.sh") + sh_path.write_text(sh, encoding="utf-8") + call(["chmod", "+x", str(sh_path.resolve())]) From 89de082170a3fb2d6eba4aa2ac8d396b7d08f5e1 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 16:22:54 -0400 Subject: [PATCH 03/21] parse ~ --- Python/freeze.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/freeze.py b/Python/freeze.py index 94adfdc83..5cb796140 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -30,6 +30,10 @@ arguments = args.args arguments = arguments.replace('"', '') controller = Path(args.controller) + # Parse ~ as the home directory. + if str(controller.resolve())[0] == "~": + controller = Path.home().joinpath(str(controller.resolve())[2:]) + if not controller.exists(): raise Exception(f"Controller not found: {controller.resolve()}") # Write the config text. From 55250337f3394383aad77a0e2cd1f5836e63a63a Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 16:40:42 -0400 Subject: [PATCH 04/21] documentation --- Documentation/misc_frontend/freeze.md | 40 +++++++++++++++++++++++++++ Python/freeze.py | 2 +- Python/setup.py | 2 +- Python/tdw/version.py | 2 +- README.md | 1 + 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 Documentation/misc_frontend/freeze.md diff --git a/Documentation/misc_frontend/freeze.md b/Documentation/misc_frontend/freeze.md new file mode 100644 index 000000000..0787f3a65 --- /dev/null +++ b/Documentation/misc_frontend/freeze.md @@ -0,0 +1,40 @@ +# Freezing your code + +"Freezing" code means creating an executable (`.exe`, `.app`, etc.) of your controller. This executable includes all of its dependencies, which means that you can launch it on a computer that doesn't have Python or TDW installed. + +## Requirements + +1. Install [`tdw` module](../python/tdw.md) +2. Clone this repo +3. Write your controller + +## Usage + +```bash +cd path/to/tdw/Python # Replace path/to with an actual path. +``` + +```bash +# Windows +py -3 freeze.py --controller CONTROLLER --args ARGS # Replace CONTROLLER and ARGS. + +# OS X and Linux +python3 freeze.py --controller CONTROLLER --args ARGS # Replace CONTROLLER and ARGS. +``` + +### Arguments + +| Argument | Description | +| -------------- | ------------------------------------------------------------ | +| `--controller` | The path to your controller. This can be a path relative to the current working directory. | +| `--args` | Arguments for the controller. Encapsulate these with double quotes. For example: `"--num 10 --size 3"` | + +### Result + +- `freeze.py` will create an executable located in `~/tdw_build/tdw_controller`, where `~` is your home directory. You can run it like an other application by double-clicking it or running it in the terminal. +- `~/tdw_build/tdw_controller/freeze.ini` is a config file that contains the original path to the controller and the arguments you supplied with `--args` (see above). +- `freeze.py` will add a shortcut that includes the arguments you supplied with `--args` (see above). + +## Limitations + +`freeze.py` can only freeze code for the operating system it is running on. For example, if it is running on OS X, it can create `tdw_controller.app` for OS X but *not* `tdw_controller.exe` for Windows. This is a limitation inherent to Python. \ No newline at end of file diff --git a/Python/freeze.py b/Python/freeze.py index 5cb796140..0801d3f30 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -85,7 +85,7 @@ # Add arguments. if arguments != "": link.arguments = arguments - elif p == "Linux": + else: sh = f"./{str(exe_path.resolve())} {arguments}" sh_path = output_dir.joinpath("tdw_controller.sh") sh_path.write_text(sh, encoding="utf-8") diff --git a/Python/setup.py b/Python/setup.py index 80b1d1e92..bfde82310 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages from pathlib import Path -__version__ = "1.6.4.0" +__version__ = "1.6.5.0" readme_path = Path('../README.md') if readme_path.exists(): long_description = readme_path.read_text(encoding='utf-8') diff --git a/Python/tdw/version.py b/Python/tdw/version.py index 0a8a8bdef..4732438ef 100644 --- a/Python/tdw/version.py +++ b/Python/tdw/version.py @@ -1 +1 @@ -__version__ = "1.6.4" +__version__ = "1.6.5" diff --git a/README.md b/README.md index bc946bb04..1f8211537 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ | --- | --- | | [C# code](https://github.com/threedworld-mit/tdw/blob/master/Documentation/contributions/c_sharp_sources.md) | Access to C# backend source code | | [Releases](https://github.com/threedworld-mit/tdw/blob/master/Documentation/misc_frontend/releases.md) | Release versioning in TDW. | +| [Freezing your code](https://github.com/threedworld-mit/tdw/blob/master/Documentation/misc_frontend/freeze.md) | "Freeze" your controller into a compiled executable. | # Remote Server From d9790463ffcc8522b89c72dbbd6141322a9e2027 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 16:53:11 -0400 Subject: [PATCH 05/21] clarified documentation --- Documentation/misc_frontend/freeze.md | 45 ++++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/Documentation/misc_frontend/freeze.md b/Documentation/misc_frontend/freeze.md index 0787f3a65..e26cdcec2 100644 --- a/Documentation/misc_frontend/freeze.md +++ b/Documentation/misc_frontend/freeze.md @@ -1,6 +1,6 @@ # Freezing your code -"Freezing" code means creating an executable (`.exe`, `.app`, etc.) of your controller. This executable includes all of its dependencies, which means that you can launch it on a computer that doesn't have Python or TDW installed. +"Freezing" code means creating an executable binary (`.exe`, `.app`, etc.) of your controller. This executable includes all of its dependencies, which means that you can launch it on a computer that doesn't have Python or TDW installed. ## Requirements @@ -10,28 +10,49 @@ ## Usage +**To test,** run `freeze.py` without any arguments; this will create a binary of the `minimal.py` example controller: + ```bash -cd path/to/tdw/Python # Replace path/to with an actual path. +cd path/to/tdw/Python # Replace path/to with the actual path. + +# Windows +py -3 freeze.py + +# OS X and Linux +python3 freeze.py ``` +**To freeze your controller,** add the `--controller` argument: + ```bash -# Windows -py -3 freeze.py --controller CONTROLLER --args ARGS # Replace CONTROLLER and ARGS. +cd path/to/tdw/Python # Replace path/to with the actual path. + +# Replace CONTROLLER with the path to your controller. +# Windows +py -3 freeze.py --controller CONTROLLER # OS X and Linux -python3 freeze.py --controller CONTROLLER --args ARGS # Replace CONTROLLER and ARGS. +python3 freeze.py --controller CONTROLLER --args ARGS ``` -### Arguments +**To add arguments for your controller,** add the `--args` argument: + +```bash +cd path/to/tdw/Python # Replace path/to with the actual path. + +# Replace CONTROLLER with the path to your controller. +# Replace ARGS with arguments for the controller. Encapsulate these with double quotes. For example: "--num 10 --size 3" -| Argument | Description | -| -------------- | ------------------------------------------------------------ | -| `--controller` | The path to your controller. This can be a path relative to the current working directory. | -| `--args` | Arguments for the controller. Encapsulate these with double quotes. For example: `"--num 10 --size 3"` | +# Windows +py -3 freeze.py --controller CONTROLLER --args ARGS + +# OS X and Linux +python3 freeze.py --controller CONTROLLER --args ARGS +``` -### Result +## Result -- `freeze.py` will create an executable located in `~/tdw_build/tdw_controller`, where `~` is your home directory. You can run it like an other application by double-clicking it or running it in the terminal. +- `freeze.py` will create an executable located in `~/tdw_build/tdw_controller`, where `~` is your home directory. **You can run it like an other application** by double-clicking it or running it in the terminal. - `~/tdw_build/tdw_controller/freeze.ini` is a config file that contains the original path to the controller and the arguments you supplied with `--args` (see above). - `freeze.py` will add a shortcut that includes the arguments you supplied with `--args` (see above). From 1e63f2bb592d86d277e0841aebf811c56503a32d Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 17:24:36 -0400 Subject: [PATCH 06/21] fixed typo --- Documentation/misc_frontend/freeze.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/misc_frontend/freeze.md b/Documentation/misc_frontend/freeze.md index e26cdcec2..25d1898be 100644 --- a/Documentation/misc_frontend/freeze.md +++ b/Documentation/misc_frontend/freeze.md @@ -32,7 +32,7 @@ cd path/to/tdw/Python # Replace path/to with the actual path. # Windows py -3 freeze.py --controller CONTROLLER # OS X and Linux -python3 freeze.py --controller CONTROLLER --args ARGS +python3 freeze.py --controller CONTROLLER ``` **To add arguments for your controller,** add the `--args` argument: From 8e97101299c8911954ee2ded5b551e44144de5a9 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:13:32 -0400 Subject: [PATCH 07/21] fixed os x datas --- Python/controller.spec | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Python/controller.spec b/Python/controller.spec index b16691e93..7d4732878 100644 --- a/Python/controller.spec +++ b/Python/controller.spec @@ -16,14 +16,11 @@ block_cipher = None import os - +datas = copy_metadata("tdw") if sys.platform == "darwin": files = [str(config_file.resolve())] - datas = [] for f in files: datas.append((f, f.split("/")[0])) -else: - datas = copy_metadata("tdw") hiddenimports = [] From ca39ca634c701f28a80e9c37cfcf4f987606b7a0 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:25:44 -0400 Subject: [PATCH 08/21] removed osx code --- Python/controller.spec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Python/controller.spec b/Python/controller.spec index 7d4732878..37c9dd618 100644 --- a/Python/controller.spec +++ b/Python/controller.spec @@ -17,10 +17,6 @@ block_cipher = None import os datas = copy_metadata("tdw") -if sys.platform == "darwin": - files = [str(config_file.resolve())] - for f in files: - datas.append((f, f.split("/")[0])) hiddenimports = [] From 272e5fb8afad40af455885a86bf150caf704392c Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:34:05 -0400 Subject: [PATCH 09/21] changelog --- Documentation/Changelog.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/Changelog.md b/Documentation/Changelog.md index 714109eb5..04d2c28e0 100644 --- a/Documentation/Changelog.md +++ b/Documentation/Changelog.md @@ -2,6 +2,24 @@ # v1.6.x +## v1.6.5 + +### Frontend + +- Added `freeze.py`. "Freeze" your controller into a portable binary executable. + +#### Backend + +- Added `controller.spec` (used for freezing controller code). + +### Documentation + +#### New Documentation + +| Document | Description | +| ----------- | ------------------------------------------------------------ | +| `freeze.md` | How to freeze your controller code into a binary executable. | + ## v1.6.4 ### `tdw` module From 131af0628b0f38a28fadc725eb6db7f934a3fd60 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:39:12 -0400 Subject: [PATCH 10/21] tkinter --- Python/freeze.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/freeze.py b/Python/freeze.py index 0801d3f30..c44696571 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -56,7 +56,9 @@ call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller" elif p == "Darwin": - call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path, + "--add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk'", + "--add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl'"]) exe = "tdw_controller.app" elif p == "Windows": q = check_call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) From 8fbcade2e4edb712f9e32d4ad1277d61c681ceb3 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:40:09 -0400 Subject: [PATCH 11/21] minor --- Python/freeze.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/freeze.py b/Python/freeze.py index c44696571..1ef7754ff 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -1,4 +1,4 @@ -from subprocess import call, check_call +from subprocess import call from distutils import dir_util from pathlib import Path from argparse import ArgumentParser @@ -61,7 +61,7 @@ "--add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl'"]) exe = "tdw_controller.app" elif p == "Windows": - q = check_call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller.exe" else: raise Exception(f"Platform not supported: {p}") From f8377a9c88999b105aec010f6ae02e10d5a48d7a Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:46:49 -0400 Subject: [PATCH 12/21] exclude tkinter --- Python/freeze.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Python/freeze.py b/Python/freeze.py index 1ef7754ff..88d05d237 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -57,8 +57,7 @@ exe = "tdw_controller" elif p == "Darwin": call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path, - "--add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk'", - "--add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl'"]) + "--exclude-module", "tkinter"]) exe = "tdw_controller.app" elif p == "Windows": call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) From 70125ffae8cb097fe8669a23585191dd01f0cb7e Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:58:58 -0400 Subject: [PATCH 13/21] manually add tkinter --- Python/freeze.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Python/freeze.py b/Python/freeze.py index 88d05d237..44d3f3f3a 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -4,6 +4,7 @@ from argparse import ArgumentParser from platform import system from pkg_resources import get_distribution, DistributionNotFound +from os import getcwd, chdir, mkdir if __name__ == "__main__": @@ -56,8 +57,7 @@ call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller" elif p == "Darwin": - call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path, - "--exclude-module", "tkinter"]) + call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller.app" elif p == "Windows": call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) @@ -69,6 +69,17 @@ assert exe_path.exists() print(f"Created: {exe_path.resolve()}") + # Add tkinter, for some reason. If you don't do this, many controllers won't work. + # Source: https://github.com/pyinstaller/pyinstaller/issues/3753 + if p == "Darwin": + cwd = getcwd() + chdir(str(exe_path.joinpath("Contents/MacOS").resolve())) + mkdir("tcl") + mkdir("tk") + for d in ["tcl", "tk", "Tk"]: + call(["cp", "-R", f"/Library/Frameworks/Python.framework/Versions/3.7/lib/{d}*", f"{d}/"]) + chdir(cwd) + # Add a shortcut with args. if p == "Windows": # Install winshell. From 85998d3d3226d07a2d445f06260f475ff6e8934c Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 18:59:16 -0400 Subject: [PATCH 14/21] 3.6 --- Python/freeze.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/freeze.py b/Python/freeze.py index 44d3f3f3a..c439da3fa 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -77,7 +77,7 @@ mkdir("tcl") mkdir("tk") for d in ["tcl", "tk", "Tk"]: - call(["cp", "-R", f"/Library/Frameworks/Python.framework/Versions/3.7/lib/{d}*", f"{d}/"]) + call(["cp", "-R", f"/Library/Frameworks/Python.framework/Versions/3.6/lib/{d}*", f"{d}/"]) chdir(cwd) # Add a shortcut with args. From c077678be363d07547d96471db6397038655fdfd Mon Sep 17 00:00:00 2001 From: alters-mit Date: Tue, 11 Aug 2020 19:08:06 -0400 Subject: [PATCH 15/21] exclude tkinter --- Python/freeze.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Python/freeze.py b/Python/freeze.py index c439da3fa..14f241ab3 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -4,7 +4,6 @@ from argparse import ArgumentParser from platform import system from pkg_resources import get_distribution, DistributionNotFound -from os import getcwd, chdir, mkdir if __name__ == "__main__": @@ -57,7 +56,9 @@ call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller" elif p == "Darwin": - call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path, "--windowed", + "--exclude-module='FixTk'", "--exclude-module='tcl'", "--exclude-module='tk'", + "--exclude-module='_tkinter'", "--exclude-module='tkinter'", "--exclude-module='Tkinter'"]) exe = "tdw_controller.app" elif p == "Windows": call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) @@ -69,17 +70,6 @@ assert exe_path.exists() print(f"Created: {exe_path.resolve()}") - # Add tkinter, for some reason. If you don't do this, many controllers won't work. - # Source: https://github.com/pyinstaller/pyinstaller/issues/3753 - if p == "Darwin": - cwd = getcwd() - chdir(str(exe_path.joinpath("Contents/MacOS").resolve())) - mkdir("tcl") - mkdir("tk") - for d in ["tcl", "tk", "Tk"]: - call(["cp", "-R", f"/Library/Frameworks/Python.framework/Versions/3.6/lib/{d}*", f"{d}/"]) - chdir(cwd) - # Add a shortcut with args. if p == "Windows": # Install winshell. From cb16f161bbd553f9b25effd570272e909fd9560b Mon Sep 17 00:00:00 2001 From: alters-mit Date: Wed, 12 Aug 2020 09:41:05 -0400 Subject: [PATCH 16/21] hmm --- Documentation/misc_frontend/freeze.md | 19 +-------- Python/controller.spec | 14 +++++-- Python/freeze.py | 60 +++++++-------------------- Python/setup.py | 3 +- 4 files changed, 29 insertions(+), 67 deletions(-) diff --git a/Documentation/misc_frontend/freeze.md b/Documentation/misc_frontend/freeze.md index 25d1898be..b2ad97f5f 100644 --- a/Documentation/misc_frontend/freeze.md +++ b/Documentation/misc_frontend/freeze.md @@ -35,26 +35,9 @@ py -3 freeze.py --controller CONTROLLER python3 freeze.py --controller CONTROLLER ``` -**To add arguments for your controller,** add the `--args` argument: - -```bash -cd path/to/tdw/Python # Replace path/to with the actual path. - -# Replace CONTROLLER with the path to your controller. -# Replace ARGS with arguments for the controller. Encapsulate these with double quotes. For example: "--num 10 --size 3" - -# Windows -py -3 freeze.py --controller CONTROLLER --args ARGS - -# OS X and Linux -python3 freeze.py --controller CONTROLLER --args ARGS -``` - ## Result -- `freeze.py` will create an executable located in `~/tdw_build/tdw_controller`, where `~` is your home directory. **You can run it like an other application** by double-clicking it or running it in the terminal. -- `~/tdw_build/tdw_controller/freeze.ini` is a config file that contains the original path to the controller and the arguments you supplied with `--args` (see above). -- `freeze.py` will add a shortcut that includes the arguments you supplied with `--args` (see above). +`freeze.py` will create an executable located in `~/tdw_build/tdw_controller`, where `~` is your home directory. **You can run it like an other application** by double-clicking it or running it in the terminal. Likewise, you can supply arguments to the executable like you can to a Python controller. ## Limitations diff --git a/Python/controller.spec b/Python/controller.spec index 37c9dd618..b4c46a73e 100644 --- a/Python/controller.spec +++ b/Python/controller.spec @@ -2,7 +2,7 @@ import sys from pathlib import Path from PyInstaller.utils.hooks import copy_metadata - +import os # Read the config file. config_file = Path.home().joinpath("tdw_build/tdw_controller/freeze.ini") @@ -14,14 +14,20 @@ controller = str(controller.resolve()) block_cipher = None -import os - datas = copy_metadata("tdw") +# Add TDW data files. +for root, dirs, files in os.walk("tdw"): + if "tdw.egg-info" in root or "__pycache__" in root: + continue + for file in files: + if ".py" in file: + continue + datas.append((root, file)) hiddenimports = [] a = Analysis([controller], - pathex=[os.getcwd()], + pathex=[str(Path(controller).parent.resolve())], binaries=[], datas=datas, hiddenimports=hiddenimports, diff --git a/Python/freeze.py b/Python/freeze.py index 14f241ab3..8af444ebd 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -3,11 +3,16 @@ from pathlib import Path from argparse import ArgumentParser from platform import system -from pkg_resources import get_distribution, DistributionNotFound + + +""" +Freeze your controller into a binary executable. + +Documentation: `tdw/Documentation/misc_frontend/freeze.md` +""" if __name__ == "__main__": - spec = "controller.spec" root_dir = Path.home().joinpath("tdw_build") if not root_dir.exists(): root_dir.mkdir() @@ -17,18 +22,10 @@ dir_util.remove_tree(str(output_dir.resolve())) output_dir.mkdir(parents=True) parser = ArgumentParser() - parser.add_argument("--args", type=str, help='Arguments for the controller when it launches. ' - 'These will be stored in a text file. ' - 'Encapsulate the arguments in quotes, e.g. "--num_images 100"') parser.add_argument("--controller", type=str, default="example_controllers/minimal.py", help="The relative path from this script to your controller. " "Example: example_controllers/minimal.py") args = parser.parse_args() - if args.args is None: - arguments = '' - else: - arguments = args.args - arguments = arguments.replace('"', '') controller = Path(args.controller) # Parse ~ as the home directory. if str(controller.resolve())[0] == "~": @@ -36,26 +33,21 @@ if not controller.exists(): raise Exception(f"Controller not found: {controller.resolve()}") - # Write the config text. - config_text = f"args={arguments}\ncontroller={str(controller.resolve())}" - output_dir.joinpath("freeze.ini").write_text(config_text, encoding="utf-8") - p = system() - # Install PyInstaller. - try: - get_distribution("pyinstaller") - except DistributionNotFound: - if p == "Windows": - call(["pip3", "install", "pyinstaller", "--user"]) - else: - call(["pip3", "install", "pyinstaller"]) + # Write the config file. This is used by controller.spec to point to the correct controller. + config_text = f"controller={str(controller.resolve())}" + ini_path = output_dir.joinpath("freeze.ini") + ini_path.write_text(config_text, encoding="utf-8") + p = system() # Create the executable. dist_path = str(output_dir.resolve()).replace("\\", "/") + spec = "controller.spec" if p == "Linux": call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller" elif p == "Darwin": + # OS X sometimes has strange problems with tkinter. Exclude tkinter because we're not using it anyway. call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path, "--windowed", "--exclude-module='FixTk'", "--exclude-module='tcl'", "--exclude-module='tk'", "--exclude-module='_tkinter'", "--exclude-module='tkinter'", "--exclude-module='Tkinter'"]) @@ -70,25 +62,5 @@ assert exe_path.exists() print(f"Created: {exe_path.resolve()}") - # Add a shortcut with args. - if p == "Windows": - # Install winshell. - for m in ["pypiwin32", "winshell"]: - try: - get_distribution(m) - except DistributionNotFound: - call(["pip3", "install", m, "--user"]) - import winshell - - link_path = str(output_dir.joinpath("tdw_controller.lnk").resolve()) - with winshell.shortcut(link_path) as link: - link.path = str(exe_path.resolve()) - link.description = "TDW controller executable." - # Add arguments. - if arguments != "": - link.arguments = arguments - else: - sh = f"./{str(exe_path.resolve())} {arguments}" - sh_path = output_dir.joinpath("tdw_controller.sh") - sh_path.write_text(sh, encoding="utf-8") - call(["chmod", "+x", str(sh_path.resolve())]) + # Remove the config file. + ini_path.unlink() diff --git a/Python/setup.py b/Python/setup.py index bfde82310..14426a80d 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -30,5 +30,6 @@ packages=find_packages(), include_package_data=True, keywords='unity simulation ml machine-learning', - install_requires=['pyzmq', 'numpy', 'scipy', 'pillow', 'tqdm', 'psutil', 'boto3', 'botocore', 'requests'], + install_requires=['pyzmq', 'numpy', 'scipy', 'pillow', 'tqdm', 'psutil', 'boto3', 'botocore', 'requests', + "pyinstaller"], ) From 51b37f511238f6f3af326c57d1b41f4bc5976b5f Mon Sep 17 00:00:00 2001 From: alters-mit Date: Wed, 12 Aug 2020 10:53:11 -0400 Subject: [PATCH 17/21] Add data files correctly --- Python/controller.spec | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Python/controller.spec b/Python/controller.spec index b4c46a73e..a0ccb656e 100644 --- a/Python/controller.spec +++ b/Python/controller.spec @@ -3,6 +3,7 @@ import sys from pathlib import Path from PyInstaller.utils.hooks import copy_metadata import os +from PyInstaller.compat import modname_tkinter # Read the config file. config_file = Path.home().joinpath("tdw_build/tdw_controller/freeze.ini") @@ -22,20 +23,15 @@ for root, dirs, files in os.walk("tdw"): for file in files: if ".py" in file: continue - datas.append((root, file)) - -hiddenimports = [] + src = str(Path(root).joinpath(file).resolve()) + datas.append((src, root)) a = Analysis([controller], - pathex=[str(Path(controller).parent.resolve())], binaries=[], datas=datas, - hiddenimports=hiddenimports, + hiddenimports=[], hookspath=[], runtime_hooks=[], - excludes=[], - win_no_prefer_redirects=False, - win_private_assemblies=False, cipher=block_cipher, noarchive=False) pyz = PYZ(a.pure, a.zipped_data, @@ -47,7 +43,7 @@ exe = EXE(pyz, a.datas, [], name='tdw_controller', - debug=False, + debug=True, bootloader_ignore_signals=False, strip=False, upx=True, From 701b7bd7a9bc501c9eee93307e9ac299f65502c0 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Wed, 12 Aug 2020 10:59:11 -0400 Subject: [PATCH 18/21] exclude tkinter on all platforms --- Python/controller.spec | 3 +-- Python/freeze.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Python/controller.spec b/Python/controller.spec index a0ccb656e..851e35cce 100644 --- a/Python/controller.spec +++ b/Python/controller.spec @@ -3,7 +3,6 @@ import sys from pathlib import Path from PyInstaller.utils.hooks import copy_metadata import os -from PyInstaller.compat import modname_tkinter # Read the config file. config_file = Path.home().joinpath("tdw_build/tdw_controller/freeze.ini") @@ -43,7 +42,7 @@ exe = EXE(pyz, a.datas, [], name='tdw_controller', - debug=True, + debug=False, bootloader_ignore_signals=False, strip=False, upx=True, diff --git a/Python/freeze.py b/Python/freeze.py index 8af444ebd..965daca0f 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -42,22 +42,25 @@ # Create the executable. dist_path = str(output_dir.resolve()).replace("\\", "/") + freeze_call = list() spec = "controller.spec" if p == "Linux": - call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + freeze_call = ["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path] exe = "tdw_controller" elif p == "Darwin": - # OS X sometimes has strange problems with tkinter. Exclude tkinter because we're not using it anyway. - call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path, "--windowed", - "--exclude-module='FixTk'", "--exclude-module='tcl'", "--exclude-module='tk'", - "--exclude-module='_tkinter'", "--exclude-module='tkinter'", "--exclude-module='Tkinter'"]) + freeze_call = ["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path] exe = "tdw_controller.app" elif p == "Windows": - call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) + freeze_call = ["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path] exe = "tdw_controller.exe" else: raise Exception(f"Platform not supported: {p}") + # tkinter causes problems in OS X and isn't used by TDW. Exclude it. + freeze_call.extend(["--exclude-module='FixTk'", "--exclude-module='tcl'", "--exclude-module='tk'", + "--exclude-module='_tkinter'", "--exclude-module='tkinter'", "--exclude-module='Tkinter'"]) + call(freeze_call) + exe_path = output_dir.joinpath(exe) assert exe_path.exists() print(f"Created: {exe_path.resolve()}") From 4bbda2d15e5f6474b20de5b55b43410d73e93c79 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Wed, 12 Aug 2020 11:52:02 -0400 Subject: [PATCH 19/21] Fixed excludes --- Documentation/misc_frontend/freeze.md | 6 ++++++ Python/controller.spec | 1 + Python/freeze.py | 12 +++--------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Documentation/misc_frontend/freeze.md b/Documentation/misc_frontend/freeze.md index b2ad97f5f..d08d41a6b 100644 --- a/Documentation/misc_frontend/freeze.md +++ b/Documentation/misc_frontend/freeze.md @@ -39,6 +39,12 @@ python3 freeze.py --controller CONTROLLER `freeze.py` will create an executable located in `~/tdw_build/tdw_controller`, where `~` is your home directory. **You can run it like an other application** by double-clicking it or running it in the terminal. Likewise, you can supply arguments to the executable like you can to a Python controller. +On Linux, you need to supply a `DISPLAY` environment to run the controller: + +```bash +DISPLAY=:0.0 ./my_controller +``` + ## Limitations `freeze.py` can only freeze code for the operating system it is running on. For example, if it is running on OS X, it can create `tdw_controller.app` for OS X but *not* `tdw_controller.exe` for Windows. This is a limitation inherent to Python. \ No newline at end of file diff --git a/Python/controller.spec b/Python/controller.spec index 851e35cce..47a06cdc7 100644 --- a/Python/controller.spec +++ b/Python/controller.spec @@ -29,6 +29,7 @@ a = Analysis([controller], binaries=[], datas=datas, hiddenimports=[], + excludes=["FixTk", "tcl", "tk", "_tkinter", "tkinter", "Tkinter", "matplotlib", "qt5"], hookspath=[], runtime_hooks=[], cipher=block_cipher, diff --git a/Python/freeze.py b/Python/freeze.py index 965daca0f..159306477 100644 --- a/Python/freeze.py +++ b/Python/freeze.py @@ -42,25 +42,19 @@ # Create the executable. dist_path = str(output_dir.resolve()).replace("\\", "/") - freeze_call = list() spec = "controller.spec" if p == "Linux": - freeze_call = ["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path] + call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller" elif p == "Darwin": - freeze_call = ["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path] + call(["python3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller.app" elif p == "Windows": - freeze_call = ["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path] + call(["py", "-3", "-m", "PyInstaller", spec, "--onefile", "--distpath", dist_path]) exe = "tdw_controller.exe" else: raise Exception(f"Platform not supported: {p}") - # tkinter causes problems in OS X and isn't used by TDW. Exclude it. - freeze_call.extend(["--exclude-module='FixTk'", "--exclude-module='tcl'", "--exclude-module='tk'", - "--exclude-module='_tkinter'", "--exclude-module='tkinter'", "--exclude-module='Tkinter'"]) - call(freeze_call) - exe_path = output_dir.joinpath(exe) assert exe_path.exists() print(f"Created: {exe_path.resolve()}") From e41ee459ce781a5d05928cb2bf3d966b54843022 Mon Sep 17 00:00:00 2001 From: alters-mit Date: Wed, 12 Aug 2020 16:35:27 -0400 Subject: [PATCH 20/21] fixed flatbuffer import of numpy --- Python/tdw/flatbuffers/encode.py | 2 +- Python/tdw/flatbuffers/number_types.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/tdw/flatbuffers/encode.py b/Python/tdw/flatbuffers/encode.py index d130eb3f5..00d9ccca0 100644 --- a/Python/tdw/flatbuffers/encode.py +++ b/Python/tdw/flatbuffers/encode.py @@ -17,7 +17,7 @@ from .compat import memoryview_type from .compat import import_numpy, NumpyRequiredForThisFeature -np = import_numpy() +import numpy as np def Get(packer_type, buf, head): """ Get decodes a value at buf[head] using `packer_type`. """ diff --git a/Python/tdw/flatbuffers/number_types.py b/Python/tdw/flatbuffers/number_types.py index 46fcb772c..06f332436 100644 --- a/Python/tdw/flatbuffers/number_types.py +++ b/Python/tdw/flatbuffers/number_types.py @@ -18,7 +18,7 @@ from . import packer from .compat import import_numpy, NumpyRequiredForThisFeature -np = import_numpy() +import numpy as np # For reference, see: # https://docs.python.org/2/library/ctypes.html#ctypes-fundamental-data-types-2 From b8899976730098e920c92c96d149822144a5c06e Mon Sep 17 00:00:00 2001 From: alters-mit Date: Wed, 12 Aug 2020 16:49:47 -0400 Subject: [PATCH 21/21] updated documentation --- Documentation/Changelog.md | 1 + Documentation/misc_frontend/freeze.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/Changelog.md b/Documentation/Changelog.md index 04d2c28e0..6bc275bac 100644 --- a/Documentation/Changelog.md +++ b/Documentation/Changelog.md @@ -11,6 +11,7 @@ #### Backend - Added `controller.spec` (used for freezing controller code). +- Adjusted how Flatbuffers imports numpy so that frozen controller code works. ### Documentation diff --git a/Documentation/misc_frontend/freeze.md b/Documentation/misc_frontend/freeze.md index d08d41a6b..9bbd2ed8d 100644 --- a/Documentation/misc_frontend/freeze.md +++ b/Documentation/misc_frontend/freeze.md @@ -39,7 +39,7 @@ python3 freeze.py --controller CONTROLLER `freeze.py` will create an executable located in `~/tdw_build/tdw_controller`, where `~` is your home directory. **You can run it like an other application** by double-clicking it or running it in the terminal. Likewise, you can supply arguments to the executable like you can to a Python controller. -On Linux, you need to supply a `DISPLAY` environment to run the controller: +On Linux, you need to supply a `DISPLAY` environment to run the controller if [the launch_build parameter in the Controller constructor is True](../python/controller.md): ```bash DISPLAY=:0.0 ./my_controller