Code Monkey home page Code Monkey logo

Comments (5)

woopla avatar woopla commented on June 24, 2024

Found the issue, and a workaround. The problem is that AlchemyDumps.__init__() checks if app is None before calling the app.cli.add_command, when this should really be done in AlchemyDumps.init_app().

The workaround:

from flask_alchemydumps.cli import alchemydumps as ad_cli
...

def create_app(config_class=Config):
    ...
    alchemydumps.init_app(app, db)
    app.cli.add_command(ad_cli)

What's weird is that if I compare to, for example Flask-Migrate (which adds a db subcommand), I don't see any call whatsoever to app.cli.add_command() in the code.

from alchemydumps.

cuducos avatar cuducos commented on June 24, 2024

Bonjour Clément : ) not sure if you speak French, but your name sounds like French to me!

Many thanks for the heads up. Just checking if I understood: it might make sense to remove this line from our source code, right?

from alchemydumps.

woopla avatar woopla commented on June 24, 2024

I am French indeed, good guess :)

After more research, I found the reason why it works for Flask-Migrate: this package uses a setup.py that's setup following the Flask-CLI convention:

entry_points={
    'flask.commands': [
        'db=flask_migrate.cli:db'
    ],
}

I looked at the documentation for Poetry, and it's not clear to me that the same thing can be achieved.

Re: removing that line, I think the most generic solution is to move these two to the end of init_app. This way it'll work both for the 'standard' and Factory Pattern use cases.

from alchemydumps.

cuducos avatar cuducos commented on June 24, 2024

I looked at the documentation for Poetry, and it's not clear to me that the same thing can be achieved.

I know they implement entry points via plugins, but the docs anre a biy blunt on the details — that is all we have there:

plugins

Poetry supports arbitrary plugins which work similarly to setuptools entry points. To match the example in the setuptools documentation, you would use the following:

[tool.poetry.plugins] # Optional super table

[tool.poetry.plugins."blogtool.parsers"]
".rst" = "some_module:SomeClass"

Re: removing that line, I think the most generic solution is to move these two to the end of init_app. This way it'll work both for the 'standard' and Factory Pattern use cases.

Sure. My bad I got it wrong. This looks like a good solution.

Are you comfortable in opening a PR?
Otherwise, I can try to implement something (either via pyproject.toml or __init__.py) this weekend.

from alchemydumps.

woopla avatar woopla commented on June 24, 2024

I can open a PR for sure, but not before at least ten days. And most probably longer... Busy work is busy 😿

from alchemydumps.

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.