Last active
August 29, 2015 14:15
-
-
Save mariocesar/c73d09478b8f112e6358 to your computer and use it in GitHub Desktop.
Setup.py util to get common description variables like version, author, etc from packages without importing the modules. (To avoid circular imports and related errors)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__version__ = "0.1" | |
__author__ = "mariocesar" | |
def get_module_meta(module_path): | |
import re | |
with open(module_path) as cakebet_meta: | |
meta = cakebet_meta.read() | |
return dict(re.findall('(?P<key>__.+__)\s=\s["\' ](?P<value>.+)["\' ]', meta)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from utils import setup_utils | |
meta = setup_utils.get_module_meta('setup_utils.py') | |
assert '__version__' in meta | |
assert '__author__' in meta | |
assert meta['__author__'] == 'mariocesar' | |
assert meta['__version__'] == '0.1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment