diff --git a/installer/__init__.py b/installer/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/installer/pyinstaller/__init__.py b/installer/pyinstaller/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/installer/pyinstaller/hidden_imports.py b/installer/pyinstaller/hidden_imports.py new file mode 100644 index 0000000000..6758eeee87 --- /dev/null +++ b/installer/pyinstaller/hidden_imports.py @@ -0,0 +1,13 @@ +from samcli.cli.command import _SAM_CLI_COMMAND_PACKAGES + +SAM_CLI_HIDDEN_IMPORTS = _SAM_CLI_COMMAND_PACKAGES + [ + "cookiecutter.extensions", + "jinja2_time", + "text_unidecode", + "samtranslator", + # default hidden import 'pkg_resources.py2_warn' is added + # since pyInstaller 4.0. + "pkg_resources.py2_warn", + "aws_lambda_builders.workflows", + "configparser", +] diff --git a/installer/pyinstaller/hook-samcli.py b/installer/pyinstaller/hook-samcli.py index 5101b96d79..1855250020 100644 --- a/installer/pyinstaller/hook-samcli.py +++ b/installer/pyinstaller/hook-samcli.py @@ -1,28 +1,8 @@ from PyInstaller.utils import hooks +from installer.pyinstaller.hidden_imports import SAM_CLI_HIDDEN_IMPORTS + +hiddenimports = SAM_CLI_HIDDEN_IMPORTS -hiddenimports = [ - "cookiecutter.extensions", - "jinja2_time", - "text_unidecode", - "samtranslator", - "samcli.commands.init", - "samcli.commands.validate.validate", - "samcli.commands.build", - "samcli.commands.local.local", - "samcli.commands.package", - "samcli.commands.deploy", - "samcli.commands.logs", - "samcli.commands.publish", - "samcli.commands.delete", - "samcli.commands.pipeline.pipeline", - "samcli.commands.pipeline.init", - "samcli.commands.pipeline.bootstrap", - # default hidden import 'pkg_resources.py2_warn' is added - # since pyInstaller 4.0. - "pkg_resources.py2_warn", - "aws_lambda_builders.workflows", - "configparser", -] datas = ( hooks.collect_data_files("samcli") + hooks.collect_data_files("samtranslator") diff --git a/tests/unit/cli/test_pyinstaller_imports.py b/tests/unit/cli/test_pyinstaller_imports.py new file mode 100644 index 0000000000..0fb215dd0a --- /dev/null +++ b/tests/unit/cli/test_pyinstaller_imports.py @@ -0,0 +1,24 @@ +import click + +from unittest import TestCase +from installer.pyinstaller import hidden_imports +from samcli.cli.command import BaseCommand + + +class TestPyinstallerImportCommands(TestCase): + def setUp(self): + pass + + def test_hook_contains_all_default_command_packages(self): + cmd = BaseCommand() + command_package_names = cmd._commands.values() + + for name in command_package_names: + self.assertIn(name, hidden_imports.SAM_CLI_HIDDEN_IMPORTS) + + def test_hook_not_contain_self_defined_command_packages(self): + cmd = BaseCommand(cmd_packages=["my.self.defined.package"]) + command_package_names = cmd._commands.values() + + for name in command_package_names: + self.assertNotIn(name, hidden_imports.SAM_CLI_HIDDEN_IMPORTS)