Skip to content

Commit 7795918

Browse files
committed
Fix issue running setup.py egg_info
Since the main __init__.py imports most of the modules in the project, it was not a good idea to add the `__version__` rariable there. While doing: ``` from ravenpackapi import __version__ ``` imported everything else, so when we run ``` python setup.py egg_info ``` For example, we would get errors like `No module named 'retry'`. By storing the variable in a separate module, we can do some "tricks" to import it in the `setup.py` but skipping the `__init__.py`.
1 parent 0da5ba0 commit 7795918

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

ravenpackapi/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
__version__ = "1.1.1"
21
from .core import RPApi
32
from .exceptions import ApiConnectionError
43
from .models.dataset import Dataset

ravenpackapi/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
22
import os
3-
from platform import python_version
43

5-
from ravenpackapi import __version__
64
from ravenpackapi.exceptions import get_exception
75
from ravenpackapi.key_events.module import KeyEventsApi
86
from ravenpackapi.models.dataset import Dataset
@@ -15,6 +13,7 @@
1513
from ravenpackapi.util import get_python_version, to_curl
1614
from ravenpackapi.utils.date_formats import as_date_str, as_datetime_str
1715
from ravenpackapi.utils.dynamic_sessions import DynamicSession
16+
from ravenpackapi.version import __version__
1817

1918
_VALID_METHODS = ("get", "post", "put", "delete", "patch")
2019

ravenpackapi/tests/unit/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
22

3-
from ravenpackapi import __version__
43
from ravenpackapi.core import RPApi
54
from ravenpackapi.util import get_python_version
5+
from ravenpackapi.version import __version__
66

77

88
class TestRPApiRequests:

ravenpackapi/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.1.1"

setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import sys
2+
13
from setuptools import find_packages, setup
24

3-
from ravenpackapi import __version__
5+
# Hack to get the version number from the package without importing the
6+
# __init__.py and all its dependencies.
7+
sys.path.insert(0, "./ravenpackapi/")
8+
__version__ = __import__("version").__version__
9+
sys.path = sys.path[1:]
10+
411

512
with open("README.rst") as readme_file:
613
readme = readme_file.read()

0 commit comments

Comments
 (0)