How to automatically handle Python namespace packages (e.g. in %pyproject_save_files)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Pythonistas.

I'd like to be able to automatically handle Python "namespace" packages from our packaging macros.

The problem:

Several Python packages share a "namespace", let's take an artificial example with food.spam and food.eggs Python packages.

1. the Python packages both have site-packages/food
2. sometimes such packages also both have site-packages/food/__init__.py
   (usually empty or mostly empty, but with different mtimes etc.)

On RPM level, this means:

1. %{python3_sitelib}/food can be co-owned
   OR it can be in an artificial python3-food(-filesystem) package [0]
   OR it can be in an existing package that is always present [1]
2. %{python3_sitelib}/food/__init__.py and
   %{python3_sitelib}/food/__pycache__/__init__.*.pyc
   will conflict if present in multiple packages,
   they need to be removed or shared from the python3-food(-filesystem) package

I want to solve this once for all, define the best practice, document it in the packaging guidelines and possible automate this in %pyproject_save_files [2].


My current idea is:

- sharing directories is safe and easy,
  let's do that instead of artificial packages (those are hard to automate)
- namespace packages should not need __init__py with modern Python 3,
  let's discourage that
- If needed for %check, the __init__.py + .pyc should be %ghosted [3]



And with the %pyproject_save_files automation, let's say that if %pyproject_save_files is used with a dot:

  %pyproject_save_files food.spam

The dots separates a namespace and:

 - food folder is co-owned
 - food/__init__.py + .pyc is %ghosted if found, possibly with a warning
 - any other Python files in food/ except spam.py or spam/ are not included

In case of nested namespaces (I have never seen that in reality), this can be applied recursively.

Since %pyproject_save_files takes globs, I propose we split the argument on dot and treat each part as a separate glob.


An alternate proposal which is less magical, more explicit about the "namespace" situation but less explicit about what to include requires a special namespace flag:

  %pyproject_save_files -N food

This says: Include food supackages, but food is a namespace package:

 - food folder is co-owned
 - food/__init__.py + .pyc is %ghosted if found, possibly with a warning
 - all other Python files in food/ are included

Alternatively, this can be combined together somehow:

  %pyproject_save_files -N food spam

But I don't like that.


Thoughts?


[0] https://src.fedoraproject.org/rpms/python-jaraco-packaging/blob/rawhide/f/python-jaraco-packaging.spec#_29 [1] https://src.fedoraproject.org/rpms/python-sphinx/blob/rawhide/f/python-sphinx.spec#_320
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1935266
[3] https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx/message/5X3HTWDQ6AEHLUNUEORZ27VLOSMN2OCI/

--
Miro Hrončok
--
Phone: +420777974800
IRC: mhroncok
_______________________________________________
packaging mailing list -- packaging@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to packaging-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/packaging@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure




[Index of Archives]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Forum]     [KDE Users]

  Powered by Linux