Skip to content

Commit

Permalink
Format code w/ black & isort
Browse files Browse the repository at this point in the history
Signed-off-by: John Strunk <[email protected]>
  • Loading branch information
JohnStrunk committed Apr 6, 2023
1 parent 56c25ee commit 817a078
Show file tree
Hide file tree
Showing 20 changed files with 1,181 additions and 645 deletions.
21 changes: 16 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-added-large-files # prevents giant files from being committed
- id: check-yaml # checks yaml files for parseable syntax
- id: end-of-file-fixer # ensures that a file is either empty, or ends with one newline
- id: trailing-whitespace # trims trailing whitespace
- id: check-added-large-files # Prevents giant files from being committed
- id: check-yaml # Checks yaml files for parseable syntax
- id: end-of-file-fixer # Ensures that a file is either empty, or ends with one newline
- id: trailing-whitespace # Trims trailing whitespace
exclude: startlist_test.py # Test data has intentional EOL whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
hooks:
- id: mypy
- id: mypy # Run mypy to check typeing
additional_dependencies:
- types-python-dateutil
- types-requests
Expand All @@ -31,3 +31,14 @@ repos:
- id: rst-directive-colons # Detect mistake of rst directive not ending with double colon or space before the double colon
- id: rst-inline-touching-normal # Detect mistake of inline code touching normal text in rst
- id: text-unicode-replacement-char # Forbid files which have a UTF-8 Unicode replacement character

- repo: https://github.com/psf/black
rev: "23.3.0"
hooks:
- id: black # Run "black" for standardized code formatting

- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort # Sort imports
args: ["--profile", "black", "--filter-files"]
49 changes: 30 additions & 19 deletions about.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

