-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add checks to determine whether "create" and "modify" can safely run #11
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
33 changes: 18 additions & 15 deletions
33
src/web/BL_Python/web/scaffolding/templates/base/{{application_name}}/__init__.py.j2
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
application_configs = [] | ||
application_modules = [] | ||
from {{application_name}}._version import __version__ | ||
|
||
{% if 'database' in module %} | ||
from BL_Python.database.config import DatabaseConfig | ||
from BL_Python.database.dependency_injection import ScopedSessionModule | ||
application_configs.append(DatabaseConfig) | ||
application_modules.append(ScopedSessionModule()) | ||
{% endif %} | ||
def create_app(): | ||
application_configs = [] | ||
application_modules = [] | ||
|
||
from BL_Python.web.application import create_app | ||
# fmt: off | ||
app = create_app( | ||
application_configs=application_configs, | ||
application_modules=application_modules | ||
) | ||
# fmt: on | ||
{% if 'database' in module %} | ||
from BL_Python.database.config import DatabaseConfig | ||
from BL_Python.database.dependency_injection import ScopedSessionModule | ||
application_configs.append(DatabaseConfig) | ||
application_modules.append(ScopedSessionModule()) | ||
{% endif %} | ||
|
||
from BL_Python.web.application import create_app as _create_app | ||
# fmt: off | ||
return _create_app( | ||
application_configs=application_configs, | ||
application_modules=application_modules | ||
) | ||
# fmt: on |
5 changes: 3 additions & 2 deletions
5
src/web/BL_Python/web/scaffolding/templates/base/{{application_name}}/__main__.py.j2
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from __init__ import app | ||
from __init__ import create_app | ||
|
||
app.run() | ||
if __name__ == '__main__': | ||
create_app().run() |
4 changes: 4 additions & 0 deletions
4
src/web/BL_Python/web/scaffolding/templates/base/{{application_name}}/_version.py.j2
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import importlib.metadata | ||
|
||
__version__ = importlib.metadata.version(__package__ or __name__) | ||
__bl_python_scaffold__ = True |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know of the existence of
importlib
and a quick Googlin' turned this up - I make no promises that this is actually addressing this problem: https://docs.python.org/3/library/importlib.html#importing-a-source-file-directlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it's not the source file itself I need here - it's the package/module. Otherwise,
SourceFileLoader.load_module
would work and reduces the complexity of usingspec_from_file_location
directly (and which I'm using in the module hook lookup, which I should replace).The package/module is needed because
_version.py
references the module's metadata withimportlib.metadata
to get the software version frompyproject.toml
. Just loading the source file fails because a source file does not contain package metadata regardless of its location. So we have to fake that the package is installed in order for Python to treat the source file as if it's loaded from a package.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alas! It seems my dashed-off suggestion is not the solution to all of your problems.