Skip to content

Use importlib_metadata backport to avoid CLI UserWarning#10070

Merged
jrbourbeau merged 5 commits intodask:mainfrom
graingert:use-importlib-metadata
Mar 16, 2023
Merged

Use importlib_metadata backport to avoid CLI UserWarning#10070
jrbourbeau merged 5 commits intodask:mainfrom
graingert:use-importlib-metadata

Conversation

@graingert
Copy link
Copy Markdown
Member

@graingert graingert commented Mar 15, 2023

@graingert graingert force-pushed the use-importlib-metadata branch from 415258d to a6ea3a2 Compare March 15, 2023 13:18
# https://github.com/python/cpython/issues/98706
# TODO: when python 3.12 is support is added this should be a
# conditional dependency
"importlib_metadata >= 4.13.0",
Copy link
Copy Markdown
Member Author

@graingert graingert Mar 15, 2023

Choose a reason for hiding this comment

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

I originally had this as:

"importlib_metadata >= 4.13.0; python_full_version < '3.10.9' or (python_version == '3.11' and python_full_version < '3.11.1')"

and then in the code:

if sys.version_info < (3, 10, 9) or ((3, 11) <= sys.version_info < (3, 11, 1)):
    from importlib_metadata import entry_points
else:
    from importlib.metadata import entry_points

however:

  • the conda recipe only supports conditional dependencies on major versions eg: - importlib_metadata # py<312
  • it made the code a bit complicated on every importlib.metadata import,
  • we don't support 3.12 yet so I made it a mandatory release with a TODO: to make it conditional when we add 3.12 support.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could probably use Jinja in the Conda recipe to add a more subtle condition, but that might not be worth it if we already prefer importlib_metadata for other reasons

@graingert graingert force-pushed the use-importlib-metadata branch from a6ea3a2 to 70d3b94 Compare March 15, 2023 13:24
@graingert graingert force-pushed the use-importlib-metadata branch from 70d3b94 to dc8329d Compare March 15, 2023 13:32
@graingert graingert changed the title use importlib_metadata backport use importlib_metadata backport to avoid dask cli UserWarning Mar 15, 2023
@graingert graingert changed the title use importlib_metadata backport to avoid dask cli UserWarning use importlib_metadata backport to avoid dask cli UserWarning Mar 15, 2023
@graingert graingert marked this pull request as ready for review March 15, 2023 14:46
@graingert
Copy link
Copy Markdown
Member Author

I tried this branch out on the distributed PR action and got: distributed/cli/tests/test_dask_spec.py::test_errors PASSED [ 1%]

https://github.com/dask/distributed/actions/runs/4427020593/jobs/7764104973#step:19:96

Copy link
Copy Markdown
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks @graingert! Overall the changes here look reasonable

Is it easy to add a test for this? Otherwise, would the lack of a warning over in distributeds CI suffice?

]
for package in packages:
v = Version(importlib.metadata.version(package))
v = Version(importlib_metadata.version(package))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is importlib version parsing also buggy? If so, using importlib_metadata here sounds good, but if not I'd prefer to stick with importlib.metadata from the stdlib where possible

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's cleaner to always use the backport throughout the whole project rather than have different versions of importlib[._]metadata used in different places

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

especially now that this PR removes entry_points from dask.compatibility I don't want to have some modules with import importlib_metadata and others with import importlib.metadata

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I disagree this is cleaner. That said, the only place this comes up is in a single test that's xfailed -- so not a big deal either way. Let's just go with what you have here

# https://github.com/python/cpython/issues/98706
# TODO: when python 3.12 is support is added this should be a
# conditional dependency
"importlib_metadata >= 4.13.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good 👍

@graingert
Copy link
Copy Markdown
Member Author

graingert commented Mar 15, 2023

Is it easy to add a test for this? Otherwise, would the lack of a warning over in distributeds CI suffice?

I looked into duplicating the strategy in test_register_backend_entrypoint but I don't think it's worth it. I'm happy with the lack of a warning over in distributed's CI if you are!

@graingert graingert requested a review from jrbourbeau March 15, 2023 15:51
@jrbourbeau
Copy link
Copy Markdown
Member

@graingert could you add importlib_metadata to the continuous_integration/environment-*.yaml conda environment files used in CI and to the import test script here

diff --git a/continuous_integration/scripts/test_imports.sh b/continuous_integration/scripts/test_imports.sh
index 1f259cc6e..1f286ec97 100644
--- a/continuous_integration/scripts/test_imports.sh
+++ b/continuous_integration/scripts/test_imports.sh
@@ -5,7 +5,7 @@ set -o errexit
 test_import () {
     echo "Create environment: python=$PYTHON_VERSION $1"
     # Create an empty environment
-    mamba create -q -y -n test-imports -c conda-forge python=$PYTHON_VERSION packaging pyyaml fsspec toolz partd click cloudpickle $1
+    mamba create -q -y -n test-imports -c conda-forge python=$PYTHON_VERSION packaging pyyaml fsspec toolz partd click cloudpickle importlib_metadata $1
     conda activate test-imports
     if [[ $1 =~ "distributed" ]]; then
         # dask[distributed] depends on the latest version of distributed

@graingert
Copy link
Copy Markdown
Member Author

@graingert could you add importlib_metadata to the continuous_integration/environment-*.yaml conda environment files used in CI and to the import test script here

@jrbourbeau done

@jrbourbeau jrbourbeau changed the title use importlib_metadata backport to avoid dask cli UserWarning Use importlib_metadata backport to avoid CLI UserWarning Mar 16, 2023
Copy link
Copy Markdown
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks @graingert!

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.

dask cli UserWarning when using entry points registered by pep660 editable installs from setuptools

4 participants