'''
"""
Display an "about" dialog
'''
"""

import textwrap
from tkinter import Text, Tk, Toplevel, font, ttk
Expand All @@ -25,10 +25,10 @@


def about(root: Tk) -> None:
'''Displays a modal dialog containing the application "about" info'''
"""Displays a modal dialog containing the application "about" info"""

dlg = Toplevel(root)
dlg.resizable(False, False) # don't allow resizing
dlg.resizable(False, False) # don't allow resizing

def dismiss():
dlg.grab_release()
Expand All @@ -42,23 +42,25 @@ def dismiss():
dlg.title("About - Wahoo! Results")
dlg.configure(padx=8, pady=8)

dlg.protocol("WM_DELETE_WINDOW", dismiss) # intercept close button
dlg.transient(root) # dialog window is related to main
dlg.wait_visibility() # can't grab until window appears, so we wait
dlg.grab_set() # ensure all input goes to our window
dlg.protocol("WM_DELETE_WINDOW", dismiss) # intercept close button
dlg.transient(root) # dialog window is related to main
dlg.wait_visibility() # can't grab until window appears, so we wait
dlg.grab_set() # ensure all input goes to our window

geo = dlg.geometry()
# parse the geometry string of the form "WxH+X+Y" to get the width and height as integers
width, height = [int(x) for x in geo.split('+')[0].split('x')]
width, height = [int(x) for x in geo.split("+")[0].split("x")]
# center the dialog on the screen
left = root.winfo_screenwidth() // 2 - width // 2
top = root.winfo_screenheight() // 2 - height // 2
dlg.geometry(f'+{left}+{top}')
dlg.geometry(f"+{left}+{top}")

dlg.wait_window() # block until window is destroyed

dlg.wait_window() # block until window is destroyed

def _set_contents(txt: Text) -> None:
contents = textwrap.dedent(f'''\
contents = textwrap.dedent(
f"""\
Wahoo! Results
Copyright (c) 2022 - John Strunk
Expand All @@ -68,28 +70,37 @@ def _set_contents(txt: Text) -> None:
https://github.com/JohnStrunk/wahoo-results
Version: {WAHOO_RESULTS_VERSION}
''')
"""
)

txtfont = font.nametofont('TkTextFont')
txtfont = font.nametofont("TkTextFont")
txtsize = txtfont.actual()["size"]

# Add contents and set default style
lines = contents.split('\n')
lines = contents.split("\n")
height = len(lines)
width = 0
for line in lines:
width = max(width, len(line))
txt.configure(state="normal", background=txt.master["background"], relief="flat",
width=width, height=height)
txt.configure(
state="normal",
background=txt.master["background"],
relief="flat",
width=width,
height=height,
)
txt.insert("1.0", contents, ("all"))
txt.tag_configure("all", foreground="black", font=f"TktextFont {txtsize}", justify="center")
txt.tag_configure(
"all", foreground="black", font=f"TktextFont {txtsize}", justify="center"
)

# Set the style for the application title text line
txt.tag_add('title', '1.0', '2.0')
txt.tag_add("title", "1.0", "2.0")
txt.tag_configure("title", font=f"TkTextFont {txtsize} bold underline")

txt.configure(state="disabled")
txt.see("1.0")


if __name__ == "__main__":
about(Tk())
84 changes: 47 additions & 37 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,37 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

'''Python script to build Wahoo! Results executable'''
"""Python script to build Wahoo! Results executable"""

import os
import semver #type: ignore
import shutil
import subprocess

import PyInstaller.__main__
import PyInstaller.utils.win32.versioninfo as vinfo
import semver # type: ignore

import wh_version

print("Starting build process...\n")

# Remove any previous build artifacts
try:
shutil.rmtree('build')
shutil.rmtree("build")
except FileNotFoundError:
pass

# Determine current git tag
git_ref = subprocess.check_output('git describe --tags --match "v*" --long', shell=True).decode("utf-8").rstrip()
git_ref = (
subprocess.check_output('git describe --tags --match "v*" --long', shell=True)
.decode("utf-8")
.rstrip()
)
wr_version = wh_version.git_semver(git_ref)
print(f"Building Wahoo Results, version: {wr_version}")
vdict = semver.parse(wr_version)

with open ('version.py', 'w' ) as f:
with open("version.py", "w") as f:
f.write("'''Version information'''\n\n")
f.write(f'WAHOO_RESULTS_VERSION = "{wr_version}"\n')

Expand All @@ -48,67 +53,72 @@
if dsn is not None:
f.write(f'SENTRY_DSN = "{dsn}"\n')
else:
f.write('SENTRY_DSN = None\n')
f.write("SENTRY_DSN = None\n")

# Segment API key
segment = os.getenv("SEGMENT_WRITE_KEY")
if segment is None:
segment = 'unknown'
segment = "unknown"
f.write(f'SEGMENT_WRITE_KEY = "{segment}"\n')

# ipinfo.io
ipinfo = os.getenv("IPINFO_TOKEN")
if ipinfo is not None:
f.write(f'IPINFO_TOKEN = "{ipinfo}"\n')
else:
f.write('IPINFO_TOKEN = None\n')
f.write("IPINFO_TOKEN = None\n")

f.flush()
f.close()

# Create file info to embed in executable
v = vinfo.VSVersionInfo(
ffi=vinfo.FixedFileInfo(
filevers=(vdict['major'], vdict['minor'], vdict['patch'], 0),
prodvers=(vdict['major'], vdict['minor'], vdict['patch'], 0),
mask=0x3f,
filevers=(vdict["major"], vdict["minor"], vdict["patch"], 0),
prodvers=(vdict["major"], vdict["minor"], vdict["patch"], 0),
mask=0x3F,
flags=0x0,
OS=0x4,
fileType=0x1,
subtype=0x0,
),
kids=[
vinfo.StringFileInfo([
vinfo.StringTable('040904e4', [
# https://docs.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
# Required fields:
vinfo.StringStruct('CompanyName', 'John D. Strunk'),
vinfo.StringStruct('FileDescription', 'Wahoo! Results'),
vinfo.StringStruct('FileVersion', wr_version),
vinfo.StringStruct('InternalName', 'wahoo_results'),
vinfo.StringStruct('ProductName', 'Wahoo! Results'),
vinfo.StringStruct('ProductVersion', wr_version),
vinfo.StringStruct('OriginalFilename', 'wahoo-results.exe'),
# Optional fields
vinfo.StringStruct('LegalCopyright', '(c) John D. Strunk - AGPL-3.0-or-later'),
])
]),
vinfo.VarFileInfo([
# 1033 -> Engligh; 1252 -> charsetID
vinfo.VarStruct('Translation', [1033, 1252])
])
]
vinfo.StringFileInfo(
[
vinfo.StringTable(
"040904e4",
[
# https://docs.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
# Required fields:
vinfo.StringStruct("CompanyName", "John D. Strunk"),
vinfo.StringStruct("FileDescription", "Wahoo! Results"),
vinfo.StringStruct("FileVersion", wr_version),
vinfo.StringStruct("InternalName", "wahoo_results"),
vinfo.StringStruct("ProductName", "Wahoo! Results"),
vinfo.StringStruct("ProductVersion", wr_version),
vinfo.StringStruct("OriginalFilename", "wahoo-results.exe"),
# Optional fields
vinfo.StringStruct(
"LegalCopyright", "(c) John D. Strunk - AGPL-3.0-or-later"
),
],
)
]
),
vinfo.VarFileInfo(
[
# 1033 -> Engligh; 1252 -> charsetID
vinfo.VarStruct("Translation", [1033, 1252])
]
),
],
)
with open('wahoo-results.fileinfo', 'w') as f:
with open("wahoo-results.fileinfo", "w") as f:
f.write(str(v))
f.flush()
f.close()

print("Invoking PyInstaller to generate executable...\n")

# Build it
PyInstaller.__main__.run([
"--distpath=.",
"--workpath=build",
'wahoo-results.spec'
])
PyInstaller.__main__.run(["--distpath=.", "--workpath=build", "wahoo-results.spec"])
35 changes: 17 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import sphinx_rtd_theme #type: ignore

import sphinx_rtd_theme # type: ignore

# -- Project information -----------------------------------------------------

project = 'Wahoo! Results'
copyright = '2020-2023, John D. Strunk'
author = 'John D. Strunk'
project = "Wahoo! Results"
copyright = "2020-2023, John D. Strunk"
author = "John D. Strunk"


# -- General configuration ---------------------------------------------------
Expand All @@ -30,39 +29,39 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
# https://plantweb.readthedocs.io/#sphinx-directives
# https://plantweb.readthedocs.io/examples.html
'plantweb.directive',
'sphinx_rtd_theme',
# https://sphinx-tabs.readthedocs.io/en/latest/
'sphinx_tabs.tabs',
# https://plantweb.readthedocs.io/#sphinx-directives
# https://plantweb.readthedocs.io/examples.html
"plantweb.directive",
"sphinx_rtd_theme",
# https://sphinx-tabs.readthedocs.io/en/latest/
"sphinx_tabs.tabs",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.venv', 'README.md']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".venv", "README.md"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Logo at top of sidebar
html_logo = 'media/wr-card2-150.png'
html_logo = "media/wr-card2-150.png"

# favicon
html_favicon = 'media/wr-icon.ico'
html_favicon = "media/wr-icon.ico"

master_doc = 'index'
master_doc = "index"
Loading

0 comments on commit 817a078

Please sign in to comment.