Giter VIP home page Giter VIP logo

Comments (4)

hagenw avatar hagenw commented on August 25, 2024

I looked into it and the extra time is completely covered by importlib_metadata.packages_distributions() which we call inside audobject.core.utils.create_class_key():

# add package name (if different from module name)
module_name = cls.__module__.split('.')[0]
package_names = packages_distributions()
if module_name in package_names:
package_name = package_names[module_name][0]
if package_name != module_name:
key += f'{package_name}{define.PACKAGE_TAG}'

It's unfortunate as we only have a different package name in very rare cases. So it would be better to call it only if really needed, but so far I don't see how to achieve this.

from audobject.

frankenjoe avatar frankenjoe commented on August 25, 2024

Maybe we can first try with module_name and only if we cannot create the object call packages_distributions()?

from audobject.

hagenw avatar hagenw commented on August 25, 2024

The package_name is indeed only needed if autoinstall=True, see

if auto_install:
audeer.install_package(
package_name,
version=version,
)

But the problem is we can only call packages_distributions() when the package is already installed, so indeed at the time we are storing the object and not when loading it as the mapping from module_name to package_name is ambiguous.

packages_distributions() is also collecting the information for all installed packages and not only for the package we require. Maybe we can look into the source code of packages_distributions(), provide the module name as argument and use only the code we need.

from audobject.

hagenw avatar hagenw commented on August 25, 2024

The code inside importlib_metadata.packages_distributions() does indeed loop over all packages, which might not be needed, compare https://github.com/python/importlib_metadata/blob/353c3dfe83e08b3c86f30d192c315501cef97454/importlib_metadata/__init__.py#L955-L969

from audobject.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.