Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use importlib instead of __file__ #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions pgcolorbar/misc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Miscellaneous routines
"""
from __future__ import print_function, division

from importlib.metadata import version
import logging
import os.path
import sys
Expand All @@ -13,34 +13,7 @@
LOG_FMT = '%(asctime)s %(filename)25s:%(lineno)-4d : %(levelname)-7s: %(message)s'

logger = logging.getLogger(__name__)



# Reads the version of the program from the first line of version.txt
try:
if getattr(sys, 'frozen', False):
# If the application is run as a bundle, the pyInstaller bootloader
# extends the sys module by a flag frozen=True and sets the app
# path into variable _MEIPASS'.
MODULE_DIR = os.path.join(sys._MEIPASS, 'cmlib')
if DEBUGGING:
print("Module dir from meipass: {}".format(MODULE_DIR), file=sys.stderr)
else:
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
if DEBUGGING:
print("Module dir from __file__: {}".format(MODULE_DIR), file=sys.stderr)

VERSION_FILE = os.path.join(MODULE_DIR, 'version.txt')
if DEBUGGING:
print("Reading version from: {}".format(VERSION_FILE), file=sys.stderr)
logger.debug("Reading version from: {}".format(VERSION_FILE))
with open(VERSION_FILE) as stream:
__version__ = stream.readline().strip()
except Exception as ex:
__version__ = "?.?.?"
logger.error("Unable to read version number: {}".format(ex))
raise

__version__ = version("cmlib")

def versionStrToTuple(versionStr):
""" Converts a version string to tuple
Expand Down Expand Up @@ -75,4 +48,3 @@ def check_class(var, cls, allowNone=False):
"""
if not isinstance(var, cls) and not (allowNone and var is None):
raise TypeError("Unexpected type {}, was expecting {}".format(type(var), cls))

6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ def err(*args, **kwargs):

# Don't import __version__ from pgcolorbar because this also tries to import PyQt, which
# can fail if PyQt is not installed.
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
VERSION_FILE = os.path.join(MODULE_DIR, 'pgcolorbar', 'version.txt')

with open(VERSION_FILE) as stream:
__version__ = stream.readline().strip()
__version__ = "1.1.2"

setup(
name = 'pgcolorbar',
Expand Down