nickjj / flask-db

A Flask CLI extension to help migrate and manage your SQL database.
MIT License
76 stars 6 forks source link

[BUG] IDE giving me syntax error #4

Closed dwreeves closed 3 years ago

dwreeves commented 3 years ago

I like this tool, I think it's a good way to do migrations with Flask. I like that it doesn't involve touching my app code with a "migrate" object, it creates a good boilerplate env.py file from the get-go. There's just one problem...

image

The problem is my IDE. PyCharm Professional 202.3 believes that this package contains is a syntax error because it sees a .py file called env.py and doesn't realize it's a template. The error is here:

from $CURRENT_APP_IMPORT_NAME import create_app  # noqa: E999

It's also extremely tedious to tell PyCharm to not look at this. This makes it a bit... annoying to incorporate into my project, as now the whole project folder has a red line underneath.

dwreeves commented 3 years ago

Unrelated issue, but when I try to run the /tests/example_app, the folder structure seems to imply that the working directory I'm supposed to be running in is /tests/example_app, but the env.py is structured as if the working directory is the project root directory. So if I run flask db migrate upgrade -m "init" it gives me:

nickjj commented 3 years ago

Hi,

That value should have been replaced with the import path of your project at the point of running the init command.

As for touching your app code with a migrate object, that's just how Alembic works. This tool is mainly a wrapper around Alembic for the migration bits.

dwreeves commented 3 years ago

That value should have been replaced with the import path of your project at the point of running the init command.

Yes, I understand. The site-package inside the venv causes the error, not the folder for migrations itself. The red line in the screenshot I'm showing is highlighting my venv. Sorry for the miscommunication, I realize that may not have been clear.

Currently on my work laptop, but when I am able to transition to my home computer I can show exactly, but it's where you'd expect it to be inside the venv/lib/Pythonx/site-packages/Flask_DB/templates folder.

This is an IDE specific issue where my IDE is doing, by default, inspections to everything inside of a repo including the venv. But the fact that this is not compatible with a popular IDE's inspection process is a bit of a problem for my ability to incorporate it into a project where I know a lot of the contributors use this IDE.

As for touching your app code with a migrate object, that's just how Alembic works. This tool is mainly a wrapper around Alembic for the migration bits.

I meant inside the app itself. I meant I appreciated I don't have a Migrate(db=db).init_app(app). I've used Alembic before in a FastAPI context.

nickjj commented 3 years ago

Oh, so the "real" file is working.

I suppose I could change the placeholder to be something that's valid Python.

If you remove the $ does PyCharm treat it as valid syntax?

dwreeves commented 3 years ago

Yep, that's the problem.

Removing the $ appears to work. PyCharm only gives you the nasty red lines for invalid Python syntax inside *.py files.

A few other solutions include substituting env.py with env.py.txt or making it a Jinja template env.py.jinja2 then rendering. But removing the dollar sign is definitely the most straightforward approach.

nickjj commented 3 years ago

Ok thanks, I've pushed 0.3.2 to PyPI which removes the $.

Should be good to go.

dwreeves commented 3 years ago

Thanks!