Skip to content

Commit

Permalink
Add flags to disable pypi.org and add own private pip repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpye authored and maresb committed Sep 13, 2024
1 parent 0837772 commit 436b16b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def make_lock_files( # noqa: C901
metadata_yamls: Sequence[pathlib.Path] = (),
with_cuda: Optional[str] = None,
strip_auth: bool = False,
disable_pypi_requests: bool = False,
private_pip_repositories: Optional[Sequence[str]] = None,
) -> None:
"""
Generate a lock file from the src files provided
Expand Down Expand Up @@ -324,6 +326,8 @@ def make_lock_files( # noqa: C901
channel_overrides=channel_overrides,
platform_overrides=platform_overrides,
required_categories=required_categories if filter_categories else None,
pip_repository_overrides=private_pip_repositories,
allow_pypi_requests_overrides=not disable_pypi_requests,
)

# Load existing lockfile if it exists
Expand Down Expand Up @@ -1132,6 +1136,8 @@ def run_lock(
metadata_choices: AbstractSet[MetadataOption] = frozenset(),
metadata_yamls: Sequence[pathlib.Path] = (),
strip_auth: bool = False,
disable_pypi_requests: bool = False,
private_pip_repositories: Optional[Sequence[str]] = None,
) -> None:
if len(environment_files) == 0:
environment_files = handle_no_specified_source_files(lockfile_path)
Expand All @@ -1158,6 +1164,8 @@ def run_lock(
metadata_choices=metadata_choices,
metadata_yamls=metadata_yamls,
strip_auth=strip_auth,
disable_pypi_requests=disable_pypi_requests,
private_pip_repositories=private_pip_repositories,
)


Expand Down Expand Up @@ -1321,6 +1329,18 @@ def main() -> None:
type=click.Path(),
help="YAML or JSON file(s) containing structured metadata to add to metadata section of the lockfile.",
)
@click.option(
"--disable-pypi-requests",
is_flag=True,
default=False,
help="Disable requests to pypi.org",
)
@click.option(
"-r",
"--private_pip_repositories",
multiple=True,
help="Add private pip repositories",
)
@click.pass_context
def lock(
ctx: click.Context,
Expand All @@ -1335,6 +1355,8 @@ def lock(
filename_template: str,
lockfile: Optional[PathLike],
strip_auth: bool,
disable_pypi_requests: bool,
private_pip_repositories: Sequence[str],
extras: Sequence[str],
filter_categories: bool,
check_input_hash: bool,
Expand Down Expand Up @@ -1408,6 +1430,8 @@ def lock(
metadata_choices=metadata_enum_choices,
metadata_yamls=[pathlib.Path(path) for path in metadata_yamls],
strip_auth=strip_auth,
disable_pypi_requests=disable_pypi_requests,
private_pip_repositories=private_pip_repositories,
)
if strip_auth:
with tempfile.TemporaryDirectory() as tempdir:
Expand Down
10 changes: 8 additions & 2 deletions conda_lock/src_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def make_lock_spec(
pip_repository_overrides: Optional[Sequence[str]] = None,
platform_overrides: Optional[Sequence[str]] = None,
required_categories: Optional[AbstractSet[str]] = None,
allow_pypi_requests_overrides: Optional[bool] = None,
) -> LockSpecification:
"""Generate the lockfile specs from a set of input src_files. If required_categories is set filter out specs that do not match those"""
platforms = (
Expand Down Expand Up @@ -124,11 +125,16 @@ def dep_has_category(d: Dependency, categories: AbstractSet[str]) -> bool:
]
for platform, dependencies in aggregated_lock_spec.dependencies.items()
}

if allow_pypi_requests_overrides is None:
allow_pypi_requests = aggregated_lock_spec.allow_pypi_requests
else:
allow_pypi_requests = (
allow_pypi_requests_overrides and aggregated_lock_spec.allow_pypi_requests
)
return LockSpecification(
dependencies=dependencies,
channels=channels,
pip_repositories=pip_repositories,
sources=aggregated_lock_spec.sources,
allow_pypi_requests=aggregated_lock_spec.allow_pypi_requests,
allow_pypi_requests=allow_pypi_requests,
)

0 comments on commit 436b16b

Please sign in to comment.