Skip to content

Override source code support files for grammars in user directory. #711

Open
@LexiconCode

Description

@LexiconCode

Currently Caster tracks grammars in the castorvoice\rules. When grammar is copied over to the user directory .caster\rules it overrides imports so that it's loaded from the user directory .caster\rules instead of source code castorvoice\rules.

For instance if you copy the grammar file eclipse.py into the user directory, It will load from the user directory not the source code. Folder structure doesn't matter eclipse.py could be placed anywhere.

However it does not do the same for support files which contain functions. The template follows this standard (AppName_support\CcrName_support). For example eclipse_support.py Even though it's included with the grammar file in the same directory it still loads from source not the user directory.

This will cause a lot of confusion. What users expect to be able to edit both the grammar and support files and have them loaded from when copied to the user directory.

Why not use conditional imports?

try: # Try first loading from user directory
    from eclipse_support import ec_con
except ImportError: # load from source code.
    from castervoice.rules.apps.editor.eclipse_rules.eclipse_support import ec_con

That does place limitations though. The user cannot rename eclipse_support.py or have it in a different directory without having to change imports.

This limitation isn't too bad as long as users copies the eclipse_rules directory. As long as the files are together this shouldn't be an issue. This is the case for all grammars in apps and ccr folder as they do not import each other.

Where this becomes a significant issue is the core directory. Application and CCR grammars do import various core support_files.

For instance "eclipse2.py" grammar imports alphabet_support.py
from castervoice.rules.core.alphabet_rules import alphabet_support

Conditional imports are too fragile as we don't know where alphabet_support.py could be placed by the user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.0.0 RewriteRelated to the 1.0.0 rewrite.Caster Core SpecIssues for Caster Specs that are not part of the application or language specific grammar/ccrGrammarRelated to a grammar for an application or programming language.Help WantedSeeking co-contributorHigh Priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions