Skip to content

feat: Check for __all__ presence in __init__.py files#766

Draft
AcquaDiGiorgio wants to merge 4 commits intoDIRACGrid:mainfrom
AcquaDiGiorgio:issue-426-__all__-in-__init__
Draft

feat: Check for __all__ presence in __init__.py files#766
AcquaDiGiorgio wants to merge 4 commits intoDIRACGrid:mainfrom
AcquaDiGiorgio:issue-426-__all__-in-__init__

Conversation

@AcquaDiGiorgio
Copy link

See #426

I tried something more sofisticated in python using importlib to check the variables in the module, both instantiated and imported, but there were multiple situations that were extremely difficult to check.

We also might want to set a common way of defining this variable, using either tuples or lists:

  • diracx/routers/health/__init__.py: __all__ = ["router"]
  • diracx/db/os/__init__.py __all__ = ("JobParametersDB",)

@read-the-docs-community
Copy link

read-the-docs-community bot commented Feb 5, 2026

Documentation build overview

📚 diracx | 🛠️ Build #31299029 | 📁 Comparing 92abfc9 against latest (9cc792e)


🔍 Preview build

No files changed.

@aldbr aldbr linked an issue Feb 5, 2026 that may be closed by this pull request
name: Check for __all__ presence in __init__.py files
language: system
entry: "sh .github/workflows/check_init_files_precommit_hook.sh"
files: ^diracx-.*__init__\.py$
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to exclude the auto-generated part of diracx-client from this i.e.

https://github.com/DIRACGrid/diracx/tree/main/diracx-client/src/diracx/client/_generated

I guess this should also apply to the example extension (gubbins):

https://github.com/DIRACGrid/diracx/tree/main/extensions/gubbins

Copy link
Author

Choose a reason for hiding this comment

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

The regex only applies for files that start with diracx-, so the extensions directory won't be searched.

Also, with the exclude: _generated in the next line, it already ignores the auto-generated files.

With the current configuration, it finds the following files:

diracx-logic/src/diracx/logic/task_queues/__init__.py
diracx-logic/src/diracx/logic/jobs/__init__.py
diracx-logic/src/diracx/logic/auth/__init__.py
diracx-logic/src/diracx/logic/__init__.py

diracx-db/src/diracx/db/sql/dummy/__init__.py
diracx-db/src/diracx/db/sql/job/__init__.py
diracx-db/src/diracx/db/sql/pilot_agents/__init__.py
diracx-db/src/diracx/db/sql/task_queue/__init__.py
diracx-db/src/diracx/db/sql/job_logging/__init__.py
diracx-db/src/diracx/db/sql/sandbox_metadata/__init__.py
diracx-db/src/diracx/db/sql/auth/__init__.py
diracx-db/tests/pilot_agents/__init__.py

diracx-core/src/diracx/core/__init__.py

diracx-routers/src/diracx/routers/utils/__init__.py
diracx-routers/src/diracx/routers/jobs/__init__.py

Copy link
Author

Choose a reason for hiding this comment

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

Or do you mean that the gubbins extension should be checked too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think they should also be checked indeed

@aldbr
Copy link
Contributor

aldbr commented Feb 6, 2026

We also might want to set a common way of defining this variable, using either tuples or lists:

I didn't see any standard way of defining __all__ but indeed, it would be better if consistent.
From what I observed, the list is generally preferred (https://stackoverflow.com/questions/66098828/using-list-instead-of-tuple-in-module-all).

Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific reason for making a bash script instead of a pixi task as done here:

- repo: local
hooks:
- id: generate-pixi-docs
name: Generate pixi tasks documentation
entry: pixi run -e default python .github/workflows/generate_pixi_tasks_doc.py
language: system
pass_filenames: false
files: ^pixi\.toml$|^pixi\.lock$ # only run if pixi files change
- repo: local
hooks:
- id: settings-doc-check
name: Generate settings documentation
entry: pixi run -e default python scripts/generate_settings_docs.py
language: system
pass_filenames: false
files: ^(diracx-.*/src/diracx/.*/settings\.py|docs/.*\.j2|docs/templates/.*\.jinja|scripts/generate_settings_docs\.py)$

If we want to enforce lists for instance, I have the feeling it would be easier to implement (and also let the possibility of unit testing it if needed).

Any opinion?

Copy link
Author

Choose a reason for hiding this comment

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

I used bash for the commodity of grep, but I can change the script to use python with pixi instead, it will definetely be much easier/cleaner to check its type that way.

@chrisburr chrisburr self-requested a review February 6, 2026 09:36
chrisburr

This comment was marked as off-topic.

chrisburr

This comment was marked as off-topic.

chrisburr

This comment was marked as off-topic.

Copy link
Member

@chrisburr chrisburr left a comment

Choose a reason for hiding this comment

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

Yet another fake review for me to be able to test something 😄

@DIRACGridBot DIRACGridBot marked this pull request as draft February 7, 2026 06:06
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.

Make sure __all__ is present in the __init__ files and up to date

3 participants