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

refactor: pkg_resources -> importlib.metadata #24514

Merged
merged 2 commits into from
Jun 28, 2023

Conversation

cwegener
Copy link
Contributor

@cwegener cwegener commented Jun 26, 2023

pkg_resources is in the process of being deprecated in favor of
importlib.metadata and importlib.resources

importlib.metadata has been available in the standard library since 3.8

And as of 3.10 the importlib.metadata API is no longer provisional

In order to support Python version older than 3.10, the
importlib_metadata backport is used instead of the actual
importlib.metadata API.

@cwegener cwegener marked this pull request as draft June 26, 2023 09:33
@cwegener cwegener marked this pull request as ready for review June 26, 2023 09:53
@cwegener cwegener marked this pull request as draft June 26, 2023 09:58
@cwegener cwegener marked this pull request as ready for review June 26, 2023 10:03
@cwegener cwegener marked this pull request as draft June 26, 2023 10:45
@cwegener cwegener marked this pull request as ready for review June 26, 2023 10:46
@john-bodley
Copy link
Member

Thanks @cwegener for the PR. Note you'll also have to re-compile the Python dependencies which ensures we have a frozen set of Python packages (and sub-packages) for testing purposes. Please refer to the CONTRIBUTING.md file with regards to how to do this.

@cwegener
Copy link
Contributor Author

Thanks @cwegener for the PR. Note you'll also have to re-compile the Python dependencies which ensures we have a frozen set of Python packages (and sub-packages) for testing purposes. Please refer to the CONTRIBUTING.md file with regards to how to do this.

Hi John. I tried, but pip-compile-multi seems to just blissfully ignore the install_dependencies from setup.py

Do you have any hints on how to make pip-compile-multi read the install_dependencies collection from setup.py?

@john-bodley
Copy link
Member

@cwegener I gather you mean install_requirements rather than install_dependencies? Note that pip-compile-multi should adhere to the requirements. Would you mind sharing the command(s) you ran?

@cwegener
Copy link
Contributor Author

@cwegener I gather you mean install_requirements rather than install_dependencies? Note that pip-compile-multi should adhere to the requirements. Would you mind sharing the command(s) you ran?

Sorry, yes. Typo. install_requires is what I'm referring to.
All good. It turns out that the result of pip-compile-multi -P importlib-metadata is simply a noop, because there is no change to the version of importlib-metadata that is already present.
And pip-compile-multi just doesn't need to know that importlib-medata is now a top-level require instead of a transitive one.

pkg_resources is in the process of being deprecated in favor of
importlib.metadata and importlib.resources

importlib.metadata has been available in the standard library since 3.8

And as of 3.10 the importlib.metadata API is no longer provisional

In order to support Python version older than 3.10, the
`importlib_metadata` backport is used instead of the actual
`importlib.metadata` API.
@cwegener
Copy link
Contributor Author

I did just force push the 'noop' result from pip-compile-multi, which is basically just adding the comment into the requirements/base.txt for good measure.

@@ -137,7 +137,9 @@ humanize==3.11.0
idna==3.2
# via email-validator
importlib-metadata==6.6.0
# via flask
# via
# apache-superset
Copy link
Member

Choose a reason for hiding this comment

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

Yes!

@cwegener
Copy link
Contributor Author

On a different note, once I'm done with this pkg_resources migration (I'll publish the other part which is the migration to importlib.resources shortly) and setuptools should then no longer be a dependency,I hope to convince the superset contributors to migrate from setuptools+pip-compile-multi to hatch+pdm ... 😄

@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Merging #24514 (5361e38) into master (ba3bdc0) will increase coverage by 0.01%.
The diff coverage is 94.73%.

❗ Current head 5361e38 differs from pull request most recent head c2c4485. Consider uploading reports for the commit c2c4485 to get more accurate results

@@            Coverage Diff             @@
##           master   #24514      +/-   ##
==========================================
+ Coverage   69.06%   69.07%   +0.01%     
==========================================
  Files        1901     1903       +2     
  Lines       74019    74027       +8     
  Branches     8116     8118       +2     
