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) ...)
other-package, therefore it is load time for
other-package. You could try checking if byte compilation is in progress like
cl--compiling-fileis to inspect the value of
(bound-and-true-p byte-compile-current-file), which is only set during byte-compilation.