Skip to content

Commit 25d97b7

Browse files
v0.5.4 - Py <3.11 crash fix
1 parent 0c69a67 commit 25d97b7

3 files changed

Lines changed: 205 additions & 7 deletions

File tree

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: Build, test n' release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches: [main]
9+
workflow_dispatch:
10+
inputs:
11+
version:
12+
description: "Version to release (e.g. 0.5.4 or 0.6.0-beta). Leave empty to use rites/_version.py"
13+
required: false
14+
type: string
15+
16+
jobs:
17+
test:
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-latest, windows-latest, macos-latest]
23+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Set up Python ${{ matrix.python-version }}
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
- name: Install package
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install .
37+
38+
- name: Smoke test (import + run examples)
39+
run: python test.py
40+
41+
build-and-release:
42+
runs-on: ubuntu-latest
43+
needs: test
44+
if: github.ref == 'refs/heads/main'
45+
46+
permissions:
47+
contents: write
48+
id-token: write
49+
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
fetch-tags: true
56+
57+
- name: Determine version
58+
id: check_version
59+
run: |
60+
SHOULD_RELEASE=false
61+
VERSION=""
62+
63+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
64+
INPUT_VERSION="${{ github.event.inputs.version }}"
65+
if [[ -n "$INPUT_VERSION" ]]; then
66+
VERSION="${INPUT_VERSION#v}"
67+
else
68+
VERSION=$(grep -E '^__version__' rites/_version.py | sed -E 's/.*"([^"]+)".*/\1/')
69+
fi
70+
SHOULD_RELEASE=true
71+
else
72+
COMMIT_MSG=$(git log -1 --pretty=%B)
73+
echo "Commit message: $COMMIT_MSG"
74+
if [[ $COMMIT_MSG =~ v([0-9]+\.[0-9]+\.[0-9]+([-+][a-zA-Z0-9.-]+)?) ]]; then
75+
VERSION="${BASH_REMATCH[1]}"
76+
SHOULD_RELEASE=true
77+
fi
78+
fi
79+
80+
if [[ "$SHOULD_RELEASE" == "true" ]]; then
81+
TAG="v${VERSION}"
82+
echo "Releasing version: $VERSION (tag: $TAG)"
83+
echo "SHOULD_RELEASE=true" >> $GITHUB_OUTPUT
84+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
85+
echo "TAG=$TAG" >> $GITHUB_OUTPUT
86+
if [[ "$VERSION" == *"-"* || "$VERSION" == *"+"* ]]; then
87+
echo "PRERELEASE=true" >> $GITHUB_OUTPUT
88+
else
89+
echo "PRERELEASE=false" >> $GITHUB_OUTPUT
90+
fi
91+
else
92+
echo "No release version found; skipping release."
93+
echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT
94+
fi
95+
96+
- name: Set up Python
97+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
98+
uses: actions/setup-python@v5
99+
with:
100+
python-version: "3.x"
101+
102+
- name: Install build tooling
103+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
104+
run: |
105+
python -m pip install --upgrade pip
106+
python -m pip install build twine
107+
108+
- name: Sync version into rites/_version.py
109+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
110+
run: |
111+
python - <<'PY'
112+
import os, re
113+
v = os.environ["VERSION"]
114+
path = "rites/_version.py"
115+
with open(path, "r", encoding="utf-8") as f:
116+
content = f.read()
117+
new = re.sub(r'__version__\s*=\s*".*"', f'__version__ = "{v}"', content)
118+
with open(path, "w", encoding="utf-8") as f:
119+
f.write(new)
120+
print(f"Set version to {v}")
121+
PY
122+
env:
123+
VERSION: ${{ steps.check_version.outputs.VERSION }}
124+
125+
- name: Build sdist and wheel
126+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
127+
run: python -m build
128+
env:
129+
RITES_PKG_VERSION: ${{ steps.check_version.outputs.VERSION }}
130+
131+
- name: Get previous tag
132+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
133+
id: prev_tag
134+
run: |
135+
tag=$(git tag --sort=-creatordate | head -1 || true)
136+
echo "Most recent tag: $tag"
137+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
138+
139+
- name: Get commit log
140+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
141+
id: commit_log
142+
run: |
143+
if [ -z "${{ steps.prev_tag.outputs.tag }}" ]; then
144+
echo "log=- First release" >> "$GITHUB_OUTPUT"
145+
else
146+
TEMP_LOG=$(mktemp)
147+
git log ${{ steps.prev_tag.outputs.tag }}..HEAD --pretty=format:"- %s (%an)" > "$TEMP_LOG"
148+
DELIMITER="COMMIT_LOG_DELIMITER_$(date +%s)"
149+
echo "log<<$DELIMITER" >> "$GITHUB_OUTPUT"
150+
cat "$TEMP_LOG" >> "$GITHUB_OUTPUT"
151+
echo "" >> "$GITHUB_OUTPUT"
152+
echo "$DELIMITER" >> "$GITHUB_OUTPUT"
153+
rm "$TEMP_LOG"
154+
fi
155+
156+
- name: Create tag
157+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
158+
run: |
159+
git config --local user.email "action@github.com"
160+
git config --local user.name "GitHub Action"
161+
if git rev-parse "${{ steps.check_version.outputs.TAG }}" >/dev/null 2>&1; then
162+
echo "Tag ${{ steps.check_version.outputs.TAG }} already exists; skipping tag creation."
163+
else
164+
git tag -a ${{ steps.check_version.outputs.TAG }} -m "Release ${{ steps.check_version.outputs.TAG }}"
165+
git push origin ${{ steps.check_version.outputs.TAG }}
166+
fi
167+
168+
- name: Create GitHub Release
169+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
170+
uses: softprops/action-gh-release@v2
171+
with:
172+
tag_name: ${{ steps.check_version.outputs.TAG }}
173+
name: "rites ${{ steps.check_version.outputs.TAG }}"
174+
body: |
175+
## rites ${{ steps.check_version.outputs.TAG }}
176+
177+
### Changes
178+
${{ steps.commit_log.outputs.log }}
179+
180+
### Install
181+
```
182+
pip install rites==${{ steps.check_version.outputs.VERSION }}
183+
```
184+
draft: false
185+
prerelease: ${{ steps.check_version.outputs.PRERELEASE }}
186+
files: dist/*
187+
token: ${{ secrets.GITHUB_TOKEN }}
188+
189+
- name: Publish to PyPI
190+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
191+
uses: pypa/gh-action-pypi-publish@release/v1
192+
193+
- name: Upload build artifacts
194+
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
195+
uses: actions/upload-artifact@v4
196+
with:
197+
name: dist
198+
path: dist/*

rites/logger/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ def printable_timestamp(self) -> str:
8585
Returns:
8686
str: The formatted timestamp
8787
"""
88-
return f"{Fore.white}[{Style.reset}{self.printer.get_color("gray")}{self._get_inline_formatted_timestamp()}{Style.reset}{Fore.white}]{Style.reset}"
88+
return f"{Fore.white}[{Style.reset}{self.printer.get_color('gray')}{self._get_inline_formatted_timestamp()}{Style.reset}{Fore.white}]{Style.reset}"
8989

9090
def formatted_name(self) -> str:
9191
""" Returns a printable colored name
9292
9393
Returns:
9494
str: The formatted name
9595
"""
96-
return f"{self.printer.get_color("gray")}{self.name}{Style.reset}"
96+
return f"{self.printer.get_color('gray')}{self.name}{Style.reset}"
9797

9898
def add_custom(self, key: str, word: str, r: int, g: int, b: int):
9999
self.printer.add_style(key, word, r, g, b)

rites/rituals/printer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def print_warning(self, *txt):
8686
string = ""
8787
for substr in txt:
8888
string += str(substr) + " "
89-
print(f"{self.get_style("warning").get_str()} {Fore.white}{string}{Style.reset}")
89+
print(f"{self.get_style('warning').get_str()} {Fore.white}{string}{Style.reset}")
9090

9191
def print_error(self, *txt):
9292
""" Prints an error message
@@ -97,7 +97,7 @@ def print_error(self, *txt):
9797
string = ""
9898
for substr in txt:
9999
string += str(substr) + " "
100-
print(f"{self.get_style("error").get_str()} {Fore.white}{string}{Style.reset}")
100+
print(f"{self.get_style('error').get_str()} {Fore.white}{string}{Style.reset}")
101101

102102
def print_debug(self, *txt):
103103
""" Prints a debug message
@@ -108,7 +108,7 @@ def print_debug(self, *txt):
108108
string = ""
109109
for substr in txt:
110110
string += str(substr) + " "
111-
print(f"{self.get_style("debug").get_str()} {Fore.white}{string}{Style.reset}")
111+
print(f"{self.get_style('debug').get_str()} {Fore.white}{string}{Style.reset}")
112112

113113
def print_info(self, *txt):
114114
""" Prints an info message
@@ -119,7 +119,7 @@ def print_info(self, *txt):
119119
string = ""
120120
for substr in txt:
121121
string += str(substr) + " "
122-
print(f"{self.get_style("info").get_str()} {Fore.white}{string}{Style.reset}")
122+
print(f"{self.get_style('info').get_str()} {Fore.white}{string}{Style.reset}")
123123

124124
def print_success(self, *txt):
125125
""" Prints a success message
@@ -130,7 +130,7 @@ def print_success(self, *txt):
130130
string = ""
131131
for substr in txt:
132132
string += str(substr) + " "
133-
print(f"{self.get_style("success").get_str()} {Fore.white}{string}{Style.reset}")
133+
print(f"{self.get_style('success').get_str()} {Fore.white}{string}{Style.reset}")
134134

135135
def print_custom(self, style_key: str, *txt):
136136
""" Prints a message using the Style specified

0 commit comments

Comments
 (0)