==========================================
+ Hits        51121    51136      +15     
+ Misses      20787    20780       -7     
  Partials     2111     2111              
Flag Coverage Δ
hive 53.89% <100.00%> (-0.01%) ⬇️
mysql 79.41% <100.00%> (-0.01%) ⬇️
postgres 79.50% <100.00%> (-0.01%) ⬇️
presto 53.79% <100.00%> (-0.01%) ⬇️
python 83.48% <100.00%> (-0.01%) ⬇️
sqlite 78.00% <100.00%> (-0.01%) ⬇️
unit 54.65% <100.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
.../plugins/plugin-chart-echarts/src/BoxPlot/index.ts 50.00% <ø> (ø)
...d/plugins/plugin-chart-echarts/src/Funnel/index.ts 50.00% <ø> (ø)
...nd/plugins/plugin-chart-echarts/src/Gauge/index.ts 50.00% <ø> (ø)
...nd/plugins/plugin-chart-echarts/src/Graph/index.ts 50.00% <ø> (ø)
.../plugin-chart-echarts/src/MixedTimeseries/index.ts 25.00% <ø> (ø)
...tend/plugins/plugin-chart-echarts/src/Pie/index.ts 50.00% <ø> (ø)
...nd/plugins/plugin-chart-echarts/src/Radar/index.ts 50.00% <ø> (ø)
...plugins/plugin-chart-echarts/src/Sunburst/index.ts 50.00% <ø> (ø)
.../plugin-chart-echarts/src/Timeseries/Area/index.ts 33.33% <ø> (ø)
...-chart-echarts/src/Timeseries/Regular/Bar/index.ts 33.33% <ø> (ø)
... and 23 more

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

@cwegener
Copy link
Contributor Author

@john-bodley Sorry about the missing import sort. I just pushed the fix for that. Can you run the GH actions again.

@john-bodley
Copy link
Member

@cwegener with regards to,

I hope to convince the superset contributors to migrate from setuptools+pip-compile-multi to hatch+pdm ...

it might make sense to first create an issue (or possibly a SIP dependency on the complexity) regarding your intentions as it's probably worth discussing the pros/cons especially given the slew of Python package managers floating around.

@john-bodley
Copy link
Member

@cwegener after rereading your PR description you mention that,

importlib.metadata has been available in the standard library since 3.8

and given we only support Python 3.9+ I was wondering why we need to use the backport.

@cwegener
Copy link
Contributor Author

and given we only support Python 3.9+ I was wondering why we need to use the backport.

The backport is needed because the API of importlib.metadata is actually different in 3.9. The API has only been stable in 3.10.

Specifically, the entry_points() signature in 3.9 was still different, it didn't have the groups parameter in the 3.9 standard library. So the stable API is only available in the backport. (Found that out when I developed this change in 3.10 accidentally and then ran unit tests in 3.9)

@john-bodley john-bodley merged commit f1b003f into apache:master Jun 28, 2023
@cwegener
Copy link
Contributor Author

Specifically, the entry_points() signature in 3.9 was still different, it didn't have the groups parameter in the 3.9 standard library. So the stable API is only available in the backport. (Found that out when I developed this change in 3.10 accidentally and then ran unit tests in 3.9)

The best I can tell, the 'select' feature wasn't there in the entry_points()

I did just see though that there also is a more specific backport of JUST the select feature for entry_points() 😁

https://github.com/jaraco/backports.entry_points_selectable

@cwegener cwegener deleted the importlib-metadata branch July 3, 2023 10:04
cwegener added a commit to cwegener/superset that referenced this pull request Jul 3, 2023
(Part 1 of 2)

setuptools' pkg_resources is in the process of being deprecated in favor
of importlib.resources and importlib.metadata (see also PR apache#24514)

importlib.resources has been available in the standard library since
Python 3.7

This change follows the importlib_resources migration guide and does not
perform any additional refactoring.

The last component that is using pkg_resources is
'superset.config.BASE_DIR'

'superset.config.BASE_DIR' is mainly used as the default file upload
directory in Flask and therefore requires special attention as this
directory needs to be writable and needs to exist for the full lifetime
of the Flask application.
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/S 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants