Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
quick and dirty parser for version number in legacy-defaults
  • Loading branch information
sawyerbfuller committed Jul 23, 2020
commit 77a38fcb32bfe698fe5b9dc2c9c0b60b36ebfd06
13 changes: 10 additions & 3 deletions control/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@ def use_legacy_defaults(version):
Parameters
----------
version : string
version number of the defaults desired. Currently only supports `0.8.3`.
version number of the defaults desired. ranges from '0.1' to '0.8.4'.
"""
if version == '0.8.3':
first_digit = int(version[0])
second_digit = int(version[2])
if second_digit < 8:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will break with >=0.10.0

Maybe use setuptool's packaging.version.parse?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found I could make a quick change that addresses this concern - does what I came up with look ok? alternatively, are you sure a dependency on the module you proposed ok to have? (is it always included in python?)

@bnavigator bnavigator Jul 24, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an edge case. setuptools should not really be needed after install, or if you get the package from something else. The other option mentioned in that SO question is undocumented but standard lib distutils.version. python-control already uses that within the test suite.

Although your quick solution works, too. I would be fine with it. (Not to imply that I have any authority. I am only here to contribute unwarranted suggestions. 😉)

# TODO: anything for 0.7 and below if needed
pass
elif second_digit == 8:
if len(version) > 4:
third_digit = int(version[4])
use_numpy_matrix(True) # alternatively: set_defaults('statesp', use_numpy_matrix=True)
else:
raise ValueError('''version number not recognized. Possible values are: ['0.8.3']''')
raise ValueError('''version number not recognized. Possible values range from '0.1' to '0.8.4'.''')
6 changes: 6 additions & 0 deletions control/tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ def test_legacy_defaults(self):
assert(isinstance(ct.ss(0,0,0,1).D, np.matrix))
ct.reset_defaults()
assert(isinstance(ct.ss(0,0,0,1).D, np.ndarray))
# test that old versions don't raise a problem
ct.use_legacy_defaults('0.6c')
ct.use_legacy_defaults('0.8.2')
ct.use_legacy_defaults('0.1')
ct.config.reset_defaults()


def test_change_default_dt(self):
ct.set_defaults('statesp', default_dt=0)
Expand Down