Skip to content

Commit

Permalink
Merge pull request #295 from scottyhq/os_name
Browse files Browse the repository at this point in the history
Add os_name environment marker for platform-dependent pypi dependencies
  • Loading branch information
maresb authored Feb 25, 2023
2 parents 2418a9d + d0138b6 commit 2d91cbb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conda_lock/pypi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ def __init__(self, python_version: str, platform: str):
if platform.startswith("osx-"):
self._sys_platform = "darwin"
self._platform_system = "Darwin"
self._os_name = "posix"
elif platform.startswith("linux-"):
self._sys_platform = "linux"
self._platform_system = "Linux"
self._os_name = "posix"
elif platform.startswith("win-"):
self._sys_platform = "win32"
self._platform_system = "Windows"
self._os_name = "nt"
else:
raise ValueError(f"Unsupported platform '{platform}'")

Expand All @@ -99,6 +102,7 @@ def get_marker_env(self) -> Dict[str, str]:
"python_version": ".".join([str(c) for c in self._python_version[:2]]),
"sys_platform": self._sys_platform,
"platform_system": self._platform_system,
"os_name": self._os_name,
}


Expand Down
8 changes: 8 additions & 0 deletions tests/test-os-name-marker/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
channels:
- conda-forge
dependencies:
- pip
- pip:
- jupyter-server ==2.3.0
platforms:
- linux-64
19 changes: 19 additions & 0 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,25 @@ def test_run_lock_with_pip(
run_lock([pip_environment], conda_exe=conda_exe)


@pytest.fixture
def os_name_marker_environment(tmp_path: Path):
return clone_test_dir("test-os-name-marker", tmp_path).joinpath("environment.yml")


def test_os_name_marker(
monkeypatch: pytest.MonkeyPatch, os_name_marker_environment: Path, conda_exe: str
):
monkeypatch.chdir(os_name_marker_environment.parent)
if is_micromamba(conda_exe):
monkeypatch.setenv("CONDA_FLAGS", "-v")
run_lock([os_name_marker_environment], conda_exe=conda_exe)
lockfile = parse_conda_lock_file(
os_name_marker_environment.parent / DEFAULT_LOCKFILE_NAME
)
for package in lockfile.package:
assert package.name != "pywinpty"


def test_run_lock_with_pip_environment_different_names_same_deps(
monkeypatch: "pytest.MonkeyPatch",
pip_environment_different_names_same_deps: Path,
Expand Down

0 comments on commit 2d91cbb

Please sign in to comment.