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

feat: Read plugin version from distribution, with fallback to package #1254

Closed
wants to merge 12 commits into from

Conversation

kgpayne
Copy link
Contributor

@kgpayne kgpayne commented Dec 7, 2022

In cases where the distribution name does not match the tap/target ID (also the package name by default) the Version reported in --about registers as [could not be detected].

e.g. tap-snowflake with package name tap_snowflake distributed as meltanolabs-tap-snowflake, to avoid PyPI name clashes.

Related to MeltanoLabs/tap-snowflake#8


📚 Documentation preview 📚: https://meltano-sdk--1254.org.readthedocs.build/en/1254/

@kgpayne kgpayne changed the title feat: get plugin version from distribution feat: plugin version read from distribution before package Dec 7, 2022
@kgpayne kgpayne changed the title feat: plugin version read from distribution before package feat: read plugin version from distribution, with fallback to package Dec 7, 2022
@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Merging #1254 (17a64b9) into main (2439682) will decrease coverage by 0.02%.
The diff coverage is 80.00%.

@@            Coverage Diff             @@
##             main    #1254      +/-   ##
==========================================
- Coverage   83.85%   83.82%   -0.03%     
==========================================
  Files          44       44              
  Lines        4150     4155       +5     
  Branches      718      719       +1     
==========================================
+ Hits         3480     3483       +3     
- Misses        490      491       +1     
- Partials      180      181       +1     
Impacted Files Coverage Δ
singer_sdk/plugin_base.py 73.59% <80.00%> (-0.40%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@kgpayne
Copy link
Contributor Author

kgpayne commented Dec 7, 2022

Windows tests are failing, and I don't have an environment (or the familiarity of Windows+Python 😅) to debug. Given this doesn't cause a hard-fail (we simply get [could not be detected] in --about if no distribution and no package is found), I feel comfortable leaving the platform-specific xfail. Maybe a Windows-familiar community member will help us out in a future iteration 👍

@kgpayne kgpayne marked this pull request as ready for review December 7, 2022 18:01
@edgarrmondragon edgarrmondragon changed the title feat: read plugin version from distribution, with fallback to package feat: Read plugin version from distribution, with fallback to package Dec 7, 2022
singer_sdk/helpers/_compat.py Outdated Show resolved Hide resolved
singer_sdk/plugin_base.py Outdated Show resolved Hide resolved
@kgpayne kgpayne marked this pull request as draft December 7, 2022 19:40
@kgpayne kgpayne marked this pull request as ready for review December 14, 2022 11:00
Comment on lines +16 to +17
if platform.system() == "Windows":
pytest.xfail("Doesn't pass on windows.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean the package name can't be retrieved in Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It means the lookup via distribution will not work, yes. The fallback to metadata.version(cls.name) was the primary mechanism before this change (it relies on the library name being the same as the class name), though I don't know how well it worked for Windows in the first place 🤔

Given the hurdles we have to jump through to try and infer the plugin version via distribution or library metadata, I still think we are better off adding __version__ = "<version>" in __init__.py and importing that for --about. poetry-dynamic-versioning supports substitution from a 0.0.0 placeholder in any file (including __init__.py by default), and this approach is standard in other python packages 🤷‍♂️ This PR specifically addresses this ask from @aaronsteers 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kgpayne Yeah, I'd say it's probably not worth spending time trying to solve a problem that's only present when migrating existing taps and targets that are published to PyPI. Wdyt?

Copy link
Contributor

@cjohnhanson cjohnhanson left a comment

Choose a reason for hiding this comment

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

approved, pending that one open thread, but looks good to me

@kgpayne
Copy link
Contributor Author

kgpayne commented Feb 8, 2023

Closing in favour of __version__ = "<version>" in __init__.py solution:

I still think we are better off adding __version__ = "<version>" in __init__.py and importing that for --about. poetry-dynamic-versioning supports substitution from a 0.0.0 placeholder in any file (including __init__.py by default), and this approach is standard in other python packages 🤷‍♂️

@kgpayne kgpayne closed this Feb 8, 2023
@kgpayne
Copy link
Contributor Author

kgpayne commented Feb 8, 2023

@kgpayne kgpayne deleted the kgpayne/missing-version-on-about-variant-bug branch February 8, 2023 16:48
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