Skip to content
Merged
Empty file added installer/__init__.py
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions installer/pyinstaller/hidden_imports.py
Original file line number Diff line number Diff line change
@@ -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",
]
26 changes: 3 additions & 23 deletions installer/pyinstaller/hook-samcli.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/cli/test_pyinstaller_imports.py
Original file line number Diff line number Diff line change
@@ -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)