Skip to content

Install actually working version of the project#228

Open
bbannier wants to merge 6 commits into
masterfrom
topic/bbannier/full-cmake-install
Open

Install actually working version of the project#228
bbannier wants to merge 6 commits into
masterfrom
topic/bbannier/full-cmake-install

Conversation

@bbannier

Copy link
Copy Markdown
Member

While this project has a perfectly fine pyproject.toml which allows
installing it with pip/pipx, we also shipped a CMakeLists.txt to
make the project installable when shipped as part of a bigger CMake
project like Zeek. The install rules we had were bare bones since they
only installed the top-level zkg script and the zeekpkg module it
depends on, but e.g., not any dependencies. It likely would also have
broken for potential future tweaks to pyproject.toml like switching to
another build backend.

This patch reworks our CMake install rules to install a fully
functioning version of this project instead. This allows users to use it
directly without having to install and manage dependencies themself.
This removes potential for user error (e.g., version mismatches) and
should also allow us to use dependency more freely/aggressively.

We accomplish this with shiv which leverages PEP441 to create
self-contained environments in zip files which can be loaded by any
Python interpreter >=python-3.4. Users invoke a small wrapper we create
which forwards to the top-level zkg script.

@bbannier bbannier self-assigned this Jun 23, 2026
@bbannier

Copy link
Copy Markdown
Member Author

This should allow #226 regardless of whether we implement zeek/zeek#5597 or not.

@bbannier bbannier force-pushed the topic/bbannier/full-cmake-install branch from 25afcbd to ed8ddc2 Compare June 23, 2026 07:58
@bbannier bbannier marked this pull request as ready for review June 23, 2026 08:12
@bbannier bbannier force-pushed the topic/bbannier/full-cmake-install branch 2 times, most recently from 41a1c10 to 34210ea Compare June 23, 2026 12:14
@bbannier

Copy link
Copy Markdown
Member Author

I opened zeek/zeek#5604 to testdrive integration of this into Zeek, and it seems to work with very minor adjustments.

@bbannier bbannier force-pushed the topic/bbannier/full-cmake-install branch from 34210ea to 81874d5 Compare June 23, 2026 14:45
@bbannier bbannier requested a review from ckreibich June 23, 2026 17:26

@ckreibich ckreibich left a comment

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.

Super interesting approach — I hadn't heard of shiv, or the fact that Python can execute a __main__.py in a ZIP file. I still need to try it out in a Zeek tree, but I'm excited.

One question: I know we have (limited, but legit) use cases where the Zeek installation happens airgapped. If we produce a source tarball for the Zeek distro, will the resulting ZIP be contained in it, or will the configure stage then go ahead and pip-download the dependencies? It's not a showstopper — right now the dependencies need to get onto such systems after all, too. Just trying to understand.

Basically, I wonder if we could keep the dependencies functioning "normally" when the user wants to, but then it's also up to the user to ensure the dependencies are satisfied (via system packages, system--wide pip install, etc).

Comment thread doc/quickstart.rst

* Python 3.6+
* git: https://git-scm.com
* GitPython: https://pypi.python.org/pypi/GitPython

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.

I'm not sure we should remove this here — these are still dependencies, we just handle them differently now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unless we want this to be some SBOM (which we then should keep up to date more diligently) I'd argue this should go away. I'd also argue that this PR did not really change our approach to dependencies since the authoritative source was always pyproject.toml or maybe the slightly out of sync requirements.txt.

Comment thread CMakeLists.txt Outdated
@bbannier bbannier force-pushed the topic/bbannier/full-cmake-install branch from 81874d5 to e443407 Compare June 29, 2026 06:26
@bbannier

Copy link
Copy Markdown
Member Author

One question: I know we have (limited, but legit) use cases where the Zeek installation happens airgapped. If we produce a source tarball for the Zeek distro, will the resulting ZIP be contained in it, or will the configure stage then go ahead and pip-download the dependencies? It's not a showstopper — right now the dependencies need to get onto such systems after all, too. Just trying to understand.

Yeah, with this PR we would produce a tarball which cannot be built in airgapped environments (the configure step should still succeed). That said, I am curious how creating a Zeek environment with working zkg would look today since fixing up the installation by making the Python dependencies available would still require internet access; AFAICT we do not document this at all. I suspect most such airgapped installation already disable zkg.

To make this work we could vendor both build and runtime dependencies and then hook them into the build with pip --find-links. To make this work we would either need to vendor wheels for all supported platforms (which would balloon the tarball size), or build all Python dependencies from source (which could introduce new requirements on the build env). None of these are great, and ideally we would punt on these.

Basically, I wonder if we could keep the dependencies functioning "normally" when the user wants to, but then it's also up to the user to ensure the dependencies are satisfied (via system packages, system--wide pip install, etc).

I'd argue that with the introduction of virtualenv and pip circa 2008 installing into the system has become not "normal". Distributions are pulling the plug on this as well with now requiring --break-system-packages which can do exactly what the label promises.

@bbannier bbannier requested a review from ckreibich July 1, 2026 14:39
@ckreibich

Copy link
Copy Markdown
Member

Yeah. I also like the line of thought during our last conversation: the airgapped use-case brings up the question of how the Python dependencies ended up on the system in the first place, so a custom, independent install of zkg (via a pip install, with system packages, whatever) seems like a reasonable ask. We can double-check with the testing group in case they have additional thoughts, but I don't think this is a show-stopper.

I just tried it out locally in a Zeek tree. This is what looks like during configure:

Collecting shiv==1.0.8
  Downloading shiv-1.0.8-py2.py3-none-any.whl.metadata (4.7 kB)
Collecting click!=7.0,>=6.7 (from shiv==1.0.8)
  Downloading click-8.4.2-py3-none-any.whl.metadata (2.6 kB)
Requirement already satisfied: pip>=9.0.3 in ./_venv/lib64/python3.14/site-packages (from shiv==1.0.8) (26.0.1)
Collecting setuptools (from shiv==1.0.8)
  Using cached setuptools-82.0.1-py3-none-any.whl.metadata (6.5 kB)
Downloading shiv-1.0.8-py2.py3-none-any.whl (20 kB)
Downloading click-8.4.2-py3-none-any.whl (119 kB)
Using cached setuptools-82.0.1-py3-none-any.whl (1.0 MB)
Installing collected packages: setuptools, click, shiv
Successfully installed click-8.4.2 setuptools-82.0.1 shiv-1.0.8

[notice] A new release of pip is available: 26.0.1 -> 26.1.2
[notice] To update, run: /home/christian/devel/zeek/zeek/build/auxil/package-manager/_venv/bin/python3 -m pip install --upgrade pip
[ 98%] shiv install
[ 98%] Built target shiv_install
[100%] Bundling zkg
Collecting zkg
  Using cached zkg-3.1.0-py2.py3-none-any.whl.metadata (4.4 kB)
Collecting GitPython>=3.1.43 (from zkg)
  Downloading gitpython-3.1.50-py3-none-any.whl.metadata (14 kB)
Collecting btest>=1.1 (from zkg)
  Downloading btest-1.3.tar.gz (111 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Collecting semantic-version>=2.10.0 (from zkg)
  Using cached semantic_version-2.10.0-py2.py3-none-any.whl.metadata (9.7 kB)
Collecting multiprocess>=0.70.16 (from btest>=1.1->zkg)
  Downloading multiprocess-0.70.19-py314-none-any.whl.metadata (7.2 kB)
Collecting gitdb<5,>=4.0.1 (from GitPython>=3.1.43->zkg)
  Using cached gitdb-4.0.12-py3-none-any.whl.metadata (1.2 kB)
Collecting smmap<6,>=3.0.1 (from gitdb<5,>=4.0.1->GitPython>=3.1.43->zkg)
  Downloading smmap-5.0.3-py3-none-any.whl.metadata (4.6 kB)
Collecting dill>=0.4.1 (from multiprocess>=0.70.16->btest>=1.1->zkg)
  Downloading dill-0.4.1-py3-none-any.whl.metadata (10 kB)
Using cached zkg-3.1.0-py2.py3-none-any.whl (72 kB)
Downloading gitpython-3.1.50-py3-none-any.whl (212 kB)
Using cached gitdb-4.0.12-py3-none-any.whl (62 kB)
Downloading smmap-5.0.3-py3-none-any.whl (24 kB)
Downloading multiprocess-0.70.19-py314-none-any.whl (160 kB)
Downloading dill-0.4.1-py3-none-any.whl (120 kB)
Using cached semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)
Building wheels for collected packages: btest
  Building wheel for btest (pyproject.toml): started
  Building wheel for btest (pyproject.toml): finished with status 'done'
  Created wheel for btest: filename=btest-1.3-py3-none-any.whl size=42905 sha256=0cdac85c22599cd7b5abaef5a9569c262c9811d21d6ba3dd86e0cbf0c1761571
  Stored in directory: /home/christian/.cache/pip/wheels/ab/cd/9b/324ef8d5f25a4af659ea692e325b29414b3018679188038983
