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 committed Jan 26, 2024
1 parent 068bd19 commit 4ff30d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
28 changes: 24 additions & 4 deletions conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,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 @@ -332,14 +334,15 @@ def make_lock_files( # noqa: C901
required_categories.add("dev")
if extras is not None:
required_categories.update(extras)

with virtual_package_repo:
lock_spec = make_lock_spec(
src_files=src_files,
channel_overrides=channel_overrides,
platform_overrides=platform_overrides,
virtual_package_repo=virtual_package_repo,
required_categories=required_categories if filter_categories else None,
pip_repository_overrides=private_pip_repositories,
allow_pypi_requests_overrides=not disable_pypi_requests,
)
original_lock_content: Optional[Lockfile] = None

Expand Down Expand Up @@ -827,9 +830,7 @@ def create_lockfile_from_spec(
platforms = []
assert spec.virtual_package_repo is not None
virtual_package_channel = spec.virtual_package_repo.channel

locked: Dict[Tuple[str, str, str], LockedDependency] = {}

for platform in platforms or spec.platforms:
deps = _solve_for_arch(
conda=conda,
Expand Down Expand Up @@ -1069,6 +1070,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[List[str]] = None,
) -> None:
if environment_files == DEFAULT_FILES:
if lockfile_path.exists():
Expand Down Expand Up @@ -1121,6 +1124,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 @@ -1285,6 +1290,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 @@ -1299,6 +1316,8 @@ def lock(
filename_template: str,
lockfile: PathLike,
strip_auth: bool,
disable_pypi_requests: bool,
private_pip_repositories: List[str],
extras: List[str],
filter_categories: bool,
check_input_hash: bool,
Expand Down Expand Up @@ -1346,7 +1365,6 @@ def lock(
else:
print(ctx.get_help())
sys.exit(1)

if pdb:
sys.excepthook = _handle_exception_post_mortem

Expand Down Expand Up @@ -1384,6 +1402,8 @@ def lock(
metadata_choices=metadata_enum_choices,
metadata_yamls=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
11 changes: 6 additions & 5 deletions conda_lock/src_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ 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 = (
list(platform_overrides)
if platform_overrides
else _parse_platforms_from_srcs(src_files)
) or DEFAULT_PLATFORMS

lock_specs = _parse_source_files(src_files, platforms)

aggregated_lock_spec = aggregate_lock_specs(lock_specs, platforms)
Expand All @@ -99,7 +99,6 @@ def make_lock_spec(
if channel_overrides
else aggregated_lock_spec.channels
)

pip_repositories = (
[
PipRepository.from_string(repo_override)
Expand All @@ -108,7 +107,6 @@ def make_lock_spec(
if pip_repository_overrides
else aggregated_lock_spec.pip_repositories
)

if required_categories is None:
dependencies = aggregated_lock_spec.dependencies
else:
Expand All @@ -125,12 +123,15 @@ 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,
virtual_package_repo=virtual_package_repo,
allow_pypi_requests=aggregated_lock_spec.allow_pypi_requests,
allow_pypi_requests=allow_pypi_requests,
)

0 comments on commit 4ff30d1

Please sign in to comment.