-
Notifications
You must be signed in to change notification settings - Fork 85
Extended YAML support #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1bf47ce
Added test:// URI schema.
cgranade 4eef89d
Config: Py3 fix and support for setting attrs.
cgranade 6507fb3
Added sub/indexing to attrs config.
cgranade e878a21
ThorLabsAPT: Example of new config support.
cgranade 8669ae7
Added to docstring.
cgranade 1ce0320
Added support for physical quantities to config.
cgranade b0c6809
pylint fixes
cgranade eaec515
More pylint fixes
cgranade c92cd6f
Tests for new setattr_expression
cgranade fc853c2
Added tests for new config, YAML.
cgranade b0f7483
pylint fix for new tests
cgranade 10915e6
Very minor pylint fix
cgranade e2f4c33
Added ruamel.yaml as testing dep.
cgranade 07d94f0
Reworked awkward sentence.
cgranade e991639
Updated docs for ruamel.yaml dep.
cgranade de20242
Merge branch 'develop' into feature-extended-yaml
cgranade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| mock | ||
| nose | ||
| pylint | ||
| ruamel.yaml | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| Module containing tests for util_fns.py | ||
| """ | ||
|
|
||
| # IMPORTS #################################################################### | ||
|
|
||
| from __future__ import absolute_import, unicode_literals | ||
|
|
||
| from io import StringIO | ||
|
|
||
| import quantities as pq | ||
|
|
||
| from instruments import Instrument | ||
| from instruments.config import ( | ||
| load_instruments, yaml | ||
| ) | ||
|
|
||
| # TEST CASES ################################################################# | ||
|
|
||
| # pylint: disable=protected-access,missing-docstring | ||
|
|
||
| def test_load_test_instrument(): | ||
| config_data = StringIO(u""" | ||
| test: | ||
| class: !!python/name:instruments.Instrument | ||
| uri: test:// | ||
| """) | ||
| insts = load_instruments(config_data) | ||
| assert isinstance(insts['test'], Instrument) | ||
|
|
||
| def test_load_test_instrument_subtree(): | ||
| config_data = StringIO(u""" | ||
| instruments: | ||
| test: | ||
| class: !!python/name:instruments.Instrument | ||
| uri: test:// | ||
| """) | ||
| insts = load_instruments(config_data, conf_path="/instruments") | ||
| assert isinstance(insts['test'], Instrument) | ||
|
|
||
| def test_yaml_quantity_tag(): | ||
| yaml_data = StringIO(u""" | ||
| a: | ||
| b: !Q 37 tesla | ||
| c: !Q 41.2 inches | ||
| d: !Q 98 | ||
| """) | ||
| data = yaml.load(yaml_data) | ||
| assert data['a']['b'] == pq.Quantity(37, 'tesla') | ||
| assert data['a']['c'] == pq.Quantity(41.2, 'inches') | ||
| assert data['a']['d'] == 98 | ||
|
|
||
| def test_load_test_instrument_setattr(): | ||
| config_data = StringIO(u""" | ||
| test: | ||
| class: !!python/name:instruments.Instrument | ||
| uri: test:// | ||
| attrs: | ||
| foo: !Q 111 GHz | ||
| """) | ||
| insts = load_instruments(config_data) | ||
| assert insts['test'].foo == pq.Quantity(111, 'GHz') |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import re | ||
| import struct | ||
| import logging | ||
| import warnings | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's split this into another PR after the yaml stuff |
||
|
|
||
| from builtins import range | ||
| import quantities as pq | ||
|
|
@@ -443,6 +444,8 @@ class MotorChannel(ThorLabsAPT.APTChannel): | |
|
|
||
| # INSTANCE VARIABLES # | ||
|
|
||
| _motor_model = None | ||
|
|
||
| #: Sets the scale between the encoder counts and physical units | ||
| #: for the position, velocity and acceleration parameters of this | ||
| #: channel. By default, set to dimensionless, indicating that the proper | ||
|
|
@@ -496,7 +499,7 @@ class MotorChannel(ThorLabsAPT.APTChannel): | |
|
|
||
| # UNIT CONVERSION METHODS # | ||
|
|
||
| def set_scale(self, motor_model): | ||
| def _set_scale(self, motor_model): | ||
| """ | ||
| Sets the scale factors for this motor channel, based on the model | ||
| of the attached motor and the specifications of the driver of which | ||
|
|
@@ -517,6 +520,38 @@ def set_scale(self, motor_model): | |
| logger.warning("Scale factors for controller %s and motor %s are " | ||
| "unknown", self._apt.model_number, motor_model) | ||
|
|
||
| # We copy the docstring below, so it's OK for this method | ||
| # to not have a docstring of its own. | ||
| # pylint: disable=missing-docstring | ||
| def set_scale(self, motor_model): | ||
| warnings.warn( | ||
| "The set_scale method has been deprecated in favor " | ||
| "of the motor_model property.", | ||
| DeprecationWarning | ||
| ) | ||
| return self._set_scale(motor_model) | ||
|
|
||
| set_scale.__doc__ = _set_scale.__doc__ | ||
|
|
||
| @property | ||
| def motor_model(self): | ||
| """ | ||
| Gets or sets the model name of the attached motor. | ||
| Note that the scale factors for this motor channel are based on the model | ||
| of the attached motor and the specifications of the driver of which | ||
| this is a channel, such that setting a new motor model will update | ||
| the scale factors accordingly. | ||
|
|
||
| :type: `str` or `None` | ||
| """ | ||
| return self._motor_model | ||
|
|
||
| @motor_model.setter | ||
| def motor_model(self, newval): | ||
| self._set_scale(newval) | ||
| self._motor_model = newval | ||
|
|
||
|
|
||
| # MOTOR COMMANDS # | ||
|
|
||
| @property | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If regular
yamlisn't being really developed anymore, lets just kill it and move to usingruamel.yaml