Skip to content

Commit

Permalink
feat: add exception types to Python bindings (conda#379)
Browse files Browse the repository at this point in the history
Co-authored-by: Wackyator <[email protected]>
  • Loading branch information
baszalmstra and Wackyator authored Oct 13, 2023
1 parent 0993ca2 commit 59494ef
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 4 deletions.
3 changes: 3 additions & 0 deletions py-rattler/docs/activation_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ActivationError

::: rattler.exceptions.ActivationError
3 changes: 3 additions & 0 deletions py-rattler/docs/cache_dir_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CacheDirError

::: rattler.exceptions.CacheDirError
4 changes: 4 additions & 0 deletions py-rattler/docs/detect_virtual_package_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# DetectVirtualPackageError

::: rattler.exceptions.DetectVirtualPackageError

4 changes: 4 additions & 0 deletions py-rattler/docs/fetch_repo_data_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# FetchRepoDataError

::: rattler.exceptions.FetchRepoDataError

4 changes: 4 additions & 0 deletions py-rattler/docs/invalid_channel_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# InvalidChannelError

::: rattler.exceptions.InvalidChannelError

4 changes: 4 additions & 0 deletions py-rattler/docs/invalid_match_spec_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# InvalidMatchSpecError

::: rattler.exceptions.InvalidMatchSpecError

4 changes: 4 additions & 0 deletions py-rattler/docs/invalid_package_name_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# InvalidPackageNameError

::: rattler.exceptions.InvalidPackageNameError

4 changes: 4 additions & 0 deletions py-rattler/docs/invalid_url_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# InvalidUrlError

::: rattler.exceptions.InvalidUrlError

4 changes: 4 additions & 0 deletions py-rattler/docs/invalid_version_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# InvalidVersionError

::: rattler.exceptions.InvalidVersionError

4 changes: 4 additions & 0 deletions py-rattler/docs/io_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# IoError

::: rattler.exceptions.IoError

4 changes: 4 additions & 0 deletions py-rattler/docs/link_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# LinkError

::: rattler.exceptions.LinkError

4 changes: 4 additions & 0 deletions py-rattler/docs/parse_arch_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ParseArchError

::: rattler.exceptions.ParseArchError

4 changes: 4 additions & 0 deletions py-rattler/docs/parse_platform_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ParsePlatformError

::: rattler.exceptions.ParsePlatformError

3 changes: 3 additions & 0 deletions py-rattler/docs/solver_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# solver_error

::: rattler.exceptions.SolverError
4 changes: 4 additions & 0 deletions py-rattler/docs/transaction_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TransactionError

::: rattler.exceptions.TransactionError

16 changes: 16 additions & 0 deletions py-rattler/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ nav:
- ActivationVariables: activation_variables.md
- Shell: shell.md
- PathModificationBehavior: path_modification_behavior.md
- exceptions:
- ActivationError: activation_error.md
- CacheDirError: cache_dir_error.md
- DetectVirtualPackageError: detect_virtual_package_error.md
- FetchRepoDataError: fetch_repo_data_error.md
- InvalidChannelError: invalid_channel_error.md
- InvalidMatchSpecError: invalid_match_spec_error.md
- InvalidPackageNameError: invalid_package_name_error.md
- InvalidUrlError: invalid_url_error.md
- InvalidVersionError: invalid_version_error.md
- IoError: io_error.md
- LinkError: link_error.md
- ParseArchError: parse_arch_error.md
- ParsePlatformError: parse_platform_error.md
- SolverError: solver_error.md
- TransactionError: transaction_error.md

plugins:
- mkdocstrings:
Expand Down
85 changes: 85 additions & 0 deletions py-rattler/rattler/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
try:
from rattler.rattler import (
InvalidVersionError,
InvalidMatchSpecError,
InvalidPackageNameError,
InvalidUrlError,
InvalidChannelError,
ActivationError,
ParsePlatformError,
ParseArchError,
TransactionError,
LinkError,
IoError,
DetectVirtualPackageError,
CacheDirError,
FetchRepoDataError,
SolverError,
)
except ImportError:
# They are only redefined for documentation purposes
# when there is no binary yet

class InvalidVersionError(Exception): # type: ignore[no-redef]
"""Error that can occur when parsing a Version"""

class InvalidMatchSpecError(Exception): # type: ignore[no-redef]
"""Error that can occur when parsing a MatchSpec"""

class InvalidPackageNameError(Exception): # type: ignore[no-redef]
"""Error that can occur when parsing a package name"""

class InvalidUrlError(Exception): # type: ignore[no-redef]
"""Error that can occur when parsing a URL"""

class InvalidChannelError(Exception): # type: ignore[no-redef]
"""Error that can occur when parsing a channel."""

class ActivationError(Exception): # type: ignore[no-redef]
"""Error that can occur when activating a conda environment"""

class ParsePlatformError(Exception): # type: ignore[no-redef]
"""An error that can occur when parsing a platform from a string."""

class ParseArchError(Exception): # type: ignore[no-redef]
"""An error that can occur when parsing an arch from a string."""

class TransactionError(Exception): # type: ignore[no-redef]
"""An error that can occur when executing a transaction"""

class LinkError(Exception): # type: ignore[no-redef]
"""An error that can occur when linking a package"""

class IoError(Exception): # type: ignore[no-redef]
"""An error that can occur during io operations"""

class DetectVirtualPackageError(Exception): # type: ignore[no-redef]
"""An error that can occur when trying to detect virtual packages"""

class CacheDirError(Exception): # type: ignore[no-redef]
"""An error that can occur when querying the cache directory"""

class FetchRepoDataError(Exception): # type: ignore[no-redef]
"""An error that can occur when fetching repo data"""

class SolverError(Exception): # type: ignore[no-redef]
"""An error that can occur when trying to solve an environment"""


__all__ = [
"ActivationError",
"CacheDirError",
"DetectVirtualPackageError",
"FetchRepoDataError",
"InvalidChannelError",
"InvalidMatchSpecError",
"InvalidPackageNameError",
"InvalidUrlError",
"InvalidVersionError",
"IoError",
"LinkError",
"ParseArchError",
"ParsePlatformError",
"SolverError",
"TransactionError",
]
26 changes: 22 additions & 4 deletions py-rattler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ mod virtual_package;

use channel::{PyChannel, PyChannelConfig};
use error::{
ActivationException, InvalidChannelException, InvalidMatchSpecException,
InvalidPackageNameException, InvalidUrlException, InvalidVersionException, ParseArchException,
ParsePlatformException, PyRattlerError,
ActivationException, CacheDirException, DetectVirtualPackageException, FetchRepoDataException,
InvalidChannelException, InvalidMatchSpecException, InvalidPackageNameException,
InvalidUrlException, InvalidVersionException, IoException, LinkException, ParseArchException,
ParsePlatformException, PyRattlerError, SolverException, TransactionException,
};
use generic_virtual_package::PyGenericVirtualPackage;
use match_spec::PyMatchSpec;
Expand Down Expand Up @@ -116,6 +117,23 @@ fn rattler(py: Python, m: &PyModule) -> PyResult<()> {
.unwrap();
m.add("ParseArchError", py.get_type::<ParseArchException>())
.unwrap();

m.add("SolverError", py.get_type::<SolverException>())
.unwrap();
m.add("TransactionError", py.get_type::<TransactionException>())
.unwrap();
m.add("LinkError", py.get_type::<LinkException>()).unwrap();
m.add("IoError", py.get_type::<IoException>()).unwrap();
m.add(
"DetectVirtualPackageError",
py.get_type::<DetectVirtualPackageException>(),
)
.unwrap();
m.add("CacheDirError", py.get_type::<CacheDirException>())
.unwrap();
m.add(
"FetchRepoDataError",
py.get_type::<FetchRepoDataException>(),
)
.unwrap();
Ok(())
}

0 comments on commit 59494ef

Please sign in to comment.