예제 #1
0
파일: definition.py 프로젝트: themill/qip
def export(path,
           package_mapping,
           output_path,
           editable_mode=False,
           custom_definition=None,
           existing_definition=None):
    """Export :term:`Wiz` definition to *path* for package mapping.

    :param path: destination path for the :term:`Wiz` definition.

    :param package_mapping: mapping of the python package built as returned by
        :func:`qip.package.install`.

    :param output_path: root destination path for Python packages installation.

    :param editable_mode: indicate whether the Python package location should
        target the source installation package. Default is False.

    :param custom_definition: :class:`wiz.definition.Definition` instance to
        update as returned by :func:`fetch_custom`. Default is None, which means
        that a default definition will be created from package mapping only.

    :param existing_definition: :class:`wiz.definition.Definition` instance to
        extract additional variants from as returned by :func:`fetch_existing`.
        Default is None which means that no additional variants will be added to
        new definition exported.

    """
    # Extract additional variants from existing definition if possible.
    additional_variants = None
    if existing_definition is not None:
        additional_variants = [
            variant.data() for variant in existing_definition.variants
        ]

    # Update definition or create a new definition.
    if custom_definition is not None:
        definition = update(
            custom_definition,
            package_mapping,
            output_path,
            editable_mode=editable_mode,
            additional_variants=additional_variants,
        )

    else:
        definition = create(package_mapping,
                            output_path,
                            editable_mode=editable_mode,
                            additional_variants=additional_variants)

    wiz.export_definition(path, definition, overwrite=True)
예제 #2
0
def test_install_ignore_registries(temporary_directory, registry_path, logger):
    """Install packages while ignoring existing definition in registry."""
    packages_path = os.path.join(temporary_directory, "packages")
    definitions_path = os.path.join(temporary_directory, "definitions")

    # Export definition to ignore.
    wiz.export_definition(registry_path, {
        "identifier": "foo",
        "version": "1.2.0",
        "description": "Foo Python Package.",
        "namespace": "library",
        "install-root": "/path/to/foo",
        "environ": {
            "PYTHONPATH": "${INSTALL_LOCATION}:${PYTHONPATH}"
        },
        "variants": [
            {
                "identifier": "2.7",
                "install-location": (
                    "${INSTALL_ROOT}/Foo/Foo-1.2.0-py27/lib/python2.7/"
                    "site-packages"
                ),
                "requirements": [
                    "python >= 2.7, < 2.8",
                    "library::bim[2.7] >=3.4, <5"
                ]
            }
        ]
    })

    runner = CliRunner()
    result = runner.invoke(
        qip.command_line.main, [
            "install", "-I",
            "foo >= 1, <= 2",
            "-o", packages_path,
            "-d", definitions_path,
        ]
    )
    assert not result.exception
    assert result.exit_code == 0

    # Check log.
    logger.info.assert_any_call("Packages installed: BIM-3.6.2, Foo-1.2.0")
    logger.warning.assert_not_called()
    logger.error.assert_not_called()

    # Check package installed.
    expected_packages = [
        os.path.join("BIM", "BIM-3.6.2-py27"),
    ]

    for package in expected_packages:
        assert os.path.isdir(os.path.join(packages_path, package))

    # Check definitions installed.
    expected_definitions = [
        "library-bim-3.6.2.json",
        "library-foo-1.2.0.json"
    ]

    definitions = os.listdir(definitions_path)
    assert sorted(definitions) == expected_definitions

    path = os.path.join(definitions_path, expected_definitions[0])
    definition = wiz.load_definition(path)
    assert definition.data() == {
        "identifier": "bim",
        "version": "3.6.2",
        "description": "Bim Python Package.",
        "namespace": "library",
        "install-root": packages_path,
        "environ": {
            "PYTHONPATH": "${INSTALL_LOCATION}:${PYTHONPATH}"
        },
        "variants": [
            {
                "identifier": "2.7",
                "install-location": (
                    "${INSTALL_ROOT}/BIM/BIM-3.6.2-py27/lib/python2.7/"
                    "site-packages"
                ),
                "requirements": [
                    "python >= 2.7, < 2.8",
                ]
            }
        ]
    }

    path = os.path.join(definitions_path, expected_definitions[1])
    definition = wiz.load_definition(path)
    assert definition.data() == {
        "identifier": "foo",
        "version": "1.2.0",
        "description": "Foo Python Package.",
        "namespace": "library",
        "install-root": packages_path,
        "command": {
            "foo": "python -m foo"
        },
        "environ": {
            "PYTHONPATH": "${INSTALL_LOCATION}:${PYTHONPATH}"
        },
        "variants": [
            {
                "identifier": "2.7",
                "install-location": (
                    "${INSTALL_ROOT}/Foo/Foo-1.2.0-py27/lib/python2.7/"
                    "site-packages"
                ),
                "requirements": [
                    "python >= 2.7, < 2.8",
                    "library::bim[2.7] >=3.4, <5"
                ]
            }
        ]
    }