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

Change to namespace package #2393

Closed
wants to merge 5 commits into from

Conversation

sebkuf
Copy link
Contributor

@sebkuf sebkuf commented Jul 24, 2023

It should change the intelmq/bots folder to a namespace package. Now it should be easier to add new Bots. The intelmqctl list bots functionality now also works with namespaces. Added a documentation how to add a new bot.
Implements #2350

It should change the bots folder to a namespace package.
Now it should be easier to add new Bot.
I used pkgutil-style namespace packages.
It should change the bots folder to a namespace package.
Now it should be easier to add new Bot.
I used pkgutil-style namespace packages.

Implements certtools#2350
@sebkuf sebkuf marked this pull request as draft July 24, 2023 08:14
@sebkuf sebkuf changed the title Change to namespace package #2350 Change to namespace package Jul 24, 2023
Fixed the 'intelmqctl list bots' funcionality, now it works for
namespaces. Added documentation how to add a new bot. Added changelog.
Copy link
Member

@sebix sebix left a comment

Choose a reason for hiding this comment

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

Thank you for your work so far. Would be very cool if we can get this feature done :)

botmodules = []
for path, name, is_pkg in iter_modules(pkg.__path__, pkg.__name__ + '.'):
if is_pkg:
botmodules = botmodules + iter_ns(importlib.import_module(name))
Copy link
Member

Choose a reason for hiding this comment

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

This line causes the current unit test failures (import of a SyntaxError-throwing-bot fails with a SyntaxError, which is not handled correctly here). An example of catching the exception is nine lines below.

@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Copy link
Member

Choose a reason for hiding this comment

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

trailing newlines missing here and in the other similar files

@@ -0,0 +1,33 @@
Metadata-Version: 2.1
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 these files should be part of the repository, should they?


setup(
name='intelmqExampleAddBot',
version=3.1, # noqa: F821
Copy link
Member

Choose a reason for hiding this comment

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

should be a string AFAIK. And let's use semantic versioning

Suggested change
version=3.1, # noqa: F821
version='3.1.0',

Comment on lines +6 to +7
maintainer='Sebastian Wagner',
maintainer_email='[email protected]',
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to be responsible for code which I never wrote and never saw =)

Suggested change
maintainer='Sebastian Wagner',
maintainer_email='[email protected]',
maintainer='Your Name',
maintainer_email='[email protected]',

version=3.1, # noqa: F821
maintainer='Sebastian Wagner',
maintainer_email='[email protected]',
python_requires='>=3.7',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
python_requires='>=3.7',

intelmq itself requires python >= 3.7 currently, that may not be true for bots. as the bots require the core library anyway, the requirement is active too without listing it here

└── your_bot.py

The ``additional_bots`` folder needs to be defined e.g. with a ``setup.py``. Only the intelmq folder contains a ``__init__.py``
file and it must contain only this line. Any additional code in ``__init__.py`` after this line will be inaccessible.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
file and it must contain only this line. Any additional code in ``__init__.py`` after this line will be inaccessible.
file, which must have only the following line. Any additional code in ``__init__.py`` after this line will be inaccessible.

botfiles = [botfile for botfile in pathlib.Path(base_path).glob('**/*.py') if botfile.is_file() and botfile.name != '__init__.py']
for file in botfiles:
file = Path(file.as_posix().replace(base_path, 'intelmq/bots'))
def iter_ns(pkg):
Copy link
Member

Choose a reason for hiding this comment

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

Could be move the function to the outer scope?

@sebix sebix added feature Indicates new feature requests or new features packaging labels Aug 11, 2023
@kamil-certat
Copy link
Contributor

I'll take over the change and create a new PR as sebkuf is no longer available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature requests or new features packaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants