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

MAINT: allow users to import id constants from api #508

Merged
merged 11 commits into from Mar 10, 2023
Merged

Conversation

homosapien-lcy
Copy link
Contributor

@homosapien-lcy homosapien-lcy commented Mar 7, 2023

Import ids constants in api, allow downstream users to import them from envisage.api.

Closes #506

@mdickinson
Copy link
Member

Thank you for the PR! A couple of things:

  • It's helpful to always include a PR description. At a minimum, the description should reference the issue that's being solved. (Also, the current settings on this repository are to use the PR title and description for the commit message, so the description is helpful there, too.)
  • Like any change to user-visible behaviour, we should have a test. Please could you add a unit test that validates these changes?
  • I see that you added two of the ids to envisage.api, but there are still several ids in envisage.ids that aren't being exported in envisage.api. Could you take a look at those ones too, please?

@homosapien-lcy
Copy link
Contributor Author

Thank you for the PR! A couple of things:

  • It's helpful to always include a PR description. At a minimum, the description should reference the issue that's being solved. (Also, the current settings on this repository are to use the PR title and description for the commit message, so the description is helpful there, too.)
  • Like any change to user-visible behaviour, we should have a test. Please could you add a unit test that validates these changes?
  • I see that you added two of the ids to envisage.api, but there are still several ids in envisage.ids that aren't being exported in envisage.api. Could you take a look at those ones too, please?

Thanks for the comments, I have two questions:

1 which other ids should be included? I actually discussed with a colleague in the same office, we thought that only these two are ids...

2 For the unit test, should I just implement an assert equal for the values imported from api vs from the ids?

@mdickinson
Copy link
Member

which other ids should be included? I actually discussed with a colleague in the same office, we thought that only these two are ids...

That's a good question - the goal here is that in the future, all imports from envisage.ids can be replaced with imports from envisage.api. So for the first cut, all the ids should be made available.

For the unit test, should I just implement an assert equal for the values imported from api vs from the ids?

That would work. It's always worth stepping back a bit before writing a unit test and asking exactly what should be tested: we're making a behaviour change for a reason (in this case so that Envisage users can import from api), and the test should reflect the new behaviour - test that the changes have their desired effect.

So in this case, the key thing is to test that these constants are importable from envisage.api - i.e., that doing from envisage.api import <some-constant> succeeds, and gives the expected value. And yes, for that second part, comparing with the value from envisage.ids might be good enough.

@mdickinson
Copy link
Member

@homosapien-lcy : Please do add a PR description when you get the chance. (Different projects have different coding standards, but on ETS projects every PR should have a description.)

@homosapien-lcy
Copy link
Contributor Author

homosapien-lcy commented Mar 8, 2023

There is a strange problem with ci test... the test runs perfectly in my local Mac:
Screen Shot 2023-03-08 at 11 07 59 AM
After looking at the test, it seems to be a unique problem with python 3.7 and 3.8 (my local python is 3.9)... Investigating

@homosapien-lcy
Copy link
Contributor Author

@homosapien-lcy : Please do add a PR description when you get the chance. (Different projects have different coding standards, but on ETS projects every PR should have a description.)

Got it! Just added

@homosapien-lcy
Copy link
Contributor Author

There is a strange problem with ci test... the test runs perfectly in my local Mac: Screen Shot 2023-03-08 at 11 07 59 AM After looking at the test, it seems to be a unique problem with python 3.7 and 3.8 (my local python is 3.9)... Investigating

It is caused by a newly merged PR... Now it's fixed.

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! I have a few minor style nitpicks - see line-by-line comments.

Please could you also add the new constants to the docstring at the top of api.py? You should be able to use the :data: Sphinx role for all of them.

envisage/api.py Outdated
@@ -65,6 +65,9 @@
from .i_plugin_manager import IPluginManager
from .i_service_registry import IServiceRegistry

from .ids import BINDINGS, COMMANDS, PREFERENCES, PREFERENCES_CATEGORIES, \
Copy link
Member

Choose a reason for hiding this comment

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

Style note: on this project, we tend to break up long import lines to place the imports one-per-line. For an example, see the from .extension_point_binding line below.

I'd also like to keep the imports alphabetically ordered as far as possible - this makes it easier for a code reader to scan the set of imports to see if something's there or not (and also helps to minimise merge conflicts in the event that two separate PRs both touch the import list). Please could you move this addition so that it's just before the from .import_manager import?

envisage/tests/test_api.py Show resolved Hide resolved
import envisage.ids as ids


class ApiTestCase(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

I suggest TestApi, to match the name of the module. (We do have a few existing *TestCase names, but in new code we should migrate away from that pattern.)

Suggested change
class ApiTestCase(unittest.TestCase):
class TestApi(unittest.TestCase):

@mdickinson
Copy link
Member

Thanks for updating the description! By the way, there's a bit of GitHub magic that's useful here: if you spell the issue reference as "Fixes #506", or "Closes #506", then when this PR is merged, the issue will be automatically closed.

More details here: https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

@homosapien-lcy
Copy link
Contributor Author

Thank you so much! Closes #508

@mdickinson
Copy link
Member

Thank you so much! Closes #508

Unfortunately, this only works if it's in the original PR description. (BTW, I think you mean #506 here.)

I've edited the description.

@homosapien-lcy
Copy link
Contributor Author

@mdickinson The changes you requested have been made

@mdickinson
Copy link
Member

@homosapien-lcy Thank you for the updates! I made a quick drive-by fix to the heading underlines. (Otherwise Sphinx will complain at some point.)

I'll merge when the CI completes.

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

Updates look good; thank you.

@mdickinson mdickinson merged commit 011c9cf into main Mar 10, 2023
@mdickinson mdickinson deleted the api_import_fix branch March 10, 2023 09:50
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.

ids should be available from envisage.api
2 participants