Skip to content

Safely ignore modules named cz_ that are not plugins #480

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

Merged
merged 6 commits into from
Feb 7, 2022

Conversation

mmartinortiz
Copy link
Contributor

When a package starting with a plugin name is found, but it is not a plugin, it becomes safely ignored.

Description

When a packages has a name that matches a plugin, but it is not a plugin, it is safely ignored and reported to the user.

Background: The company where I work, and where I use commitizen for releasing package versions, is called CZ. And because we are not very imaginative, we use to call the packages that we develop for internal use something like cz_.

This collides with the way that commitizen discover plugins, and the discovery process raises an exception when a package starts with the name cz_ is found but is not implemented as a plugin.

This MR proposes a way to ignore those packages that collide in name but are not plugins. This proposal tries to be as agnostic as possible, not very Pythonic, but I am open to suggestions.

Checklist

  • Add test cases to all the changes you introduce
  • Run ./script/format and ./script/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

When the CLI searches for plugins, those packages that have a name cz_ but lack the discover_this attribute, will be ignored and the user will get a warning

Steps to Test This Pull Request

  1. Create a package with a name starting with cz_. It can be located under a src folder
  2. Install commitizen
  3. Run commitizen changelog --help. Without this patch, an exception will be risen.

Additional context

When a package starting with a plugin name is found, but it is not a plugin, it becomes safely ignored.
…not-plugins

fix: Ignore packages that are not plugins
@mmartinortiz
Copy link
Contributor Author

Hi,

This is a terrible PR made at the wrong time of the day from the wrong operating system. I'll fix this and update the PR in the next days.

@mmartinortiz mmartinortiz marked this pull request as draft January 28, 2022 18:03
@codecov
Copy link

codecov bot commented Jan 30, 2022

Codecov Report

Merging #480 (e6f1dc3) into master (71d2d58) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #480      +/-   ##
==========================================
+ Coverage   98.04%   98.05%   +0.01%     
==========================================
  Files          39       39              
  Lines        1431     1441      +10     
==========================================
+ Hits         1403     1413      +10     
  Misses         28       28              
Flag Coverage Δ
unittests 98.05% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
commitizen/cz/__init__.py 100.00% <100.00%> (ø)

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 258f7c9...e6f1dc3. Read the comment docs.

@mmartinortiz mmartinortiz marked this pull request as ready for review January 30, 2022 13:48
@mmartinortiz
Copy link
Contributor Author

This pull request is ready to review. Please let me know if you require some additional changes.

@woile
Copy link
Member

woile commented Feb 5, 2022

Looks good to me, @Lee-W ?

try:
if name.startswith("cz_"):
plugins[name] = importlib.import_module(name).discover_this # type: ignore
except AttributeError as e:
Copy link
Member

@Lee-W Lee-W Feb 6, 2022

Choose a reason for hiding this comment

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

Overall, I like the idea. Most of the part looks good to me

@woile do you think we should go with the exit code method in this case as well?

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean? like a code to easily identify where this warning is coming from?
I'm not sure it's needed, the warning should point to the line in the code AFAIK 🤔

Copy link
Member

Choose a reason for hiding this comment

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

like what we define here so that user can decide whether to suppress the warning. but I'm ok with this PR now. we could create another one if we think that's necessary. it won't break anything if we do that in the future

Copy link
Member

Choose a reason for hiding this comment

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

I just approved it. If you agree with not handling this at this moment, I think we're good to merge it

try:
if name.startswith("cz_"):
plugins[name] = importlib.import_module(name).discover_this # type: ignore
except AttributeError as e:
Copy link
Member

Choose a reason for hiding this comment

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

like what we define here so that user can decide whether to suppress the warning. but I'm ok with this PR now. we could create another one if we think that's necessary. it won't break anything if we do that in the future

@woile woile merged commit 4b5e66d into commitizen-tools:master Feb 7, 2022
@Lee-W Lee-W mentioned this pull request Mar 29, 2022
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.

3 participants