pallets / flask-ext-migrate Goto Github PK
View Code? Open in Web Editor NEWA script for migrating extension import syntax.
License: Other
A script for migrating extension import syntax.
License: Other
I tried this for https://github.com/louking/rrwebapp/releases/tag/2.6.0 and witnessed the following exception. No files had been changed.
(rrwebapp) C:\Users\Lou\Documents\Lou's Software\projects\rrwebapp>flask_ext_migrate rrwebapp
Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\Lou\Documents\Lou's Software\projects\rrwebapp\rrwebapp\Scripts\flask_ext_migrate.exe\__main__.py", line 9, in <module>
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\click\core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\click\core.py", line 696, in main
rv = self.invoke(ctx)
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\click\core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\click\core.py", line 534, in invoke
return callback(*args, **kwargs)
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\flask_ext_migrate\startup.py", line 21, in startup
fix(filepath)
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\flask_ext_migrate\__init__.py", line 142, in fix
ast = fix_function_calls(ast)
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\flask_ext_migrate\__init__.py", line 106, in fix_function_calls
if (node.value[0].value == 'flask' and
File "c:\users\lou\documents\lou's software\projects\rrwebapp\rrwebapp\lib\site-packages\redbaron\base_nodes.py", line 691, in __getattr__
self.__class__.__name__, key, key))
AttributeError: ListComprehensionNode instance has no attribute 'value' and 'value' is not a valid identifier of another node
See below, the abort
method was unnecessarily aliased to the same identifier of itself. from flask_restful import abort
would have been suffice.
$ flask_ext_migrate api/views/forum.py
$ git diff
diff --git a/api/views/forum.py b/api/views/forum.py
index bdc9803..065f7ac 100644
--- a/api/views/forum.py
+++ b/api/views/forum.py
@@ -1,5 +1,5 @@
from flask import request
-from flask.ext.restful import abort
+from flask_restful import abort as abort
See discussion in #5.
For example:
-from flask.ext.assets import Environment
+from flask_assets import Environment as Environment
I think this adds unnecessary verbosity.
Example one with parens:
from flask.ext.security.decorators import (login_required, auth_token_required)
causes redbaron to freak out with:
baron.parser.ParsingError: Error, got an unexpected token LEFT_PARENTHESIS here:
1 import flask_( <---- here
The token LEFT_PARENTHESIS should be one of those: AS, COMMA, COMMENT, DOT, ENDL, NAME, SEMICOLON, SPACE
Example two:
from flask.ext.security.decorators import login_required
Becomes:
import flask_login_required as login_required
But it should be:
from flask_security.decorators import login_required
It would be helpful to add an argument which allows for running the fixer over an entire directory of .py
files recursively.
This would involve adding an optional argument to flask-ext-migrate/startup.py
, which currently only accepts a single file argument. Additionally flask-ext-migrate/__init__.py
would require an additional method to find files in the specified directory and call fix()
on each individually.
Not exactly sure what went wrong here as the code runs perfectly fine in Flask 0.10.1
. I want to get rid of the import warnings after upgrading to Flask 0.11.1
so I ran flask-ext-migrate on this file and flask_ext_migrate
command crashed as follow.
$ flask_ext_migrate api/views/appointments.py
Traceback (most recent call last):
File "/Users/ye/.envs/py35/bin/flask_ext_migrate", line 11, in <module>
sys.exit(startup())
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/flask_ext_migrate/startup.py", line 9, in startup
fix(input_file)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/flask_ext_migrate/__init__.py", line 149, in fix
ast = read_source(input_file)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/flask_ext_migrate/__init__.py", line 15, in read_source
red = RedBaron(source_code.read())
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/redbaron/redbaron.py", line 36, in __init__
self.node_list = base_nodes.NodeList.from_fst(baron.parse(source_code), parent=self, on_attribute="root")
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/baron/baron.py", line 49, in parse
tokens = tokenize(source_code, False)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/baron/baron.py", line 70, in tokenize
return mark_indentation(inner_group(space_group(_tokenize(group(split(pouet)), print_function))))
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/baron/inner_formatting_grouper.py", line 112, in group
return list(group_generator(sequence))
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/baron/inner_formatting_grouper.py", line 165, in group_generator
fail_on_bad_token(iterator.show_next(), debug_file_content, in_grouping_mode)
File "/Users/ye/.envs/py35/lib/python3.5/site-packages/baron/inner_formatting_grouper.py", line 125, in fail_on_bad_token
raise GroupingError("Fail to group formatting tokens, here:\n%s <----\n\n'%s' should have been in: %s\n\nCurrent value of 'in_grouping_mode': %s" % (debug_file_content, token, ', '.join(sorted(GROUP_ON)), in_grouping_mode))
baron.inner_formatting_grouper.GroupingError: Fail to group formatting tokens, here:
271
272 client_notes = args.get('misc', {}).get('notes') or None
273
274 appointment <----
'('NAME', 'appointment')' should have been in: AMPER, AMPER_EQUAL, AND, AS, BINARY_RAW_STRING, BINARY_STRING, CIRCUMFLEX, CIRCUMFLEX_EQUAL, COLON, COLON, COMMA, DOT, DOUBLE_SLASH, DOUBLE_SLASH_EQUAL, DOUBLE_STAR, DOUBLE_STAR_EQUAL, ELSE, ENDL, EQUAL, EQUAL_EQUAL, FOR, GREATER, GREATER_EQUAL, IF, IMPORT, IN, IS, LEFT_BRACKET, LEFT_PARENTHESIS, LEFT_SHIFT, LEFT_SHIFT_EQUAL, LEFT_SQUARE_BRACKET, LEFT_SQUARE_BRACKET, LESS, LESS_EQUAL, MINUS, MINUS_EQUAL, NOT, NOT_EQUAL, OR, PERCENT, PERCENT_EQUAL, PLUS, PLUS_EQUAL, RAW_STRING, RAW_STRING, RIGHT_BRACKET, RIGHT_PARENTHESIS, RIGHT_SHIFT, RIGHT_SHIFT_EQUAL, RIGHT_SQUARE_BRACKET, SLASH, SLASH_EQUAL, STAR, STAR_EQUAL, STRING, UNICODE_RAW_STRING, UNICODE_RAW_STRING, UNICODE_STRING, UNICODE_STRING, VBAR, VBAR_EQUAL
Current value of 'in_grouping_mode': -1
After manual migration, the real change looks like this:
$ git diff api/views/appointments.py
diff --git a/api/views/appointments.py b/api/views/appointments.py
index 676332f..be09030 100644
--- a/api/views/appointments.py
+++ b/api/views/appointments.py
@@ -5,7 +5,7 @@
from sqlalchemy.orm.exc import NoResultFound
-from flask.ext.restful import abort
+from flask_restful import abort
from flask import request, Response
So why does flask_ext_migrate
stuck with a non-sense error?
The version of flask-ext-migrate that is downloadable via pip does not match the version posted here on Github, and specifically is unable to be called on a directory.
Just for debug, demo.py is an empty file
flask_ext_migrate demo.py
Traceback (most recent call last):
File "/home/vagrant/myproject/venv/bin/flask_ext_migrate", line 9, in <module>
load_entry_point('flask-ext-migrate==0.0.1', 'console_scripts', 'flask_ext_migrate')()
File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/flask_ext_migrate/startup.py", line 9, in startup
fix(input_file)
File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/flask_ext_migrate/__init__.py", line 153, in fix
check_user_input(input_file)
TypeError: check_user_input() takes no arguments (1 given)
Needs to have a license added. Not sure if there is an expectation for what license to use for pocoo projects.
I'm trying to run the flask_ext_migrate like this:
flask_ext_migrate app.py
but I'm receiving an error like that:
Traceback (most recent call last):
File "app/bin/flask_ext_migrate", line 11, in <module>
sys.exit(startup())
File "app/lib/python3.4/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "app/lib/python3.4/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "app/lib/python3.4/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "app/lib/python3.4/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File ".virtualenvs/app/lib/python3.4/site-packages/flask_ext_migrate/startup.py", line 9, in startup
fix(input_file)
File ".virtualenvs/app/lib/python3.4/site-packages/flask_ext_migrate/__init__.py", line 153, in fix
check_user_input(input_file)
TypeError: check_user_input() takes 0 positional arguments but 1 was given
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.