有没有办法检查django版本的功能弃用?

[英]Is there way to check feature deprecation against django version?


As some features get deprecated with new versions of Django, is there a way to check for that on an existing project code say on github.

由于某些功能在新版本的Django中被弃用,有没有办法在github上检查现有项目代码。

Could a tool do that. Is there a way to detect that through testcases.

工具可以做到这一点。有没有办法通过测试用例检测到它。

Would it be possible to do the same against a python version.

是否有可能对python版本做同样的事情。

I guess one way could be to run through a specific version of django / python using tox and then check for errors.

我猜一种方法可能是使用tox运行特定版本的django / python然后检查错误。

I am just looking for something more elegant or direct, something like which says - "Note this feature has been deprecated", something which can be done in strongly typed language like Java.

我只是在寻找更优雅或更直接的东西,比如说“注意这个功能已被弃用”,这可以用像Java这样的强类型语言来完成。

If one wanted to build such a tool, what could be starting point for that, if possible.

如果有人想要构建这样一个工具,那么如果可能的话,可能是什么的起点。

2 个解决方案

#1


2  

This is how I got tox to run one project of mine against Django 1.6, 1.7 and 1.8 with deprecation warnings on:

这就是我如何运行tox来运行我的一个项目来对抗Django 1.6,1.7和1.8以及弃用警告:

[tox]
envlist = {py27,py34}-{django16,django17,django18}

[testenv]
basepython =
           py27: python2.7
           py34: python3.4

deps =
     django16: Django>=1.6,<1.7
     django17: Django>=1.7,<1.8
     django18: Django>=1.8,<1.9

commands =
         python -Wmodule ./manage.py test

The -Wmodule argument causes Python to output each deprecation warning the first time it occurs in a module, which was good enough for me. I was able to deal with instances where I used from django.core.cache import get_cache, which will be gone in Django 1.9.

-Wmodule参数导致Python在模块第一次出现时输出每个弃用警告,这对我来说已经足够了。我能够处理从django.core.cache导入get_cache使用的实例,这将在Django 1.9中消失。

In cases where -Wmodule outputs too much, you might want to be more selective. Python's documentation gives the lowdown on how to use this argument. I've purposely not used -Werror because this would not just make the individual tests fail but would make my test suite fail to execute any test because the suite uses deprecated features.

在-Wmodule输出太多的情况下,您可能希望更具选择性。 Python的文档给出了如何使用这个参数的内容。我故意不使用-Werror,因为这不仅会使单个测试失败,而且会使我的测试套件无法执行任何测试,因为该套件使用了不推荐的功能。

#2


2  

I think this would have to be in the unit tests for your project.

我认为这必须在你的项目的单元测试中。

If your tests exercise code that will be deprecated in a future version of Django you will get warnings. If you've jumped to a version of Django where the feature is already deprecated you'll get exceptions and failed tests of course.

如果您的测试执行将在Django的未来版本中弃用的代码,您将收到警告。如果您已经跳转到已弃用该功能的Django版本,那么您将获得例外和失败的测试。

You can tell the Python interpreter to promote warnings to exceptions, which would cause tests to fail.

您可以告诉Python解释器向异常发出警告,这会导致测试失败。

Instructions here to apply the same trick to the popular nosetests test framework.

这里的说明将相同的技巧应用于流行的nosetests测试框架。

If you know already (from Django docs) that some code you're writing will need to change depending on Django version it is run under (eg you're distributing a reusable Django app) I would suggest a form of feature detection using try ... except

如果您已经知道(来自Django docs)您正在编写的某些代码需要根据Django版本进行更改(例如,您正在分发可重用的Django应用程序),我会建议使用try进行一种特征检测。 .. 除

For example, here I wanted to conditionally use the new transaction.atomic feature from Django >= 1.6: .

例如,在这里我想有条件地使用Django> = 1.6的新transaction.atomic功能:。

As you anticipated, I then run the tests against different versions of Django with the help of Tox.

正如您所预料的那样,我在Tox的帮助下针对不同版本的Django运行测试。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2014/04/22/5616863da9986ff1f8720568ab6b491.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号