From 6fa0ffc8162a2450551f6062b6bf27fd4fb14458 Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Thu, 23 May 2019 15:06:16 +0200 Subject: [PATCH] Working setup with pyinstaller --- .gitignore | 2 ++ README.md | 9 +++++++++ cli.spec | 35 +++++++++++++++++++++++++++++++++++ funkwhale_cli/cli.py | 26 ++++++++++++++++++++------ setup.cfg | 2 +- 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 cli.spec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b823a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist +build diff --git a/README.md b/README.md index dddb164..cd6ce4e 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,12 @@ This cli requires python 3.6 or greater: # Usage ``funkwhale --help`` + +# Build the binary + +You can build the binarie for you platform using the following commands: + + pip install .[dev] + pyinstaller cli.spec + +This will output a binary in `./dist/funkwhale`. diff --git a/cli.spec b/cli.spec new file mode 100644 index 0000000..3116b1c --- /dev/null +++ b/cli.spec @@ -0,0 +1,35 @@ +# -*- mode: python -*- + +block_cipher = None + + +a = Analysis( + ["funkwhale_cli/cli.py"], + pathex=["/home/eliotberriot/projects/funkwhale/cli"], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + 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, + a.binaries, + a.zipfiles, + a.datas, + [], + name="funkwhale", + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + console=True, +) diff --git a/funkwhale_cli/cli.py b/funkwhale_cli/cli.py index 1948581..c3170d0 100644 --- a/funkwhale_cli/cli.py +++ b/funkwhale_cli/cli.py @@ -7,6 +7,14 @@ import datetime import dotenv import functools import keyring + +# importing the backends explicitely is required for PyInstaller to work +import keyring.backends.kwallet +import keyring.backends.Windows +import keyring.backends.OS_X +import keyring.backends.SecretService +import keyring.backends.chainer + import logging import math import urllib.parse @@ -16,11 +24,12 @@ import pathvalidate import pathlib import urllib.parse import tqdm -from . import api -from . import config -from . import exceptions -from . import logs -from . import output + +from funkwhale_cli import api +from funkwhale_cli import config +from funkwhale_cli import exceptions +from funkwhale_cli import logs +from funkwhale_cli import output click_log.basic_config(logs.logger) @@ -173,7 +182,12 @@ def set_server(ctx, url, token, use_auth=True): @TOKEN_DECORATOR @click_log.simple_verbosity_option(logs.logger, expose_value=True) @click.pass_context -def cli(ctx, env_file, url, verbosity, token, quiet): +def cli(ctx, env_file, url, verbosity, token, quiet, no_login): + # small hack to fix some weird issues with pyinstaller and keyring + # there seems to be a cache issue somewhere + del keyring.backend.get_all_keyring.__wrapped__.always_returns + keyring.core.init_backend() + # /end of hack ctx.ensure_object(dict) logs.logger.disabled = quiet set_server(ctx, url, token, use_auth=not no_login) diff --git a/setup.cfg b/setup.cfg index a32bac1..37b5220 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,7 @@ dev = pytest pytest-mock pytest-env - + pyinstaller [options.packages.find] -- GitLab