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

US1198694: add nidcpower.Session.get_channel_names() #1578

Merged

Conversation

luisgomes252
Copy link
Contributor

@luisgomes252 luisgomes252 commented Apr 7, 2021

  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

Add get_channel_names() for NI-DCPower API

List issues fixed by this Pull Request below, if any.

Closes #1588

What testing has been done?

Added new system test and ran all unit tests. System tests will be run by CI.

@nimi-bot
Copy link

nimi-bot commented Apr 7, 2021

Can one of the admins verify this patch?

@marcoskirsch
Copy link
Member

FYI merge conflict @luisgomes252

@marcoskirsch marcoskirsch changed the title Us1198694/nidcpower get channel names US1198694 add nidcpower.Session.get_channel_names() Apr 9, 2021
@sbethur
Copy link
Contributor

sbethur commented Apr 9, 2021

ok to test

@codecov
Copy link

codecov bot commented Apr 9, 2021

Codecov Report

Merging #1578 (a5643de) into master (661c2f3) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1578      +/-   ##
==========================================
- Coverage   91.68%   91.67%   -0.01%     
==========================================
  Files          20       20              
  Lines        3463     3509      +46     
==========================================
+ Hits         3175     3217      +42     
- Misses        288      292       +4     
Flag Coverage Δ
codegenunittests 88.34% <100.00%> (+0.06%) ⬆️
nifakeunittests 96.36% <ø> (ø)
nimodinstunittests 95.37% <ø> (ø)
nitclkunittests 95.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
build/helper/__init__.py 100.00% <100.00%> (ø)
build/helper/helper.py 91.33% <100.00%> (+3.04%) ⬆️
build/helper/metadata_add_all.py 80.68% <100.00%> (-0.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 661c2f3...a5643de. Read the comment docs.

@marcoskirsch
Copy link
Member

ok to test

@sbethur
Copy link
Contributor

sbethur commented Apr 14, 2021

test this please

@sbethur
Copy link
Contributor

sbethur commented Apr 19, 2021

@luisgomes252, a system test is failing:

multi_instrument_session = nidcpower.Session(resource_name='PXI1Slot2,PXI1Slot5', channels='', reset=False, options='Simulate=1, DriverSetup=Model:4162; BoardType:PXIe')

    def test_get_channel_names(multi_instrument_session):
        # Once we have support for independent channels, we should update this test to include
        # the instrument names in the expected channel names -- or possibly add a separate test
        # expected_string = ['{0}/{1}'.format(instruments[0], x) for x in range(12)]
        expected_string = ['{0}'.format(x) for x in range(12)]
        channel_indices = ['0-1, 2, 3:4', 5, (6, 7), range(8, 10), slice(10, 12)]
>       assert multi_instrument_session.get_channel_names(indices=channel_indices) == expected_string

..\..\src\nidcpower\system_tests\test_system_nidcpower.py:48: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

@sbethur
Copy link
Contributor

sbethur commented Apr 26, 2021

Please update the description and referenced issue.

Also, you can use a particular format to auto-close the issue when PR is merged: https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue

@sbethur
Copy link
Contributor

sbethur commented Apr 27, 2021

Linter is complaining:

src/nidcpower/system_tests/test_system_nidcpower.py:7:1: E302 expected 2 blank lines, found 1

@pytest.fixture(scope='function')

^

ERROR: InvocationError for command /home/travis/build/ni/nimi-python/.tox/64/py38-flake8/bin/flake8 --config=./tox.ini src/nidcpower/system_tests/ src/nidcpower/examples/ (exited with code 1)

@luisgomes252
Copy link
Contributor Author

Linter is complaining:

src/nidcpower/system_tests/test_system_nidcpower.py:7:1: E302 expected 2 blank lines, found 1

@pytest.fixture(scope='function')

^

ERROR: InvocationError for command /home/travis/build/ni/nimi-python/.tox/64/py38-flake8/bin/flake8 --config=./tox.ini src/nidcpower/system_tests/ src/nidcpower/examples/ (exited with code 1)

Argh. I keep doing this.

Where did you go to see the Linter output?

@sbethur
Copy link
Contributor

sbethur commented Apr 27, 2021

Linter is complaining:

src/nidcpower/system_tests/test_system_nidcpower.py:7:1: E302 expected 2 blank lines, found 1

@pytest.fixture(scope='function')

^

ERROR: InvocationError for command /home/travis/build/ni/nimi-python/.tox/64/py38-flake8/bin/flake8 --config=./tox.ini src/nidcpower/system_tests/ src/nidcpower/examples/ (exited with code 1)

Argh. I keep doing this.

Where did you go to see the Linter output?

image

Here's the link to it: https://travis-ci.org/github/ni/nimi-python/builds/768570772

@sbethur
Copy link
Contributor

sbethur commented May 3, 2021

test this please

@@ -271,7 +275,11 @@ def _add_render_in_session_base(f):
def _add_is_repeated_capability(parameter):
Copy link
Member

Choose a reason for hiding this comment

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

This whole method is one big hack. We're inferring if a parameter is a repeated capability based on the name of the parameter; unless explicitly denoted. There are historical reasons for it, but I strongly question it nowadays:

Shouldn't we fix this in metadata? Then (I think) we can remove the inferring code and we can remove all this camel case conversion business.

Here's the thing: converting snakecase_to_camelcase in order to reverse the python name is a bit sketchy. It assumes that python name to C name are always camelCase to snake_case. Which happens to be true right now but doesn't really have to be true.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we fix this in metadata? Then (I think) we can remove the inferring code and we can remove all this camel case conversion business.

Agreed, that the right fix, but it involves retrofitting metadata for all the drivers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Between the comments in this PR, and now the ones here in this PR, this relatively small user story is beginning to feel like a giant exercise of pulling at threads to see how can much can be unraveled. I won't dispute that there was some technical debt in the code that should probably be addressed at some point -- although I'm not the expert here, I can certainly agree that making assumptions on repeated capabilities based on the name of the parameter doesn't sound great. But I really wonder whether an "inner source" project in which we were asked to help complete the CXP API changes for nidcpower is the best vehicle for solving all this tech debt. After all, we also have a lot of tech debt in TSM that is waiting for attention too. The user story was ostensibly about adding support for instrument-based repeated capabilities for attributes (not even for function parameters). Here we are, almost a month later, and I'm no longer sure what the scope of the user story is any more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I stand corrected. This PR isn't even for the repeated capabilities user story (it's been so long, all these PRs are beginning to blur into each other). This one was just for the get_channel_names entry point, which isn't even related to repeated capabilities. It just exposed this issue because I needed to add support in the metadata for python_name in function parameters, which then introduced the need to update the _repeated_capability_parameter_names looksups . So I guess it's more relevant to Marcos' comment than my first comment implied. But we're still pretty far afield from the original user story.

