Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed May 1, 2024
1 parent f2b535c commit df48cf2
Show file tree
Hide file tree
Showing 12 changed files with 4,304 additions and 2,650 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

pages:
runs-on: ubuntu-latest
if: false
if: false
# disable til moved to conda-incubator
# github.ref == 'refs/heads/main'
needs: [docs]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ dmypy.json
.pyre/

# pixi
.pixi/
.pixi/
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# disable autofixing PRs, commenting "pre-commit.ci autofix" on a pull request triggers a autofix
ci:
autofix_prs: false
# generally speaking we ignore all vendored code as well as tests data
# TODO: Restore index and solver exclude lines before merge
exclude: |
(?x)^(
tests/data/.* |
conda_pypi/data/.* |
pixi.lock
)$
repos:
# generic verification and formatting
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
# standard end of line/end of file cleanup
- id: mixed-line-ending
- id: end-of-file-fixer
- id: trailing-whitespace
# ensure syntaxes are valid
- id: check-toml
- id: check-yaml
exclude: |
(?x)^(
(conda\.)?recipe/meta.yaml
)
# catch git merge/rebase problems
- id: check-merge-conflict
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
# auto format Python codes within docstrings
- id: blacken-docs
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
# lint & attempt to correct failures (e.g. pyupgrade)
- id: ruff
args: [--fix]
# compatible replacement for black
- id: ruff-format
- repo: meta
# see https://pre-commit.com/#meta-hooks
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: local
hooks:
- id: git-diff
name: git diff
entry: git diff --exit-code
language: system
pass_filenames: false
always_run: true
8 changes: 7 additions & 1 deletion conda_pypi/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
conda pip subcommand for CLI
"""

from __future__ import annotations

import argparse
Expand Down Expand Up @@ -69,7 +70,12 @@ def execute(args: argparse.Namespace) -> int:
from conda.common.io import Spinner
from conda.models.match_spec import MatchSpec
from .dependencies import analyze_dependencies
from .main import (validate_target_env, ensure_externally_managed, run_conda_install, run_pip_install)
from .main import (
validate_target_env,
ensure_externally_managed,
run_conda_install,
run_pip_install,
)
from .utils import get_prefix

prefix = get_prefix(args.prefix, args.name)
Expand Down
3 changes: 2 additions & 1 deletion conda_pypi/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .cli import configure_parser, execute
from .main import ensure_target_env_has_externally_managed


@plugins.hookimpl
def conda_subcommands():
yield plugins.CondaSubcommand(
Expand All @@ -19,4 +20,4 @@ def conda_post_commands():
name="conda-pypi-ensure-target-env-has-externally-managed",
action=ensure_target_env_has_externally_managed,
run_for={"install", "create", "update", "remove"},
)
)
3 changes: 2 additions & 1 deletion conda_pypi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ def get_externally_managed_path(prefix: os.PathLike = None) -> Iterator[Path]:
if not found:
raise ValueError("Could not locate EXTERNALLY-MANAGED file")


def pypi_spec_variants(spec_str: str) -> Iterator[str]:
yield spec_str
spec = MatchSpec(spec_str)
seen = {spec_str}
for name_variant in (
spec.name.replace("-", "_"),
spec.name.replace("_", "-"),
):
):
if name_variant not in seen: # only yield if actually different
yield str(MatchSpec(spec, name=name_variant))
seen.add(name_variant)
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Welcome to the conda-pypi documentation!
```{toctree}
quickstart
why
```
```
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ This package is not available on conda-forge. We will analyze the dependency tre

This file is designed after [PEP668](https://peps.python.org/pep-0668/). You can read more about in [Externally Managed Environments at packaging.python.org](https://packaging.python.org/en/latest/specifications/externally-managed-environments/).

Essentially, the presence of this file in a given environment will prevent users from using `pip` directly on them. An [informative error message](https://github.com/jaimergp/conda-pip/blob/main/conda_pypi/data/EXTERNALLY-MANAGED) is provided instead.
Essentially, the presence of this file in a given environment will prevent users from using `pip` directly on them. An [informative error message](https://github.com/jaimergp/conda-pip/blob/main/conda_pypi/data/EXTERNALLY-MANAGED) is provided instead.
Loading

0 comments on commit df48cf2

Please sign in to comment.