Skip to content

Commit 38d5c95

Browse files
committed
Modified setup.py and control/__init__.py to match numpy.
I tried to avoid using the _CONTROL_SETUP_ switch like numpy but this was causing some issues for Travis CI. This means for setup.py test to work we can't do control import * so I had to change to explicit imports for discrete_test.py. Closes python-control#37.
1 parent 731112b commit 38d5c95

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

control/tests/discrete_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55

66
import unittest
77
import numpy as np
8-
from control import *
8+
from control.statesp import StateSpace
9+
from control import matlab
10+
from control.xferfcn import TransferFunction
11+
from control.lti import isdtime, timebase, isctime, timebaseEqual
12+
from control.dtime import sample_system
13+
from control.bdalg import feedback
14+
from control.timeresp import step_response, impulse_response, forced_response
15+
from control.freqplot import bode
16+
917

1018
class TestDiscrete(unittest.TestCase):
1119
"""Tests for the DiscreteStateSpace class."""

setup.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
MAJOR = 0
2020
MINOR = 6
21-
MICRO = 5
21+
MICRO = 6
2222
ISRELEASED = True
2323
DISTNAME = 'control'
2424
DESCRIPTION = 'Python control systems library'
@@ -36,15 +36,6 @@
3636
tests_require=['scipy', 'matplotlib', 'nose']
3737
)
3838

39-
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
40-
41-
import os
42-
import sys
43-
import subprocess
44-
45-
46-
from setuptools import setup, find_packages
47-
4839
CLASSIFIERS = """\
4940
Development Status :: 3 - Alpha
5041
Intended Audience :: Science/Research
@@ -60,6 +51,23 @@
6051
Operating System :: MacOS
6152
"""
6253

54+
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
55+
56+
import os
57+
import sys
58+
import subprocess
59+
from setuptools import setup, find_packages
60+
61+
# check for python version
62+
if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2):
63+
raise RuntimeError("Python version 2.6, 2.7 or >= 3.2 required.")
64+
65+
# use builtins to store if we are running setup
66+
if sys.version_info[0] >= 3:
67+
import builtins
68+
else:
69+
import __builtin__ as builtins
70+
6371

6472
# Return the git revision as a string
6573
def git_version():
@@ -88,6 +96,12 @@ def _minimal_ext_cmd(cmd):
8896

8997
return GIT_REVISION
9098

99+
# This is a bit hackish: we are setting a global variable so that the main
100+
# numpy __init__ can detect if it is being loaded by the setup routine, to
101+
# avoid attempting to load components that aren't built yet. While ugly, it's
102+
# a lot more robust than what was previously being used.
103+
builtins.__CONTROL_SETUP__ = True
104+
91105

92106
def get_version_info():
93107
# Adding the git rev number needs to be done inside write_version_py(),
@@ -100,10 +114,12 @@ def get_version_info():
100114
# must be a source distribution, use existing version file
101115
try:
102116
from control.version import git_revision as GIT_REVISION
103-
except ImportError:
104-
raise ImportError("Unable to import git_revision. Try removing "
105-
"control/version.py and the build directory "
106-
"before building.")
117+
except ImportError as e:
118+
raise ImportError(
119+
str(e) +
120+
", Unable to import git_revision. Try removing "
121+
"control/version.py and the build directory "
122+
"before building.")
107123
else:
108124
GIT_REVISION = "Unknown"
109125

0 commit comments

Comments
 (0)