Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to PEP 420 (Implicit namespace packages) #194

Open
2 of 12 tasks
icemac opened this issue Mar 8, 2023 · 26 comments
Open
2 of 12 tasks

Switch to PEP 420 (Implicit namespace packages) #194

icemac opened this issue Mar 8, 2023 · 26 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@icemac
Copy link
Member

icemac commented Mar 8, 2023

Currently we use pkg_resources-style namespace packages. Using pkg_resources is deprecated (see https://setuptools.pypa.io/en/latest/pkg_resources.html), it seems not yet clear when it is removed from setuptools.

The current future are PEP 420: Implicit namespace packages.

This requires:

  • all the packages sharing a namespace to switch over to PEP 420.
  • removing the __init__.py files existing to create a namespace
  • removing namespace_packages declaration from setup.py
  • maybe removal of the dependency on setuptools? (Maybe we could even switch to pyproject.toml.)

zopefoundation hosts the following namespaces:

  • zope, zope.app – 117 repos
  • z3c, z3c.recipe, z3c.layer, z3c.formwidget, z3c.menu – 43 repos
  • zc, zc.recipe – 22 repos
  • Products – 22 repos
  • keas (probably only some packages of that namespace) – 1 repo
  • refline (probably only some packages of that namespace) - 1 repo
  • grokcore – 17 repos
  • grokui – all repos archived
  • hurry – 2 repos
  • cipher – 2 repos
  • five – 4 repos
  • megrok: 1 repos (Switch to implicit (PEP 420) namespace. megrok.strictrequire#8)

See the discussion in pypa/setuptools#3434 for some more details.

Suggestion:

  • Try out on a small namespace where probably all packages are hosted by zopefoundation (grokcore?, z3c?, zope.app?)
  • If this works fine (especially in zc.buildout), adapt the other namespaces.
    • This will require coordination with the Plone folks.
    • This would also require a big warning sign that other packages hosted outside zopefoundation but using the same namespaces also have to switch to PEP 420.

Cc-ing: @dataflake @mauritsvanrees @gforcada @mgedmin @jensens

See also https://packaging.python.org/en/latest/guides/packaging-namespace-packages/

@icemac icemac added enhancement New feature or request question Further information is requested labels Mar 8, 2023
@dataflake
Copy link
Member

This looks like a ton of work... but if we could really get rid of setuptools it would be worth it. Setuptools is nothing but trouble at this point.

@mauritsvanrees
Copy link
Member

I left two comments in the setuptools discussion, with some numbers. Let's see if we can get a timeline for when setuptools will drop support.

Zope and Plone can only move to native namespaces in a major release. Since Plone 6 was only released a few months ago, I expect it will take two to three years before we have Plone 7, which would need a Zope 6. We may need to speed that up. But I hope we can let this rest for another year.

If we know that for example setuptools 70 is going to drop support, I suppose we could add setuptools<70 in install_requires to prevent installation of incompatible packages side by side.

@jensens
Copy link
Member

jensens commented Mar 8, 2023

+1 to start the process of modernization here. Some remarks:

  • I agree, this change is necessary at some point.
  • I agree with @mauritsvanrees that this is a breaking change at some point and would need a new major Zope release.
  • I think a good idea is to introduce this change incrementally:
    • first all controlled zope.* packages can be changed relatively easy, probably the same is valid for five.*, z3c.* and zc.* (and maybe some other in the list above I do not know/use). This might go into the Zope 5 release series.
    • With the Products.* namespace it gets difficult, this is a bunch of packages, including CMF, Plone and all add-ons. It needs tight coordination.
    • If we switch everything to PEP420 in Plone this would be possible only in a Plone 7.
  • if this topic is touched I would switch to full to pyproject.yml w/o any setup.* along with it. For my company projects I use already PEP420 style packages along with pyproject.toml w/o any problems.
  • ad getting rid of Setuptools: What is the idea behind this?
    • Setuptools is settled, widely used, has lots of tooling available and is relatively fast.
    • What is the alternative we want? We need some PEP 518 [build-system]. I am not that a fan of Poetry, did not try Flit or PDM.

@dataflake
Copy link
Member

The idea of getting rid of setuptools was not based on any knowledge of replacements, but on some comments in that setuptools discussion on GitHub. It may not be possible. Where I come from is endless issues with the Zope packages that use C-code in conjunction with macOS and the different builds that exist for it (x86_64, aarch64 and universal2). I described that at #181.

@icemac
Copy link
Member Author

icemac commented Mar 9, 2023

I am not aware of an alternative to setuptools which can handle C code. But I am open to learn if there is one.

@mgedmin
Copy link
Member

mgedmin commented Mar 9, 2023

Request for clarification: is it possible to mix and match PEP-420 namespace packages with pkg_resources namespace packages from the same namespace in the same virtualenv?

Are we talking about a flag day here, with major version bumps and coordinated releases for every zope.* package at the same time? (And similar efforts for zc.*, z3c.*, grok.*, collective.* namespaces)?

@d-maurer
Copy link

d-maurer commented Mar 9, 2023 via email

@d-maurer
Copy link

d-maurer commented Mar 9, 2023 via email

@jensens
Copy link
Member

jensens commented Mar 9, 2023

Request for clarification: is it possible to mix and match PEP-420 namespace packages with pkg_resources namespace packages from the same namespace in the same virtualenv?

I did not read the PEPs in detail nor the code about it, but about a year ago I just tried it and it just did not work. Ago then, I found some source-on-the-internet stating exact: it does not mix (but currently I can not find it again).

@mauritsvanrees
Copy link
Member

mauritsvanrees commented Mar 9, 2023

That would be the Python Packaging User Guide, which says:

Warning: While native namespace packages and pkgutil-style namespace packages are largely compatible, pkg_resources-style namespace packages are not compatible with the other methods. It’s inadvisable to use different methods in different distributions that provide packages to the same namespace.

It also gives one specific reason for using pkg_resources-style namespace packages:
"This method is recommended if you need compatibility with packages already using this method or if your package needs to be zip-safe."

Do we need that for some reason?
I guess not: in a lot of Zope and Plone package I see zip_safe=False, so the other way around.

@jensens
Copy link
Member

jensens commented Mar 10, 2023

"This method is recommended if you need compatibility with packages already using this method or if your package needs to be zip-safe."

Do we need that for some reason?

"It is very unlikely that the values of zip_safe will affect modern deployments that use pip for installing packages. Moreover, new users of setuptools should not attempt to create egg files using the deprecated build_egg command. Therefore, this flag is considered obsolete." https://setuptools.pypa.io/en/latest/deprecated/zip_safe.html

@graingert
Copy link

graingert commented Mar 15, 2023

for the jaraco. namespace @jaraco was able to do a staged migration to pkgutil namespace packages see pypa/setuptools#3434 (comment)

I think the packaging tutorial docs may be incorrect as there's a test for pkg_resources and pkgutil namespaces in one virtual environment https://github.com/pypa/sample-namespace-packages/blob/df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45/noxfile.py#L79-L88 which shows a staged migration is possible

@graingert
Copy link

There's now work to test staged migration of namespace packages in pypa/sample-namespace-packages#22 referring to the table it looks like as long as you don't mind about not supporting pip install -e . a staged migration to pep 420 is supported

@mauritsvanrees
Copy link
Member

Let's see if I understand it correctly.

So "staged migration" means: migrate some packages in a namespace to pep420 while some others still use pkg_resources?

For Zope/Plone in that table the lines near the bottom with "cross_pkg_resources_pep420" are the relevant ones. I don't see a difference in behavior for Python versions, so that is good.
And you can use either a normal or editable install for old pkg_resources packages, but the pep420 ones then only work with normal installs.
So editable installs can be tricky, but a standard pip install Zope or Plone will just work, regardless of which type of namespaces are used.

That is better than I had hoped for!

It does make it a bit tricky in the transition period. Say you want to start with the Products namespace and start working on the first package. You do an editable install of the old code, and it works. Then you edit setup.py to move to native namespaces. Now you can no longer do an editable install. That makes it harder to check that it actually works before making a release.
Well, pip install . should still work, so it is not the end of the world. But when you want to fix an actual bug in the code, then after editing your files you need to explicitly run pip install . again, which is a pain.
So we should still try to keep the transition period short.

@icemac
Copy link
Member Author

icemac commented Jan 25, 2024

Heads up: zope.testrunner currently does not support implicit namespaces, see zopefoundation/zope.testrunner#160

@jensens
Copy link
Member

jensens commented Jan 29, 2024

Btw., I wrote I small blog about the mix of old and new style packages in one namespace problem last year, while confronted with this problem while working on a different project: https://yenzenz.com/blog/2023/mixed_python_pep420/

@malthe
Copy link

malthe commented Jan 31, 2024

Here's a vote for pip install -e. – I use that all the time!

@icemac
Copy link
Member Author

icemac commented Mar 22, 2024

I updated the list of needed packages to be ported in the description of the issue.

@npilon
Copy link

npilon commented Jun 7, 2024

I've gotten a lot of good use out of various zope packages, especially zope.sqlalchemy and zope.interfaces, so I'd love to help with this migration. It looks like buildout might also need some adjustment - or replacement? How can a new volunteer chip in?

@dataflake
Copy link
Member

Thanks for the offer. It looks like right now there's still too much confusion and no actual plan.

@npilon
Copy link

npilon commented Jun 8, 2024

Thanks for the offer. It looks like right now there's still too much confusion and no actual plan.

Is there anywhere central discussion or planning is happening? From trying to PEP 420 zope.sqlalchemy a bit yesterday it feels like adjusting zc.buildout to work with current packaging conventions would maybe be the place to start?

@d-maurer
Copy link

d-maurer commented Jun 8, 2024 via email

@npilon
Copy link

npilon commented Jun 8, 2024

The blog post from #194 (comment) just describes problems with editable installs and #194 (comment) seems to indicate it should work - again, outside of mixed editable installs.

Are there other documented strange behaviors? If it’s just mixed editable installs it seems like the right approach is just upgrade and maybe have minimum versions in requirements on cross dependencies?

@d-maurer
Copy link

d-maurer commented Jun 8, 2024 via email

@npilon
Copy link

npilon commented Jun 8, 2024

That’s actually exactly what I ran into trying to tinker together a simple solution for one zope subpackage yesterday so I think I have some idea about what’s going on; I’m hoping that starting with zc.buildout I can bypass that.

@d-maurer
Copy link

d-maurer commented Jun 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

9 participants