Skip to content

SpionQuark/Automatic-Blueprint-Builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1. Blueprint Manager

Importing blueprints can get messy fast if you have too many. Yet blueprints are a great way to build something and having many of them can happen quickly. So, let's clean that up.

So, welcome to the blueprint manager. This script/class allows you to directly let all blueprints within a certain directory to be added.

1.1 Usage

Using this is quite easy.

from quart import Quart
from manager.blueprintmanager import BlueprintManager

app = Quart(__name__)

BlueprintManager(app)

if __name__ == "__main__":
    app.run()

1.1.1 Import the class

We can import the class using:

from manager.blueprintmanager import BlueprintManager

1.1.2 Creating an instance

Now we need to create an instance of the BlueprintManager

bpm = BlueprintManager(app=app, default_dir='blueprints', debugging = True)
Parameter Description Default
app Instance of Quart() Required
default_dir Directory where blueprints are stored "blueprints"
debugging Enables detailed logging False

Once the instance is created all blueprints inside the directory are automatically registered. No additional configuration or setup required

1.1.3 It did not work?!

If the blueprints are not loaded, it is helpful to understand how the Blueprint Manager works internally.

Continue with section 1.2 for more inforamtion on how it works. For error fixing go to section 1.4

1.2 How it works

The most important thing is always to know how something works. So, here is a quick overview.

1.2.1 Creating an instance of BlueprintManager

  1. The blueprint directory is checked
  2. If the directory does not exist, it will be created
  3. The manager scans all .py files inside the directory
  4. Blueprint instances are detected
  5. All detected blueprints are registered to the Quart app

If no default_dir is provided, the manager uses

blueprints/

If the folder already exists, it will not be recreated.

1.2.2 How does it know what a blueprint is?

The BlueprintManager includes a failsafe system.

It scans Python files and searches for Blueprint instances. If a file inside the blueprint directory does not contain a blueprint, it will simply be ignored.

This means you can safely place:

  • helper scripts
  • utilities
  • configuration files
  • documentation files inside the blueprint directory without breaking anything.

Only valid Blueprint objects will be registered.

1.2.3 Why use debugging?

Debugging mode helps identify problems during blueprint discovery and registration.

When debugging is enabled, the manager prints structured log messages with error codes.

This makes it easier to:

  • detect missing blueprints
  • find import errors
  • locate parsing issues
  • understand failures
  • report bugs

1.3 Debugging Codes

Code Meaning Error
[AA00] The directory was not found. Creating a new one
[AB01] Somehow creating a new directory failed.
[AC02] Tried to fetch all blueprints as a list. An error occured
[AD03] The given app-value is not an instance of the class Quart
[AE04] There were no blueprints in the folder
[AF05] There has been an error importing one blueprint
[AH07] An unknown error occured whilst trying to apply the blueprints
[AI08] Somehow we extracted an instance that is not a blueprint, failsave prevented issues
[AJ09] An error occured whilst trying to parse a certain file
[AK10] Registering one blueprint was successful

Reporting errors

If an error occurs:

  1. copy the full log message
  2. include the error code
  3. include the stack trace
  4. open an issue in the repository

This helps identify and fix problems quickly.

1.4 Troubleshootin common issues

So, it is important to look at your folder structure. For the setup to work it should look like this:

project/
│
├── app.py
├── manager/
│   └── blueprintmanager.py
│
└── blueprints/
    ├── bp_api.py
    ├── bp_auth.py
    └── bp_smth.py

The name of your blueprint-files is not really important. There are some rules to follow though:

  1. Do not use spaces: The name blueprint super good.py is not allowed and will result in import issues.
  2. Do not use '-': If the name is blueprint-super-good.py it will too result in import issues.
  3. Do not use special characters: Why ever you should feel the urge to name the file blueprint?super#good.py it will too result in import issues.

Recommended naming:

A recommended naming convention is:

bp_[role].py

where role describes the functionality of the blueprint.

blueprints/
    ├── bp_api.py
    ├── bp_auth.py
    ├── bp_projects.py
    ├── bp_chat.py
    └── bp_user.py

About

A semi automatic blueprint adder for Quart

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages