Skip to content

Commit

Permalink
Add PyInstaller for 3.11 and safeguard publishing (#93)
Browse files Browse the repository at this point in the history
Added PyInstaller and locked in Python 3.11 for future contributions. Also added a build script and modified the pyproject.toml to prevent accidental publishing
  • Loading branch information
Owez authored Jan 19, 2023
1 parent 0be9ede commit ea0f67c
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode
demo/
**/.DS*
build/
dist/
__pycache__/
374 changes: 277 additions & 97 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,32 @@ license = "MIT"
readme = "README.md"
repository = "https://github.com/owez/yark"
classifiers = [
"Topic :: System :: Archiving",
"Topic :: System :: Archiving :: Backup",
"Topic :: Multimedia :: Video",
]
include = [{ path = "templates/*" }]
"Private :: Do not Upload",
] # NOTE: work around for poetry #1537 <https://github.com/python-poetry/poetry/issues/1537>

[tool.poetry.dependencies]
python = "^3.9"
python = "~3.11"
Flask = "^2.2.2"
colorama = "^0.4.6"
yt-dlp = "^2023.1.2"
requests = "^2.28.1"

[tool.poetry.scripts]
yark = "yark.cli:_cli"

[tool.poetry.group.dev.dependencies]
mypy = "^0.991"
poethepoet = "^0.17.1"
types-urllib3 = "^1.26.25.4"
types-colorama = "^0.4.15.4"
types-requests = "^2.28.11.7"
black = "^22.12.0"
pyinstaller = "^5.7.0"

[tool.poetry.scripts]
yark = "yark.cli:_cli"

[tool.poe.tasks]
lint = { shell = "set -e && mypy yark examples/madness.py" }
fmt = "black yark examples/madness.py"
build = "pyinstaller yark.spec"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
49 changes: 49 additions & 0 deletions yark.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Specification file for building Yark using PyInstaller"""

block_cipher = None


a = Analysis(
["yark/launcher.py"],
pathex=[],
binaries=[],
datas=[("yark/templates", "templates")],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name="yark",
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name="yark",
)
6 changes: 6 additions & 0 deletions yark/launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Launcher stub workaround for pyinstaller #2560 <https://github.com/pyinstaller/pyinstaller/issues/2560>"""

from yark import cli

if __name__ == "__main__":
cli._cli()
16 changes: 12 additions & 4 deletions yark/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
)
from .archive import Archive
from .video import Note
import sys
from pathlib import Path

routes = Blueprint("routes", __name__, template_folder="templates")

Expand Down Expand Up @@ -80,9 +82,7 @@ def archive(name, kind):
error=request.args.get("error"),
)
except ArchiveNotFoundException:
return redirect(
url_for("routes.index", error="Couldn't open archive's archive")
)
return redirect(url_for("routes.index", error="Couldn't open archive"))
except Exception as e:
return redirect(url_for("routes.index", error=f"Internal server error:\n{e}"))

Expand Down Expand Up @@ -220,7 +220,7 @@ def archive_image(name, id):
def viewer() -> Flask:
"""Generates viewer flask app, launch by just using the typical `app.run()`"""
# Make flask app
app = Flask(__name__)
app = _make_app()

# Only log errors
log = logging.getLogger("werkzeug")
Expand Down Expand Up @@ -302,3 +302,11 @@ def _encode_timestamp(timestamp: int) -> str:

# Return
return ":".join(parts)


def _make_app() -> Flask:
"""Loads app with proper templates folder; this is so frozen PyInstaller installs work"""
if getattr(sys, "frozen", False):
template_folder = Path(sys._MEIPASS) / "templates" # type: ignore
return Flask(__name__, template_folder=str(template_folder))
return Flask(__name__)

0 comments on commit ea0f67c

Please sign in to comment.