The comment of npostavs is true. When you
"other-package" during byte compilation the test result on byte-compilation in
"other-package" is negative.
You need to remember in the original package that you are byte-compiling.
You can do that by let-binding:
A minimal example:
Content of the original package:
(let ((other-package-loading-for-compilation t))
(unless (bound-and-true-p other-package-loading-for-compilation)
(message "For initialization only"))
I assume that you have already compiled
In that case
(cl-eval-when (load) ...)
The doc-string of
(cl-eval-when (WHEN...) BODY...)
Control when BODY is evaluated.
If ‘compile’ is in WHEN, BODY is evaluated when compiled at top-level.
If ‘load’ is in WHEN, BODY is evaluated when loaded after top-level compile.
If ‘eval’ is in WHEN, BODY is evaluated when interpreted or at non-top-level.
From my perspective the
load case description is a bit misleading. It means that BODY is evaluated when the byte-compiled library is loaded -- not only directly after byte-compilation.
You can also combine the cases.
If you want BODY to be evaluated also when the source file is loaded you can use
(cl-eval-when (eval load) ...)