这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions conda/cli/main_env_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
_StoreAction,
_SubParsersAction,
)
from pathlib import Path

from .. import CondaError
from ..cli.main_config import set_keys
from ..deprecations import deprecated
from ..notices import notices

Expand Down Expand Up @@ -209,6 +211,12 @@ def execute(args: Namespace, parser: ArgumentParser) -> int:
)
)

if context.subdir != context._native_subdir():
set_keys(
("subdir", context.subdir),
path=Path(prefix, ".condarc"),
)

if env.variables:
prefix_data.set_environment_env_vars(env.variables)

Expand Down
19 changes: 19 additions & 0 deletions news/14956-bugfix-for-env-create-platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Respect `--platform` option on subsequent environment operations after initial `conda env create` call. (#14949 via #14956)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
46 changes: 46 additions & 0 deletions tests/env/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,49 @@ def test_create_env_from_non_existent_plugin(
"You have chosen an unrecognized environment specifier type (nonexistent_plugin)"
in str(excinfo.value)
)


def test_create_env_custom_platform(
conda_cli: CondaCLIFixture,
tmp_env: TmpEnvFixture,
path_factory: PathFactoryFixture,
test_recipes_channel: str,
):
"""
Ensures that the `--platform` option works correctly when creating an environment by
creating a `.condarc` file with `subir: osx-64`.
"""
env_file = path_factory("test_recipes_channel.yml")
env_file.write_text(
f"""
name: test-env
channels:
- {test_recipes_channel}
dependencies:
- dependency
"""
)

if context._native_subdir() == "osx-arm64":
platform = "linux-64"
else:
platform = "osx-arm64"

with tmp_env() as prefix:
conda_cli(
"env",
"create",
f"--prefix={prefix}",
"--file",
str(env_file),
f"--platform={platform}",
)
prefix_data = PrefixData(prefix)

assert prefix_data.exists()
assert prefix_data.is_environment()

config = prefix / ".condarc"

assert config.is_file()
assert f"subdir: {platform}" in config.read_text()
Loading