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

Namespace the client so we do from pystac.client import Client #1334

Open
alexgleith opened this issue Apr 28, 2024 · 4 comments · May be fixed by #1365
Open

Namespace the client so we do from pystac.client import Client #1334

alexgleith opened this issue Apr 28, 2024 · 4 comments · May be fixed by #1365

Comments

@alexgleith
Copy link

This is a pedantic nice-to-have!

I would love to be able to get the client like from pystac.client import Client rather than from pystac_client import Client.

It's a little thing, but it would make me happy!

@gadomski
Copy link
Member

🤔 I'm not sure how this would work in practice — from my understanding (and experience with) namespace packages, they don't allow top-level imports, e.g. if we had from pystac.client import Client we couldn't have from pystac import Item. I could be wrong about this, though...

In the past, we've considered merging pystac-client into pystac itself, which would get you what you wanted. We haven't done this because we didn't want to increase pystac's dependencies, and we felt that using optional dependencies was a bit awkward. The awkwardness of having a separate API client library is part of the reason why we haven't pushed pystac-client to v1, because we haven't been totally sure that it should be its own thing.

@jsignell
Copy link
Member

Dask certainly has both top-level imports from dask import delayed and namespaced imports from dask.distributed import Client. It implements that just by having a distributed.py file within dask proper.

from __future__ import annotations

_import_error_message = (
    "dask.distributed is not installed.\n\n"
    "Please either conda or pip install distributed:\n\n"
    "  conda install dask distributed             # either conda install\n"
    '  python -m pip install "dask[distributed]" --upgrade    # or pip install'
)

try:
    from distributed import *
except ImportError as e:
    if e.msg == "No module named 'distributed'":
        raise ImportError(_import_error_message) from e
    else:
        raise


def __getattr__(value):
    try:
        import distributed
    except ImportError as e:
        raise ImportError(_import_error_message) from e
    return getattr(distributed, value)

https://github.com/dask/dask/blob/dafb6ac0a647d751f662d0e30f616c62cf62b799/dask/distributed.py

@gadomski gadomski transferred this issue from stac-utils/pystac-client Apr 29, 2024
@gadomski
Copy link
Member

Nice, thanks @jsignell . Moving this issue to pystac as we'd need to implement here.

@alexgleith
Copy link
Author

Thanks for being open to this!

@jsignell jsignell linked a pull request Jul 16, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants