milieux.errors

 1from pathlib import Path
 2from typing import Union
 3
 4from milieux.utils import distro_sty, env_sty
 5
 6
 7class MilieuxError(ValueError):
 8    """Custom class for errors meant to be handled gracefully."""
 9
10class UserInputError(MilieuxError):
11    """Error for invalid user input."""
12
13class ConfigNotFoundError(MilieuxError):
14    """Error for when the user's config file cannot be found."""
15
16class DistroError(MilieuxError):
17    """Error related to a distro."""
18
19class DistroExistsError(DistroError):
20    """Error for when a distro already exists."""
21
22class NoSuchDistroError(DistroError):
23    """Error for when a distribution does not exist."""
24    def __init__(self, distro_name: str) -> None:
25        self.distro_name = distro_name
26        super().__init__(f'No distro named {distro_sty(distro_name)}')
27
28class InvalidDistroError(DistroError):
29    """Error for when a distro is invalid."""
30
31class EnvError(MilieuxError):
32    """Error related to an environment."""
33
34class EnvironmentExistsError(EnvError):
35    """Error for when an environment already exists."""
36
37class NoSuchEnvironmentError(EnvError):
38    """Error for when an environment does not exist."""
39    def __init__(self, env_name: str) -> None:
40        self.env_name = env_name
41        super().__init__(f'No environment named {env_sty(env_name)}')
42
43class NoPackagesError(MilieuxError):
44    """Error for when no packages are provided."""
45
46class NoSuchRequirementsFileError(MilieuxError):
47    """Error for when a requirements file does not exist."""
48    def __init__(self, reqs_path: Union[str, Path]) -> None:
49        self.reqs_path = reqs_path
50        super().__init__(f'No requirements file: {reqs_path}')
51
52class TemplateError(MilieuxError):
53    """Error involving a jinja template."""
54
55class NoSuchTemplateError(TemplateError):
56    """Error for when a template file does not exist."""
57    def __init__(self, template_file: Union[str, Path]) -> None:
58        self.template_file = template_file
59        super().__init__(f'Template file {template_file} does not exist')
class MilieuxError(builtins.ValueError):
8class MilieuxError(ValueError):
9    """Custom class for errors meant to be handled gracefully."""

Custom class for errors meant to be handled gracefully.

class UserInputError(MilieuxError):
11class UserInputError(MilieuxError):
12    """Error for invalid user input."""

Error for invalid user input.

class ConfigNotFoundError(MilieuxError):
14class ConfigNotFoundError(MilieuxError):
15    """Error for when the user's config file cannot be found."""

Error for when the user's config file cannot be found.

class DistroError(MilieuxError):
17class DistroError(MilieuxError):
18    """Error related to a distro."""

Error related to a distro.

class DistroExistsError(DistroError):
20class DistroExistsError(DistroError):
21    """Error for when a distro already exists."""

Error for when a distro already exists.

class NoSuchDistroError(DistroError):
23class NoSuchDistroError(DistroError):
24    """Error for when a distribution does not exist."""
25    def __init__(self, distro_name: str) -> None:
26        self.distro_name = distro_name
27        super().__init__(f'No distro named {distro_sty(distro_name)}')

Error for when a distribution does not exist.

NoSuchDistroError(distro_name: str)
25    def __init__(self, distro_name: str) -> None:
26        self.distro_name = distro_name
27        super().__init__(f'No distro named {distro_sty(distro_name)}')
distro_name
class InvalidDistroError(DistroError):
29class InvalidDistroError(DistroError):
30    """Error for when a distro is invalid."""

Error for when a distro is invalid.

class EnvError(MilieuxError):
32class EnvError(MilieuxError):
33    """Error related to an environment."""

Error related to an environment.

class EnvironmentExistsError(EnvError):
35class EnvironmentExistsError(EnvError):
36    """Error for when an environment already exists."""

Error for when an environment already exists.

class NoSuchEnvironmentError(EnvError):
38class NoSuchEnvironmentError(EnvError):
39    """Error for when an environment does not exist."""
40    def __init__(self, env_name: str) -> None:
41        self.env_name = env_name
42        super().__init__(f'No environment named {env_sty(env_name)}')

Error for when an environment does not exist.

NoSuchEnvironmentError(env_name: str)
40    def __init__(self, env_name: str) -> None:
41        self.env_name = env_name
42        super().__init__(f'No environment named {env_sty(env_name)}')
env_name
class NoPackagesError(MilieuxError):
44class NoPackagesError(MilieuxError):
45    """Error for when no packages are provided."""

Error for when no packages are provided.

class NoSuchRequirementsFileError(MilieuxError):
47class NoSuchRequirementsFileError(MilieuxError):
48    """Error for when a requirements file does not exist."""
49    def __init__(self, reqs_path: Union[str, Path]) -> None:
50        self.reqs_path = reqs_path
51        super().__init__(f'No requirements file: {reqs_path}')

Error for when a requirements file does not exist.

NoSuchRequirementsFileError(reqs_path: Union[str, pathlib.Path])
49    def __init__(self, reqs_path: Union[str, Path]) -> None:
50        self.reqs_path = reqs_path
51        super().__init__(f'No requirements file: {reqs_path}')
reqs_path
class TemplateError(MilieuxError):
53class TemplateError(MilieuxError):
54    """Error involving a jinja template."""

Error involving a jinja template.

class NoSuchTemplateError(TemplateError):
56class NoSuchTemplateError(TemplateError):
57    """Error for when a template file does not exist."""
58    def __init__(self, template_file: Union[str, Path]) -> None:
59        self.template_file = template_file
60        super().__init__(f'Template file {template_file} does not exist')

Error for when a template file does not exist.

NoSuchTemplateError(template_file: Union[str, pathlib.Path])
58    def __init__(self, template_file: Union[str, Path]) -> None:
59        self.template_file = template_file
60        super().__init__(f'Template file {template_file} does not exist')
template_file