Repository navigation
fix: keep plugins in other sys.path entries importable - #584
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
Conversation
pySigma 2.0 added sigma/__init__.py to provide sigma.default_policy. That
turned sigma from an implicit namespace package into a regular package, so
Python stops looking for sigma.* modules in other sys.path entries. Plugins
installed in editable mode (e.g. poetry install in a backend checkout) or into
another site directory can no longer be imported:
ModuleNotFoundError: No module named 'sigma.backends.logpoint'
Extend sigma.__path__ with pkgutil.extend_path so these portions are found
again, while keeping sigma.default_policy where it is.
This was referenced Oct 5, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pySigma 2.0.0 added
sigma/__init__.py(forsigma.default_policy). Before that,sigmawas an implicit namespace package. Now it is a regular package, so Python no longer combinessigma/directories from differentsys.pathentries. Backends, pipelines and validators that are installed outside pySigma's own site-packages directory can't be imported any more. The most common case is an editable install, which is whatpoetry installdoes in every backend checkout and CI job.Reproduction in fresh venvs, using
import sigma.backends.logpointwith pySigma-backend-logpoint:pip install -epip install -eModuleNotFoundError: No module named 'sigma.backends.logpoint'pip install(non-editable)pip install -eThe same error shows up in CI for backends that move to pySigma 2.0. For example, logpoint/pySigma-backend-logpoint#40 fails at test collection: https://github.com/logpoint/pySigma-backend-logpoint/actions/runs/37338362378/job/111858805629
Fix:
sigma/__init__.pycallspkgutil.extend_pathsosigma.__path__again coverssigma/directories on allsys.pathentries.sigma.backendsandsigma.pipelinesstay namespace packages, andsigma.default_policyand its documented override keep working unchanged.The alternative would be to move
default_policyintosigma.policyand deletesigma/__init__.pyagain. That would also fix the problem, but it changes thesigma.default_policyAPI documented indocs/guides/sigma_policy.rst. I went with the smaller change, but I'm happy to switch if you prefer that approach.Testing
tests/test_namespace.pyimports a plugin module placed in a separatePYTHONPATHentry in a subprocess. It fails without the change (ModuleNotFoundError) and passes with it.-m "not online").mypy sigmaandblack --checkare clean.InstalledSigmaPlugins.autodiscover()finds them.