怎么安装联想dp515打印机安装680

5436人阅读
【Python】(31)
本文主要介绍pylint的配置与使用,如何安装请参考,详细信息可参考pylint官方网站的帮助文档。
获取帮助信息
pylint安装成功后,可以通过运行&pylint --help&来快速查看pylint的帮助信息;相关信息基本能够支撑起快速使用起来pylint的基本功能。
bob@Ubuntu:~$ pylint --help
No config file found, using default configuration
pylint [options] module_or_package
Check that a module satisfies a coding standard (and more !).
pylint --help
Display this help message and exit.
pylint --help-msg &msg-id&[,&msg-id&]
Display help messages about given message identifiers and exit.
show program's version number and exit
-h, --help
show this help message and exit
--long-help
more verbose help.
--rcfile=&file&
Specify a configuration file.
-E, --errors-only
In error mode, checkers without error messages are
disabled and for others, only the ERROR messages are
displayed, and no reports are done by default
--ignore=&file&[,&file&...]
Add files or directories to the blacklist. They should
be base names, not paths. [current: CVS]
--help-msg=&msg-id&
Display a help message for the given message id and
exit. The value may be a comma separated list of
message ids.
--generate-rcfile
Generate a sample configuration file according to the
current configuration. You can put other options
before this one to get them in the generated
configuration.
Messages control:
-e &msg ids&, --enable=&msg ids&
Enable the message, report, category or checker with
the given id(s). You can either give multiple
identifier separated by comma (,) or put this option
multiple time. See also the &--disable& option for
-d &msg ids&, --disable=&msg ids&
Disable the message, report, category or checker with
the given id(s). You can either give multiple
identifiers separated by comma (,) or put this option
multiple times (only on the command line, not in the
configuration file where it should appear only
once).You can also use &--disable=all& to disable
everything first and then reenable specific checks.
For example, if you want to run only the similarities
checker, you can use &--disable=all
--enable=similarities&. If you want to run only the
classes checker, but have no Warning level messages
displayed, use&--disable=all --enable=classes
--disable=W&
-f &format&, --output-format=&format&
Set the output format. Available formats are text,
parseable, colorized, msvs (visual studio) and html.
You can also give a reporter class, eg
mypackage.mymodule.MyReporterClass. [current: text]
-r &y_or_n&, --reports=&y_or_n&
Tells whether to display a full report or only the
messages [current: yes]
--msg-template=&template&
Template used to display messages. This is a python
new-style format string used to format the message
information. See doc for all details
生成配置文件
可以通过&pylint --generate-rcfile&生成配置文件模板,可以在模板文件上定制相关的统一的配置文件。配置文件中包含了master, message control, reports, typecheck, similarities,& basic, variables, format, design, classes, imports, exception相关的lint配置信息,用户可以进行私人订制。
bob@Ubuntu:~$ cat pylint.conf
# Specify a configuration file.
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Profiled execution.
profile=no
# Add files or directories to the blacklist. They should be base names, not
ignore=CVS
# Pickle collected data for later comparisons.
persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
[MESSAGES CONTROL]
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time. See also the &--disable& option for examples.
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once).You can also use &--disable=all& to
# disable everything first and then reenable specific checks. For example, if
# you want to run only the similarities checker, you can use &--disable=all
# --enable=similarities&. If you want to run only the classes checker, but have
# no Warning level messages displayed, use&--disable=all --enable=classes
# --disable=W&
disable=logging-not-lazy, line-too-long, trailing-whitespace, bare-except, broad-except
# Set the output format. Available formats are text, parseable, colorized, msvs
# (visual studio) and html. You can also give a reporter class, eg
# mypackage.mymodule.MyReporterClass.
output-format=text
# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name &pylint_global.[txt|html]&.
files-output=no
# Tells whether to display a full report or only the messages
reports=yes
# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
# respectively contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
# Add a comment according to your evaluation note. This is used by the global
# evaluation report (RP0004).
comment=no
# Template used to display messages. This is a python new-style format string
# used to format the massage information. See doc for all details
#msg-template=
[TYPECHECK]
# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with &mixin& (case insensitive).
ignore-mixin-members=yes
# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set).
ignored-classes=SQLObject
# When zope mode is activated, add a predefined set of Zope acquired attributes
# to generated-members.
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular
# expressions are accepted.
generated-members=REQUEST,acl_users,aq_parent
[SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines=4
# Ignore comments when computing similarities.
ignore-comments=yes
# Ignore docstrings when computing similarities.
ignore-docstrings=yes
# Ignore imports when computing similarities.
ignore-imports=no
# Required attributes for module, separated by a comma
required-attributes=
# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input
# Regular expression which should only match correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
# Regular expression which should only match correct module level names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
# Regular expression which should only match correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$
# Regular expression which should only match correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct attribute names in class
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
# Regular expression which should only match correct list comprehension /
# generator expression variable names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
# Regular expression which should only match function or class names that do
# not require a docstring.
no-docstring-rgx=__.*__
# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=-1
[VARIABLES]
# Tells whether we should check for unused import in __init__ files.
init-import=no
# A regular expression matching the beginning of the name of dummy variables
# (i.e. not used).
dummy-variables-rgx=_$|dummy
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=
# Maximum number of characters on a single line.
max-line-length=120
# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?&?https?://\S+&?$
# Maximum number of lines in a module
max-module-lines=1000
# String used as indentation unit. This is usually & & (4 spaces) or &\t& (1
indent-string='
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
# Maximum number of arguments for function / method
max-args=5
# Argument names that match this expression will be ignored. Default to name
# with leading underscore
ignored-argument-names=_.*
# Maximum number of locals for function / method body
max-locals=15
# Maximum number of return / yield for function / method body
max-returns=6
# Maximum number of branch for function / method body
max-branches=12
# Maximum number of statements in function / method body
max-statements=50
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of attributes for a class (see R0902).
max-attributes=7
# Minimum number of public methods for a class (see R0903).
min-public-methods=2
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
# List of interface methods to ignore, separated by a comma. This is used for
# instance to not check methods defines in Zope's Interface base class.
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp
# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
# List of valid names for the first argument in a metaclass class method.
valid-metaclass-classmethod-first-arg=mcs
# Deprecated modules which should not be used, separated by a comma
deprecated-modules=regsub,TERMIOS,Bastion,rexec
# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report RP0402 must not be disabled)
import-graph=
# Create a graph of external dependencies in the given file (report RP0402 must
# not be disabled)
ext-import-graph=
# Create a graph of internal dependencies in the given file (report RP0402 must
# not be disabled)
int-import-graph=
[EXCEPTIONS]
# Exceptions that will emit a warning when being caught. Defaults to
# &Exception&
检查源码文件
配置好rcfile配置文件后,就可以使用pylint开始对源码文件进行配置检查了,可以通过类似命令&pylint --rcfile=/home/bob/pylint.conf /opt/app/login/login.py&来完成,命令参数包含配置文件的路径和源码文件路径。
pylint会生成检查报告,接下来我们来解析报告的内容:
W: 10, 0: Unused import help (unused-import)报告中安装上述的格式生成检查结果,W代表生成的检查级别,级别分为4种:error, warning, refactor, convention;可以根据首字母来对应相应的级别。&10, 0& 代表告警所在源码文件中的行号和列号,可以通过Eclipse中CTRL+L快捷键快速查找所在到问题所在的行。“Unused import help&表述问题的详细信息。”(unused-import)为问题的消息ID信息。
下面的信息是按照消息的类别进行分类,对4种级别的告警信息进行汇总:
Messages by category
--------------------
+-----------+-------+---------+-----------+
|number |previous |difference |
+===========+=======+=========+===========+
|convention |2
+-----------+-------+---------+-----------+
+-----------+-------+---------+-----------+
+-----------+-------+---------+-----------+
+-----------+-------+---------+-----------+
下面是按照消息类型进行统计,记录具体告警发生的次数
+------------------+------------+
|message id
|occurrences |
+==================+============+
|mixed-indentation |8
+------------------+------------+
|unused-import
+------------------+------------+
|invalid-name
+------------------+------------+
|redefined-builtin |1
+------------------+------------+
获取告警帮助信息
如需对某告警类型获取帮助信息,可以使用&pylint --help-msg &msg-id&&命令来获取:
bob@Ubuntu:~$ pylint --help-msg unused-import
:unused-import (W0611): *Unused import %s*
Used when an imported module or variable is not used. This message belongs to
the variables checker.
局部关闭某告警类型
在某些情况,可能需要关闭某文件中的某些告警类型,而非配置文件那种全局配置的情况,可以通过下列的方式来达到目的,通过注释的方式,来禁掉某些检查,如对meth2函数不检查未使用的参数情况。
&&&pylint option block-disable&&&
__revision__ = None
class Foo(object):
&&&block-disable test&&&
def __init__(self):
def meth1(self, arg):
&&&this issues a message&&&
print self
def meth2(self, arg):
&&&and this one not&&&
# pylint: disable=unused-argument
print self\
通过本文的介绍,基本可以快速使用pylint来对Python代码进行静态代码的检查;如果想获取更多使用或配置信息,可以查看官网的帮助文档:
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:84398次
积分:1618
积分:1618
排名:千里之外
原创:80篇
(5)(6)(4)(1)(3)(3)(1)(3)(2)(4)(7)(9)(9)(7)(5)(2)(1)(4)(6)(2)(1)(1)(2)Pylint插件:忽略Django的国际化代码调用报错 - 推酷
Pylint插件:忽略Django的国际化代码调用报错
NOTICE:如果更新到Django1.4+以上版本后,就不会报类似Error级别的提示了。
用Django写Web开发类型的程序,经常会用到程序的国际化操作,例如,保存如下代码为example.py:
from django.utils.translation import ugettext_lazy as _
print _('damn it!')
如果项目中用到Pylint来检查代码,执行如下:
pylint -E example.py
这个时候会显示一个Error级别的提示,如下:
No config file found, using default configuration
************* Module example
3,6: _ is not callable
熟悉Django的人,一定会觉得很奇怪,怎么可能函数不能被调用,这里就不具体展开说明原因了:
可以认为是Pylint不够智能
也可以认为Python本身太灵活,Django中调用的国际化模块,刚好用了一些动态语言的特性
Pylint提供了灵活的配置设置,过了一遍配置,发现没有自定义设置可以忽略这个情况
Google之,但很多是说直接忽略那条规则,这样虽然可以达到忽略的效果,但是同样也忽略了不应该忽略的检查,比如:a = 1; a()这种语法错误
看Pylint官方文档,发现Pylint扩展性还是不错的,提供自定义插件机制,–load-plugin参数指定插件即可,那么就自己写个插件来处理这种情况吧!
继续Google,发现有人写过类似插件,虽然是处理别的问题,但很类似:
写个插件!
代码很简单,原理就是写个假的函数调用,在Pylint执行该模块的函数检查时候,直接调用了假的函数,从而绕过该报错,但又不会影响这条规则检查其它代码时候报告Error级别信息。保存如下代码为astng_django.py
from logilab.astng import MANAGER
from logilab.astng.builder import ASTNGBuilder
def hashlib_transform(module):
if module.name == 'django.utils.translation':
fake = ASTNGBuilder(MANAGER).string_build('''
def ugettext_lazy(value):
return u''
def ugettext(value):
return u''
for hashfunc in ('ugettext_lazy', 'ugettext'):
module.locals[hashfunc] = fake.locals[hashfunc]
def register(linter):
&&&called when loaded by pylint --load-plugins, register our tranformation
function here
MANAGER.register_transformer(hashlib_transform)
这个时候执行命令(需要PYTHONPATH能找到astng_django.py)
pylint -E example.py --load-plugins=astng_django
输出如下:
No config file found, using default configuration
就没有刚才的Error级别的提示了。
保存如下代码为error.py,再验证下报错的情况是否被忽略:
fake_function = 1
fake_function()
执行命令:
pylint -E error.py --load-plugins=astng_django
输出如下:
No config file found, using default configuration
************* Module error
2,0: fake_function is not callable
这样就算初步解决这个问题了,即可以不让Django程序报干扰的Error级别信息,又不会忽略的确需要报的Error级别信息。
照例,GitHub上先占个坑:
后续TODO:
前面有说明必须指定PYTHONPATH,有点麻烦,但作为临时解决问题是够了。后续需要做个完整的Python库,然后发布到PyPI,然后作为正式的安装包,就更方便别人使用了。
另外,这个插件还是相对简单,其实Django中的国际化处理有好多函数,需要后续补充。
将上述的相关验证转化为对应的测试代码。
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 联想dp680 的文章

 

随机推荐