question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build dedicated Python Package for `try_import()`

See original GitHub issue

Dear Optuna team,

I very much like your try_import() utility from here: https://github.com/optuna/optuna/blob/99484054fcec97eb530960a8612c3e6058ee5690/optuna/_imports.py

I would like to use that kind of functionality in other Python Packages that we want to develop. But that package does not have an optuna dependency. That’s why I ask:

Do you plan to release that as an utility package that can be reused by other packages?

If not I would like to inform you that I am creating such a package and open source it under the same MIT License.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
hvycommented, Jul 6, 2021

Sorry for the late reply. Appreciate you checking.

Creating an independent library sounds interesting. I could see it being applicable to other applications as you say. Unfortunately, there’s no plan for the time being in doing so. try_import was mostly implemented as a quick internal/private tool to DRY code. There might be room for improving the API, or perhaps even including other related features such as the lazy submodule import helper.

Having that said, I don’t see problems in you creating a library deriving it given your description (e.g. the MIT license). If you don’t mind, mentioning Optuna would be very much appreciated, though.

1reaction
PhilipMaycommented, Aug 5, 2021

Thanks again. We have published the try_import functionality here: https://github.com/telekom/lazy-imports

Although we took the _LazyModule class from HuggingFace. This implementation somehow worked better for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Packaging Python Projects
This tutorial walks you through how to package a simple Python project. It will show you how to add the necessary files and...
Read more >
How can I import a module dynamically given the full path?
For Python 3.3 and 3.4 use: from importlib.machinery import SourceFileLoader foo = SourceFileLoader("module.name", "/path/to/file.py").load_module() foo.
Read more >
Packaging Pitfalls — PyOxidizer 0.4.0 documentation
Many Python packages compile extension modules to native code. (Typically C is used to implement extension modules.) The way this typically works is...
Read more >
Publishing your own Python package | by Shay Palachy
In the following post I'll try to walk you through the minimal process I have settled on for packaging Python code, building on...
Read more >
Python and TOML: New Best Friends - Real Python
Format and Style TOML Documents; Create TOML From Scratch With tomlkit ... A new module for TOML parsing is being added to Python's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found