Copy link
Contributor

Choose a reason for hiding this comment

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

Spoke with @luisgomes252 offline and suggested to remove the workaround in _add_is_repeated_capability and add is_repeated_capability = false to nidcpower metadata to prevent the rep cap tip from getting added to the docstring.

The inferring logic will still be present and we should clean it up, not that's outside the scope of this PR.

Even setting is_repeated_capability = false can be done in a separate PR since others are blocked on this PR going in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on the conversation with @sbethur, I've reverted the changes that I had made to use the python_name metadata in determining whether to add the repeated capability. Currently, get_channel_names is incorrectly being generated with metadata, but I'll fix that by updating the dcpower metadata in a subsequent PR so that I can get this one submitted as soon as possible, because a) other PRs are being gated by this one, and b) if I have to grab a new metadata export, that will also pull in a bunch of unrelated changes into this diff. So I'd like to split the PRs, if possible. @marcoskirsch: if you agree, and you have no other objections, please approve this PR when you have a chance.

@sbethur
Copy link
Contributor

sbethur commented May 3, 2021

test this please

…feedback. I will fix the incorrect repeated capability for the parameter names later, by adding metadata is_repeated_capability tags to the get_channel_names parameters.
@luisgomes252 luisgomes252 requested a review from marcoskirsch May 6, 2021 15:58
@sbethur
Copy link
Contributor

sbethur commented May 6, 2021

test this please

@luisgomes252 luisgomes252 changed the title US1198694 add nidcpower.Session.get_channel_names() US1198694: add nidcpower.Session.get_channel_names() May 7, 2021
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.

get_channel_name() should be deprecated and replaced by get_channel_names() in nidcpower
4 participants