Successfully built btest
Installing collected packages: smmap, semantic-version, dill, multiprocess, gitdb, GitPython, btest, zkg

Successfully installed GitPython-3.1.50 btest-1.3 dill-0.4.1 gitdb-4.0.12 multiprocess-0.70.19 semantic-version-2.10.0 smmap-5.0.3 zkg-3.1.0
[100%] zkg bundle
[100%] Built target zkg_pyz

Pretty cool. I'm pretty much ready to approve, just two more thoughts:

  • Does this need to grab btest? I realize this happens because it's listed as a regular dependency, but that's for the model where the btest command becomes available alongside zkg, so Zeek packages can run btest for their testing. I think that doesn't hold here.
  • I noticed that we install into ZEEKROOT/share/zkg/bundled/zkg.pyz. Since the archive essentially behaves like a Python module, I wonder if we should keep it under ZEEKROOT/lib64/zeek/python, i.e. where all the other Python stuff is? Perhaps ZEEKROOT/lib64/zeek/python/zkg/zkg.pyz?

@bbannier bbannier force-pushed the topic/bbannier/full-cmake-install branch from e443407 to 57ff7e8 Compare July 2, 2026 07:17
@bbannier

bbannier commented Jul 2, 2026

Copy link
Copy Markdown
Member Author
  • Does this need to grab btest? I realize this happens because it's listed as a regular dependency, but that's for the model where the btest command becomes available alongside zkg, so Zeek packages can run btest for their testing. I think that doesn't hold here.

Yeah, btest gets bundled since it is a regular dependency. When installing via CMake we do not make its executable visible, and I think we should not. To not include it would require something like conditional patching of pyproject.toml for the CMake install, and that seems complicated and not really needed (the pulled in btest is not visible). If possible I'd prefer to just keep this as is.

Having btest as a dependency was something that folks explicitly requested to support pip install workflows, so we rolled back a previous cleanup in #191.

  • I noticed that we install into ZEEKROOT/share/zkg/bundled/zkg.pyz. Since the archive essentially behaves like a Python module, I wonder if we should keep it under ZEEKROOT/lib64/zeek/python, i.e. where all the other Python stuff is? Perhaps ZEEKROOT/lib64/zeek/python/zkg/zkg.pyz?

The zkg.pyz file is not a Python module, but a zipped up prefix, and it e.g., cannot be imported. I do not expect it to have any use outside of the wrapper script we install from zkg.sh.in. I renamed the install location to share/zkg/lib which seems more standard. Does that look better to you?

Comment thread zkg.sh.in
bbannier added 6 commits July 6, 2026 17:04
While this project has a perfectly fine `pyproject.toml` which allows
installing it with `pip`/`pipx`, we also shipped a `CMakeLists.txt` to
make the project installable when shipped as part of a bigger CMake
project like Zeek. The `install` rules we had were bare bones since they
only installed the top-level `zkg` script and the `zeekpkg` module it
depends on, but e.g., not any dependencies. It likely would also have
broken for potential future tweaks to `pyproject.toml` like switching to
another build backend.

This patch reworks our CMake install rules to install a fully
functioning version of this project instead. This allows users to use it
directly without having to install and manage dependencies themself.
This removes potential for user error (e.g., version mismatches) and
should also allow us to use dependency more freely/aggressively.

We accomplish this with `shiv` which leverages PEP441 to create
self-contained environments in zip files which can be loaded by any
Python interpreter >=python-3.4. Users invoke a small wrapper we create
which forwards to the top-level `zkg` script.
We would previously potentially leave CMake variables in the zkg script
since they would only get expanded by a CMake build, but not by e.g.,
`pip`. The CMake install rewrite in the previous patch also did not
expand them anymore.

This patch adds that lost functionality back into the wrapper script
which we now have and which is only used by a CMake install.
This project does not do any compilation, so checking for a C compiler
(which is the default if no language was specified in `project`) is just
doing busywork.
This bumps the minimum CMake version to the one required by e.g., Zeek.
We would previously document dependencies which are already expressed
programmatically in `pyproject.toml`, so this added information not
useful for readers, but also introduced potential for things to get out
of sync (which they had already). Just drop anything already expressed
in the project config.
@bbannier bbannier force-pushed the topic/bbannier/full-cmake-install branch from 57ff7e8 to fea4017 Compare July 6, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants