Skip to content
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

Add xml parameterizable directories (Sourcery refactored) #25

Open
wants to merge 1 commit into
base: dir-xml-support
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Oct 26, 2021

Pull Request #24 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the dir-xml-support branch, then run:

git fetch origin sourcery/dir-xml-support
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from tfcollins October 26, 2021 01:02
Comment on lines -89 to +118
if "hw" in ctx and hasattr(_iio_emu, "auto") and _iio_emu.auto:
if _iio_emu.current_device != ctx["hw"]:
# restart with new hw
if _iio_emu.p:
print("Stopping iio-emu")
_iio_emu.stop()
else:
print("Using same hardware not restarting iio-emu")
map = get_hw_map(request)
fn, dd = get_filename(map, ctx["hw"])
if not fn:
return ctx
if request.config.getoption("--emu-xml-dir"):
path = request.config.getoption("--emu-xml-dir")
exml = os.path.join(path, fn)
print("exml", exml)
else:
path = pathlib.Path(__file__).parent.absolute()
exml = os.path.join(path, "resources", "devices", fn)
if not os.path.exists(exml):
pytest.skip("No XML file found for hardware")
_iio_emu.xml_path = exml
_iio_emu.current_device = ctx["hw"]
_iio_emu.data_devices = dd
print("Starting iio-emu")
_iio_emu.start()
if (
"hw" in ctx
and hasattr(_iio_emu, "auto")
and _iio_emu.auto
and _iio_emu.current_device != ctx["hw"]
):
# restart with new hw
if _iio_emu.p:
print("Stopping iio-emu")
_iio_emu.stop()
else:
print("Using same hardware not restarting iio-emu")
map = get_hw_map(request)
fn, dd = get_filename(map, ctx["hw"])
if not fn:
return ctx
if request.config.getoption("--emu-xml-dir"):
path = request.config.getoption("--emu-xml-dir")
exml = os.path.join(path, fn)
print("exml", exml)
else:
path = pathlib.Path(__file__).parent.absolute()
exml = os.path.join(path, "resources", "devices", fn)
if not os.path.exists(exml):
pytest.skip("No XML file found for hardware")
_iio_emu.xml_path = exml
_iio_emu.current_device = ctx["hw"]
_iio_emu.data_devices = dd
print("Starting iio-emu")
_iio_emu.start()
Copy link
Author

Choose a reason for hiding this comment

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

Function handle_iio_emu refactored with the following changes:

Comment on lines -222 to +228
else:
for dec in _contexts:
if dec["hw"] in marker.args[0]:
return dec
for dec in _contexts:
if dec["hw"] in marker.args[0]:
return dec
Copy link
Author

Choose a reason for hiding this comment

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

Function single_ctx_desc refactored with the following changes:

Comment on lines -265 to +270
else:
for dec in _contexts:
if dec["hw"] in marker.args[0]:
return handle_iio_emu(dec, request, _iio_emu)
for dec in _contexts:
if dec["hw"] in marker.args[0]:
return handle_iio_emu(dec, request, _iio_emu)
Copy link
Author

Choose a reason for hiding this comment

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

Function _iio_emu_func refactored with the following changes:

Comment on lines -296 to +298
devices = []
for field in map[hw]:
if isinstance(field, str):
devices.append(field)
devices = [field for field in map[hw] if isinstance(field, str)]
Copy link
Author

Choose a reason for hiding this comment

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

Function _iio_emu refactored with the following changes:

Comment on lines -319 to +323
ctx_plus_hw = []
for hw in _iio_emu.hw:
ctx_plus_hw.append(
{
ctx_plus_hw = [{
"uri": _iio_emu.uri,
"type": "emu",
"devices": _iio_emu.hw[hw]["devices"],
"hw": hw,
}
)
} for hw in _iio_emu.hw]
Copy link
Author

Choose a reason for hiding this comment

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

Function _contexts refactored with the following changes:

Comment on lines -400 to -409
for hw_ctx_attr in ctx_attrs:
for hw_ctx_attr, value in ctx_attrs.items():
if (
hw_ctx_attr == attr_name
and attr_dict[attr_name]
in ctx_attrs[hw_ctx_attr]
and attr_dict[attr_name] in value
):
found += 1
# Compare other attribute types ...
if attr_type == "dev_attr":
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function lookup_hw_from_map refactored with the following changes:

This removes the following comments ( why? ):

# Compare other attribute types ...

Comment on lines -431 to +422
if request.config.getoption("--skip-scan"):
ctxs = None
else:
ctxs = iio.scan_contexts()
ctxs = None if request.config.getoption("--skip-scan") else iio.scan_contexts()
Copy link
Author

Choose a reason for hiding this comment

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

Function find_contexts refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Oct 26, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 2.20%.

Quality metrics Before After Change
Complexity 22.08 😞 18.77 😞 -3.31 👍
Method Length 79.68 🙂 78.89 🙂 -0.79 👍
Working memory 9.14 🙂 9.20 🙂 0.06 👎
Quality 54.59% 🙂 56.79% 🙂 2.20% 👍
Other metrics Before After Change
Lines 426 414 -12
Changed files Quality Before Quality After Quality Change
pytest_libiio/plugin.py 54.59% 🙂 56.79% 🙂 2.20% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
pytest_libiio/plugin.py lookup_hw_from_map 63 ⛔ 177 😞 16 ⛔ 19.45% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
pytest_libiio/plugin.py _contexts 18 🙂 169 😞 11 😞 42.70% 😞 Try splitting into smaller methods. Extract out complex expressions
pytest_libiio/plugin.py _iio_emu 22 😞 145 😞 9 🙂 46.24% 😞 Refactor to reduce nesting. Try splitting into smaller methods
pytest_libiio/plugin.py handle_iio_emu 12 🙂 139 😞 12 😞 48.99% 😞 Try splitting into smaller methods. Extract out complex expressions
pytest_libiio/plugin.py find_contexts 8 ⭐ 125 😞 11 😞 56.02% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants