Skip to content

Bugfix: unexpected global package import#114

Merged
da-h merged 2 commits intomasterfrom
bugfix_for_imports
Oct 6, 2022
Merged

Bugfix: unexpected global package import#114
da-h merged 2 commits intomasterfrom
bugfix_for_imports

Conversation

@da-h
Copy link
Copy Markdown
Owner

@da-h da-h commented Oct 5, 2022

Bugfix: Unreliable imports.

This MR finalizes #112 by fixing an unexpected global package-import instead of a local minifflask module.

Description

From #112 on, miniflask tries to use pythons import statement if possible to load modules.
The solution was to import the module name using the importname, i.e. without the module-base-directory in its identifier. Interestingly, this indeed loaded the correct modules in most cases.
However, in case a system-module with that name exists, miniflask would load that instead of the local module.

Setup:

  1. Install any python package under the name setup.
  2. Run pytest.

Problem:
Due to a module under ./tests/event/beforeafter/modules named setup, the setup above will result in an error.

Things done in this MR

The solution is quite simple: the module-id actually contains the base-directory name (in case the module directory has not been named otherwise in the mf.init-call - thus the string is correct in exactly those cases in which we want the internal import to be used.

There is one special case, that needed to be resolved to make this work consistently:
The miniflask-internal modules settings, events, modules, etc. have been placed in miniflask/module/*, but have been referenced using miniflask.* instead of miniflask.module.*. To make things consistent, this MR moves all those modules directly into the miniflask base directory.

Check all before creating this PR:

  • Documentation adapted
  • unit tests adapted / created

@da-h da-h requested a review from sbrodehl October 5, 2022 14:57
@da-h da-h force-pushed the bugfix_for_imports branch 2 times, most recently from fe3ccb8 to 19d4023 Compare October 5, 2022 15:00
@da-h
Copy link
Copy Markdown
Owner Author

da-h commented Oct 5, 2022

Just a side-note: The linting errors (solved in #113) will throw errors here.
I will rebase whenever #113 is merged.

Copy link
Copy Markdown
Collaborator

@sbrodehl sbrodehl left a comment

Choose a reason for hiding this comment

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

Looks good so far, just two comments in the code on possibly duplicated code and regarding the renaming of modules in the mf.init-call.

Comment thread src/miniflask/__init__.py Outdated
Comment thread src/miniflask/miniflask.py
@da-h da-h mentioned this pull request Oct 6, 2022
2 tasks
@da-h da-h force-pushed the bugfix_for_imports branch from 19d4023 to 7fac07a Compare October 6, 2022 10:23
@da-h da-h force-pushed the bugfix_for_imports branch from 7fac07a to 327f13b Compare October 6, 2022 10:25
@da-h
Copy link
Copy Markdown
Owner Author

da-h commented Oct 6, 2022

Rebased onto master.

@da-h da-h force-pushed the bugfix_for_imports branch from 327f13b to 86d303e Compare October 6, 2022 10:26
@da-h da-h requested a review from sbrodehl October 6, 2022 10:28
@da-h da-h merged commit 8853045 into master Oct 6, 2022
@da-h da-h deleted the bugfix_for_imports branch October 6, 2022 10:30
github-actions Bot pushed a commit that referenced this pull request Oct 6, 2022
Bugfix: unexpected global package import
@da-h da-h mentioned this pull request Oct 6, 2022
@sbrodehl sbrodehl mentioned this pull request Oct 11, 2022
2 tasks
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.

2 participants