Code Monkey home page Code Monkey logo

Comments (5)

dwrolvink avatar dwrolvink commented on September 20, 2024 1

The module system was designed to be, wait for it, as modular as possible.
For example, I have written a module in Rust that replaces the built-in parse_metadata module. It is around 4x as fast. (Though this only saves a couple microconds, as the module doesn't do much work, so not really relevant except for as a proof of concept).

The idea that I am trying to paint is that any module should be able to be exchanged by any other (custom user)module that functionally does the same thing. Combining this with a choose-your-own-combination, is really complex to implement and configure.

So, fast forwarding a bit, I think the error checking is the only viable option from the list. Should be easy to implement, as every module already defines what files they provide. I could give an error like this:

Module X claims to require file yyy.yaml, but this file is not present at time of execution.
Make sure a module is executed that provides this file before this module is run.

The following modules in the module_list provide this file (without requiring it themselves):
 - Module Z
 - Module A
 - ...

The following built-in modules provide this file (without requiring it themselves):
- Module B
- ...

(Second list for people with very terse module_list configs).

Some notes for myself:

  • Binary modules should implement a method to advertise provides/requires
  • Built-in modules should be fetched and loaded before module execution to be able to compile a list of provides/requires. Or have a separate function in their file that returns these values (probably the latter is better).

from obsidian-html.

dwrolvink avatar dwrolvink commented on September 20, 2024

Okay, now I got to the point where setup_module (always the first to run), will output the modfile_dependencies.json file. Contents at the bottom of the post.

This should be a good basis to build the checking on top of.

Still not sure if I should do an ahead-of-time check, or have each module check itself and use this data as a basis for suggesting better module ordering. I'm leaning toward the latter as that gives more power to the modules to decide themselves how to deal with a missing file.

{
  "log.resources": {
    "provided_by": [
      "resource_logger (ResourceLoggerMetaModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "config.yml": {
    "provided_by": [
      "setup_module (SetupModule)"
    ],
    "required_by": [
      "resource_logger (ResourceLoggerMetaModule)",
      "process_config (ProcessConfigModule)",
      "load_paths (LoadPathsModule)",
      "html_templater (HtmlTemplaterModule)",
      "load_graphers (LoadGrapherModule)",
      "get_file_list (GetFileListModule)",
      "copy_vault_to_tempdirectory (VaultCopyModule)",
      "prepare_output_folders (PrepareOutputFoldersModule)"
    ],
    "altered_by": [
      "process_config (ProcessConfigModule)"
    ]
  },
  "capabilities.json": {
    "provided_by": [
      "process_config (ProcessConfigModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "arguments.yml": {
    "provided_by": [
      "setup_module (SetupModule)"
    ],
    "required_by": [
      "process_config (ProcessConfigModule)"
    ],
    "altered_by": []
  },
  "paths.json": {
    "provided_by": [
      "load_paths (LoadPathsModule)"
    ],
    "required_by": [
      "get_file_list (GetFileListModule)",
      "parse_metadata_rs (BinaryModule)",
      "filter_on_metadata (FilterOnMetadataModule)",
      "copy_vault_to_tempdirectory (VaultCopyModule)",
      "prepare_output_folders (PrepareOutputFoldersModule)",
      "parse_metadata (ParseMetadataModule) [not configured]"
    ],
    "altered_by": [
      "copy_vault_to_tempdirectory (VaultCopyModule)"
    ]
  },
  "html/note.template.html": {
    "provided_by": [
      "html_templater (HtmlTemplaterModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "html/dynamic_inclusions.html": {
    "provided_by": [
      "html_templater (HtmlTemplaterModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "html/dynamic_footer_inclusions.html": {
    "provided_by": [
      "html_templater (HtmlTemplaterModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "html/graph.template.html": {
    "provided_by": [
      "load_graphers (LoadGrapherModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "html/graph_full_page.template.html": {
    "provided_by": [
      "load_graphers (LoadGrapherModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "graphers.json": {
    "provided_by": [
      "load_graphers (LoadGrapherModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "index/files.json": {
    "provided_by": [
      "get_file_list (GetFileListModule)"
    ],
    "required_by": [
      "parse_metadata_rs (BinaryModule)",
      "filter_on_metadata (FilterOnMetadataModule)",
      "copy_vault_to_tempdirectory (VaultCopyModule)"
    ],
    "altered_by": [
      "filter_on_metadata (FilterOnMetadataModule)",
      "copy_vault_to_tempdirectory (VaultCopyModule)"
    ]
  },
  "index/excluded_files.json": {
    "provided_by": [
      "get_file_list (GetFileListModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "index/markdown_files.json": {
    "provided_by": [
      "get_file_list (GetFileListModule)"
    ],
    "required_by": [
      "filter_on_metadata (FilterOnMetadataModule)",
      "parse_metadata (ParseMetadataModule) [not configured]"
    ],
    "altered_by": [
      "filter_on_metadata (FilterOnMetadataModule)"
    ]
  },
  "index/metadata.json": {
    "provided_by": [
      "parse_metadata_rs (BinaryModule)",
      "parse_metadata (ParseMetadataModule) [not configured]"
    ],
    "required_by": [
      "filter_on_metadata (FilterOnMetadataModule)"
    ],
    "altered_by": []
  },
  "excluded_files_by_metadata.json": {
    "provided_by": [
      "filter_on_metadata (FilterOnMetadataModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "guid.txt": {
    "provided_by": [
      "setup_module (SetupModule)"
    ],
    "required_by": [
      "prepare_output_folders (PrepareOutputFoldersModule)"
    ],
    "altered_by": []
  },
  "user_config.yml": {
    "provided_by": [
      "setup_module (SetupModule)"
    ],
    "required_by": [],
    "altered_by": []
  },
  "modfile_dependencies.json": {
    "provided_by": [
      "setup_module (SetupModule)"
    ],
    "required_by": [],
    "altered_by": []
  }
}

from obsidian-html.

dwrolvink avatar dwrolvink commented on September 20, 2024

Ah, I never clicked comment lol.
In the mean time I have the first version done already.

If you try to run a module that requires a file that is not present, you will be greeted with this terminating error:

[ ERROR ] * Module filter_on_metadata (FilterOnMetadataModule) requires index/metadata.json to exist, but it does not.
            Make sure a module is run that provides it, before running filter_on_metadata (FilterOnMetadataModule)
            Note: The modfile index/metadata.json is provided by the following modules:
              - rust_example_module (BinaryModule)
              - parse_metadata (ParseMetadataModule)

This will work for any module.
It first takes the modules from the module_list (as configured in the user's config file), then it loads on top of that the built-in modules. This means that the message is also able to tell you whether the module that provides the file is present in the module_list (and thus in the wrong order), or available but not configured.

If there are no modules known that provide the file, you will get this error:

[ ERROR ] * Module filter_on_metadata (FilterOnMetadataModule) requires bla.json to exist, but it does not.
            Make sure a module is run that provides it, before running filter_on_metadata (FilterOnMetadataModule)
            Note: The modfile bla.json is not provided by any built-in or configured module.
            Perhaps you have to configure a custom module?

Hope I covered all the bases here.

Nice thing of this change is that nothing needs to be added to the modules for this to work. I just changed the provides/requires/alters property abstract methods to static methods so that they can be called before the module is instantiated, which required some work under the hood of the module system, but it left the modules themselves unaltered except for the type change.

In short, I am happy with the way I was able to implement this.

from obsidian-html.

cquenelle avatar cquenelle commented on September 20, 2024

Nice resolution, thanks. Sounds like a really good solution!

from obsidian-html.

dwrolvink avatar dwrolvink commented on September 20, 2024

Nice!
Closing this for now, as it is basically finished at this point

from obsidian-html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.