Skip to content

Commit

Permalink
Merge pull request conda#12554 from kenodegard/black-isort
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard authored Mar 31, 2023
2 parents 86e8392 + 32f055e commit 435d7e4
Show file tree
Hide file tree
Showing 243 changed files with 21,087 additions and 13,434 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# pyupgrade generated (#11909)
fc92ea3353cce71df24fac31ce333ec9f8cf7ba7

# black & isort auto format (#12554)
7679aed18153056f140e56da98011e27ebf4feb1
41 changes: 27 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# disable autofixing PRs, commenting "pre-commit.ci autofix" on a pull request triggers a autofix
ci:
autofix_prs: false
autofix_prs: false
# generally speaking we ignore all vendored code as well as tests data
# ignore patches/diffs since slight reformatting can break them
exclude: |
(?x)^(
conda/_vendor |
conda/auxlib |
tests/data/(
conda_format_repo |
env_metadata/.+ |
Expand All @@ -13,9 +15,11 @@ exclude: |
tar_traversal |
corrupt
) |
.*\.(patch|diff) |
tools/vendoring/patches
)/
repos:
# generic verification and formatting
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -29,30 +33,39 @@ repos:
exclude: ^(conda\.)?recipe/meta.yaml
# catch git merge/rebase problems
- id: check-merge-conflict
# Python verification and formatting
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.4.2
hooks:
# auto inject license blurb
- id: insert-license
files: \.py$
args: [--license-filepath, .github/disclaimer.txt, --no-extra-eol]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
# upgrade standard Python codes
- id: pyupgrade
args: ["--py37-plus"]
args: [--py38-plus]
exclude: ^conda/exports.py
- repo: https://github.com/akaihola/darker
rev: 1.7.1
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
# auto sort Python imports
- id: isort
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: darker
additional_dependencies: [black==22.10.0]
- repo: https://github.com/asottile/blacken-docs
# auto format Python codes
- id: black
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.13.0
hooks:
# auto format Python codes within docstrings
- id: blacken-docs
additional_dependencies: [black]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
# lint Python codes
- id: flake8
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.4.2
hooks:
- id: insert-license
files: \.py$
args: [--license-filepath, .github/disclaimer.txt, --no-extra-eol]
exclude: ^conda/auxlib/
55 changes: 34 additions & 21 deletions conda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
"""OS-agnostic, system-level binary package manager."""
from json import JSONEncoder
import os
from os.path import abspath, dirname
import sys
from json import JSONEncoder
from os.path import abspath, dirname

from .__version__ import __version__
from .deprecations import deprecated


__all__ = (
"__name__", "__version__", "__author__", "__email__", "__license__", "__summary__", "__url__",
"CONDA_PACKAGE_ROOT", "CondaError", "CondaMultiError", "CondaExitZero", "conda_signal_handler",
"__name__",
"__version__",
"__author__",
"__email__",
"__license__",
"__summary__",
"__url__",
"CONDA_PACKAGE_ROOT",
"CondaError",
"CondaMultiError",
"CondaExitZero",
"conda_signal_handler",
"__copyright__",
)

Expand Down Expand Up @@ -40,6 +49,7 @@
def another_to_unicode(val):
return val


class CondaError(Exception):
return_code = 1
reportable = False # Exception may be reported to core maintainers
Expand All @@ -57,14 +67,16 @@ def __str__(self):
try:
return str(self.message % self._kwargs)
except Exception:
debug_message = "\n".join((
"class: " + self.__class__.__name__,
"message:",
self.message,
"kwargs:",
str(self._kwargs),
"",
))
debug_message = "\n".join(
(
"class: " + self.__class__.__name__,
"message:",
self.message,
"kwargs:",
str(self._kwargs),
"",
)
)
print(debug_message, file=sys.stderr)
raise

Expand All @@ -76,13 +88,12 @@ def dump_map(self):
message=str(self),
error=repr(self),
caused_by=repr(self._caused_by),
**self._kwargs
**self._kwargs,
)
return result


class CondaMultiError(CondaError):

def __init__(self, errors):
self.errors = errors
super().__init__(None)
Expand All @@ -97,18 +108,19 @@ def __repr__(self):
# by using e.__repr__() instead of repr(e)
# https://github.com/scrapy/cssselect/issues/34
errs.append(e.__repr__())
res = '\n'.join(errs)
res = "\n".join(errs)
return res

def __str__(self):
return "\n".join(str(e) for e in self.errors) + "\n"

def dump_map(self):
return dict(exception_type=str(type(self)),
exception_name=self.__class__.__name__,
errors=tuple(error.dump_map() for error in self.errors),
error="Multiple Errors Encountered.",
)
return dict(
exception_type=str(type(self)),
exception_name=self.__class__.__name__,
errors=tuple(error.dump_map() for error in self.errors),
error="Multiple Errors Encountered.",
)

def contains(self, exception_class):
return any(isinstance(e, exception_class) for e in self.errors)
Expand All @@ -130,6 +142,7 @@ def conda_signal_handler(signum, frame):
p.send_signal(signum)

from .exceptions import CondaSignalInterrupt

raise CondaSignalInterrupt(signum)


Expand Down
Loading

0 comments on commit 435d7e4

Please sign in to comment.