From fb31a4a12fa982684d6a197d2a771f6efec67609 Mon Sep 17 00:00:00 2001 From: Tyler Tian Date: Tue, 6 Oct 2020 00:09:24 -0400 Subject: [PATCH] Update version loading code and bump version Update version loading code in setup.py to use importlib instead of using exec() to load the version module. Bump version to 0.4.0a1. --- pyryver/version.py | 2 +- setup.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pyryver/version.py b/pyryver/version.py index 2dda1fc..46287dd 100644 --- a/pyryver/version.py +++ b/pyryver/version.py @@ -5,4 +5,4 @@ this way the version can be obtained without having to import everything else, which may not be possible due to missing dependencies, thus breaking `setup.py install`. """ -__version__ = "0.4.0a0" +__version__ = "0.4.0a1" diff --git a/setup.py b/setup.py index c04d991..92abc29 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +import importlib +import os import setuptools with open("README.md", "r") as fh: @@ -6,13 +8,22 @@ with open("requirements.txt", "r") as fh: install_requires = fh.read().splitlines() -__version__ = "" -with open("pyryver/version.py", "r") as fh: - exec(fh.read()) # pylint: disable=exec-used + +def get_lib_ver(): + """ + Magical function that loads the version from pyryver/version.py. + + Credits to @mincrmatt12. + """ + spec = importlib.util.spec_from_file_location("pyryver.version", os.path.join(os.path.dirname(__file__), "pyryver/version.py")) + version = importlib.util.module_from_spec(spec) + spec.loader.exec_module(version) + return version.__version__ + setuptools.setup( name="pyryver", - version=__version__, + version=get_lib_ver(), author="Tyler Tian, Matthew Mirvish", author_email="tylertian123@gmail.com, matthew@mm12.xyz", description="An unofficial async Python library for Ryver.",