Skip to content

Commit

Permalink
fix: remove gettext from project
Browse files Browse the repository at this point in the history
Internationalization made it hard to maintain this package.
Therefore, we remove gettext from the project.

BREAKING CHANGE: no internationalization anymore
  • Loading branch information
siemdejong committed Oct 3, 2024
1 parent 50fc048 commit e05747c
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 412 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ jobs:
- name: Setup | Force correct release branch on workflow sha
run: git checkout -B ${{ github.ref_name }} ${{ github.sha }}

- name: Install babel
run: pip install Babel

- name: Build MO files
run: python setup.py compile_catalog

- name: Action | Semantic Version Release
id: release
# Adjust tag with desired version if applicable.
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ options:
Merge output. Defaults to --no-merge
-s {front,back,both}, --side {front,back,both}
Side(s) to generate. Defaults to both.
-l {en,nl}, --lang {en,nl}
Language. 'en' and 'nl' supported. Defaults to 'en'.
-f {pdf,png}, --format {pdf,png}
Output format. 'pdf' and 'png' supported. Defaults to 'pdf'.
-r, --rank, --no-rank
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61.0", "babel"]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -44,7 +44,7 @@ exclude = ["shithappens.opensans"]
namespaces = false

[tool.setuptools.package-data]
shithappens = ["opensans/fonts/ttf/*.ttf", "images/*.png", "locales/*/LC_MESSAGES/*.mo"]
shithappens = ["opensans/fonts/ttf/*.ttf", "images/*.png"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ matplotlib
pandas
openpyxl
PyPDF2
tqdm
babel
tqdm
20 changes: 0 additions & 20 deletions setup.cfg

This file was deleted.

26 changes: 0 additions & 26 deletions setup.py

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pandas as pd
import tkinter as tk
from tkinter import filedialog
from pathlib import Path

sys.path.append(str(Path(__file__).absolute().parent.parent))

Expand Down Expand Up @@ -36,7 +35,6 @@ def select_folder():

merge = st.checkbox("Merge output", value=True)
side = st.selectbox("Side(s) to generate", ["both", "front", "back"])
lang = st.selectbox("Language", ["en", "nl"])
format = st.selectbox("Output format", ["pdf", "png"])
workers = st.number_input("Number of workers", value=4)
chunks = st.number_input("Number of chunks for the workers to process", value=30)
Expand All @@ -50,6 +48,5 @@ def select_folder():
format=format,
workers=workers,
chunks=chunks,
lang=lang,
)
st.write("Cards written to ", output_dir)
8 changes: 0 additions & 8 deletions src/shithappens/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ def cli():
default="both",
help="Side(s) to generate.",
)
@click.option(
"-l",
"--language",
"lang",
type=click.Choice(["en", "nl"], case_sensitive=False),
default="en",
help="Language.",
)
@click.option(
"-f",
"--format",
Expand Down
17 changes: 6 additions & 11 deletions src/shithappens/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@
from glob import glob
import click

from shithappens.utils import install_lang

_ = install_lang("en")


def verify_input_dir(input_dir: Path):
while True:
if input_dir.exists():
break
input_dir = Path(
input(
_(
"Input directory {} does not exist. Please specify an existing input directory.\n"
).format(input_dir)
f"Input directory {input_dir} does not exist. "
"Please specify an existing input directory.\n"
)
)

output_dir = input_dir / "outputs"
print(_("Reading files from {}.").format(input_dir))
print(_("Output files in {}.").format(output_dir))
print(f"Reading files from {input_dir}.")
print(f"Output files in {output_dir}.")

xlsx_paths = glob(f"{input_dir / '*.xlsx'}")
xlsx_paths_num = len(xlsx_paths)
if not xlsx_paths_num:
print(_("Please provide an Excel file in {}.").format(input_dir))
print("Please provide an Excel file in {input_dir}.")
exit(1)
elif xlsx_paths_num > 1:
while True:
print(_("\nMore than one input file found."))
print("\nMore than one input file found.")
for i, xlsx_path in enumerate(xlsx_paths, 1):
print(f"[{i}] {xlsx_path}")
try:
Expand Down
71 changes: 13 additions & 58 deletions src/shithappens/create_cards.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import gettext
import textwrap
from functools import partial
from glob import glob
Expand All @@ -16,28 +15,14 @@
from matplotlib.patches import Rectangle
from matplotlib.text import Annotation
from matplotlib.transforms import Bbox

try:
from tqdm import tqdm
except ImportError:

def tqdm(iterable, *args, **kwargs):
del args, kwargs
return iterable
from tqdm import tqdm


from shithappens.card import Card
from shithappens.cli.utils import verify_input_dir
from shithappens.utils import merge_pdfs, slugify


def install_lang(locale: str):
localedir = Path(__file__).parent.resolve() / "locales"
lang = gettext.translation("shithappens", localedir=localedir, languages=[locale])
lang.install()
global _
_ = lang.gettext


def text_with_wrap_autofit(
ax: plt.Axes,
txt: str,
Expand Down Expand Up @@ -133,7 +118,6 @@ class ShitHappensArgs(argparse.Namespace):
merge: bool
rank: bool
side: Literal["front", "back", "both"]
lang: Literal["en", "nl"]
format: Literal["pdf", "png"]
workers: int
chunks: int
Expand All @@ -156,7 +140,7 @@ def parse_excel(input_path: Path, desc_col: int, misery_index_col: int) -> pd.Da
input_path, usecols=[desc_col, misery_index_col], engine="openpyxl"
)
except Exception:
print(_("{} is not an excel file.").format(input_path))
print(f"{input_path} is not an excel file.")
exit()

return df
Expand Down Expand Up @@ -241,7 +225,7 @@ def plot_card_front(card: Card) -> Figure:
color="yellow",
)

mi_desc = _("misery index")
mi_desc = "misery index"
ax.text(
x_total / 2,
1.3 * y_size / 8 + bleed,
Expand Down Expand Up @@ -309,7 +293,7 @@ def plot_card_back(card: Card, input_dir: Path) -> Figure:
)

game_name = "Shit Happens"
expansion_text = _("edition")
expansion_text = "edition"
expansion_text_full = card.expansion_name + " " + expansion_text

ax.text(
Expand Down Expand Up @@ -374,7 +358,7 @@ def save_card(
dpi: int = 300,
format: str = "pdf",
) -> None:
side_fn = _("front") if side == "front" else _("back")
side_fn = "front" if side == "front" else "back"

output_dir = output_dir / side_fn

Expand Down Expand Up @@ -416,10 +400,6 @@ def create_card(
save_card(card, output_dir, "back", format=ext)


def _init(locale):
install_lang(locale)


def create_cards(
df: pd.DataFrame,
expansion_name: str,
Expand All @@ -430,7 +410,6 @@ def create_cards(
ext: Literal["pdf", "png"],
workers: int,
chunks: int,
locale: str,
) -> None:
nmax = df.shape[0]
chunksize = nmax // chunks
Expand All @@ -442,9 +421,9 @@ def create_cards(
side=side,
ext=ext,
)
desc = _("Plotting cards")
desc = "Plotting cards"
if chunksize:
with Pool(workers, _init, initargs=(locale,)) as p:
with Pool(workers) as p:
list(
tqdm(
p.imap_unordered(create_card_par, df.iterrows(), chunksize),
Expand All @@ -457,23 +436,12 @@ def create_cards(

if merge:
if side == "front" or side == "both":
merge_pdfs(output_dir / _("front"))
merge_pdfs(output_dir / "front")
if side == "back" or side == "both":
merge_pdfs(output_dir / _("back"))
merge_pdfs(output_dir / "back")


def main(**args) -> None:
install_lang(args["lang"])

try:
import tqdm
except ImportError:
print(_("'pip install shithappens[pbar]' to show a progress bar."))
else:
del tqdm

from shithappens.cli.utils import verify_input_dir

input_dir = Path(args["input_dir"])
xlsx_path, output_dir = verify_input_dir(input_dir)

Expand All @@ -489,24 +457,12 @@ def main(**args) -> None:
else:
expansion_name = input_dir.stem
print(
_(
"Argument -n/--name not given. " "Expansion name inferred to be {}."
).format(expansion_name)
"Argument -n/--name not given. "
f"Expansion name inferred to be {expansion_name}."
)

df = parse_excel(xlsx_path, 0, 1)

if args["merge"]:
try:
import PyPDF2

args["merge"] = True
except ImportError:
args["merge"] = False
print(_("'pip install shithappens[merge]' for pdf merging."))
else:
del PyPDF2

create_cards(
df,
expansion_name,
Expand All @@ -517,15 +473,14 @@ def main(**args) -> None:
args["format"],
args["workers"],
args["chunks"],
args["lang"],
)


def main_cli(**kwargs):
try:
main(**kwargs)
except KeyboardInterrupt:
print(_("Interrupted."))
print("Interrupted.")


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit e05747c

Please sign in to comment.