Skip to content
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

Add support for pulling configuration from pyproject.toml files #10219

Merged
merged 52 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8059a6d
Add gitignore entries for pyenv
TheCleric Mar 17, 2021
b86c6c0
Add support for pulling configuration from pyproject.toml files
TheCleric Mar 17, 2021
6435a9d
Allow pyproject.toml with no mypy section
TheCleric Mar 17, 2021
9f70b29
Move pyproject tests to their own test
TheCleric Mar 17, 2021
da965ec
Further delineate pyproject tests
TheCleric Mar 18, 2021
fe201b5
Escape special chars with single quotes
TheCleric Mar 18, 2021
76d6b6c
Update docs for pyproject.toml
TheCleric Mar 18, 2021
6618f2c
Fix some (the rest🤞) of the pyproject tests
TheCleric Mar 18, 2021
76e1197
Remove unnessecary .test changes
TheCleric Mar 18, 2021
34f246b
Restore config_parser functions to original typing and create new one…
TheCleric Mar 18, 2021
df8db18
Helps if you get the types right BEFORE commiting 🤦
TheCleric Mar 18, 2021
94de3d5
3.5 doesn't have typing.Type?
TheCleric Mar 18, 2021
60a4558
Deepcopy segfaults mypyc
TheCleric Mar 19, 2021
0278242
Fix typing issue found by mypyc
TheCleric Mar 20, 2021
771964c
Use OrderedDict to preserve option orders in python 3.5
TheCleric Apr 1, 2021
4c4c589
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 1, 2021
109f590
Fix revealed type expected messages to use double quotes
TheCleric Apr 1, 2021
1a9be45
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 5, 2021
7e8b7ba
Update single quotes to double quotes in "Name ... is" tests
TheCleric Apr 5, 2021
a40af96
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 7, 2021
291a0c6
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 8, 2021
7aab519
Remove *.so from .gitignore
TheCleric Apr 12, 2021
9d8d6ec
Add example pyproject.toml to the docs
TheCleric Apr 12, 2021
a29a319
Fix docstring for try_split
TheCleric Apr 12, 2021
68490cc
Add more specific config value types
TheCleric Apr 12, 2021
1686682
Simpler checking for mypy in toml file
TheCleric Apr 12, 2021
ba2c3ae
Fix convert_to_boolean docstring
TheCleric Apr 12, 2021
6b981b3
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 12, 2021
adeea90
Fix latest single to doublt quote test changes
TheCleric Apr 12, 2021
b74d91d
Modify tests to new override format in pyproject.toml
TheCleric Apr 14, 2021
d6ec65d
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 14, 2021
c9ba081
Make package overrides in the pyproject.toml a little cleaner
TheCleric Apr 15, 2021
77a2c04
Clean up config doc
TheCleric Apr 16, 2021
ec0c061
Add tests for possible errors in the new overrides toml config
TheCleric Apr 16, 2021
c528831
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 21, 2021
c921668
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 22, 2021
9d21341
Remove extraneous print
TheCleric Apr 23, 2021
9cbef16
Add multimodule examples to documenatiton for toml config
TheCleric Apr 23, 2021
fe357e1
Remove vestigial string split for toml keys
TheCleric Apr 23, 2021
d594d15
Make pyproject errors more tailored to actual toml not ini
TheCleric Apr 23, 2021
b7e02e6
Convert TOML parse ValueError to custom ValueError
TheCleric Apr 24, 2021
0a44423
Add tests to ensure new errors are caught
TheCleric Apr 24, 2021
8f0e6d2
Ensure toml load stays an OrderedDict on copy
TheCleric Apr 24, 2021
3416337
Strip pyproject testing down now that we know it works
TheCleric Apr 24, 2021
ddb3922
Fix some mistyping
TheCleric Apr 24, 2021
6e5dc11
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 24, 2021
74c29e7
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 27, 2021
3249676
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 29, 2021
c7110fa
Merge branch 'master' into feature/pyproject_toml_support
TheCleric Apr 30, 2021
b4f7d79
Flesh out some feature tests of the pyproject.toml config
TheCleric Apr 30, 2021
d9d091e
Fix double to single quotes for test paths
TheCleric May 2, 2021
742059f
Merge branch 'master' into feature/pyproject_toml_support
TheCleric May 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mypyc/doc/_build
*.iml
/out/
.venv*/
venv/
.mypy_cache/
.incremental_checker_cache.json
.cache
Expand Down Expand Up @@ -44,6 +45,8 @@ htmlcov
bin/
lib/
include/
.python-version
pyvenv.cfg

