From f1435ce51f2fa2bfac9dcff55d94992e4b5e7e00 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 28 Dec 2014 14:50:25 +0100 Subject: [PATCH] Use a dirty hack to copy icon files into package. See #325. --- .gitignore | 1 + MANIFEST.in | 1 + qutebrowser/app.py | 2 +- qutebrowser/utils/utils.py | 10 ++-------- setup.py | 20 ++++++++++++-------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 3cb08b141..b1147c670 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ __pycache__ /setuptools-*.egg /setuptools-*.zip /qutebrowser/git-commit-id +/qutebrowser/icons /doc/*.html /README.html /qutebrowser/html/doc/ diff --git a/MANIFEST.in b/MANIFEST.in index 7f3eeb898..919ef3d55 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,6 @@ recursive-include qutebrowser/html *.html recursive-include qutebrowser/test *.py +recursive-include qutebrowser/icons * recursive-include icons * include qutebrowser/test/testfile include qutebrowser/git-commit-id diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 5989cc6a8..c6d2d5ea1 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -203,7 +203,7 @@ class Application(QApplication): icon = QIcon() for size in (16, 24, 32, 48, 64, 96, 128, 256, 512): filename = 'icons/qutebrowser-{}x{}.png'.format(size, size) - data = utils.read_file(filename, binary=True, use_requirement=True) + data = utils.read_file(filename, binary=True) pixmap = QPixmap() ok = pixmap.loadFromData(data, 'PNG') if not ok: diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index b2aea8112..4b40f997d 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -64,15 +64,13 @@ def compact_text(text, elidelength=None): return out -def read_file(filename, binary=False, use_requirement=False): +def read_file(filename, binary=False): """Get the contents of a file contained with qutebrowser. Args: filename: The filename to open as string. binary: Whether to return a binary string. If False, the data is UTF-8-decoded. - use_requirement: Use a pkg_resources.Requirement object to get - non-package data. Return: The file contents as string. @@ -87,11 +85,7 @@ def read_file(filename, binary=False, use_requirement=False): with open(fn, 'r', encoding='utf-8') as f: return f.read() else: - if use_requirement: - target = pkg_resources.Requirement('qutebrowser', '', '') - else: - target = qutebrowser.__name__ - data = pkg_resources.resource_string(target, filename) + data = pkg_resources.resource_string(qutebrowser.__name__, filename) if not binary: data = data.decode('UTF-8') return data diff --git a/setup.py b/setup.py index fcbb19aae..f525b6775 100755 --- a/setup.py +++ b/setup.py @@ -24,16 +24,21 @@ import os import os.path import glob +import shutil from scripts import setupcommon as common import setuptools -try: - BASEDIR = os.path.dirname(os.path.realpath(__file__)) -except NameError: - BASEDIR = None +BASEDIR = os.path.dirname(os.path.realpath(__file__)) + + +icon_path = os.path.join('qutebrowser', 'icons') +shutil.rmtree(icon_path) +os.mkdir(icon_path) +for fn in glob.glob('icons/*.png'): + shutil.copy(fn, icon_path) try: @@ -50,7 +55,6 @@ try: **common.setupdata ) finally: - if BASEDIR is not None: - path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id') - if os.path.exists(path): - os.remove(path) + path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id') + if os.path.exists(path): + os.remove(path)