Skip to content

Commit

Permalink
Fix migrations access when packaged into egg
Browse files Browse the repository at this point in the history
Use pkg_resources to access migrations files. When dexbot is packaged
into egg file (normal `setup.py install` result), we cannot just access
files inside egg (zip archive), so we're using native setuptools API to
extract the files (resource_filename()). In case files are not in egg,
pkg_resources will use normal file access.

https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access
https://setuptools.readthedocs.io/en/latest/setuptools.html#accessing-data-files-at-runtime
http://peak.telecommunity.com/DevCenter/PythonEggs#accessing-package-resources
  • Loading branch information
bitphage committed Aug 21, 2019
1 parent 3f95476 commit a60a142
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions dexbot/storage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import os.path
import sys
import inspect
import json
import threading
import queue
Expand Down Expand Up @@ -227,9 +226,8 @@ def __init__(self, **kwargs):
bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
migrations_dir = os.path.join(bundle_dir, 'migrations')
else:
# Path to migrations, platform-independent
import dexbot
migrations_dir = os.path.join(os.path.dirname(inspect.getfile(dexbot)), 'migrations')
from pkg_resources import resource_filename
migrations_dir = resource_filename('dexbot', 'migrations')

if os.path.exists(sqlite_file) and os.path.getsize(sqlite_file) > 0:
# Run migrations on existing database
Expand Down

0 comments on commit a60a142

Please sign in to comment.