예제 #1
0
    def test_bundle_no_deps(self):
        tempdir = tempfile.mkdtemp()

        try:
            zpm.create_project(tempdir, template='python')
            with open(os.path.join(tempdir, 'zapp.yaml')) as zapp_yaml:
                zapp = yaml.safe_load(zapp_yaml)

            # add some files to "bundling" section
            touch_file(tempdir, 'main.py')
            zapp['bundling'].append('main.py')

            # rewrite the zapp.yaml
            with open(os.path.join(tempdir, 'zapp.yaml'), 'w') as zapp_yaml:
                zapp_yaml.write(yaml.dump(zapp))

            zpm.bundle_project(tempdir)
            zapp_file = os.path.join(tempdir,
                                     os.path.basename(tempdir) + '.zapp')
            tar = tarfile.open(zapp_file)
            expected_file_names = [
                'boot/system.map',
                'zapp.yaml',
                'main.py',
            ]
            assert expected_file_names == [x.name for x in tar.getmembers()]
        finally:
            shutil.rmtree(tempdir)
예제 #2
0
파일: commands.py 프로젝트: barkinet/zpm
def bundle(args):
    """Bundle a ZeroVM application

    This command creates a Zapp using the instructions in zapp.yaml.
    The file is read from the project root.
    """
    root = zpm.find_project_root()
    zpm.bundle_project(root, refresh_deps=args.refresh_deps)
예제 #3
0
파일: commands.py 프로젝트: al-maisan/zpm
def bundle(args):
    """Bundle a ZeroVM application

    This command creates a ZAR using the instructions in ``zar.json``.
    The file is read from the project root.
    """
    root = zpm.find_project_root()
    zpm.bundle_project(root)
예제 #4
0
def bundle(args):
    """Bundle a ZeroVM application

    This command creates a Zapp using the instructions in zapp.yaml.
    The file is read from the project root.
    """
    root = zpm.find_project_root()
    zpm.bundle_project(root, refresh_deps=args.refresh_deps)
예제 #5
0
    def test_bundle(self):
        tempdir = tempfile.mkdtemp()
        zapp_file = os.path.join(tempdir, os.path.basename(tempdir) + '.zapp')
        site_pkgs = os.path.join(tempdir, '.zapp/.zapp/venv/lib/python2.7/'
                                          'site-packages')
        try:
            zpm.create_project(tempdir, template='python')
            with open(os.path.join(tempdir, 'zapp.yaml')) as zapp_yaml:
                zapp = yaml.safe_load(zapp_yaml)

            # add some files to "bundling" section
            touch_file(tempdir, 'main.py')
            zapp['bundling'].append('main.py')

            # add dependencies:
            zapp['dependencies'] = [
                'dep1',
                'dep2',
                ['dontcare', 'foodep3'],
            ]

            # rewrite the zapp.yaml
            with open(os.path.join(tempdir, 'zapp.yaml'), 'w') as zapp_yaml:
                zapp_yaml.write(yaml.dump(zapp))

            ######################
            # Test normal bundling
            def tox_fetch_deps(*args, **kwargs):
                # fake creating a venv and installing deps with tox
                os.makedirs(site_pkgs)
                # add the deps: dep1.py (module) and dep2/ (package)
                touch_file(site_pkgs, 'dep1.py')
                os.makedirs(os.path.join(site_pkgs, 'dep2'))
                touch_file(os.path.join(site_pkgs, 'dep2'), '__init__.py')
                touch_file(os.path.join(site_pkgs, 'dep2'), 'foo.py')
                os.makedirs(os.path.join(site_pkgs, 'foodep3'))
                touch_file(os.path.join(site_pkgs, 'foodep3'), '__init__.py')
                touch_file(os.path.join(site_pkgs, 'foodep3'), 'foodep3.py')
                return 0

            with mock.patch('subprocess.Popen') as sppo:
                instance = sppo.return_value
                instance.wait.side_effect = tox_fetch_deps
                zpm.bundle_project(tempdir)
            # Test the deps file:
            with open(os.path.join(tempdir, '.zapp', 'deps.txt')) as deps_file:
                assert 'dep1\ndep2\ndontcare\n' == deps_file.read()
            # Test the subprocess call to tox:
            assert sppo.call_args[0][0] == [
                'tox', '-c', os.path.join(tempdir, '.zapp', 'tox.ini')
            ]
            tar = tarfile.open(zapp_file)
            expected_file_names = [
                'boot/system.map',
                'zapp.yaml',
                'main.py',
                'lib/python2.7/site-packages/dep1.py',
                'lib/python2.7/site-packages/dep2',
                'lib/python2.7/site-packages/dep2/__init__.py',
                'lib/python2.7/site-packages/dep2/foo.py',
                'lib/python2.7/site-packages/foodep3',
                'lib/python2.7/site-packages/foodep3/__init__.py',
                'lib/python2.7/site-packages/foodep3/foodep3.py',
            ]
            assert sorted(expected_file_names) == sorted(
                [x.name for x in tar.getmembers()]
            )
            tar.close()

            ###################################
            # Test bundling with --refresh-deps
            # Different dependencies this time
            zapp['dependencies'] = ['dep1']
            with open(os.path.join(tempdir, 'zapp.yaml'), 'w') as zapp_yaml:
                zapp_yaml.write(yaml.dump(zapp))

            def tox_fetch_deps(*args, **kwargs):
                # fake creating a venv and installing deps with tox
                shutil.rmtree(site_pkgs)
                os.makedirs(site_pkgs)
                # add the deps: dep1.py (module) and dep2/ (package)
                touch_file(site_pkgs, 'dep1.py')
                return 0

            with mock.patch('subprocess.Popen') as sppo:
                instance = sppo.return_value
                instance.wait.side_effect = tox_fetch_deps
                zpm.bundle_project(tempdir, refresh_deps=True)

            assert sppo.call_args[0][0] == [
                'tox', '-r', '-c', os.path.join(tempdir, '.zapp', 'tox.ini')
            ]

            tar = tarfile.open(zapp_file)
            expected_file_names = [
                'boot/system.map',
                'zapp.yaml',
                'main.py',
                'lib/python2.7/site-packages/dep1.py',
            ]
            assert sorted(expected_file_names) == sorted(
                [x.name for x in tar.getmembers()]
            )
            tar.close()
        finally:
            shutil.rmtree(tempdir)