Skip to content

Conversation

@drfho
Copy link
Contributor

@drfho drfho commented Nov 25, 2025

HINT: PR is replaced by #450


Since the code-change zopefoundation/Zope@b465923 Zope changed pkg_resources-namespace and thus Products.zms does not get initialized anymore when installed in --editable mode.

Installing--editable with pip-parameter --use-pep517

With pip ≥ 21.3 and setuptools ≥ 64.0.0. Zope will find the init-path for ZMS:

pip install --use-pep517 --config-settings editable_mode=compat -e git+https://github.com/zms-publishing/ZMS.git@main#egg=ZMS

Ref: 955d8ba

Otherwise the initialize-path can be set explizit via zope-configuration-file:

Registering ZMS via $INSTANCE/etc/site.zcml

Adding just one new line

<five:registerPackage package="Products.zms" initialize="Products.zms.initialize" />

into the Zope instance's ./etc/site.zcml will do the same job for registering the ZMS package to Zope 6.
This variant does not need a reinstall of ZMS if the initial installation of ZMS installed Zope 5.13 in editable mode and the updated by git. Using this way of registering ZMS leads to a (harmless) doubled init of ZMS when downgrading to Zope5 (this can be simply fixed by commenting the line)

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:meta="http://namespaces.zope.org/meta"
    xmlns:five="http://namespaces.zope.org/five">

  <include package="Zope2.App" />
  <!-- Register the ZMS package for Zope 6 -->
  <five:registerPackage package="Products.zms" initialize="Products.zms.initialize" />

  <!-- Load the meta -->
  <include files="package-includes/*-meta.zcml" />
  <five:loadProducts file="meta.zcml"/>

  <!-- Load the configuration -->
  <include files="package-includes/*-configure.zcml" />
  <five:loadProducts />

  <!-- Load the configuration overrides-->
  <includeOverrides files="package-includes/*-overrides.zcml" />
  <five:loadProductsOverrides />

</configure>

@drfho drfho changed the title Zope 6.0: Gerring ZMS initialized Zope 6.0: Getting ZMS initialized Nov 25, 2025
@drfho
Copy link
Contributor Author

drfho commented Nov 27, 2025

More Registration Issues: Shared/DC

Products.SQLAlchemyDA may fall into registration issues and not be able to import Shared libraries. The ImportError: cannot import name 'ZRDB' from 'Shared.DC' can be been fixed by:

  1. Created missing namespace package init.py files in site-packages:

    a. ./lib/python3.13/site-packages/Shared/init.py
    b. ./lib/python3.13/site-packages/Shared/DC/init.py

and add the line to each files:

__import__('pkg_resources').declare_namespace(__name__)

HINT: this fix [1] may not be necessary if at least [2] is available.

  1. Updated the namespace package .pth file (zope-5.13-nspkg.pth paths before the source paths, ensuring proper namespace merging.
import sys, types, os;p = os.path.join('/home/zope/venv/lib/python3.13/site-packages', *('Shared',));importlib = __import__('importlib.util');__import__('importlib.machinery');m = sys.modules.setdefault('Shared', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('Shared', [os.path.dirname(p)])));m = m or sys.modules.setdefault('Shared', types.ModuleType('Shared'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
import sys, types, os;p = os.path.join('/home/zope/venv/lib/python3.13/site-packages', *('Shared', 'DC'));importlib = __import__('importlib.util');__import__('importlib.machinery');m = sys.modules.setdefault('Shared.DC', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('Shared.DC', [os.path.dirname(p)])));m = m or sys.modules.setdefault('Shared.DC', types.ModuleType('Shared.DC'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p);m and setattr(sys.modules['Shared'], 'DC', m)

The root cause is that Products.ZSQLMethods (which provides Shared.DC.ZRDB]) was installed in site-packages, but the namespace package mechanism wasn't properly merging the site-packages location with the editable Zope source installation. Now both locations are correctly included in Shared.DC.path allowing ZRDB to be imported successfully.

@drfho
Copy link
Contributor Author

drfho commented Nov 28, 2025

INFO: PR "Adding pyproject.toml #302" is merged into this PR

@dwt
Copy link
Contributor

dwt commented Dec 2, 2025

Wie sollte es funktionieren: Mit pep 420 native Namespace Packages, sollten alle namespace Pakete nur noch als Ordner vorliegen. Es fallen alle __init__.py, *.pth, *.pkg und ähnliche Dateien weg.

Der python import mechanismus sollte beim import eines Paketes Products.zms feststellen, das in den site-packages ein Ordner Products liegt, und diesen weil er kein __init__.py enthällt, als namespace Package registrieren.

Wir haben jetzt den komplizierteren Fall das wir noch editable Pakete haben. Hier hat das installierende Paket (für uns setuptools) jetzt wieder die Freiheit zu machen was es will - und soweit ich das sehe macht setuptools das derzeit über *-namespace.pth Dateien, sowie zusätzlich über ein __editable__.*.pth und __editable__.*.py Datei.

@drfho
Copy link
Contributor Author

drfho commented Dec 2, 2025

..soweit ich das sehe macht setuptools das derzeit über *-namespace.pth Dateien, sowie zusätzlich über ein __editable__.*.pth und __editable__.*.py Datei.

Although setuptools seems appropriate for Zope 5+, if the [build-system] block of pyprojecr.toml is removed the behaviour will be the same.
I added an 'initialize' section, which looks quite like what we like to archive. But: no effect for editable mode, and normal install works well with it:

ZMS/pyproject.toml

Lines 94 to 95 in 2d743d1

[project.entry-points."zope2.initialize"]
"Products.zms" = "Products.zms:initialize"

This fixes import of editable zms install, being discoverable by
pkgutils.iter_modules()
@dwt dwt force-pushed the zope6_pkg_registering branch from 2d743d1 to 6a36343 Compare December 2, 2025 19:05
drfho and others added 3 commits December 2, 2025 20:37
Adapt docker build to the src layout, and also switch to uv now that
this is possible for much faster docker build times
@drfho
Copy link
Contributor Author

drfho commented Dec 2, 2025

ZMS6: Reorganized ZMS Source Data into src-Folder

Ref: https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/

./Products/zms
==>
./src/Products/zms

Adding a new container-folder src on top-level and moving the source-code from Products/zms into the folder solves the problem. Zope does the same to utilize implicit path-registration. With the change ZMS gets initialized with standard and editable installation.

IMPORTANT NOTE:
updating by git pull may not work when the folders are organised the former way; the new pathes need a reinstallation of ZMS:

./pip uninstall zms
./pip install -e ../src/zms/.

@drfho drfho mentioned this pull request Dec 8, 2025
@dwt dwt force-pushed the zope6_pkg_registering branch from d7164e3 to 9ff9099 Compare January 6, 2026 14:55
Copy link
Contributor Author

@drfho drfho left a comment

Choose a reason for hiding this comment

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

The modified dockerfile https://github.com/zms-publishing/ZMS/blob/7c06fe11ffd1c853762ee01566c5c3f9344f8f8b/docker/variants/alpine/dockerfile lets ZMS6 (this branch) run on Py3.14.2 and latest Zope6

Image

@drfho
Copy link
Contributor Author

drfho commented Jan 20, 2026

Cave: Source-Update ZMS5->6 in editable-mode does not work

Because of the path-reorganisation a updating the code in editable-mode by a simple git pull does not work anymore, e.g. with an existing Zope5-Installation

image

For evaluation just add an src-update to the existing dockerfile for ZMS5: https://github.com/zms-publishing/ZMS/blob/main/docker/variants/alpine/dockerfile

# Update ZMS-src with ZMS6-branch from GitHub
RUN cd /home/zope/venv/src/zms/ && \
    git fetch origin && \
    git checkout -b zope6_pkg_registering && \
    git pull origin zope6_pkg_registering

dockerfile.yaml

Solution: Code-Update by pip-install

In an existing Zope5-environment the ZMS-Code can be updated to ZMS6 by a pip install ; the compatibility flags (--use-pep517 --config-settings editable_mode=compat) are not needed with ZMS6

pip install -e git+https://github.com/zms-publishing/ZMS.git@zope6_pkg_registering#egg=ZMS 

@drfho
Copy link
Contributor Author

drfho commented Jan 20, 2026

PR is replaced by #450

@drfho drfho closed this Jan 20, 2026
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.

3 participants