.tox
pip-wheel-metadata
Expand Down
2 changes: 1 addition & 1 deletion docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Config file

This flag makes mypy read configuration settings from the given file.

By default settings are read from ``mypy.ini``, ``.mypy.ini``, or ``setup.cfg``
By default settings are read from ``mypy.ini``, ``.mypy.ini``, ``pyproject.toml``, or ``setup.cfg``
in the current directory. Settings override mypy's built-in defaults and
command line flags can override settings.

Expand Down
83 changes: 81 additions & 2 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ The mypy configuration file
===========================

Mypy supports reading configuration settings from a file. By default
it uses the file ``mypy.ini`` with a fallback to ``.mypy.ini``, then ``setup.cfg`` in
the current directory, then ``$XDG_CONFIG_HOME/mypy/config``, then
it uses the file ``mypy.ini`` with a fallback to ``.mypy.ini``, then ``pyproject.toml``,
then ``setup.cfg`` in the current directory, then ``$XDG_CONFIG_HOME/mypy/config``, then
``~/.config/mypy/config``, and finally ``.mypy.ini`` in the user home directory
if none of them are found; the :option:`--config-file <mypy --config-file>` command-line flag can be used
to read a different file instead (see :ref:`config-file-flag`).
Expand Down Expand Up @@ -885,5 +885,84 @@ These options may only be set in the global section (``[mypy]``).

Controls how much debug output will be generated. Higher numbers are more verbose.


Using a pyproject.toml file
***************************

Instead of using a ``mypy.ini`` file, a ``pyproject.toml`` file (as specified by
`PEP 518`_) may be used instead. A few notes on doing so:

* The ``[mypy]`` section should have ``tool.`` prepended to its name:

* I.e., ``[mypy]`` would become ``[tool.mypy]``

* The module specific sections should be moved into ``[[tool.mypy.overrides]]`` sections:

* For example, ``[mypy-packagename]`` would become:

.. code-block:: toml

[[tool.mypy.overrides]]
module = 'packagename'
...

* Multi-module specific sections can be moved into a single ``[[tools.mypy.overrides]]`` section with a
module property set to an array of modules:

* For example, ``[mypy-packagename,packagename2]`` would become:

.. code-block:: toml

[[tool.mypy.overrides]]
module = [
'packagename',
'packagename2'
]
...

* The following care should be given to values in the ``pyproject.toml`` files as compared to ``ini`` files:

* Strings must be wrapped in double quotes, or single quotes if the string contains special characters

* Boolean values should be all lower case

Please see the `TOML Documentation`_ for more details and information on
what is allowed in a ``toml`` file. See `PEP 518`_ for more information on the layout
and structure of the ``pyproject.toml`` file.

Example ``pyproject.toml``
**************************

Here is an example of a ``pyproject.toml`` file. To use this config file, place it at the root
of your repo (or append it to the end of an existing ``pyproject.toml`` file) and run mypy.

.. code-block:: toml

# mypy global options:

[tool.mypy]
python_version = "2.7"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it wise to have deprecated python versions in new code?

warn_return_any = true
warn_unused_configs = true

# mypy per-module options:

[[tool.mypy.overrides]]
module = "mycode.foo.*"
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = "mycode.bar"
warn_return_any = false

[[tool.mypy.overrides]]
module = [
"somelibrary",
"some_other_library"
]
ignore_missing_imports = true

TheCleric marked this conversation as resolved.
Show resolved Hide resolved
.. _lxml: https://pypi.org/project/lxml/
.. _SQLite: https://www.sqlite.org/
.. _PEP 518: https://www.python.org/dev/peps/pep-0518/
.. _TOML Documentation: https://toml.io/
Loading