1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
|
Profiles / Configuration
========================
The behaviour of prospector can be configured by creating a profile. A profile is
a YAML file containing several sections as described below.
Prospector will search for a ``.prospector.yaml`` file (and `several others`_) in the path that it is checking.
If found, it will automatically be loaded. Otherwise, you
can pass in the profile as an argument::
prospector --profile /path/to/your/profile.yaml
You can also use a name instead of the path, if it is on the ``profile-path``::
prospector --profile my_profile
In general, command-line arguments override and take precedence over values found
in profiles.
.. _several others: https://github.com/PyCQA/prospector/blob/master/prospector/profiles/__init__.py
.. _profile_path:
Profile Path
------------
The name of a profile is the filename without the ``.yaml`` extension. So if you create
a profile called 'my_project.yaml', the name will be 'my_project'. Inheritance works
by searching the ``profile-path`` for files matching the name in the inheritance list.
The ``profile-path`` is where Prospector should search when looking for profiles. By
default, it will look in the directory containing the `built-in profiles`_, as well as
the directory where prospector is running, and a ``.prospector`` directory relative to
that. To add additional places to search::
prospector --profile-path path/to/your/profiles
.. _built-in profiles: https://github.com/PyCQA/prospector/tree/master/prospector/profiles/profiles
Example
-------
Here is an example profile::
output-format: json
strictness: medium
test-warnings: true
doc-warnings: false
inherits:
- my/other/profile.yml
ignore-paths:
- docs
ignore-patterns:
- (^|/)skip(this)?(/|$)
pycodestyle:
disable:
- W602
- W603
enable:
- W601
options:
max-line-length: 79
mccabe:
run: false
Builtin Profiles
----------------
Prospector comes with several built-in profiles, which power some of strictness and style
options. You can see the `full list on GitHub <https://github.com/PyCQA/prospector/tree/master/prospector/profiles/profiles>`_.
Global Configuration options
----------------------------
Global configuration options for tools are the following:
* output-format_
* strictness_
* test-warnings_
* doc-warnings_
* member-warnings_
* inherits_
* ignore-paths_
* ignore-patterns_
* autodetect_
* uses_
* max-line-length_
.. _output-format:
Output-format
.............
Same command line options are available.
See :doc:`Output format <usage>`
.. _strictness:
Strictness
..........
There is a command line argument to tweak how picky Prospector will be::
prospector --strictness
This is implemented using profiles, and is simply a list of messages to disable at each
level of strictness.
If creating your own profile, you can use the ``strictness`` like so::
strictness: medium
Valid values are 'verylow', 'low', 'medium' (the default), 'high' and 'veryhigh'. If you don't specify a
strictness value, then the default of 'medium' will be used. To avoid using any of Prospector's default
strictness profiles, set ``strictness: none``.
There are some aspects of analysis which can be turned on or off separately from the strictness or
individual tuning of the tools. Example:
.. _doc-warnings:
Documentation Warnings
......................
By default prospector will not produce warnings about missing documentation or
`docstring styleguide violations <https://www.python.org/dev/peps/pep-0257/>`_.
If you want to see these, use the ``--doc-warnings`` flag at runtime or include it in
your profile::
doc-warnings: true
This will turn on the otherwise disabled ``pycodestyle`` tool.
.. _test-warnings:
Test Warnings
.............
Prospector will not inspect unit tests and test files by default. You can
turn this on using the ``--test-warnings`` flag or in your profile::
test-warnings: true
.. _member-warnings:
Member Warnings
...............
Pylint generates warnings when you try to access an attribute of a class that does not exist, or
import a module that does not exist. Unfortunately it is not always accurate and in some projects,
this message is a large amount of noise. Prospector therefore turns these messages off by default,
but you can turn it on using the ``--member-warnings`` flag or in a profile::
member-warnings: true
.. _uses:
.. _autodetect:
Libraries Used and Autodetect
.............................
Prospector will adjust the behaviour of the underlying tools based on the libraries that your project
uses. If you use Django, for example, the `pylint-django <https://github.com/PyCQA/pylint-django>`_ plugin
will be loaded. This will happen automatically.
If prospector is not correctly determining which of its supported libraries you use, you can specify
it manually in the profile::
uses:
- django
- celery
- flask
Currently, Django, Flask and Celery have plugins.
If prospector is incorrectly deciding that you use one of these, you can turn off autodetection::
autodetect: false
.. _inherits:
Inheritance
...........
Profiles can inherit from other profiles, and can inherit from more than one profile.
Prospector merges together all of the options in each profile, starting at the top
of the inheritance tree and overwriting values with those found lower.
The example profile above inherits from another profile provided by the user,
``my/other/profile.yml``. This allows you to have, for example, a project wide
default profile with specific overrides for each individual repository or library.
It is possible to inherit from the built-in prospector profiles as well, although
there are shortcuts for most of the built-ins, see below.::
inherits:
- strictness_medium
- full_pep8
For lists, such as the ``ignore`` section, they will be merged together rather than
overwritten - so essentially, the ``ignore`` section will accumulate.
The profile named in the ``inherits`` section must be on the :ref:`profile path <profile_path>`.
Inheritance can also be optional - for example, if each developer might have a local prospector configuration
but that's not guaranteed, then you can inherit from a profile with the ``?`` suffix and if it is not present,
prospector will simply carry on. For example::
inherits:
- project_config
- local_config?
In this case, if a developer has a local profile called 'local_config' it would append to the project-wide configuration,
but if they don't, prospector won't error with a ``ProfileNotFound`` exception.
Note that when using profiles, prospector does not automatically configure ``strictness``.
The assumption is that if you provide a profile, you provide all the information about which
messages to turn on or off. To keep the strictness functionality, simply inherit from the
built-in prospector profiles::
inherits:
- strictness_medium
The ``inherits`` file can also be in an external package, if you specify a name Prospector will search for a tile named
``prospector.yaml`` or ``prospector.yml`` in the module ``prospector-profile-<name>``. And if the name contains a ``:``
this mean that we use the syntax ``<module>:<file>`` to search the file named ``<file>.yaml`` or ``<file>.yml``
in the module name ``prospector-profile-<module>``. For example::
inherits:
- my_module
- my_module:my_file
.. _ignore-paths:
.. _ignore-patterns:
Ignoring Paths and patterns
...........................
There are two ways to ignore paths or files.
Firstly, with the ``ignore-paths`` section. This is a list of paths to ignore relative to the repository root.
It can be a directory, in which case the directory contents and all subdirectories are ignored, or it can be a
specific file. For example, ``docs`` would ignore a directory in the repository root called "docs", while
``mypackage/vendor`` would ignore anything in the directory at "mypackage/vendor".
Secondly, ``ignore-patterns`` is a list of regular expressions. The relative path of files and directories is *searched*
for each regular expression, and ignored if any matches are found. If the expression matches a directory, the directory
contents and all subdirectories are ignored. For example, ``^example/doc_.*\.py$`` would ignore any files in the
"example" directory beginning with "doc\_". Another example: ``(^|/)docs(/|$)`` would ignore all directories called
"docs" in the entire repository.
Note that a further option called ``ignore`` is available. This is equivalent to ``ignore-patterns``, and is from
an older version of the configuration. It will continue working, but it is deprecated, and you should update
your profile if you are using it.
.. _max-line-length:
Max Line Length
...............
This general option, provides a way to select maximum line length allowed.
.. Note:: This general option overrides and takes precedence over same option in a particular tool (pycodestyle or pylint)
Individual Configuration Options
--------------------------------
Each tool can be individually configured with a section beginning with the tool name
(in lowercase). Valid values are ``bandit``, ``dodgy``, ``frosted``, ``mccabe``, ``mypy``, ``pydocstyle``, ``pycodestyle``,
``pyflakes``, ``pylint``, ``pyright``, ``pyroma`` and ``vulture``.
Enabling and Disabling Tools
............................
There are :doc:`7 default and 5 optional <supported_tools>`. Unless otherwise configured,
the defaults are enabled and the optional tools are disabled.
In a profile, you can enable or disable a tool using the boolean ``run``::
pyroma:
run: true
Note that the ``--tools`` :doc:`command line argument <usage>` overrides profiles if used.
Enabling and Disabling Messages
...............................
Messages can be enabled or disabled using the tool's code for the output. These codes are
either from the tool itself, or provided by prospector for those tools which do not have
message codes. The list of tools and message codes can be found
`in the tools package <https://github.com/PyCQA/prospector/tree/master/prospector/tools>`_.
The typical desired action is to disable messages::
pylint:
disable:
- method-hidden
- access-member-before-definition
However, you can also enable messages which were disabled by parent profiles::
pylint:
enable:
- method-hidden
- access-member-before-definition
Pylint Plugins
..............
It is possible to specify list of plugins for Pylint. You can do this by using ``load-plugins``
option in ``pylint`` section::
pylint:
load-plugins:
- plugin
- plugin
Note that this option doesn't affect loading of :ref:`autodetected plugins <ignore-patterns>`.
PEP8 Control
............
The strictness will turn on or off different messages generated by the `pycodestyle <https://pycodestyle.pycqa.org>`_
tool depending on how picky they are. However, if you want to have the standard 'medium' strictness but get either
complete or zero pep8 style warnings, you can use a shorthand like below::
pep8:
full: true
Or::
pep8:
none: true
Note that this section is also the section for configuring the pycodestyle tool, see below. Therefore you can turn
on all warnings from pep8 but turn off just one or two individually or otherwise tweak the tool like so::
pycodestyle:
full: true
disable:
- E126
options:
max-line-length: 120
Tool Options
............
Some tools can be further configured or tweaked using an options hash::
pycodestyle:
options:
max-line-length: 120
The available options are:
+----------------+------------------------+----------------------------------------------+
| Tool + Option Name + Possible Values |
+================+========================+==============================================+
| mccabe | max-complexity | Maximum number of paths allowed in a method |
+----------------+------------------------+----------------------------------------------+
| pycodestyle | max-line-length | Maximum line length allowed (This option is |
| | | overridden by global option max-line-length_)|
+----------------+------------------------+----------------------------------------------+
| pylint | -anything- | Any of the `pylint options`_ |
+----------------+------------------------+----------------------------------------------+
| mypy | strict | strict mode |
+----------------+------------------------+----------------------------------------------+
| mypy | follow-imports | How to treat imports |
+----------------+------------------------+----------------------------------------------+
| mypy | ignore-missing-import | Silently ignore imports of missing modules |
+----------------+------------------------+----------------------------------------------+
| mypy | platform | Check for the given platform |
+----------------+------------------------+----------------------------------------------+
| mypy | python-version | assume it will be running on Python x.y |
+----------------+------------------------+----------------------------------------------+
| mypy | strict-optional | Checking of Optional types and None values |
+----------------+------------------------+----------------------------------------------+
| mypy | namespace-packages | Import discovery uses namespace packages |
+----------------+------------------------+----------------------------------------------+
| mypy | use-dmypy | Use mypy daemon (mypy server) for faster |
| | | checks |
+----------------+------------------------+----------------------------------------------+
| bandit | config | configuration filename |
+----------------+------------------------+----------------------------------------------+
| bandit | profile | profile to use |
+----------------+------------------------+----------------------------------------------+
| bandit | severity | report only issues of a given severity |
+----------------+------------------------+----------------------------------------------+
| bandit | confidence | report only issues of a given confidence |
+----------------+------------------------+----------------------------------------------+
| pyright | level | Minimum diagnostic level (error or warning) |
+----------------+------------------------+----------------------------------------------+
| pyright | project | Path to location of configuration file |
+----------------+------------------------+----------------------------------------------+
| pyright | pythonplatform | Analyze for a specific platform (Darwin, |
| | | Linux, Windows) |
+----------------+------------------------+----------------------------------------------+
| pyright | pythonversion | Analyze for a specific version |
+----------------+------------------------+----------------------------------------------+
| pyright | skipunannotated | Skip analysis of functions with no type |
| | | annotations |
+----------------+------------------------+----------------------------------------------+
| pyright | typeshed-path | Path to location of typeshed type stubs |
+----------------+------------------------+----------------------------------------------+
| pyright | venv-path | Directory that contains virtual environments |
+----------------+------------------------+----------------------------------------------+
See `mypy options`_ for more details
See `bandit options`_ for more details
See `pyright options`_ for more details
.. _pylint options: https://pylint.readthedocs.io/en/latest/user_guide/run.html
.. _bandit options: https://bandit.readthedocs.io/en/latest/config.html
.. _mypy options: https://mypy.readthedocs.io/en/stable/command_line.html
.. _pyright options: https://microsoft.github.io/pyright/#/command-line
Example
-------
Next is another example using most options::
output-format: json
strictness: medium
test-warnings: true
doc-warnings: false
member-warnings: false
inherits:
- default
ignore-paths:
- docs
ignore-patterns:
- (^|/)skip(this)?(/|$)
autodetect: true
max-line-length: 88
bandit:
run: true
options:
config: .bandit.yml
dodgy:
run: true
frosted:
disable:
- E103
- E306
mccabe:
run: false
options:
max-complexity: 10
pycodestyle:
disable:
- W602
- W603
enable:
- W601
options:
max-line-length: 79
pydocstyle:
disable:
- D100
- D101
pyflakes:
disable:
- F403
- F810
pylint:
disable:
- bad-builtin
- too-few-public-methods
options:
max-locals: 15
max-returns: 6
max-branches: 15
max-statements: 60
max-parents: 7
max-attributes: 7
min-public-methods: 1
max-public-methods: 20
max-module-lines: 1000
max-line-length: 99
pyroma:
disable:
- PYR15
- PYR18
pyright:
options:
level: warning
pythonversion: 3.7
skipunannotated: true
mypy:
run: true
options:
ignore-missing-imports: true
follow-imports: skip
vulture:
run: true
|