Exemple #1
0
def build_isolated(config, report, session):
    build_info = get_build_info(config.setupdir, report)
    package_venv = session.getvenv(config.isolated_build_env)
    package_venv.envconfig.deps_matches_subset = True

    # we allow user specified dependencies so the users can write extensions to
    # install additional type of dependencies (e.g. binary)
    user_specified_deps = package_venv.envconfig.deps
    package_venv.envconfig.deps = [
        DepConfig(r, None) for r in build_info.requires
    ]
    package_venv.envconfig.deps.extend(user_specified_deps)

    if not session.setupenv(package_venv):
        session.finishvenv(package_venv)

    build_requires = get_build_requires(build_info, package_venv, session)
    # we need to filter out requirements already specified in pyproject.toml or user deps
    base_build_deps = {
        pkg_resources.Requirement(r.name).key
        for r in package_venv.envconfig.deps
    }
    build_requires_dep = [
        DepConfig(r, None) for r in build_requires
        if pkg_resources.Requirement(r).key not in base_build_deps
    ]
    if build_requires_dep:
        with session.newaction(package_venv, "build_requires",
                               package_venv.envconfig.envdir) as action:
            package_venv.run_install_command(packages=build_requires_dep,
                                             action=action)
        session.finishvenv(package_venv)
    return perform_isolated_build(build_info, package_venv, session, config)
def build(config, session):
    build_info = get_build_info(config.setupdir)
    package_venv = session.getvenv(config.isolated_build_env)
    package_venv.envconfig.deps_matches_subset = True

    # we allow user specified dependencies so the users can write extensions to
    # install additional type of dependencies (e.g. binary)
    user_specified_deps = package_venv.envconfig.deps
    package_venv.envconfig.deps = [DepConfig(r, None) for r in build_info.requires]
    package_venv.envconfig.deps.extend(user_specified_deps)

    if package_venv.setupenv():
        package_venv.finishvenv()
    if isinstance(package_venv.status, Exception):
        raise package_venv.status

    build_requires = get_build_requires(build_info, package_venv, config.setupdir)
    # we need to filter out requirements already specified in pyproject.toml or user deps
    base_build_deps = {
        canonicalize_name(Requirement(r.name).name) for r in package_venv.envconfig.deps
    }
    build_requires_dep = [
        DepConfig(r, None)
        for r in build_requires
        if canonicalize_name(Requirement(r).name) not in base_build_deps
    ]
    if build_requires_dep:
        with package_venv.new_action("build_requires", package_venv.envconfig.envdir) as action:
            package_venv.run_install_command(packages=build_requires_dep, action=action)
        package_venv.finishvenv()
    return perform_isolated_build(build_info, package_venv, config.distdir, config.setupdir)
Exemple #3
0
def tox_configure(config):
    # type: (Config) -> None
    # Only run if we're enabled
    toxinidir = str(config.toxinidir)
    cfg = get_config(toxinidir)
    if "wikimedia" not in cfg:
        verbosity2("[wikimedia] tox-wikimedia is not enabled, skipping")
        return

    verbosity2("[wikimedia] tox-wikimedia is enabled")
    for envname, econfig in config.envconfigs.items():
        for factor in econfig.factors:
            # factors are py35, flake8, pytest, etc.
            try:
                fconfig = TOOLS[factor]  # type: dict
            except KeyError:
                continue

            for dep in fconfig["deps"]:
                # Check to make sure the dep is not already
                # specific (e.g. to specify a constraint)
                for cdep in econfig.deps:
                    if dep in cdep.name:
                        break
                else:
                    econfig.deps.append(DepConfig(dep))
                    verbosity2("[wikimedia] {}: Adding dep on {}".format(
                        envname, dep))
            if fconfig.get("requirements"):
                for txtdep in [
                        "requirements.txt",
                        "test-requirements.txt",
                ]:
                    if os.path.exists(os.path.join(toxinidir, txtdep)):
                        verbosity2("[wikimedia] {}: Adding dep on {}".format(
                            envname, txtdep))
                        econfig.deps.append(DepConfig("-r{}".format(txtdep)))
            if econfig.commands:
                verbosity2("[wikimedia] {}: overridden commands: {}".format(
                    envname, repr(econfig.commands)))
            if not econfig.commands:
                # If there's no command, then set one
                cmd = []
                for part in fconfig["commands"]:
                    if "{" in part:
                        # Needs formatting
                        part = part.format(**cfg["wikimedia"])
                    cmd.append(part)
                econfig.commands.append(cmd)
                verbosity2("[wikimedia] {}: Setting command to {}".format(
                    envname, str(cmd)))
            if not econfig.description:
                econfig.description = fconfig["description"]
Exemple #4
0
def tox_configure(config):
    # This is a pretty cheesy workaround. It allows tox to consider changes to
    # the conda dependencies when it decides whether an existing environment
    # needs to be updated before being used
    for _, envconfig in config.envconfigs.items():
        # Make sure the right environment is activated. This works because we're
        # creating environments using the `-p/--prefix` option in `tox_testenv_create`
        envconfig.setenv["CONDA_DEFAULT_ENV"] = envconfig.setenv["TOX_ENV_DIR"]

        conda_deps = [DepConfig(str(name)) for name in envconfig.conda_deps]
        # Add the conda-spec.txt file to the end of the conda deps b/c any deps
        # after --file option(s) are ignored
        if envconfig.conda_spec:
            conda_deps.append(DepConfig("--file={}".format(envconfig.conda_spec)))
        envconfig.deps.extend(conda_deps)
Exemple #5
0
    def get_file_list(self):
        for module in self.build.find_all_modules():
            self.files.append((os.path.abspath(module[2]), module[2]))

        deps = self.config_data.get('deps', [])
        if deps:
            try:
                deps.remove('-I')
            except ValueError:
                pass
            deps.insert(0, '-I')

            ixserver = self.venv.envconfig.config.indexserver['default']
            self.venv.create()
            self.venv.envconfig.deps = [
                DepConfig(dep, ixserver) for dep in deps
            ]
            site_packages = self.venv.envconfig.envsitepackagesdir()
            self.venv.install_deps()

            for root, _, files in os.walk(site_packages):
                for filename in files:
                    if not self.with_pyc and re.search('\.py[co]$', filename):
                        continue
                    filepath = os.path.abspath(os.path.join(root, filename))
                    arcname = filepath[len(site_packages) + 1:]
                    self.files.append((filepath, arcname))

        self.sdist.finalize_options()
        self.sdist.get_file_list()

        for _file in self.sdist.filelist.files:
            self.files.append((os.path.abspath(_file), _file))

        return self.files
Exemple #6
0
def tox_configure(config):
    # This is a pretty cheesy workaround. It allows tox to consider changes to
    # the conda dependencies when it decides whether an existing environment
    # needs to be updated before being used
    for _, envconfig in config.envconfigs.items():
        conda_deps = [DepConfig(str(name)) for name in envconfig.conda_deps]
        envconfig.deps.extend(conda_deps)
Exemple #7
0
    def test_deps(self):
        env_config = TestenvConfig(sentinel.name, sentinel.config,
                                   sentinel.factors, sentinel.reader)
        env_config.deps = [DepConfig('dummy')]
        config = Config(sentinel.pluginmanager, sentinel.option,
                        sentinel.interpreters, Parser(), sentinel.args)
        config.envconfigs[sentinel.name] = env_config

        tox_configure(config)

        self.assertEqual(len(config.envconfigs[sentinel.name].deps), 2)
        self.assertEqual(config.envconfigs[sentinel.name].deps[0].name,
                         'dummy')
        self.assertEqual(config.envconfigs[sentinel.name].deps[1].name, 'ipdb')
def tox_runenvreport(venv, action):
    if 'TESTMON_DATAFILE' in venv.envconfig.setenv:
        datafile = venv.envconfig.setenv['TESTMON_DATAFILE']
        action.setactivity('testmon', 'keeping TESTMON_DATAFILE=%s' % datafile)
    else:
        datafile = str(venv.path.join('.testmondata'))
        action.setactivity('testmon', 'setting TESTMON_DATAFILE=%s' % datafile)
        venv.envconfig.setenv['TESTMON_DATAFILE'] = datafile

    if (_uses_testmon(venv.envconfig)
            and 'pytest-testmon' not in (x.name for x in venv.envconfig.deps)):
        if not installed_testmon(venv):
            action.setactivity('testmon', 'installing pytest-testmon')
            # Uses _install for handling configured indexservers.
            # venv.run_install_command(['pytest-testmon'], action=action)
            venv._install([DepConfig('pytest-testmon')], action=action)

            touch_stampfile(venv)
Exemple #9
0
def get_project_install(venv, mount, no_deps=False, overwrite=None):
    if venv.envconfig.skip_install or venv.envconfig.config.skipsdist:
        return None
    if venv.envconfig.usedevelop and venv.envconfig.skip_install is False:
        what = mount  # install the folder itself
    else:
        if overwrite is None:
            what = mount.join(
                venv.package.relto(venv.envconfig.config.toxinidir)
            )  # install relative to root
        else:
            what = mount.join(
                venv.package.basename)  # package at root level in folder
    what = str(what)
    if venv.envconfig.extras:
        what = f'{what}[{",".join(venv.envconfig.extras)}]'
    pip_install = get_pip_install(venv, [DepConfig(what, None)])
    if no_deps:
        pip_install.append("--no-deps")
    return pip_install
Exemple #10
0
def tox_configure(config: Config) -> None:
    """Add ipdb to dependencies of every tox environment."""
    for envconfig in config.envconfigs.values():
        envconfig.deps.append(DepConfig('ipdb'))