New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate flask.ext and create migration tool to flask_* #1135

Closed
DasIch opened this Issue Jul 27, 2014 · 17 comments

Comments

Projects
None yet
7 participants
@DasIch
Contributor

DasIch commented Jul 27, 2014

No description provided.

@untitaker untitaker added this to the 1.0 milestone Oct 7, 2014

@methane methane referenced this issue Oct 19, 2014

Closed

Deprecate and remove APIs #1182

6 of 6 tasks complete
@untitaker

This comment has been minimized.

Member

untitaker commented Oct 19, 2014

A migration tool could be a simple lib2to3-based, but i am not sure if such a thing is necessary. This case seems to be an easy enough task for simple search-and-replace or regexes.

@untitaker

This comment has been minimized.

Member

untitaker commented Nov 5, 2014

Some introductory information for new contributors:

  • Flask used to have flaskext as a namespace for extensions, so they were importable as flaskext.foo. This didn't work well, so the new form flask_foo was introduced. flask.ext.foo is a compatibility layer that will try to import both variants. See http://flask.pocoo.org/docs/0.10/extensions/
  • flask.ext.foo is hard to maintain, and since now all extensions have switched to the new package naming scheme, it is no longer worth it. We want to deprecate it for 1.0, so we need some sort of tool which can help users to rewrite all their old imports in their apps.
  • One could write a Python script similar to this beast. This will get the job done, but as its docstring says, it's a terrible hack.
  • lib2to3 proved useful for writing larger migration tools, but it's nontrivial to use it.
    • https://github.com/mitsuhiko/python-modernize/ is one based on it, and it seems to me that's the easiest project one could rip off from.
    • I wasn't able to find complete tutorials that are useful for this. Most seem to be focused on porting to Python 3, which would imply running the default 2to3 fixers on the user's codebase (which we definetly don't want)
    • One will have to read the sourcecode of 2to3 and lib2to3 to understand, i think. This is doable by entering libraryname hg.python.org into Google, where the libraryname is either 2to3 or lib2to3.
    • The current state for doing sourcecode manipulation in Python sucks, and i'd like to see a library which wraps lib2to3 and provides a more concise API.
@keyan

This comment has been minimized.

Member

keyan commented Feb 3, 2015

I'd like to try to tackle this. Just to get some clarification, the proposed migration tool would essentially search old sourcecode and replace instances of import flask.ext.foo with import flask_foo, am I understanding this correctly?

@ThiefMaster

This comment has been minimized.

Member

ThiefMaster commented Feb 3, 2015

Yes. It would have to cover these imports (unless I missed anything):

from flask.ext import foo
from flask.ext.foo import <anything>
import flask.ext.foo[.anything]
@keyan

This comment has been minimized.

Member

keyan commented Feb 3, 2015

And the aforementioned imports would be replaced with what?

@ThiefMaster

This comment has been minimized.

Member

ThiefMaster commented Feb 3, 2015

flask.ext.foo => flask_foo

@untitaker

This comment has been minimized.

Member

untitaker commented Feb 3, 2015

Exactly what ThiefMaster said. Thanks for giving this a try!

And the aforementioned imports would be replaced with what?

  • from flask.ext import foo => import flask_foo as foo
  • from flask.ext.foo import bam => from flask_foo import bam
  • import flask.ext.foo => We'd have to rewrite any reference to flask.ext.foo in the code further below. If that's too hard, just skip those and show a warning.
@davidism

This comment has been minimized.

Member

davidism commented Feb 3, 2015

If you can actually evaluate the import, you could try to figure out the actual package name, rather than guessing that it's flask_<name>. But that might be overkill over just printing "make sure we got it right" at the end.

@untitaker

This comment has been minimized.

Member

untitaker commented Feb 3, 2015

True, but then you'd be dependent on whether the migration script is running in the correct virtualenv, and things like that. Also I don't think anybody actually uses flaskext extensions anymore.

keyan added a commit to keyan/flask that referenced this issue Feb 6, 2015

Early commit for issue pallets#1135
Add support migrating single imports from the flask.ext style to flask_

keyan added a commit to keyan/flask that referenced this issue Feb 11, 2015

keyan added a commit to keyan/flask that referenced this issue Feb 13, 2015

Add support for function call fixing, add tests
Addresses pallets#1135, some code cleanup and refactoring. Changes wrapper function which handles testing, further modularized code, added test to cover function call fixing, and fixed duplicate test function name.

untitaker added a commit that referenced this issue Feb 18, 2015

Merge pull request #1342 from keyanp/issue1135
flask.ext Import Migration Tool #1135
@lepture

This comment has been minimized.

Member

lepture commented Mar 11, 2015

Let's correct every answer on http://stackoverflow.com/search?q=flask.ext, and encourage users to use flask_foo instead of flask.ext.foo.

There are many Flask extentions whose documentation contains from flask.ext.foo import bar. We should encourage the developers to change the documentation. For example: https://pythonhosted.org/Flask-Testing/

lepture added a commit to lepture/flask-cache that referenced this issue Mar 11, 2015

@keyan

This comment has been minimized.

Member

keyan commented Mar 11, 2015

@lepture that's certainly ambitious, I think it would be nice to resolve #1367 and #1366 before doing something like that. The current documentation still suggests using the .ext format. It will be easier to encourage a transition once the docs are fixed and use of the migration tool is fully supported and documented.

That said, I've fixed it a couple times when I happen to be using extensions and notice they had the old format in their examples.

@lepture

This comment has been minimized.

Member

lepture commented Mar 11, 2015

@keyanp in the meanwhile, we should notify Flask extention developers. Their documentations would also confuse users.

@keyan

This comment has been minimized.

Member

keyan commented Mar 11, 2015

@lepture sure, we can certainly try to let some developers know, alerting all extension developers is probably unrealistic.

@lepture

This comment has been minimized.

Member

lepture commented Mar 11, 2015

@keyanp that's what I am doing. I will do a search on these projects, find out who should be notified.

@jeffwidman

This comment has been minimized.

Member

jeffwidman commented Apr 4, 2016

#1484 made the deprecation explicit in the docs and added runtime warnings if you try to import flask.ext.*.

The migration script is here: https://github.com/pocoo/flask-ext-migrate
#1765 tracks making sure the migration script is linked from the docs.

For anyone coming here researching how to migrate their Flask project, the migration script is convenient but not a necessity. I've migrated multiple Flask projects to the new format using a simple find-and-replace for flask.ext. to flask_.

Closing.

@jeffwidman jeffwidman closed this Apr 4, 2016

@k-nut k-nut referenced this issue Jun 2, 2016

Closed

[POC] Flask views #2971

opnfv-github pushed a commit to opnfv/qtip that referenced this issue Jan 9, 2017

modify deprecated imports
Add description for the api specs

flask.ext.xx is deprecated. need to use flask_xx instead

pallets/flask#1135

Change-Id: I9960dd44d03243bde73df8633c45ec3a1f437cea
Signed-off-by: Akhil Batra <akhil.batra@research.iiit.ac.in>

thegeorgeous added a commit to Richard-Mathie/flask-cqlalchemy that referenced this issue Mar 4, 2017

Change deprecated import syntax in tests
The `flask.ext` syntax has been deprecated in favour of the `flask_`
syntax

pallets/flask#1135

@nOOb3167 nOOb3167 referenced this issue Jun 24, 2018

Merged

Misc fixes #102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment