Skip to content

Commit 1759fd2

Browse files
authored
drop python 3.7, upgrade dependencies (#28)
1 parent b7420ca commit 1759fd2

File tree

18 files changed

+319
-687
lines changed

18 files changed

+319
-687
lines changed

.github/workflows/lint.yaml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
14+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- uses: actions/setup-python@v4
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
1919
with:
2020
python-version: ${{ matrix.python-version }}
21-
- uses: abatilo/actions-poetry@v2
22-
with:
23-
poetry-version: "1.2.2"
24-
- run: poetry config virtualenvs.create false
25-
- run: poetry install -E pygments -E rich
26-
- run: isort --check .
27-
- run: black --check .
28-
- run: pylint catppuccin
29-
- run: mypy .
21+
- uses: abatilo/actions-poetry@v3
22+
- run: poetry install --all-extras
23+
- run: poetry run ruff check
24+
- run: poetry run ruff format --check --diff
25+
- run: poetry run mypy .

.github/workflows/publish.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ jobs:
66
publish:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010
with:
1111
fetch-depth: 0
12-
- uses: actions/setup-python@v4
12+
- uses: actions/setup-python@v5
1313
with:
14-
python-version: "3.11"
14+
python-version: "3.12"
1515
- uses: abatilo/actions-poetry@v2
16-
with:
17-
poetry-version: "1.2.2"
1816
- run: poetry self add "poetry-dynamic-versioning[plugin]"
19-
- run: poetry config virtualenvs.create false
2017
- run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
21-
- run: poetry build
22-
- run: poetry publish
18+
- run: poetry publish --build

.github/workflows/test.yaml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
14+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- uses: actions/setup-python@v4
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
1919
with:
2020
python-version: ${{ matrix.python-version }}
21-
- uses: abatilo/actions-poetry@v2
22-
with:
23-
poetry-version: "1.2.2"
24-
- run: poetry config virtualenvs.create false
25-
- run: poetry install -E pygments
26-
- run: pytest --cov catppuccin
21+
- uses: abatilo/actions-poetry@v3
22+
- run: poetry install --all-extras
23+
- run: poetry run pytest --cov catppuccin

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ instructions](https://python-poetry.org/docs/#installation).
105105
Install the project's dependencies including extras:
106106

107107
```bash
108-
poetry install -E pygments
108+
poetry install --all-extras
109109
```
110110

111111
#### Code Standards
@@ -114,9 +114,8 @@ Before committing changes, it is recommended to run the following tools to
114114
ensure consistency in the codebase.
115115

116116
```bash
117-
isort .
118-
black .
119-
pylint catppuccin
117+
ruff format
118+
ruff check
120119
mypy .
121120
pytest --cov catppuccin
122121
```
@@ -128,7 +127,7 @@ path.
128127

129128
## 💝 Thanks to
130129

131-
- [backwardspy](https://github.com/backwardspy)
130+
- [backwardspy](https://github.com/backwardspy)
132131

133132
 
134133

catppuccin/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
"""🐍 Soothing pastel theme for Python."""
2-
from catppuccin.colour import Colour as Colour
3-
from catppuccin.flavour import Flavour as Flavour
2+
from catppuccin.colour import Colour
3+
from catppuccin.flavour import Flavour
4+
5+
__all__ = ["Colour", "Flavour"]

catppuccin/colour.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
"""
2-
Functionality relating to individual colours.
3-
"""
1+
"""Functionality relating to individual colours."""
42
from __future__ import annotations
53

64
import re
75
from dataclasses import dataclass
8-
from typing import Any, Tuple
96

107
from catppuccin.hsl import rgb_to_hsl
118

9+
HEXLEN_NO_ALPHA = 6
10+
HEXLEN_ALPHA = 8
11+
MAX_ALPHA = 255
12+
1213

1314
@dataclass(frozen=True)
1415
class Colour:
@@ -17,58 +18,70 @@ class Colour:
1718
red: int
1819
green: int
1920
blue: int
20-
alpha: int = 255
21+
alpha: int = MAX_ALPHA
2122

2223
@property
23-
def rgb(self) -> Tuple[int, int, int]:
24+
def rgb(self) -> tuple[int, int, int]:
2425
"""Get the colour as a 3-tuple of red, green, and blue."""
2526
return self.red, self.green, self.blue
2627

2728
@property
28-
def rgba(self) -> Tuple[int, int, int, int]:
29+
def rgba(self) -> tuple[int, int, int, int]:
2930
"""Get the colour as a 4-tuple of red, green, blue, and alpha."""
3031
return self.red, self.green, self.blue, self.alpha
3132

3233
@property
33-
def hsl(self) -> Tuple[float, float, float]:
34+
def hsl(self) -> tuple[float, float, float]:
3435
"""Get the colour as a 3-tuple of hue, saturation, and lightness."""
3536
return rgb_to_hsl(*self.rgb)
3637

3738
@property
38-
def hsla(self) -> Tuple[float, float, float, float]:
39+
def hsla(self) -> tuple[float, float, float, float]:
3940
"""Get the colour as a 4-tuple of hue, saturation, lightness, and alpha."""
4041
return (*self.hsl, self.alpha)
4142

4243
@property
4344
def hex(self) -> str:
4445
"""Get the colour as a lowercase hex string."""
45-
if self.alpha < 255:
46+
if self.alpha < MAX_ALPHA:
4647
return f"{self.red:02x}{self.green:02x}{self.blue:02x}{self.alpha:02x}"
4748
return f"{self.red:02x}{self.green:02x}{self.blue:02x}"
4849

49-
def __eq__(self, other: Any) -> bool:
50+
def __eq__(self, other: object) -> bool:
51+
"""Check equality against another colour."""
5052
if not isinstance(other, Colour):
51-
raise ValueError("Cannot check equality with non-colour types.")
53+
e = "Cannot check equality with non-colour types."
54+
raise TypeError(e)
5255

5356
return self.hex == other.hex
5457

5558
@classmethod
5659
def from_hex(cls, hex_string: str) -> Colour:
5760
"""Create a colour from hex string."""
58-
if len(hex_string) not in (6, 8):
59-
raise ValueError("Hex string must be 6 or 8 characters long.")
60-
61-
num_groups = 3 if len(hex_string) == 6 else 4
61+
if len(hex_string) not in (HEXLEN_NO_ALPHA, HEXLEN_ALPHA):
62+
e = (
63+
f"Hex string must be {HEXLEN_NO_ALPHA} or "
64+
f"{HEXLEN_ALPHA} characters long."
65+
)
66+
raise ValueError(e)
67+
68+
num_groups = (
69+
HEXLEN_NO_ALPHA // 2
70+
if len(hex_string) == HEXLEN_NO_ALPHA
71+
else HEXLEN_ALPHA // 2
72+
)
6273
match = re.match(r"([\da-fA-F]{2})" * num_groups, hex_string)
6374
if match is None:
64-
raise ValueError("Hex string has an invalid format.")
75+
e = "Hex string has an invalid format."
76+
raise ValueError(e)
6577

6678
components = (int(col, 16) for col in match.groups())
6779
return Colour(*components)
6880

6981
def opacity(self, opacity: float) -> Colour:
7082
"""Return a new colour with the given opacity."""
7183
if not 0 <= opacity <= 1:
72-
raise ValueError("Opacity must be between 0 and 1.")
84+
e = "Opacity must be between 0 and 1."
85+
raise ValueError(e)
7386

74-
return Colour(self.red, self.green, self.blue, int(opacity * 255))
87+
return Colour(self.red, self.green, self.blue, int(opacity * MAX_ALPHA))

catppuccin/extras/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""The extras submodule contains code for integration with other packages."""

catppuccin/extras/pygments.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""
2-
Pygments styles for all Catppuccin flavours.
3-
"""
4-
from typing import Dict
1+
"""Pygments styles for all Catppuccin flavours."""
2+
from __future__ import annotations
53

64
from pygments.style import Style
75
from pygments.token import (
@@ -23,7 +21,7 @@
2321
from catppuccin.flavour import Flavour
2422

2523

26-
def _make_styles(flavour: Flavour) -> Dict[_TokenType, str]:
24+
def _make_styles(flavour: Flavour) -> dict[_TokenType, str]:
2725
return {
2826
Token: f"#{flavour.text.hex}",
2927
Text: f"#{flavour.text.hex}",
@@ -53,7 +51,7 @@ def _make_styles(flavour: Flavour) -> Dict[_TokenType, str]:
5351
}
5452

5553

56-
class LatteStyle(Style): # pylint: disable=too-few-public-methods
54+
class LatteStyle(Style):
5755
"""Catppuccin Latte pygments style."""
5856

5957
_flavour = Flavour.latte()
@@ -65,7 +63,7 @@ class LatteStyle(Style): # pylint: disable=too-few-public-methods
6563
styles = _make_styles(_flavour)
6664

6765

68-
class FrappeStyle(Style): # pylint: disable=too-few-public-methods
66+
class FrappeStyle(Style):
6967
"""Catppuccin Frappé pygments style."""
7068

7169
_flavour = Flavour.frappe()
@@ -77,7 +75,7 @@ class FrappeStyle(Style): # pylint: disable=too-few-public-methods
7775
styles = _make_styles(_flavour)
7876

7977

80-
class MacchiatoStyle(Style): # pylint: disable=too-few-public-methods
78+
class MacchiatoStyle(Style):
8179
"""Catppuccin Macchiato pygments style."""
8280

8381
_flavour = Flavour.macchiato()
@@ -89,7 +87,7 @@ class MacchiatoStyle(Style): # pylint: disable=too-few-public-methods
8987
styles = _make_styles(_flavour)
9088

9189

92-
class MochaStyle(Style): # pylint: disable=too-few-public-methods
90+
class MochaStyle(Style):
9391
"""Catppuccin Mocha pygments style."""
9492

9593
_flavour = Flavour.mocha()

catppuccin/extras/rich_ctp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Rich themes for all Catppuccin flavours.
3-
"""
1+
"""Rich themes for all Catppuccin flavours."""
42
from rich.theme import Theme
53

64
from catppuccin.flavour import Flavour
@@ -35,7 +33,7 @@ def _make_theme(flavour: Flavour) -> Theme:
3533
"base": f"#{flavour.base.hex}",
3634
"mantle": f"#{flavour.mantle.hex}",
3735
"crust": f"#{flavour.crust.hex}",
38-
}
36+
},
3937
)
4038

4139

catppuccin/flavour.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""
2-
Functionality relating to Catppuccin flavours.
1+
"""Functionality relating to Catppuccin flavours.
2+
33
A flavour is a collection of colours.
44
"""
55
from dataclasses import dataclass
@@ -8,7 +8,7 @@
88

99

1010
@dataclass(frozen=True)
11-
class Flavour: # pylint: disable=too-many-instance-attributes
11+
class Flavour:
1212
"""All the colours in a flavour of Catppuccin."""
1313

1414
name: str

0 commit comments

Comments
 (0)