Пример #1
0
def test_install_django():

    os.system('pip uninstall django -y -q')

    with pytest.raises(ImportError):
        import django

    file_resource = pw.pip_package('django==1.6.2')

    with pytest.raises(ImportError):
        import django

    changes = file_resource.apply()

    with pytest.raises(ImportError):
        import django

    changes[0].commit()

    # ok
    import django

    changes = file_resource.rollback()

    # still ok
    reload(django)

    changes[0].commit()


    with pytest.raises(Exception):
        reload(django)
Пример #2
0
    def pre_setup(cls):
        super(Common, cls).pre_setup()

        cls.load_features()

        ctx = Context()

        with pw.resource_set(ctx, name='main'):
            for feature in cls.FEATURES:
                requirements = []
                for req in feature.get_required_packages(cls):
                    requirements.append(req)

                if requirements:
                    ctx.apply(
                        pw.pip_package(*requirements)
                    )

        changes = ctx.changeset()

        if changes.needed():

            if len(sys.argv) == 2 and sys.argv[1] == '--requirements':
                print('\nChanges to be applied:\n')
                for item in changes.items:
                    print('\t - %s' % item.description)

                changes.commit()

                exit(0)

            else:
                print('\nSome required packages are not installed:\n')
                for item in changes.items:
                    print('\t - %s' % item.description)

                print 'Execute "cratis --requirements" to install those'

                exit(1)