Skip to content

Commit d594b1b

Browse files
committed
File watcher and matplotlib bugfix
1 parent 748f9a4 commit d594b1b

File tree

9 files changed

+198
-12
lines changed

9 files changed

+198
-12
lines changed

CODE_OF_CONDUCT.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
https://www.twitch.tv/drgreengiant.
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series
86+
of actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or
93+
permanent ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within
113+
the community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.0, available at
119+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120+
121+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122+
enforcement ladder](https://github.com/mozilla/diversity).
123+
124+
[homepage]: https://www.contributor-covenant.org
125+
126+
For answers to common questions about this code of conduct, see the FAQ at
127+
https://www.contributor-covenant.org/faq. Translations are available at
128+
https://www.contributor-covenant.org/translations.

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributing
2+
3+
This file is very much TODO. If you'd like to contribute in any way and are unsure, use the discussion tab.
4+
5+
EVERYONE is welcome to contribute!
6+
7+
I shall, of course, update this guide in the near future.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
To build the exe run:
1616

1717
```shell
18-
pyinstaller -n statsaphobia.exe --onefile run.py
18+
python build.py
1919
```

assets/icon.png

12.9 KB
Loading

build.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!./.venv/bin/python3
2+
import importlib.metadata
3+
import pathlib
4+
import platform
5+
6+
import PyInstaller.__main__ as pyinstaller
7+
8+
VERSION = importlib.metadata.version("statsaphobia")
9+
DIRPATH = pathlib.Path().absolute()
10+
ENTRYPOINT = f'{DIRPATH / "run.py"}'
11+
SEPARATOR = ";" if platform.platform().startswith("Windows") else ":"
12+
NAME = f"statsaphobia-{VERSION.replace('.', '_')}"
13+
14+
DATAFILES = [
15+
f'{DIRPATH / "README.md"}{SEPARATOR}.',
16+
f'{DIRPATH / "LICENSE"}{SEPARATOR}.',
17+
f'{DIRPATH / "CONTRIBUTING.md"}{SEPARATOR}.',
18+
f'{DIRPATH / "CODE_OF_CONDUCT.md"}{SEPARATOR}.',
19+
]
20+
21+
ICON = f'{DIRPATH / "assets" / "icon.png"}'
22+
23+
24+
def build():
25+
add_data = (("--add-data", item) for item in DATAFILES)
26+
add_data = [item for tup in add_data for item in tup]
27+
28+
pyinstaller.run(
29+
[
30+
ENTRYPOINT,
31+
# '--clean',
32+
"-n",
33+
NAME,
34+
"--onefile",
35+
"--noconfirm",
36+
"--log-level",
37+
"WARN",
38+
*add_data,
39+
"-i",
40+
ICON,
41+
]
42+
)
43+
44+
45+
if __name__ == "__main__":
46+
build()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "statsaphobia"
7-
version = "0.0.0"
7+
version = "0.0.1"
88
requires-python = ">=3.12"
99
authors = [
1010
{ name = "Simon Howroyd", email = "[email protected]" },

src/statsaphobia/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def on_change() -> None:
6464
if oldfile:
6565
diff.print_diff(oldfile, jsonfile)
6666
html.do_html(jsonfile, outdir)
67-
graphfiles: dict[str, pathlib.Path] = plot.do_plot(jsonfile, outdir / "graphs")
67+
plot.do_plot(jsonfile, outdir / "graphs")
6868
oldfile = jsonfile
6969

7070
on_change()

src/statsaphobia/phasmophobia/plot.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import json
22
import pathlib
33

4+
import matplotlib as mpl
5+
6+
mpl.use("Agg") # Stops matplotlib using an x server, I think
47
import matplotlib.pyplot as plt
58

69

@@ -95,10 +98,12 @@ def plot_common_ghosts(data: dict, outdir: pathlib.Path) -> pathlib.Path:
9598
return outdir / "common_ghosts.png"
9699

97100

98-
def do_plot(infile: pathlib.Path, outdir: pathlib.Path) -> pathlib.Path:
101+
def do_plot(infile: pathlib.Path, outdir: pathlib.Path) -> dict[str, pathlib.Path]:
99102
outdir.mkdir(parents=True, exist_ok=True)
100103

101104
data: dict = json.loads(infile.read_text())
102105

103-
played_maps: pathlib.Path = plot_played_maps(data, outdir)
104-
common_ghosts: pathlib.Path = plot_common_ghosts(data, outdir)
106+
return {
107+
"played_maps": plot_played_maps(data, outdir),
108+
"common_ghosts": plot_common_ghosts(data, outdir),
109+
}

src/statsaphobia/watcher.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ class FileWatcher:
1919
def __init__(self, eventhandler: Callable, path: pathlib.Path) -> None:
2020
self.eventhandler = eventhandler
2121
self.path = path
22-
self.event = Event(eventhandler, path.parent)
22+
self.event = Event(eventhandler)
2323
self.thread = threading.Thread(target=self._thread)
24-
self.observer = Observer()
25-
self.observer.schedule(self.event, str(self.path.parent))
2624
self.kill_event = threading.Event()
2725

2826
def __enter__(self):
@@ -34,8 +32,10 @@ def __exit__(self, exc_type, exc_value, traceback):
3432
self.thread.join()
3533

3634
def _thread(self):
37-
self.observer.start()
35+
observer = Observer()
36+
observer.schedule(self.event, self.path.parent)
37+
observer.start()
3838
print(f"Watching {self.path}")
3939
self.kill_event.wait()
40-
self.observer.stop()
41-
self.observer.join()
40+
observer.stop()
41+
observer.join()

0 commit comments

Comments
 (0)