Skip to content

Add __version__ to init#247

Merged
c-bata merged 4 commits intooptuna:mainfrom
nabenabe0928:add-version-to-init
Aug 21, 2025
Merged

Add __version__ to init#247
c-bata merged 4 commits intooptuna:mainfrom
nabenabe0928:add-version-to-init

Conversation

@nabenabe0928
Copy link
Copy Markdown
Contributor

Motivation

This PR adds __version__ to directly under optuna_integration.

Description of the changes

  • Enable importing __version__ from optuna_integration

@nabenabe0928 nabenabe0928 added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Aug 19, 2025
@nabenabe0928 nabenabe0928 added this to the v4.6.0 milestone Aug 19, 2025
Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

Thank you for your pull request. I left one suggestion.

"tensorboard": ["TensorBoardCallback"],
"tensorflow": ["TensorFlowPruningHook"],
"tfkeras": ["TFKerasPruningCallback"],
"version": ["__version__"],
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.

nit: optuna_integration.version modules has no dependencies, so can we simply add from optuna_integration import version and update __all__ variable to include it?

Suggested change
"version": ["__version__"],

Copy link
Copy Markdown
Contributor Author

@nabenabe0928 nabenabe0928 Aug 19, 2025

Choose a reason for hiding this comment

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

I don't know if my modification is what you wanted, but I applied some changes.

import optuna_integration
from optuna_integration import __version__
from optuna_integration import version

print(optuna_integration.__version__, version.__version__, __version__)

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.

Thanks for the update! My original intention was that since optuna_integration.version has no dependencies, we don’t need to include it in _import_structure for lazy import. Instead, we can just import __version__ like below.

diff --git a/optuna_integration/__init__.py b/optuna_integration/__init__.py
index c9436ff..18cab7e 100644
--- a/optuna_integration/__init__.py
+++ b/optuna_integration/__init__.py
@@ -4,6 +4,7 @@ from types import ModuleType
 from typing import Any
 from typing import TYPE_CHECKING

+from optuna_integration import version
 from optuna_integration.version import __version__


@@ -30,13 +31,13 @@ _import_structure = {
     "tensorboard": ["TensorBoardCallback"],
     "tensorflow": ["TensorFlowPruningHook"],
     "tfkeras": ["TFKerasPruningCallback"],
-    "version": ["__version__"],
     "wandb": ["WeightsAndBiasesCallback"],
     "xgboost": ["XGBoostPruningCallback"],
 }


 __all__ = [
+    "version",
     "__version__",
     "AllenNLPExecutor",
     "AllenNLPPruningCallback",

However, I've just noticed that above change does not work as expected:

$ python -c "import optuna_integration; print(optuna_integration.version.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/cbata/go/src/github.com/optuna/optuna-integration/optuna_integration/__init__.py", line 128, in __getattr__
    raise AttributeError("module {} has no attribute {}".format(self.__name__, name))
AttributeError: module optuna_integration has no attribute version

Could you please revert back to the previous implementation? Sorry for the confusion 🙇 I will approve once it's reverted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@c-bata
Thank you for the clarification, I have reverted the code!

@c-bata c-bata added other Issue/PR that does not fit into any other label. and removed enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. labels Aug 19, 2025
@c-bata
Copy link
Copy Markdown
Member

c-bata commented Aug 19, 2025

Let me remove the enhancement label since the definition is "Change that does not break compatibility and not affect public interfaces, but improves performance".
https://github.com/optuna/optuna-integration/labels

Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

I confirmed that the following code works as expected.

>>> import optuna_integration
>>> optuna_integration.__version__
'4.6.0.dev'
>>> optuna_integration.version.__version__
'4.6.0.dev'

@c-bata c-bata merged commit d106c3e into optuna:main Aug 21, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

other Issue/PR that does not fit into any other label.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants