Exemple #1
0
def pyproject_callback(pyproject_file: Path = typer.Option(Path(".") /
                                                           "pyproject.toml",
                                                           "-f",
                                                           "--pyproject-file",
                                                           exists=True)):
    PyProject.read_toml(pyproject_file)
    chdir(PyProject.get().config_path.parent)
def test_pyproject_to_conda_creates_recipe_right_params():
    PyProject.read_toml(SIMPLE_PYPROJECT_TOML)
    recipe = pyproject_to_meta()
    # it should ignore the dev-environments
    assert recipe.package.name == "test_name"
    assert recipe.package.version == "0.1.0"
    assert "python" in recipe.requirements.host[0]
    assert "3.7.0" in recipe.requirements.host[0]
def test_pyproject_to_conda_dev_env_dict_generates_env_with_dev_deps():
    PyProject.read_toml(SIMPLE_PYPROJECT_TOML)
    env_dict = pyproject_to_conda_env_dict()
    dep_names = [d.split(" ")[0] for d in env_dict["dependencies"]]

    assert len(env_dict["dependencies"]) == 8
    # it should not ignore the dev-environments
    assert "python" in dep_names
    assert "ensureconda" in dep_names
    assert "appdirs" in dep_names
    assert "pyinstaller" in dep_names
    assert "pytest" in dep_names
def test_pyproject_to_conda_creates_recipe_with_deps():
    PyProject.read_toml(SIMPLE_PYPROJECT_TOML)
    recipe = pyproject_to_meta()
    deps = recipe.requirements.run
    dep_names = [d.split(" ")[0] for d in deps]
    # it should ignore the dev-environments
    assert len(deps) == 6
    assert "python" in dep_names
    assert "ensureconda" in dep_names
    assert "click" in dep_names
    assert "tomlkit" in dep_names
    assert "appdirs" in dep_names
    assert "conda-lock" in dep_names
Exemple #5
0
def test_remove_config_key_removes_it_from_file(temp_pyproject, cli_runner):
    cli_runner.invoke(
        app,
        [
            "config",
            "set",
            "env.build-system",
            "poetry",
            "-f",
            str(temp_pyproject),
        ],
    )

    cli_runner.invoke(
        app,
        [
            "config",
            "remove",
            "env.build-system",
            "-f",
            str(temp_pyproject),
        ],
    )

    assert (PyProject.read_toml(temp_pyproject).senv.env.build_system ==
            BuildSystem.CONDA)
Exemple #6
0
def test_conda_build_dir_can_not_be_in_project(tmp_path):
    tmp_toml = tmp_path / "tmp_toml"
    config_dict = {
        "tool": {
            "senv": {
                "name": "senv3",
                "package": {
                    "conda-build-path": "./dist",
                },
            },
        }
    }
    tmp_toml.write_text(toml.dumps(config_dict))

    with cd(tmp_path), pytest.raises(SenvBadConfiguration):
        PyProject.read_toml(tmp_toml)
Exemple #7
0
 def _build_temp_pyproject(pyproject_path: Path):
     temp_path = tmp_path / "pyproject.toml"
     copyfile(pyproject_path, temp_path)
     c = PyProject.read_toml(temp_path)
     project = tmp_path / c.package_name.replace("-", "_") / "main.py"
     project.parent.mkdir(parents=True, exist_ok=True)
     project.write_text("print('hello world')")
     return temp_path
Exemple #8
0
def test_set_config_with_wrong_value_does_not_change_pyproject(
        temp_pyproject, cli_runner):
    original_config = PyProject.read_toml(temp_pyproject).dict()
    cli_runner.invoke(
        app,
        [
            "-f",
            str(temp_pyproject),
            "config",
            "set",
            "conda-path",
            "none_existing_path",
        ],
        catch_exceptions=False,
    )

    new_config = PyProject.read_toml(temp_pyproject).dict()
    assert new_config == original_config
Exemple #9
0
def test_set_config_add_value_to_pyproject(temp_pyproject, cli_runner):
    result = cli_runner.invoke(
        app,
        [
            "config",
            "-f",
            str(temp_pyproject),
            "set",
            "env.conda-lock-platforms",
            "linux-64",
        ],
        catch_exceptions=False,
    )

    assert result.exit_code == 0

    PyProject.read_toml(temp_pyproject)
    assert PyProject.get().senv.env.conda_lock_platforms == {"linux-64"}
def test_env_locks_builds_the_lock_files_in_the_configured_directory(
    temp_pyproject, cli_runner
):
    lock_file = temp_pyproject.parent / "my_lock_folder"
    PyProject.read_toml(temp_pyproject)
    set_new_setting_value(AllowedConfigKeys.CONDA_ENV_LOCK_PATH, str(lock_file))
    result = cli_runner.invoke(
        app,
        [
            "env",
            "-f",
            str(temp_pyproject),
            "lock",
            "--platforms",
            "osx-64",
        ],
        catch_exceptions=False,
    )
    assert result.exit_code == 0
    assert lock_file.exists()
    combined_lock = CombinedCondaLock.parse_file(lock_file)

    assert set(combined_lock.platform_tar_links.keys()) == {"osx-64"}
def test_pyproject_to_conda_dev_env_dict_senv_overrides_values():
    PyProject.read_toml(SENV_OVERRIDE_PYPROJECT_TOML)
    env_dict = pyproject_to_conda_env_dict()
    assert len(env_dict["channels"]) == 2
    assert env_dict["name"] == "overridden_name"
def test_pyproject_to_conda_dev_env_dict_has_no_channel_and_basic_name():
    PyProject.read_toml(SIMPLE_PYPROJECT_TOML)
    env_dict = pyproject_to_conda_env_dict()
    assert len(env_dict["channels"]) == 0
    assert env_dict["name"] == "test_name"