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

Required dependencies, lazy imports #72

Closed
adamjstewart opened this issue Aug 5, 2021 · 0 comments · Fixed by #287
Closed

Required dependencies, lazy imports #72

adamjstewart opened this issue Aug 5, 2021 · 0 comments · Fixed by #287
Assignees
Milestone

Comments

@adamjstewart
Copy link
Collaborator

Our number of dependencies is rapidly increasing. We should think about which of these dependencies are required (install_requires) vs. optional (extras_require). Here is a proposal:

  1. Required: dependencies that are needed to do just about anything with TorchGeo
  2. Optional: dependencies that are only needed for optional functionality, or for a small number of datasets

This gets a bit tricky, and is currently at odds with our dependency list. For example, rasterio is only used in RasterDataset, and fiona is only used in VectorDataset. While almost half of our datasets are RasterDataset, ony 1 is currently VectorDataset. Also, matplotlib is only needed to plot example samples.

Here is another proposal:

  1. Required: any dependency that is used in regular usage
  2. Optional: dependencies used only in rare cases (single dataset)

This may be a better default. Most users will likely run pip install torchgeo, which will install only the things in install_requires. We don't want a useless installation to be the default, and extras_require is off by default. Alternatively, we could do a better job of documenting the recommended way to install TorchGeo and specify that you may want pip install torchgeo[datasets,train] or something like that.

Another thing to consider is how to handle these optional imports. We can't put them at the module level (in the case of datasets) so we use lazy imports instead. We also may want to create a wrapper like importorraise (akin to pytest's importorskip) that prints a more useful error message upon ImportError. We could go even further and use lazy imports for almost all imports, not just optional ones. This will greatly speed up importing torchgeo.

@adamjstewart adamjstewart added this to the 0.2.0 milestone Nov 20, 2021
@adamjstewart adamjstewart self-assigned this Dec 14, 2021
@adamjstewart adamjstewart added utilities Utilities for working with geospatial data and removed utilities Utilities for working with geospatial data labels Jan 2, 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 a pull request may close this issue.

1 participant