Skip to content

Commit f26c305

Browse files
authored
Merge pull request #836 from AlbertDeFusco/feat/disable-pypi-requests
[feature] support allow-pypi-requests in environment yaml
2 parents 47b17e2 + 562662d commit f26c305

File tree

6 files changed

+78
-1
lines changed

6 files changed

+78
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ url = "https://username:password@example.repo/simple"
189189
190190
The location of this file can be determined with `python -c 'from conda_lock._vendor.poetry.locations import CONFIG_DIR; print(CONFIG_DIR)'`
191191
192-
Private repositories will be used in addition to `pypi.org`. For projects using `pyproject.toml`, it is possible to [disable `pypi.org` entirely](#disabling-pypiorg).
192+
By default, private repositories will be used in addition to `pypi.org`, but it is also possible to [disable `pypi.org` entirely](#disabling-pypiorg).
193193
194194
### --dev-dependencies/--no-dev-dependencies
195195
@@ -451,11 +451,19 @@ skip-non-conda-lock = true
451451
452452
When using private pip repos, it is possible to disable `pypi.org` entirely. This can be useful when using `conda-lock` behind a network proxy that does not allow access to `pypi.org`.
453453
454+
You can do this in `pyproject.toml`:
455+
454456
```toml
455457
[tool.conda-lock]
456458
allow-pypi-requests = false
457459
```
458460
461+
Or in `environment.yml`:
462+
463+
```yaml
464+
allow-pypi-requests: false
465+
```
466+
459467
## Dockerfile example
460468
461469
In order to use conda-lock in a docker-style context you want to add the lockfile to the

conda_lock/src_parser/environment_yaml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def parse_environment_file(
131131
pass
132132

133133
pip_repositories: list[str] = env_yaml_data.get("pip-repositories", [])
134+
allow_pypi_requests: bool = env_yaml_data.get("allow-pypi-requests", True)
134135

135136
# These extension fields are nonstandard
136137
category: str = env_yaml_data.get("category") or "main"
@@ -148,4 +149,5 @@ def parse_environment_file(
148149
channels=channels, # type: ignore
149150
pip_repositories=pip_repositories, # type: ignore
150151
sources=[environment_file],
152+
allow_pypi_requests=allow_pypi_requests,
151153
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: allow-pypi
2+
3+
allow-pypi-requests: true
4+
5+
channels:
6+
- conda-forge
7+
8+
dependencies:
9+
- python=3.10
10+
- pip
11+
- pip:
12+
- requests
13+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: allow-pypi
2+
3+
channels:
4+
- conda-forge
5+
6+
dependencies:
7+
- python=3.10
8+
- pip
9+
- pip:
10+
- requests
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: no-allow-pypi
2+
3+
allow-pypi-requests: false
4+
5+
channels:
6+
- conda-forge
7+
8+
dependencies:
9+
- python=3.10
10+
- pip
11+
- pip:
12+
- requests
13+

tests/test_conda_lock.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ def blas_mkl_environment(tmp_path: Path):
222222
)
223223

224224

225+
@pytest.fixture
226+
def env_yaml_allow_pypi_requests(tmp_path: Path):
227+
return clone_test_dir("test-env-yaml-allow-pypi-requests", tmp_path)
228+
229+
225230
@pytest.fixture
226231
def meta_yaml_environment(tmp_path: Path):
227232
return clone_test_dir("test-recipe", tmp_path).joinpath("meta.yaml")
@@ -493,6 +498,31 @@ def test_parse_environment_file_with_pip(pip_environment: Path):
493498
]
494499

495500

501+
def test_parse_environment_file_allow_pypi_requests(env_yaml_allow_pypi_requests: Path):
502+
implicit = env_yaml_allow_pypi_requests / "env.implicit.yml"
503+
implicit_spec = parse_environment_file(
504+
implicit, platforms=DEFAULT_PLATFORMS, mapping_url=DEFAULT_MAPPING_URL
505+
)
506+
assert implicit_spec.allow_pypi_requests
507+
508+
explicit = env_yaml_allow_pypi_requests / "env.explicit.yml"
509+
explicit_spec = parse_environment_file(
510+
explicit, platforms=DEFAULT_PLATFORMS, mapping_url=DEFAULT_MAPPING_URL
511+
)
512+
assert explicit_spec.allow_pypi_requests
513+
514+
no_pypi = env_yaml_allow_pypi_requests / "env.no-pypi-requests.yml"
515+
no_pypi_spec = parse_environment_file(
516+
no_pypi, platforms=DEFAULT_PLATFORMS, mapping_url=DEFAULT_MAPPING_URL
517+
)
518+
assert not no_pypi_spec.allow_pypi_requests
519+
520+
agg = aggregate_lock_specs(
521+
lock_specs=[implicit_spec, no_pypi_spec], platforms=DEFAULT_PLATFORMS
522+
)
523+
assert not agg.allow_pypi_requests
524+
525+
496526
def test_parse_environment_file_with_git(git_environment: Path):
497527
res = parse_environment_file(
498528
git_environment, platforms=DEFAULT_PLATFORMS, mapping_url=DEFAULT_MAPPING_URL

0 commit comments

Comments
 (0)