meme-errors 0.1.5__tar.gz → 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {meme_errors-0.1.5 → meme_errors-0.1.7}/PKG-INFO +1 -2
- meme_errors-0.1.7/meme_errors/__init__.py +85 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors.egg-info/PKG-INFO +1 -2
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors.egg-info/requires.txt +0 -1
- {meme_errors-0.1.5 → meme_errors-0.1.7}/setup.cfg +1 -2
- meme_errors-0.1.5/meme_errors/__init__.py +0 -68
- {meme_errors-0.1.5 → meme_errors-0.1.7}/MANIFEST.in +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/README.md +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors/sounds/__init__.py +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors/sounds/emotional-damage-meme.mp3 +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors/sounds/galaxy-meme.mp3 +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors/sounds/movie_1_C2K5NH0.mp3 +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors.egg-info/SOURCES.txt +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors.egg-info/dependency_links.txt +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/meme_errors.egg-info/top_level.txt +0 -0
- {meme_errors-0.1.5 → meme_errors-0.1.7}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meme-errors
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: Play funny meme sounds when Python errors occur!
|
|
5
5
|
Home-page: https://github.com/JAY-MU-4098/meme_errors
|
|
6
6
|
Author: Jay Gogra
|
|
@@ -10,7 +10,6 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
12
|
Requires-Dist: pygame
|
|
13
|
-
Requires-Dist: pydub
|
|
14
13
|
|
|
15
14
|
# Meme Errors
|
|
16
15
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import pygame
|
|
5
|
+
import importlib.resources as resources
|
|
6
|
+
from . import sounds
|
|
7
|
+
|
|
8
|
+
# Initialize pygame mixer once
|
|
9
|
+
pygame.mixer.init()
|
|
10
|
+
|
|
11
|
+
DEFAULT_SOUNDS = {
|
|
12
|
+
"TypeError": "emotional-damage-meme.mp3",
|
|
13
|
+
"FileNotFoundError": "galaxy-meme.mp3",
|
|
14
|
+
"Exception": "movie_1_C2K5NH0.mp3"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def play_meme_sound(exc_type, duration_ms=3000):
|
|
19
|
+
# Get sound file based on exception name
|
|
20
|
+
sound_file = DEFAULT_SOUNDS.get(exc_type.__name__, DEFAULT_SOUNDS["Exception"])
|
|
21
|
+
try:
|
|
22
|
+
# Get path directly from package resources
|
|
23
|
+
traversable = resources.files(sounds).joinpath(sound_file)
|
|
24
|
+
|
|
25
|
+
with resources.as_file(traversable) as path:
|
|
26
|
+
pygame.mixer.music.load(str(path))
|
|
27
|
+
pygame.mixer.music.play()
|
|
28
|
+
|
|
29
|
+
# This loop waits for the sound to finish
|
|
30
|
+
# To limit to 3 seconds, you can add a counter here
|
|
31
|
+
start_time = pygame.time.get_ticks()
|
|
32
|
+
while pygame.mixer.music.get_busy():
|
|
33
|
+
# Stop if it exceeds 3 seconds (3000ms)
|
|
34
|
+
if pygame.time.get_ticks() - start_time > duration_ms:
|
|
35
|
+
pygame.mixer.music.stop()
|
|
36
|
+
break
|
|
37
|
+
pygame.time.Clock().tick(10)
|
|
38
|
+
|
|
39
|
+
except Exception as e:
|
|
40
|
+
# Silently fail so we don't cause an error during an error
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def meme_excepthook(exc_type, exc_value, traceback):
|
|
45
|
+
play_meme_sound(exc_type)
|
|
46
|
+
sys.__excepthook__(exc_type, exc_value, traceback)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Global hook
|
|
50
|
+
sys.excepthook = meme_excepthook
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Decorator for function-level errors
|
|
54
|
+
def meme_sound_on_error(func=None, *, duration_ms=3000):
|
|
55
|
+
"""
|
|
56
|
+
Usage:
|
|
57
|
+
|
|
58
|
+
@meme_sound_on_error
|
|
59
|
+
def func(): ...
|
|
60
|
+
|
|
61
|
+
OR
|
|
62
|
+
|
|
63
|
+
@meme_sound_on_error(duration_ms=5000)
|
|
64
|
+
def func(): ...
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
if func is None:
|
|
68
|
+
return lambda f: meme_sound_on_error(f, duration_ms=duration_ms)
|
|
69
|
+
|
|
70
|
+
def wrapper(*args, **kwargs):
|
|
71
|
+
try:
|
|
72
|
+
return func(*args, **kwargs)
|
|
73
|
+
except Exception as e:
|
|
74
|
+
play_meme_sound(type(e), duration_ms=duration_ms)
|
|
75
|
+
raise
|
|
76
|
+
|
|
77
|
+
return wrapper
|
|
78
|
+
|
|
79
|
+
def set_error_sound(exc_type, mp3_path):
|
|
80
|
+
"""Allows users to map a custom .mp3 to an error type"""
|
|
81
|
+
path = Path(mp3_path)
|
|
82
|
+
if not path.exists():
|
|
83
|
+
raise FileNotFoundError(f"{mp3_path} does not exist!")
|
|
84
|
+
# Store the absolute path string in the dictionary
|
|
85
|
+
DEFAULT_SOUNDS[exc_type.__name__] = str(path.absolute())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meme-errors
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: Play funny meme sounds when Python errors occur!
|
|
5
5
|
Home-page: https://github.com/JAY-MU-4098/meme_errors
|
|
6
6
|
Author: Jay Gogra
|
|
@@ -10,7 +10,6 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
12
|
Requires-Dist: pygame
|
|
13
|
-
Requires-Dist: pydub
|
|
14
13
|
|
|
15
14
|
# Meme Errors
|
|
16
15
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = meme-errors
|
|
3
|
-
version = 0.1.
|
|
3
|
+
version = 0.1.7
|
|
4
4
|
author = Jay Gogra
|
|
5
5
|
author_email = pyex1.1@gmail.com
|
|
6
6
|
description = Play funny meme sounds when Python errors occur!
|
|
@@ -17,7 +17,6 @@ packages = find:
|
|
|
17
17
|
include_package_data = True
|
|
18
18
|
install_requires =
|
|
19
19
|
pygame
|
|
20
|
-
pydub
|
|
21
20
|
|
|
22
21
|
[options.packages.find]
|
|
23
22
|
where = .
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import tempfile
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
|
-
import pygame
|
|
6
|
-
from pydub import AudioSegment
|
|
7
|
-
import importlib.resources as resources
|
|
8
|
-
|
|
9
|
-
from . import sounds
|
|
10
|
-
|
|
11
|
-
# Initialize the mixer once at the top level
|
|
12
|
-
pygame.mixer.init()
|
|
13
|
-
|
|
14
|
-
DEFAULT_SOUNDS = {
|
|
15
|
-
"TypeError": "emotional-damage-meme.mp3",
|
|
16
|
-
"FileNotFoundError": "galaxy-meme.mp3",
|
|
17
|
-
"Exception": "movie_1_C2K5NH0.mp3"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def play_meme_sound(exc_type, duration_ms=3000):
|
|
22
|
-
sound_file = DEFAULT_SOUNDS.get(exc_type.__name__, DEFAULT_SOUNDS["Exception"])
|
|
23
|
-
try:
|
|
24
|
-
traversable = resources.files(sounds).joinpath(sound_file)
|
|
25
|
-
with resources.as_file(traversable) as path:
|
|
26
|
-
audio = AudioSegment.from_file(path)
|
|
27
|
-
trimmed = audio[:duration_ms] if len(audio) > duration_ms else audio
|
|
28
|
-
|
|
29
|
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
|
|
30
|
-
temp_path = tmp.name
|
|
31
|
-
trimmed.export(temp_path, format="mp3")
|
|
32
|
-
|
|
33
|
-
# Pygame playback
|
|
34
|
-
pygame.mixer.music.load(temp_path)
|
|
35
|
-
pygame.mixer.music.play()
|
|
36
|
-
|
|
37
|
-
# Keep alive just long enough to hear the sound
|
|
38
|
-
while pygame.mixer.music.get_busy():
|
|
39
|
-
pygame.time.Clock().tick(10)
|
|
40
|
-
|
|
41
|
-
except Exception as e:
|
|
42
|
-
print(f"[Meme Errors] Failed to play sound: {e}")
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def meme_excepthook(exc_type, exc_value, traceback):
|
|
46
|
-
play_meme_sound(exc_type)
|
|
47
|
-
sys.__excepthook__(exc_type, exc_value, traceback)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sys.excepthook = meme_excepthook
|
|
51
|
-
|
|
52
|
-
# Add or change meme for an error type
|
|
53
|
-
def set_error_sound(exc_type, mp3_path):
|
|
54
|
-
path = Path(mp3_path)
|
|
55
|
-
if not path.exists():
|
|
56
|
-
raise FileNotFoundError(f"{mp3_path} does not exist!")
|
|
57
|
-
|
|
58
|
-
DEFAULT_SOUNDS[exc_type.__name__] = str(path)
|
|
59
|
-
|
|
60
|
-
# Decorator for function-level errors
|
|
61
|
-
def meme_sound_on_error(func, duration_ms=3000):
|
|
62
|
-
def wrapper(*args, **kwargs):
|
|
63
|
-
try:
|
|
64
|
-
return func(*args, **kwargs)
|
|
65
|
-
except Exception as e:
|
|
66
|
-
play_meme_sound(type(e), duration_ms)
|
|
67
|
-
raise e
|
|
68
|
-
return wrapper
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|