Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/.lock +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/INSTALLER +1 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/LICENSE +166 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/METADATA +420 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/RECORD +13 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/REQUESTED +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/WHEEL +5 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/top_level.txt +1 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/INSTALLER +1 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/LICENSE +17 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/METADATA +96 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/RECORD +14 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/REQUESTED +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/WHEEL +5 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/top_level.txt +1 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/__init__.py +15 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/_elffile.py +108 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/_structures.py +69 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/metadata.py +978 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/py.typed +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/pylock.py +635 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/requirements.py +86 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/specifiers.py +1068 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/NOTICE +10 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/__init__.py +44 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_apply_pyprojecttoml.py +534 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/NOTICE +438 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/__init__.py +34 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/error_reporting.py +338 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/extra_validations.py +151 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_exceptions.py +51 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_validations.py +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/formats.py +464 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/distutils.schema.json +26 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/expand.py +452 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/pyprojecttoml.py +477 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/setupcfg.py +782 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/setuptools.schema.json +433 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/__init__.py +13 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/compat/__init__.py +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/compat/py39.py +3 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/__init__.py +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/downloads/__init__.py +59 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/downloads/preload.py +18 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/setupcfg_examples.txt +22 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_apply_pyprojecttoml.py +794 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_expand.py +247 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_pyprojecttoml.py +421 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_pyprojecttoml_dynamic_deps.py +111 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_setupcfg.py +987 -0
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/.lock
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
This version of the GNU Lesser General Public License incorporates
|
| 10 |
+
the terms and conditions of version 3 of the GNU General Public
|
| 11 |
+
License, supplemented by the additional permissions listed below.
|
| 12 |
+
|
| 13 |
+
0. Additional Definitions.
|
| 14 |
+
|
| 15 |
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
| 16 |
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
| 17 |
+
General Public License.
|
| 18 |
+
|
| 19 |
+
"The Library" refers to a covered work governed by this License,
|
| 20 |
+
other than an Application or a Combined Work as defined below.
|
| 21 |
+
|
| 22 |
+
An "Application" is any work that makes use of an interface provided
|
| 23 |
+
by the Library, but which is not otherwise based on the Library.
|
| 24 |
+
Defining a subclass of a class defined by the Library is deemed a mode
|
| 25 |
+
of using an interface provided by the Library.
|
| 26 |
+
|
| 27 |
+
A "Combined Work" is a work produced by combining or linking an
|
| 28 |
+
Application with the Library. The particular version of the Library
|
| 29 |
+
with which the Combined Work was made is also called the "Linked
|
| 30 |
+
Version".
|
| 31 |
+
|
| 32 |
+
The "Minimal Corresponding Source" for a Combined Work means the
|
| 33 |
+
Corresponding Source for the Combined Work, excluding any source code
|
| 34 |
+
for portions of the Combined Work that, considered in isolation, are
|
| 35 |
+
based on the Application, and not on the Linked Version.
|
| 36 |
+
|
| 37 |
+
The "Corresponding Application Code" for a Combined Work means the
|
| 38 |
+
object code and/or source code for the Application, including any data
|
| 39 |
+
and utility programs needed for reproducing the Combined Work from the
|
| 40 |
+
Application, but excluding the System Libraries of the Combined Work.
|
| 41 |
+
|
| 42 |
+
1. Exception to Section 3 of the GNU GPL.
|
| 43 |
+
|
| 44 |
+
You may convey a covered work under sections 3 and 4 of this License
|
| 45 |
+
without being bound by section 3 of the GNU GPL.
|
| 46 |
+
|
| 47 |
+
2. Conveying Modified Versions.
|
| 48 |
+
|
| 49 |
+
If you modify a copy of the Library, and, in your modifications, a
|
| 50 |
+
facility refers to a function or data to be supplied by an Application
|
| 51 |
+
that uses the facility (other than as an argument passed when the
|
| 52 |
+
facility is invoked), then you may convey a copy of the modified
|
| 53 |
+
version:
|
| 54 |
+
|
| 55 |
+
a) under this License, provided that you make a good faith effort to
|
| 56 |
+
ensure that, in the event an Application does not supply the
|
| 57 |
+
function or data, the facility still operates, and performs
|
| 58 |
+
whatever part of its purpose remains meaningful, or
|
| 59 |
+
|
| 60 |
+
b) under the GNU GPL, with none of the additional permissions of
|
| 61 |
+
this License applicable to that copy.
|
| 62 |
+
|
| 63 |
+
3. Object Code Incorporating Material from Library Header Files.
|
| 64 |
+
|
| 65 |
+
The object code form of an Application may incorporate material from
|
| 66 |
+
a header file that is part of the Library. You may convey such object
|
| 67 |
+
code under terms of your choice, provided that, if the incorporated
|
| 68 |
+
material is not limited to numerical parameters, data structure
|
| 69 |
+
layouts and accessors, or small macros, inline functions and templates
|
| 70 |
+
(ten or fewer lines in length), you do both of the following:
|
| 71 |
+
|
| 72 |
+
a) Give prominent notice with each copy of the object code that the
|
| 73 |
+
Library is used in it and that the Library and its use are
|
| 74 |
+
covered by this License.
|
| 75 |
+
|
| 76 |
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
| 77 |
+
document.
|
| 78 |
+
|
| 79 |
+
4. Combined Works.
|
| 80 |
+
|
| 81 |
+
You may convey a Combined Work under terms of your choice that,
|
| 82 |
+
taken together, effectively do not restrict modification of the
|
| 83 |
+
portions of the Library contained in the Combined Work and reverse
|
| 84 |
+
engineering for debugging such modifications, if you also do each of
|
| 85 |
+
the following:
|
| 86 |
+
|
| 87 |
+
a) Give prominent notice with each copy of the Combined Work that
|
| 88 |
+
the Library is used in it and that the Library and its use are
|
| 89 |
+
covered by this License.
|
| 90 |
+
|
| 91 |
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
| 92 |
+
document.
|
| 93 |
+
|
| 94 |
+
c) For a Combined Work that displays copyright notices during
|
| 95 |
+
execution, include the copyright notice for the Library among
|
| 96 |
+
these notices, as well as a reference directing the user to the
|
| 97 |
+
copies of the GNU GPL and this license document.
|
| 98 |
+
|
| 99 |
+
d) Do one of the following:
|
| 100 |
+
|
| 101 |
+
0) Convey the Minimal Corresponding Source under the terms of this
|
| 102 |
+
License, and the Corresponding Application Code in a form
|
| 103 |
+
suitable for, and under terms that permit, the user to
|
| 104 |
+
recombine or relink the Application with a modified version of
|
| 105 |
+
the Linked Version to produce a modified Combined Work, in the
|
| 106 |
+
manner specified by section 6 of the GNU GPL for conveying
|
| 107 |
+
Corresponding Source.
|
| 108 |
+
|
| 109 |
+
1) Use a suitable shared library mechanism for linking with the
|
| 110 |
+
Library. A suitable mechanism is one that (a) uses at run time
|
| 111 |
+
a copy of the Library already present on the user's computer
|
| 112 |
+
system, and (b) will operate properly with a modified version
|
| 113 |
+
of the Library that is interface-compatible with the Linked
|
| 114 |
+
Version.
|
| 115 |
+
|
| 116 |
+
e) Provide Installation Information, but only if you would otherwise
|
| 117 |
+
be required to provide such information under section 6 of the
|
| 118 |
+
GNU GPL, and only to the extent that such information is
|
| 119 |
+
necessary to install and execute a modified version of the
|
| 120 |
+
Combined Work produced by recombining or relinking the
|
| 121 |
+
Application with a modified version of the Linked Version. (If
|
| 122 |
+
you use option 4d0, the Installation Information must accompany
|
| 123 |
+
the Minimal Corresponding Source and Corresponding Application
|
| 124 |
+
Code. If you use option 4d1, you must provide the Installation
|
| 125 |
+
Information in the manner specified by section 6 of the GNU GPL
|
| 126 |
+
for conveying Corresponding Source.)
|
| 127 |
+
|
| 128 |
+
5. Combined Libraries.
|
| 129 |
+
|
| 130 |
+
You may place library facilities that are a work based on the
|
| 131 |
+
Library side by side in a single library together with other library
|
| 132 |
+
facilities that are not Applications and are not covered by this
|
| 133 |
+
License, and convey such a combined library under terms of your
|
| 134 |
+
choice, if you do both of the following:
|
| 135 |
+
|
| 136 |
+
a) Accompany the combined library with a copy of the same work based
|
| 137 |
+
on the Library, uncombined with any other library facilities,
|
| 138 |
+
conveyed under the terms of this License.
|
| 139 |
+
|
| 140 |
+
b) Give prominent notice with the combined library that part of it
|
| 141 |
+
is a work based on the Library, and explaining where to find the
|
| 142 |
+
accompanying uncombined form of the same work.
|
| 143 |
+
|
| 144 |
+
6. Revised Versions of the GNU Lesser General Public License.
|
| 145 |
+
|
| 146 |
+
The Free Software Foundation may publish revised and/or new versions
|
| 147 |
+
of the GNU Lesser General Public License from time to time. Such new
|
| 148 |
+
versions will be similar in spirit to the present version, but may
|
| 149 |
+
differ in detail to address new problems or concerns.
|
| 150 |
+
|
| 151 |
+
Each version is given a distinguishing version number. If the
|
| 152 |
+
Library as you received it specifies that a certain numbered version
|
| 153 |
+
of the GNU Lesser General Public License "or any later version"
|
| 154 |
+
applies to it, you have the option of following the terms and
|
| 155 |
+
conditions either of that published version or of any later version
|
| 156 |
+
published by the Free Software Foundation. If the Library as you
|
| 157 |
+
received it does not specify a version number of the GNU Lesser
|
| 158 |
+
General Public License, you may choose any version of the GNU Lesser
|
| 159 |
+
General Public License ever published by the Free Software Foundation.
|
| 160 |
+
|
| 161 |
+
If the Library as you received it specifies that a proxy can decide
|
| 162 |
+
whether future versions of the GNU Lesser General Public License shall
|
| 163 |
+
apply, that proxy's public statement of acceptance of any version is
|
| 164 |
+
permanent authorization for you to choose that version for the
|
| 165 |
+
Library.
|
| 166 |
+
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/METADATA
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: autocommand
|
| 3 |
+
Version: 2.2.2
|
| 4 |
+
Summary: A library to create a command-line program from a function
|
| 5 |
+
Home-page: https://github.com/Lucretiel/autocommand
|
| 6 |
+
Author: Nathan West
|
| 7 |
+
License: LGPLv3
|
| 8 |
+
Project-URL: Homepage, https://github.com/Lucretiel/autocommand
|
| 9 |
+
Project-URL: Bug Tracker, https://github.com/Lucretiel/autocommand/issues
|
| 10 |
+
Platform: any
|
| 11 |
+
Classifier: Development Status :: 6 - Mature
|
| 12 |
+
Classifier: Intended Audience :: Developers
|
| 13 |
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
| 14 |
+
Classifier: Programming Language :: Python
|
| 15 |
+
Classifier: Programming Language :: Python :: 3
|
| 16 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 17 |
+
Classifier: Topic :: Software Development
|
| 18 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 19 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 20 |
+
Requires-Python: >=3.7
|
| 21 |
+
Description-Content-Type: text/markdown
|
| 22 |
+
License-File: LICENSE
|
| 23 |
+
|
| 24 |
+
[](https://badge.fury.io/py/autocommand)
|
| 25 |
+
|
| 26 |
+
# autocommand
|
| 27 |
+
|
| 28 |
+
A library to automatically generate and run simple argparse parsers from function signatures.
|
| 29 |
+
|
| 30 |
+
## Installation
|
| 31 |
+
|
| 32 |
+
Autocommand is installed via pip:
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
$ pip install autocommand
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Usage
|
| 39 |
+
|
| 40 |
+
Autocommand turns a function into a command-line program. It converts the function's parameter signature into command-line arguments, and automatically runs the function if the module was called as `__main__`. In effect, it lets your create a smart main function.
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
from autocommand import autocommand
|
| 44 |
+
|
| 45 |
+
# This program takes exactly one argument and echos it.
|
| 46 |
+
@autocommand(__name__)
|
| 47 |
+
def echo(thing):
|
| 48 |
+
print(thing)
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
$ python echo.py hello
|
| 53 |
+
hello
|
| 54 |
+
$ python echo.py -h
|
| 55 |
+
usage: echo [-h] thing
|
| 56 |
+
|
| 57 |
+
positional arguments:
|
| 58 |
+
thing
|
| 59 |
+
|
| 60 |
+
optional arguments:
|
| 61 |
+
-h, --help show this help message and exit
|
| 62 |
+
$ python echo.py hello world # too many arguments
|
| 63 |
+
usage: echo.py [-h] thing
|
| 64 |
+
echo.py: error: unrecognized arguments: world
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
As you can see, autocommand converts the signature of the function into an argument spec. When you run the file as a program, autocommand collects the command-line arguments and turns them into function arguments. The function is executed with these arguments, and then the program exits with the return value of the function, via `sys.exit`. Autocommand also automatically creates a usage message, which can be invoked with `-h` or `--help`, and automatically prints an error message when provided with invalid arguments.
|
| 68 |
+
|
| 69 |
+
### Types
|
| 70 |
+
|
| 71 |
+
You can use a type annotation to give an argument a type. Any type (or in fact any callable) that returns an object when given a string argument can be used, though there are a few special cases that are described later.
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
@autocommand(__name__)
|
| 75 |
+
def net_client(host, port: int):
|
| 76 |
+
...
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
Autocommand will catch `TypeErrors` raised by the type during argument parsing, so you can supply a callable and do some basic argument validation as well.
|
| 80 |
+
|
| 81 |
+
### Trailing Arguments
|
| 82 |
+
|
| 83 |
+
You can add a `*args` parameter to your function to give it trailing arguments. The command will collect 0 or more trailing arguments and supply them to `args` as a tuple. If a type annotation is supplied, the type is applied to each argument.
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
# Write the contents of each file, one by one
|
| 87 |
+
@autocommand(__name__)
|
| 88 |
+
def cat(*files):
|
| 89 |
+
for filename in files:
|
| 90 |
+
with open(filename) as file:
|
| 91 |
+
for line in file:
|
| 92 |
+
print(line.rstrip())
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
```
|
| 96 |
+
$ python cat.py -h
|
| 97 |
+
usage: ipython [-h] [file [file ...]]
|
| 98 |
+
|
| 99 |
+
positional arguments:
|
| 100 |
+
file
|
| 101 |
+
|
| 102 |
+
optional arguments:
|
| 103 |
+
-h, --help show this help message and exit
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### Options
|
| 107 |
+
|
| 108 |
+
To create `--option` switches, just assign a default. Autocommand will automatically create `--long` and `-s`hort switches.
|
| 109 |
+
|
| 110 |
+
```python
|
| 111 |
+
@autocommand(__name__)
|
| 112 |
+
def do_with_config(argument, config='~/foo.conf'):
|
| 113 |
+
pass
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
$ python example.py -h
|
| 118 |
+
usage: example.py [-h] [-c CONFIG] argument
|
| 119 |
+
|
| 120 |
+
positional arguments:
|
| 121 |
+
argument
|
| 122 |
+
|
| 123 |
+
optional arguments:
|
| 124 |
+
-h, --help show this help message and exit
|
| 125 |
+
-c CONFIG, --config CONFIG
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
The option's type is automatically deduced from the default, unless one is explicitly given in an annotation:
|
| 129 |
+
|
| 130 |
+
```python
|
| 131 |
+
@autocommand(__name__)
|
| 132 |
+
def http_connect(host, port=80):
|
| 133 |
+
print('{}:{}'.format(host, port))
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
```
|
| 137 |
+
$ python http.py -h
|
| 138 |
+
usage: http.py [-h] [-p PORT] host
|
| 139 |
+
|
| 140 |
+
positional arguments:
|
| 141 |
+
host
|
| 142 |
+
|
| 143 |
+
optional arguments:
|
| 144 |
+
-h, --help show this help message and exit
|
| 145 |
+
-p PORT, --port PORT
|
| 146 |
+
$ python http.py localhost
|
| 147 |
+
localhost:80
|
| 148 |
+
$ python http.py localhost -p 8080
|
| 149 |
+
localhost:8080
|
| 150 |
+
$ python http.py localhost -p blah
|
| 151 |
+
usage: http.py [-h] [-p PORT] host
|
| 152 |
+
http.py: error: argument -p/--port: invalid int value: 'blah'
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
#### None
|
| 156 |
+
|
| 157 |
+
If an option is given a default value of `None`, it reads in a value as normal, but supplies `None` if the option isn't provided.
|
| 158 |
+
|
| 159 |
+
#### Switches
|
| 160 |
+
|
| 161 |
+
If an argument is given a default value of `True` or `False`, or
|
| 162 |
+
given an explicit `bool` type, it becomes an option switch.
|
| 163 |
+
|
| 164 |
+
```python
|
| 165 |
+
@autocommand(__name__)
|
| 166 |
+
def example(verbose=False, quiet=False):
|
| 167 |
+
pass
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
```
|
| 171 |
+
$ python example.py -h
|
| 172 |
+
usage: example.py [-h] [-v] [-q]
|
| 173 |
+
|
| 174 |
+
optional arguments:
|
| 175 |
+
-h, --help show this help message and exit
|
| 176 |
+
-v, --verbose
|
| 177 |
+
-q, --quiet
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
Autocommand attempts to do the "correct thing" in these cases- if the default is `True`, then supplying the switch makes the argument `False`; if the type is `bool` and the default is some other `True` value, then supplying the switch makes the argument `False`, while not supplying the switch makes the argument the default value.
|
| 181 |
+
|
| 182 |
+
Autocommand also supports the creation of switch inverters. Pass `add_nos=True` to `autocommand` to enable this.
|
| 183 |
+
|
| 184 |
+
```
|
| 185 |
+
@autocommand(__name__, add_nos=True)
|
| 186 |
+
def example(verbose=False):
|
| 187 |
+
pass
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
```
|
| 191 |
+
$ python example.py -h
|
| 192 |
+
usage: ipython [-h] [-v] [--no-verbose]
|
| 193 |
+
|
| 194 |
+
optional arguments:
|
| 195 |
+
-h, --help show this help message and exit
|
| 196 |
+
-v, --verbose
|
| 197 |
+
--no-verbose
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
Using the `--no-` version of a switch will pass the opposite value in as a function argument. If multiple switches are present, the last one takes precedence.
|
| 201 |
+
|
| 202 |
+
#### Files
|
| 203 |
+
|
| 204 |
+
If the default value is a file object, such as `sys.stdout`, then autocommand just looks for a string, for a file path. It doesn't do any special checking on the string, though (such as checking if the file exists); it's better to let the client decide how to handle errors in this case. Instead, it provides a special context manager called `smart_open`, which behaves exactly like `open` if a filename or other openable type is provided, but also lets you use already open files:
|
| 205 |
+
|
| 206 |
+
```python
|
| 207 |
+
from autocommand import autocommand, smart_open
|
| 208 |
+
import sys
|
| 209 |
+
|
| 210 |
+
# Write the contents of stdin, or a file, to stdout
|
| 211 |
+
@autocommand(__name__)
|
| 212 |
+
def write_out(infile=sys.stdin):
|
| 213 |
+
with smart_open(infile) as f:
|
| 214 |
+
for line in f:
|
| 215 |
+
print(line.rstrip())
|
| 216 |
+
# If a file was opened, it is closed here. If it was just stdin, it is untouched.
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
```
|
| 220 |
+
$ echo "Hello World!" | python write_out.py | tee hello.txt
|
| 221 |
+
Hello World!
|
| 222 |
+
$ python write_out.py --infile hello.txt
|
| 223 |
+
Hello World!
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
### Descriptions and docstrings
|
| 227 |
+
|
| 228 |
+
The `autocommand` decorator accepts `description` and `epilog` kwargs, corresponding to the `description <https://docs.python.org/3/library/argparse.html#description>`_ and `epilog <https://docs.python.org/3/library/argparse.html#epilog>`_ of the `ArgumentParser`. If no description is given, but the decorated function has a docstring, then it is taken as the `description` for the `ArgumentParser`. You can also provide both the description and epilog in the docstring by splitting it into two sections with 4 or more - characters.
|
| 229 |
+
|
| 230 |
+
```python
|
| 231 |
+
@autocommand(__name__)
|
| 232 |
+
def copy(infile=sys.stdin, outfile=sys.stdout):
|
| 233 |
+
'''
|
| 234 |
+
Copy an the contents of a file (or stdin) to another file (or stdout)
|
| 235 |
+
----------
|
| 236 |
+
Some extra documentation in the epilog
|
| 237 |
+
'''
|
| 238 |
+
with smart_open(infile) as istr:
|
| 239 |
+
with smart_open(outfile, 'w') as ostr:
|
| 240 |
+
for line in istr:
|
| 241 |
+
ostr.write(line)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
```
|
| 245 |
+
$ python copy.py -h
|
| 246 |
+
usage: copy.py [-h] [-i INFILE] [-o OUTFILE]
|
| 247 |
+
|
| 248 |
+
Copy an the contents of a file (or stdin) to another file (or stdout)
|
| 249 |
+
|
| 250 |
+
optional arguments:
|
| 251 |
+
-h, --help show this help message and exit
|
| 252 |
+
-i INFILE, --infile INFILE
|
| 253 |
+
-o OUTFILE, --outfile OUTFILE
|
| 254 |
+
|
| 255 |
+
Some extra documentation in the epilog
|
| 256 |
+
$ echo "Hello World" | python copy.py --outfile hello.txt
|
| 257 |
+
$ python copy.py --infile hello.txt --outfile hello2.txt
|
| 258 |
+
$ python copy.py --infile hello2.txt
|
| 259 |
+
Hello World
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
### Parameter descriptions
|
| 263 |
+
|
| 264 |
+
You can also attach description text to individual parameters in the annotation. To attach both a type and a description, supply them both in any order in a tuple
|
| 265 |
+
|
| 266 |
+
```python
|
| 267 |
+
@autocommand(__name__)
|
| 268 |
+
def copy_net(
|
| 269 |
+
infile: 'The name of the file to send',
|
| 270 |
+
host: 'The host to send the file to',
|
| 271 |
+
port: (int, 'The port to connect to')):
|
| 272 |
+
|
| 273 |
+
'''
|
| 274 |
+
Copy a file over raw TCP to a remote destination.
|
| 275 |
+
'''
|
| 276 |
+
# Left as an exercise to the reader
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
### Decorators and wrappers
|
| 280 |
+
|
| 281 |
+
Autocommand automatically follows wrapper chains created by `@functools.wraps`. This means that you can apply other wrapping decorators to your main function, and autocommand will still correctly detect the signature.
|
| 282 |
+
|
| 283 |
+
```python
|
| 284 |
+
from functools import wraps
|
| 285 |
+
from autocommand import autocommand
|
| 286 |
+
|
| 287 |
+
def print_yielded(func):
|
| 288 |
+
'''
|
| 289 |
+
Convert a generator into a function that prints all yielded elements
|
| 290 |
+
'''
|
| 291 |
+
@wraps(func)
|
| 292 |
+
def wrapper(*args, **kwargs):
|
| 293 |
+
for thing in func(*args, **kwargs):
|
| 294 |
+
print(thing)
|
| 295 |
+
return wrapper
|
| 296 |
+
|
| 297 |
+
@autocommand(__name__,
|
| 298 |
+
description= 'Print all the values from START to STOP, inclusive, in steps of STEP',
|
| 299 |
+
epilog= 'STOP and STEP default to 1')
|
| 300 |
+
@print_yielded
|
| 301 |
+
def seq(stop, start=1, step=1):
|
| 302 |
+
for i in range(start, stop + 1, step):
|
| 303 |
+
yield i
|
| 304 |
+
```
|
| 305 |
+
|
| 306 |
+
```
|
| 307 |
+
$ seq.py -h
|
| 308 |
+
usage: seq.py [-h] [-s START] [-S STEP] stop
|
| 309 |
+
|
| 310 |
+
Print all the values from START to STOP, inclusive, in steps of STEP
|
| 311 |
+
|
| 312 |
+
positional arguments:
|
| 313 |
+
stop
|
| 314 |
+
|
| 315 |
+
optional arguments:
|
| 316 |
+
-h, --help show this help message and exit
|
| 317 |
+
-s START, --start START
|
| 318 |
+
-S STEP, --step STEP
|
| 319 |
+
|
| 320 |
+
STOP and STEP default to 1
|
| 321 |
+
```
|
| 322 |
+
|
| 323 |
+
Even though autocommand is being applied to the `wrapper` returned by `print_yielded`, it still retreives the signature of the underlying `seq` function to create the argument parsing.
|
| 324 |
+
|
| 325 |
+
### Custom Parser
|
| 326 |
+
|
| 327 |
+
While autocommand's automatic parser generator is a powerful convenience, it doesn't cover all of the different features that argparse provides. If you need these features, you can provide your own parser as a kwarg to `autocommand`:
|
| 328 |
+
|
| 329 |
+
```python
|
| 330 |
+
from argparse import ArgumentParser
|
| 331 |
+
from autocommand import autocommand
|
| 332 |
+
|
| 333 |
+
parser = ArgumentParser()
|
| 334 |
+
# autocommand can't do optional positonal parameters
|
| 335 |
+
parser.add_argument('arg', nargs='?')
|
| 336 |
+
# or mutually exclusive options
|
| 337 |
+
group = parser.add_mutually_exclusive_group()
|
| 338 |
+
group.add_argument('-v', '--verbose', action='store_true')
|
| 339 |
+
group.add_argument('-q', '--quiet', action='store_true')
|
| 340 |
+
|
| 341 |
+
@autocommand(__name__, parser=parser)
|
| 342 |
+
def main(arg, verbose, quiet):
|
| 343 |
+
print(arg, verbose, quiet)
|
| 344 |
+
```
|
| 345 |
+
|
| 346 |
+
```
|
| 347 |
+
$ python parser.py -h
|
| 348 |
+
usage: write_file.py [-h] [-v | -q] [arg]
|
| 349 |
+
|
| 350 |
+
positional arguments:
|
| 351 |
+
arg
|
| 352 |
+
|
| 353 |
+
optional arguments:
|
| 354 |
+
-h, --help show this help message and exit
|
| 355 |
+
-v, --verbose
|
| 356 |
+
-q, --quiet
|
| 357 |
+
$ python parser.py
|
| 358 |
+
None False False
|
| 359 |
+
$ python parser.py hello
|
| 360 |
+
hello False False
|
| 361 |
+
$ python parser.py -v
|
| 362 |
+
None True False
|
| 363 |
+
$ python parser.py -q
|
| 364 |
+
None False True
|
| 365 |
+
$ python parser.py -vq
|
| 366 |
+
usage: parser.py [-h] [-v | -q] [arg]
|
| 367 |
+
parser.py: error: argument -q/--quiet: not allowed with argument -v/--verbose
|
| 368 |
+
```
|
| 369 |
+
|
| 370 |
+
Any parser should work fine, so long as each of the parser's arguments has a corresponding parameter in the decorated main function. The order of parameters doesn't matter, as long as they are all present. Note that when using a custom parser, autocommand doesn't modify the parser or the retrieved arguments. This means that no description/epilog will be added, and the function's type annotations and defaults (if present) will be ignored.
|
| 371 |
+
|
| 372 |
+
## Testing and Library use
|
| 373 |
+
|
| 374 |
+
The decorated function is only called and exited from if the first argument to `autocommand` is `'__main__'` or `True`. If it is neither of these values, or no argument is given, then a new main function is created by the decorator. This function has the signature `main(argv=None)`, and is intended to be called with arguments as if via `main(sys.argv[1:])`. The function has the attributes `parser` and `main`, which are the generated `ArgumentParser` and the original main function that was decorated. This is to facilitate testing and library use of your main. Calling the function triggers a `parse_args()` with the supplied arguments, and returns the result of the main function. Note that, while it returns instead of calling `sys.exit`, the `parse_args()` function will raise a `SystemExit` in the event of a parsing error or `-h/--help` argument.
|
| 375 |
+
|
| 376 |
+
```python
|
| 377 |
+
@autocommand()
|
| 378 |
+
def test_prog(arg1, arg2: int, quiet=False, verbose=False):
|
| 379 |
+
if not quiet:
|
| 380 |
+
print(arg1, arg2)
|
| 381 |
+
if verbose:
|
| 382 |
+
print("LOUD NOISES")
|
| 383 |
+
|
| 384 |
+
return 0
|
| 385 |
+
|
| 386 |
+
print(test_prog(['-v', 'hello', '80']))
|
| 387 |
+
```
|
| 388 |
+
|
| 389 |
+
```
|
| 390 |
+
$ python test_prog.py
|
| 391 |
+
hello 80
|
| 392 |
+
LOUD NOISES
|
| 393 |
+
0
|
| 394 |
+
```
|
| 395 |
+
|
| 396 |
+
If the function is called with no arguments, `sys.argv[1:]` is used. This is to allow the autocommand function to be used as a setuptools entry point.
|
| 397 |
+
|
| 398 |
+
## Exceptions and limitations
|
| 399 |
+
|
| 400 |
+
- There are a few possible exceptions that `autocommand` can raise. All of them derive from `autocommand.AutocommandError`.
|
| 401 |
+
|
| 402 |
+
- If an invalid annotation is given (that is, it isn't a `type`, `str`, `(type, str)`, or `(str, type)`, an `AnnotationError` is raised. The `type` may be any callable, as described in the `Types`_ section.
|
| 403 |
+
- If the function has a `**kwargs` parameter, a `KWargError` is raised.
|
| 404 |
+
- If, somehow, the function has a positional-only parameter, a `PositionalArgError` is raised. This means that the argument doesn't have a name, which is currently not possible with a plain `def` or `lambda`, though many built-in functions have this kind of parameter.
|
| 405 |
+
|
| 406 |
+
- There are a few argparse features that are not supported by autocommand.
|
| 407 |
+
|
| 408 |
+
- It isn't possible to have an optional positional argument (as opposed to a `--option`). POSIX thinks this is bad form anyway.
|
| 409 |
+
- It isn't possible to have mutually exclusive arguments or options
|
| 410 |
+
- It isn't possible to have subcommands or subparsers, though I'm working on a few solutions involving classes or nested function definitions to allow this.
|
| 411 |
+
|
| 412 |
+
## Development
|
| 413 |
+
|
| 414 |
+
Autocommand cannot be important from the project root; this is to enforce separation of concerns and prevent accidental importing of `setup.py` or tests. To develop, install the project in editable mode:
|
| 415 |
+
|
| 416 |
+
```
|
| 417 |
+
$ python setup.py develop
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
This will create a link to the source files in the deployment directory, so that any source changes are reflected when it is imported.
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/RECORD
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
autocommand-2.2.2.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
autocommand-2.2.2.dist-info/LICENSE,sha256=reeNBJgtaZctREqOFKlPh6IzTdOFXMgDSOqOJAqg3y0,7634
|
| 3 |
+
autocommand-2.2.2.dist-info/METADATA,sha256=OADZuR3O6iBlpu1ieTgzYul6w4uOVrk0P0BO5TGGAJk,15006
|
| 4 |
+
autocommand-2.2.2.dist-info/RECORD,,
|
| 5 |
+
autocommand-2.2.2.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
autocommand-2.2.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
| 7 |
+
autocommand-2.2.2.dist-info/top_level.txt,sha256=AzfhgKKS8EdAwWUTSF8mgeVQbXOY9kokHB6kSqwwqu0,12
|
| 8 |
+
autocommand/__init__.py,sha256=zko5Rnvolvb-UXjCx_2ArPTGBWwUK5QY4LIQIKYR7As,1037
|
| 9 |
+
autocommand/autoasync.py,sha256=AMdyrxNS4pqWJfP_xuoOcImOHWD-qT7x06wmKN1Vp-U,5680
|
| 10 |
+
autocommand/autocommand.py,sha256=hmkEmQ72HtL55gnURVjDOnsfYlGd5lLXbvT4KG496Qw,2505
|
| 11 |
+
autocommand/automain.py,sha256=A2b8i754Mxc_DjU9WFr6vqYDWlhz0cn8miu8d8EsxV8,2076
|
| 12 |
+
autocommand/autoparse.py,sha256=WVWmZJPcbzUKXP40raQw_0HD8qPJ2V9VG1eFFmmnFxw,11642
|
| 13 |
+
autocommand/errors.py,sha256=7aa3roh9Herd6nIKpQHNWEslWE8oq7GiHYVUuRqORnA,886
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/REQUESTED
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.38.4)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
autocommand
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 2 |
+
of this software and associated documentation files (the "Software"), to
|
| 3 |
+
deal in the Software without restriction, including without limitation the
|
| 4 |
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 5 |
+
sell copies of the Software, and to permit persons to whom the Software is
|
| 6 |
+
furnished to do so, subject to the following conditions:
|
| 7 |
+
|
| 8 |
+
The above copyright notice and this permission notice shall be included in
|
| 9 |
+
all copies or substantial portions of the Software.
|
| 10 |
+
|
| 11 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 12 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 13 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 14 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 15 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 16 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 17 |
+
IN THE SOFTWARE.
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: jaraco.text
|
| 3 |
+
Version: 4.0.0
|
| 4 |
+
Summary: Module for text manipulation
|
| 5 |
+
Author-email: "Jason R. Coombs" <jaraco@jaraco.com>
|
| 6 |
+
Project-URL: Source, https://github.com/jaraco/jaraco.text
|
| 7 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 8 |
+
Classifier: Intended Audience :: Developers
|
| 9 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 10 |
+
Classifier: Programming Language :: Python :: 3
|
| 11 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 12 |
+
Requires-Python: >=3.8
|
| 13 |
+
Description-Content-Type: text/x-rst
|
| 14 |
+
License-File: LICENSE
|
| 15 |
+
Requires-Dist: jaraco.functools
|
| 16 |
+
Requires-Dist: jaraco.context >=4.1
|
| 17 |
+
Requires-Dist: autocommand
|
| 18 |
+
Requires-Dist: more-itertools
|
| 19 |
+
Requires-Dist: importlib-resources ; python_version < "3.9"
|
| 20 |
+
Provides-Extra: doc
|
| 21 |
+
Requires-Dist: sphinx >=3.5 ; extra == 'doc'
|
| 22 |
+
Requires-Dist: jaraco.packaging >=9.3 ; extra == 'doc'
|
| 23 |
+
Requires-Dist: rst.linker >=1.9 ; extra == 'doc'
|
| 24 |
+
Requires-Dist: furo ; extra == 'doc'
|
| 25 |
+
Requires-Dist: sphinx-lint ; extra == 'doc'
|
| 26 |
+
Requires-Dist: jaraco.tidelift >=1.4 ; extra == 'doc'
|
| 27 |
+
Provides-Extra: inflect
|
| 28 |
+
Requires-Dist: inflect ; extra == 'inflect'
|
| 29 |
+
Provides-Extra: test
|
| 30 |
+
Requires-Dist: pytest !=8.1.*,>=6 ; extra == 'test'
|
| 31 |
+
Requires-Dist: pytest-checkdocs >=2.4 ; extra == 'test'
|
| 32 |
+
Requires-Dist: pytest-cov ; extra == 'test'
|
| 33 |
+
Requires-Dist: pytest-mypy ; extra == 'test'
|
| 34 |
+
Requires-Dist: pytest-enabler >=2.2 ; extra == 'test'
|
| 35 |
+
Requires-Dist: pathlib2 ; (python_version < "3.10") and extra == 'test'
|
| 36 |
+
Requires-Dist: pytest-ruff >=0.2.1 ; (sys_platform != "cygwin") and extra == 'test'
|
| 37 |
+
|
| 38 |
+
.. image:: https://img.shields.io/pypi/v/jaraco.text.svg
|
| 39 |
+
:target: https://pypi.org/project/jaraco.text
|
| 40 |
+
|
| 41 |
+
.. image:: https://img.shields.io/pypi/pyversions/jaraco.text.svg
|
| 42 |
+
|
| 43 |
+
.. image:: https://github.com/jaraco/jaraco.text/actions/workflows/main.yml/badge.svg
|
| 44 |
+
:target: https://github.com/jaraco/jaraco.text/actions?query=workflow%3A%22tests%22
|
| 45 |
+
:alt: tests
|
| 46 |
+
|
| 47 |
+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
|
| 48 |
+
:target: https://github.com/astral-sh/ruff
|
| 49 |
+
:alt: Ruff
|
| 50 |
+
|
| 51 |
+
.. image:: https://readthedocs.org/projects/jaracotext/badge/?version=latest
|
| 52 |
+
:target: https://jaracotext.readthedocs.io/en/latest/?badge=latest
|
| 53 |
+
|
| 54 |
+
.. image:: https://img.shields.io/badge/skeleton-2024-informational
|
| 55 |
+
:target: https://blog.jaraco.com/skeleton
|
| 56 |
+
|
| 57 |
+
.. image:: https://tidelift.com/badges/package/pypi/jaraco.text
|
| 58 |
+
:target: https://tidelift.com/subscription/pkg/pypi-jaraco.text?utm_source=pypi-jaraco.text&utm_medium=readme
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
This package provides handy routines for dealing with text, such as
|
| 62 |
+
wrapping, substitution, trimming, stripping, prefix and suffix removal,
|
| 63 |
+
line continuation, indentation, comment processing, identifier processing,
|
| 64 |
+
values parsing, case insensitive comparison, and more. See the docs
|
| 65 |
+
(linked in the badge above) for the detailed documentation and examples.
|
| 66 |
+
|
| 67 |
+
Layouts
|
| 68 |
+
=======
|
| 69 |
+
|
| 70 |
+
One of the features of this package is the layouts module, which
|
| 71 |
+
provides a simple example of translating keystrokes from one keyboard
|
| 72 |
+
layout to another::
|
| 73 |
+
|
| 74 |
+
echo qwerty | python -m jaraco.text.to-dvorak
|
| 75 |
+
',.pyf
|
| 76 |
+
echo "',.pyf" | python -m jaraco.text.to-qwerty
|
| 77 |
+
qwerty
|
| 78 |
+
|
| 79 |
+
Newline Reporting
|
| 80 |
+
=================
|
| 81 |
+
|
| 82 |
+
Need to know what newlines appear in a file?
|
| 83 |
+
|
| 84 |
+
::
|
| 85 |
+
|
| 86 |
+
$ python -m jaraco.text.show-newlines README.rst
|
| 87 |
+
newline is '\n'
|
| 88 |
+
|
| 89 |
+
For Enterprise
|
| 90 |
+
==============
|
| 91 |
+
|
| 92 |
+
Available as part of the Tidelift Subscription.
|
| 93 |
+
|
| 94 |
+
This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.
|
| 95 |
+
|
| 96 |
+
`Learn more <https://tidelift.com/subscription/pkg/pypi-jaraco.text?utm_source=pypi-jaraco.text&utm_medium=referral&utm_campaign=github>`_.
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jaraco.text-4.0.0.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
jaraco.text-4.0.0.dist-info/LICENSE,sha256=htoPAa6uRjSKPD1GUZXcHOzN55956HdppkuNoEsqR0E,1023
|
| 3 |
+
jaraco.text-4.0.0.dist-info/METADATA,sha256=XC_QkBLJVPE5sQYkl41TNaZUw0AUzQb29GbKaD28nFY,3731
|
| 4 |
+
jaraco.text-4.0.0.dist-info/RECORD,,
|
| 5 |
+
jaraco.text-4.0.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
jaraco.text-4.0.0.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
|
| 7 |
+
jaraco.text-4.0.0.dist-info/top_level.txt,sha256=0JnN3LfXH4LIRfXL-QFOGCJzQWZO3ELx4R1d_louoQM,7
|
| 8 |
+
jaraco/text/Lorem ipsum.txt,sha256=N_7c_79zxOufBY9HZ3yzMgOkNv-TkOTTio4BydrSjgs,1335
|
| 9 |
+
jaraco/text/__init__.py,sha256=lazNYXo8IhOR1bFigLAyGiiQao6jtO3KGWh8bZZPx3c,16762
|
| 10 |
+
jaraco/text/layouts.py,sha256=HTC8aSTLZ7uXipyOXapRMC158juecjK6RVwitfmZ9_w,643
|
| 11 |
+
jaraco/text/show-newlines.py,sha256=jT0vp4gLhG20hX2lTB-zKo_i3NgKzj79yRAdz4eMzIM,903
|
| 12 |
+
jaraco/text/strip-prefix.py,sha256=NfVXV8JVNo6nqcuYASfMV7_y4Eo8zMQqlCOGvAnRIVw,412
|
| 13 |
+
jaraco/text/to-dvorak.py,sha256=36nPPsiifwv6RfpAb--3zpgbIx8ohnnI1aR29IJTO9s,118
|
| 14 |
+
jaraco/text/to-qwerty.py,sha256=IQoFY9v7vLTEybcput4KBYm_5GR35pmtgZ_xyrmdTgI,118
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/REQUESTED
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (71.1.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco.text-4.0.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
jaraco
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
|
| 5 |
+
__title__ = "packaging"
|
| 6 |
+
__summary__ = "Core utilities for Python packages"
|
| 7 |
+
__uri__ = "https://github.com/pypa/packaging"
|
| 8 |
+
|
| 9 |
+
__version__ = "26.0"
|
| 10 |
+
|
| 11 |
+
__author__ = "Donald Stufft and individual contributors"
|
| 12 |
+
__email__ = "donald@stufft.io"
|
| 13 |
+
|
| 14 |
+
__license__ = "BSD-2-Clause or Apache-2.0"
|
| 15 |
+
__copyright__ = f"2014 {__author__}"
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/_elffile.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ELF file parser.
|
| 3 |
+
|
| 4 |
+
This provides a class ``ELFFile`` that parses an ELF executable in a similar
|
| 5 |
+
interface to ``ZipFile``. Only the read interface is implemented.
|
| 6 |
+
|
| 7 |
+
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import enum
|
| 13 |
+
import os
|
| 14 |
+
import struct
|
| 15 |
+
from typing import IO
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class ELFInvalid(ValueError):
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class EIClass(enum.IntEnum):
|
| 23 |
+
C32 = 1
|
| 24 |
+
C64 = 2
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class EIData(enum.IntEnum):
|
| 28 |
+
Lsb = 1
|
| 29 |
+
Msb = 2
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class EMachine(enum.IntEnum):
|
| 33 |
+
I386 = 3
|
| 34 |
+
S390 = 22
|
| 35 |
+
Arm = 40
|
| 36 |
+
X8664 = 62
|
| 37 |
+
AArc64 = 183
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class ELFFile:
|
| 41 |
+
"""
|
| 42 |
+
Representation of an ELF executable.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
def __init__(self, f: IO[bytes]) -> None:
|
| 46 |
+
self._f = f
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
ident = self._read("16B")
|
| 50 |
+
except struct.error as e:
|
| 51 |
+
raise ELFInvalid("unable to parse identification") from e
|
| 52 |
+
magic = bytes(ident[:4])
|
| 53 |
+
if magic != b"\x7fELF":
|
| 54 |
+
raise ELFInvalid(f"invalid magic: {magic!r}")
|
| 55 |
+
|
| 56 |
+
self.capacity = ident[4] # Format for program header (bitness).
|
| 57 |
+
self.encoding = ident[5] # Data structure encoding (endianness).
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
# e_fmt: Format for program header.
|
| 61 |
+
# p_fmt: Format for section header.
|
| 62 |
+
# p_idx: Indexes to find p_type, p_offset, and p_filesz.
|
| 63 |
+
e_fmt, self._p_fmt, self._p_idx = {
|
| 64 |
+
(1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
|
| 65 |
+
(1, 2): (">HHIIIIIHHH", ">IIIIIIII", (0, 1, 4)), # 32-bit MSB.
|
| 66 |
+
(2, 1): ("<HHIQQQIHHH", "<IIQQQQQQ", (0, 2, 5)), # 64-bit LSB.
|
| 67 |
+
(2, 2): (">HHIQQQIHHH", ">IIQQQQQQ", (0, 2, 5)), # 64-bit MSB.
|
| 68 |
+
}[(self.capacity, self.encoding)]
|
| 69 |
+
except KeyError as e:
|
| 70 |
+
raise ELFInvalid(
|
| 71 |
+
f"unrecognized capacity ({self.capacity}) or encoding ({self.encoding})"
|
| 72 |
+
) from e
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
(
|
| 76 |
+
_,
|
| 77 |
+
self.machine, # Architecture type.
|
| 78 |
+
_,
|
| 79 |
+
_,
|
| 80 |
+
self._e_phoff, # Offset of program header.
|
| 81 |
+
_,
|
| 82 |
+
self.flags, # Processor-specific flags.
|
| 83 |
+
_,
|
| 84 |
+
self._e_phentsize, # Size of section.
|
| 85 |
+
self._e_phnum, # Number of sections.
|
| 86 |
+
) = self._read(e_fmt)
|
| 87 |
+
except struct.error as e:
|
| 88 |
+
raise ELFInvalid("unable to parse machine and section information") from e
|
| 89 |
+
|
| 90 |
+
def _read(self, fmt: str) -> tuple[int, ...]:
|
| 91 |
+
return struct.unpack(fmt, self._f.read(struct.calcsize(fmt)))
|
| 92 |
+
|
| 93 |
+
@property
|
| 94 |
+
def interpreter(self) -> str | None:
|
| 95 |
+
"""
|
| 96 |
+
The path recorded in the ``PT_INTERP`` section header.
|
| 97 |
+
"""
|
| 98 |
+
for index in range(self._e_phnum):
|
| 99 |
+
self._f.seek(self._e_phoff + self._e_phentsize * index)
|
| 100 |
+
try:
|
| 101 |
+
data = self._read(self._p_fmt)
|
| 102 |
+
except struct.error:
|
| 103 |
+
continue
|
| 104 |
+
if data[self._p_idx[0]] != 3: # Not PT_INTERP.
|
| 105 |
+
continue
|
| 106 |
+
self._f.seek(data[self._p_idx[1]])
|
| 107 |
+
return os.fsdecode(self._f.read(data[self._p_idx[2]])).strip("\0")
|
| 108 |
+
return None
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/_structures.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
|
| 5 |
+
import typing
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@typing.final
|
| 9 |
+
class InfinityType:
|
| 10 |
+
__slots__ = ()
|
| 11 |
+
|
| 12 |
+
def __repr__(self) -> str:
|
| 13 |
+
return "Infinity"
|
| 14 |
+
|
| 15 |
+
def __hash__(self) -> int:
|
| 16 |
+
return hash(repr(self))
|
| 17 |
+
|
| 18 |
+
def __lt__(self, other: object) -> bool:
|
| 19 |
+
return False
|
| 20 |
+
|
| 21 |
+
def __le__(self, other: object) -> bool:
|
| 22 |
+
return False
|
| 23 |
+
|
| 24 |
+
def __eq__(self, other: object) -> bool:
|
| 25 |
+
return isinstance(other, self.__class__)
|
| 26 |
+
|
| 27 |
+
def __gt__(self, other: object) -> bool:
|
| 28 |
+
return True
|
| 29 |
+
|
| 30 |
+
def __ge__(self, other: object) -> bool:
|
| 31 |
+
return True
|
| 32 |
+
|
| 33 |
+
def __neg__(self: object) -> "NegativeInfinityType":
|
| 34 |
+
return NegativeInfinity
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Infinity = InfinityType()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@typing.final
|
| 41 |
+
class NegativeInfinityType:
|
| 42 |
+
__slots__ = ()
|
| 43 |
+
|
| 44 |
+
def __repr__(self) -> str:
|
| 45 |
+
return "-Infinity"
|
| 46 |
+
|
| 47 |
+
def __hash__(self) -> int:
|
| 48 |
+
return hash(repr(self))
|
| 49 |
+
|
| 50 |
+
def __lt__(self, other: object) -> bool:
|
| 51 |
+
return True
|
| 52 |
+
|
| 53 |
+
def __le__(self, other: object) -> bool:
|
| 54 |
+
return True
|
| 55 |
+
|
| 56 |
+
def __eq__(self, other: object) -> bool:
|
| 57 |
+
return isinstance(other, self.__class__)
|
| 58 |
+
|
| 59 |
+
def __gt__(self, other: object) -> bool:
|
| 60 |
+
return False
|
| 61 |
+
|
| 62 |
+
def __ge__(self, other: object) -> bool:
|
| 63 |
+
return False
|
| 64 |
+
|
| 65 |
+
def __neg__(self: object) -> InfinityType:
|
| 66 |
+
return Infinity
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
NegativeInfinity = NegativeInfinityType()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/metadata.py
ADDED
|
@@ -0,0 +1,978 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import email.feedparser
|
| 4 |
+
import email.header
|
| 5 |
+
import email.message
|
| 6 |
+
import email.parser
|
| 7 |
+
import email.policy
|
| 8 |
+
import keyword
|
| 9 |
+
import pathlib
|
| 10 |
+
import sys
|
| 11 |
+
import typing
|
| 12 |
+
from typing import (
|
| 13 |
+
Any,
|
| 14 |
+
Callable,
|
| 15 |
+
Generic,
|
| 16 |
+
Literal,
|
| 17 |
+
TypedDict,
|
| 18 |
+
cast,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
from . import licenses, requirements, specifiers, utils
|
| 22 |
+
from . import version as version_module
|
| 23 |
+
|
| 24 |
+
if typing.TYPE_CHECKING:
|
| 25 |
+
from .licenses import NormalizedLicenseExpression
|
| 26 |
+
|
| 27 |
+
T = typing.TypeVar("T")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
if sys.version_info >= (3, 11): # pragma: no cover
|
| 31 |
+
ExceptionGroup = ExceptionGroup # noqa: F821
|
| 32 |
+
else: # pragma: no cover
|
| 33 |
+
|
| 34 |
+
class ExceptionGroup(Exception):
|
| 35 |
+
"""A minimal implementation of :external:exc:`ExceptionGroup` from Python 3.11.
|
| 36 |
+
|
| 37 |
+
If :external:exc:`ExceptionGroup` is already defined by Python itself,
|
| 38 |
+
that version is used instead.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
message: str
|
| 42 |
+
exceptions: list[Exception]
|
| 43 |
+
|
| 44 |
+
def __init__(self, message: str, exceptions: list[Exception]) -> None:
|
| 45 |
+
self.message = message
|
| 46 |
+
self.exceptions = exceptions
|
| 47 |
+
|
| 48 |
+
def __repr__(self) -> str:
|
| 49 |
+
return f"{self.__class__.__name__}({self.message!r}, {self.exceptions!r})"
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class InvalidMetadata(ValueError):
|
| 53 |
+
"""A metadata field contains invalid data."""
|
| 54 |
+
|
| 55 |
+
field: str
|
| 56 |
+
"""The name of the field that contains invalid data."""
|
| 57 |
+
|
| 58 |
+
def __init__(self, field: str, message: str) -> None:
|
| 59 |
+
self.field = field
|
| 60 |
+
super().__init__(message)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# The RawMetadata class attempts to make as few assumptions about the underlying
|
| 64 |
+
# serialization formats as possible. The idea is that as long as a serialization
|
| 65 |
+
# formats offer some very basic primitives in *some* way then we can support
|
| 66 |
+
# serializing to and from that format.
|
| 67 |
+
class RawMetadata(TypedDict, total=False):
|
| 68 |
+
"""A dictionary of raw core metadata.
|
| 69 |
+
|
| 70 |
+
Each field in core metadata maps to a key of this dictionary (when data is
|
| 71 |
+
provided). The key is lower-case and underscores are used instead of dashes
|
| 72 |
+
compared to the equivalent core metadata field. Any core metadata field that
|
| 73 |
+
can be specified multiple times or can hold multiple values in a single
|
| 74 |
+
field have a key with a plural name. See :class:`Metadata` whose attributes
|
| 75 |
+
match the keys of this dictionary.
|
| 76 |
+
|
| 77 |
+
Core metadata fields that can be specified multiple times are stored as a
|
| 78 |
+
list or dict depending on which is appropriate for the field. Any fields
|
| 79 |
+
which hold multiple values in a single field are stored as a list.
|
| 80 |
+
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
# Metadata 1.0 - PEP 241
|
| 84 |
+
metadata_version: str
|
| 85 |
+
name: str
|
| 86 |
+
version: str
|
| 87 |
+
platforms: list[str]
|
| 88 |
+
summary: str
|
| 89 |
+
description: str
|
| 90 |
+
keywords: list[str]
|
| 91 |
+
home_page: str
|
| 92 |
+
author: str
|
| 93 |
+
author_email: str
|
| 94 |
+
license: str
|
| 95 |
+
|
| 96 |
+
# Metadata 1.1 - PEP 314
|
| 97 |
+
supported_platforms: list[str]
|
| 98 |
+
download_url: str
|
| 99 |
+
classifiers: list[str]
|
| 100 |
+
requires: list[str]
|
| 101 |
+
provides: list[str]
|
| 102 |
+
obsoletes: list[str]
|
| 103 |
+
|
| 104 |
+
# Metadata 1.2 - PEP 345
|
| 105 |
+
maintainer: str
|
| 106 |
+
maintainer_email: str
|
| 107 |
+
requires_dist: list[str]
|
| 108 |
+
provides_dist: list[str]
|
| 109 |
+
obsoletes_dist: list[str]
|
| 110 |
+
requires_python: str
|
| 111 |
+
requires_external: list[str]
|
| 112 |
+
project_urls: dict[str, str]
|
| 113 |
+
|
| 114 |
+
# Metadata 2.0
|
| 115 |
+
# PEP 426 attempted to completely revamp the metadata format
|
| 116 |
+
# but got stuck without ever being able to build consensus on
|
| 117 |
+
# it and ultimately ended up withdrawn.
|
| 118 |
+
#
|
| 119 |
+
# However, a number of tools had started emitting METADATA with
|
| 120 |
+
# `2.0` Metadata-Version, so for historical reasons, this version
|
| 121 |
+
# was skipped.
|
| 122 |
+
|
| 123 |
+
# Metadata 2.1 - PEP 566
|
| 124 |
+
description_content_type: str
|
| 125 |
+
provides_extra: list[str]
|
| 126 |
+
|
| 127 |
+
# Metadata 2.2 - PEP 643
|
| 128 |
+
dynamic: list[str]
|
| 129 |
+
|
| 130 |
+
# Metadata 2.3 - PEP 685
|
| 131 |
+
# No new fields were added in PEP 685, just some edge case were
|
| 132 |
+
# tightened up to provide better interoperability.
|
| 133 |
+
|
| 134 |
+
# Metadata 2.4 - PEP 639
|
| 135 |
+
license_expression: str
|
| 136 |
+
license_files: list[str]
|
| 137 |
+
|
| 138 |
+
# Metadata 2.5 - PEP 794
|
| 139 |
+
import_names: list[str]
|
| 140 |
+
import_namespaces: list[str]
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# 'keywords' is special as it's a string in the core metadata spec, but we
|
| 144 |
+
# represent it as a list.
|
| 145 |
+
_STRING_FIELDS = {
|
| 146 |
+
"author",
|
| 147 |
+
"author_email",
|
| 148 |
+
"description",
|
| 149 |
+
"description_content_type",
|
| 150 |
+
"download_url",
|
| 151 |
+
"home_page",
|
| 152 |
+
"license",
|
| 153 |
+
"license_expression",
|
| 154 |
+
"maintainer",
|
| 155 |
+
"maintainer_email",
|
| 156 |
+
"metadata_version",
|
| 157 |
+
"name",
|
| 158 |
+
"requires_python",
|
| 159 |
+
"summary",
|
| 160 |
+
"version",
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
_LIST_FIELDS = {
|
| 164 |
+
"classifiers",
|
| 165 |
+
"dynamic",
|
| 166 |
+
"license_files",
|
| 167 |
+
"obsoletes",
|
| 168 |
+
"obsoletes_dist",
|
| 169 |
+
"platforms",
|
| 170 |
+
"provides",
|
| 171 |
+
"provides_dist",
|
| 172 |
+
"provides_extra",
|
| 173 |
+
"requires",
|
| 174 |
+
"requires_dist",
|
| 175 |
+
"requires_external",
|
| 176 |
+
"supported_platforms",
|
| 177 |
+
"import_names",
|
| 178 |
+
"import_namespaces",
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
_DICT_FIELDS = {
|
| 182 |
+
"project_urls",
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def _parse_keywords(data: str) -> list[str]:
|
| 187 |
+
"""Split a string of comma-separated keywords into a list of keywords."""
|
| 188 |
+
return [k.strip() for k in data.split(",")]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def _parse_project_urls(data: list[str]) -> dict[str, str]:
|
| 192 |
+
"""Parse a list of label/URL string pairings separated by a comma."""
|
| 193 |
+
urls = {}
|
| 194 |
+
for pair in data:
|
| 195 |
+
# Our logic is slightly tricky here as we want to try and do
|
| 196 |
+
# *something* reasonable with malformed data.
|
| 197 |
+
#
|
| 198 |
+
# The main thing that we have to worry about, is data that does
|
| 199 |
+
# not have a ',' at all to split the label from the Value. There
|
| 200 |
+
# isn't a singular right answer here, and we will fail validation
|
| 201 |
+
# later on (if the caller is validating) so it doesn't *really*
|
| 202 |
+
# matter, but since the missing value has to be an empty str
|
| 203 |
+
# and our return value is dict[str, str], if we let the key
|
| 204 |
+
# be the missing value, then they'd have multiple '' values that
|
| 205 |
+
# overwrite each other in a accumulating dict.
|
| 206 |
+
#
|
| 207 |
+
# The other potential issue is that it's possible to have the
|
| 208 |
+
# same label multiple times in the metadata, with no solid "right"
|
| 209 |
+
# answer with what to do in that case. As such, we'll do the only
|
| 210 |
+
# thing we can, which is treat the field as unparsable and add it
|
| 211 |
+
# to our list of unparsed fields.
|
| 212 |
+
#
|
| 213 |
+
# TODO: The spec doesn't say anything about if the keys should be
|
| 214 |
+
# considered case sensitive or not... logically they should
|
| 215 |
+
# be case-preserving and case-insensitive, but doing that
|
| 216 |
+
# would open up more cases where we might have duplicate
|
| 217 |
+
# entries.
|
| 218 |
+
label, _, url = (s.strip() for s in pair.partition(","))
|
| 219 |
+
|
| 220 |
+
if label in urls:
|
| 221 |
+
# The label already exists in our set of urls, so this field
|
| 222 |
+
# is unparsable, and we can just add the whole thing to our
|
| 223 |
+
# unparsable data and stop processing it.
|
| 224 |
+
raise KeyError("duplicate labels in project urls")
|
| 225 |
+
urls[label] = url
|
| 226 |
+
|
| 227 |
+
return urls
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def _get_payload(msg: email.message.Message, source: bytes | str) -> str:
|
| 231 |
+
"""Get the body of the message."""
|
| 232 |
+
# If our source is a str, then our caller has managed encodings for us,
|
| 233 |
+
# and we don't need to deal with it.
|
| 234 |
+
if isinstance(source, str):
|
| 235 |
+
payload = msg.get_payload()
|
| 236 |
+
assert isinstance(payload, str)
|
| 237 |
+
return payload
|
| 238 |
+
# If our source is a bytes, then we're managing the encoding and we need
|
| 239 |
+
# to deal with it.
|
| 240 |
+
else:
|
| 241 |
+
bpayload = msg.get_payload(decode=True)
|
| 242 |
+
assert isinstance(bpayload, bytes)
|
| 243 |
+
try:
|
| 244 |
+
return bpayload.decode("utf8", "strict")
|
| 245 |
+
except UnicodeDecodeError as exc:
|
| 246 |
+
raise ValueError("payload in an invalid encoding") from exc
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
# The various parse_FORMAT functions here are intended to be as lenient as
|
| 250 |
+
# possible in their parsing, while still returning a correctly typed
|
| 251 |
+
# RawMetadata.
|
| 252 |
+
#
|
| 253 |
+
# To aid in this, we also generally want to do as little touching of the
|
| 254 |
+
# data as possible, except where there are possibly some historic holdovers
|
| 255 |
+
# that make valid data awkward to work with.
|
| 256 |
+
#
|
| 257 |
+
# While this is a lower level, intermediate format than our ``Metadata``
|
| 258 |
+
# class, some light touch ups can make a massive difference in usability.
|
| 259 |
+
|
| 260 |
+
# Map METADATA fields to RawMetadata.
|
| 261 |
+
_EMAIL_TO_RAW_MAPPING = {
|
| 262 |
+
"author": "author",
|
| 263 |
+
"author-email": "author_email",
|
| 264 |
+
"classifier": "classifiers",
|
| 265 |
+
"description": "description",
|
| 266 |
+
"description-content-type": "description_content_type",
|
| 267 |
+
"download-url": "download_url",
|
| 268 |
+
"dynamic": "dynamic",
|
| 269 |
+
"home-page": "home_page",
|
| 270 |
+
"import-name": "import_names",
|
| 271 |
+
"import-namespace": "import_namespaces",
|
| 272 |
+
"keywords": "keywords",
|
| 273 |
+
"license": "license",
|
| 274 |
+
"license-expression": "license_expression",
|
| 275 |
+
"license-file": "license_files",
|
| 276 |
+
"maintainer": "maintainer",
|
| 277 |
+
"maintainer-email": "maintainer_email",
|
| 278 |
+
"metadata-version": "metadata_version",
|
| 279 |
+
"name": "name",
|
| 280 |
+
"obsoletes": "obsoletes",
|
| 281 |
+
"obsoletes-dist": "obsoletes_dist",
|
| 282 |
+
"platform": "platforms",
|
| 283 |
+
"project-url": "project_urls",
|
| 284 |
+
"provides": "provides",
|
| 285 |
+
"provides-dist": "provides_dist",
|
| 286 |
+
"provides-extra": "provides_extra",
|
| 287 |
+
"requires": "requires",
|
| 288 |
+
"requires-dist": "requires_dist",
|
| 289 |
+
"requires-external": "requires_external",
|
| 290 |
+
"requires-python": "requires_python",
|
| 291 |
+
"summary": "summary",
|
| 292 |
+
"supported-platform": "supported_platforms",
|
| 293 |
+
"version": "version",
|
| 294 |
+
}
|
| 295 |
+
_RAW_TO_EMAIL_MAPPING = {raw: email for email, raw in _EMAIL_TO_RAW_MAPPING.items()}
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
# This class is for writing RFC822 messages
|
| 299 |
+
class RFC822Policy(email.policy.EmailPolicy):
|
| 300 |
+
"""
|
| 301 |
+
This is :class:`email.policy.EmailPolicy`, but with a simple ``header_store_parse``
|
| 302 |
+
implementation that handles multi-line values, and some nice defaults.
|
| 303 |
+
"""
|
| 304 |
+
|
| 305 |
+
utf8 = True
|
| 306 |
+
mangle_from_ = False
|
| 307 |
+
max_line_length = 0
|
| 308 |
+
|
| 309 |
+
def header_store_parse(self, name: str, value: str) -> tuple[str, str]:
|
| 310 |
+
size = len(name) + 2
|
| 311 |
+
value = value.replace("\n", "\n" + " " * size)
|
| 312 |
+
return (name, value)
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
# This class is for writing RFC822 messages
|
| 316 |
+
class RFC822Message(email.message.EmailMessage):
|
| 317 |
+
"""
|
| 318 |
+
This is :class:`email.message.EmailMessage` with two small changes: it defaults to
|
| 319 |
+
our `RFC822Policy`, and it correctly writes unicode when being called
|
| 320 |
+
with `bytes()`.
|
| 321 |
+
"""
|
| 322 |
+
|
| 323 |
+
def __init__(self) -> None:
|
| 324 |
+
super().__init__(policy=RFC822Policy())
|
| 325 |
+
|
| 326 |
+
def as_bytes(
|
| 327 |
+
self, unixfrom: bool = False, policy: email.policy.Policy | None = None
|
| 328 |
+
) -> bytes:
|
| 329 |
+
"""
|
| 330 |
+
Return the bytes representation of the message.
|
| 331 |
+
|
| 332 |
+
This handles unicode encoding.
|
| 333 |
+
"""
|
| 334 |
+
return self.as_string(unixfrom, policy=policy).encode("utf-8")
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
def parse_email(data: bytes | str) -> tuple[RawMetadata, dict[str, list[str]]]:
|
| 338 |
+
"""Parse a distribution's metadata stored as email headers (e.g. from ``METADATA``).
|
| 339 |
+
|
| 340 |
+
This function returns a two-item tuple of dicts. The first dict is of
|
| 341 |
+
recognized fields from the core metadata specification. Fields that can be
|
| 342 |
+
parsed and translated into Python's built-in types are converted
|
| 343 |
+
appropriately. All other fields are left as-is. Fields that are allowed to
|
| 344 |
+
appear multiple times are stored as lists.
|
| 345 |
+
|
| 346 |
+
The second dict contains all other fields from the metadata. This includes
|
| 347 |
+
any unrecognized fields. It also includes any fields which are expected to
|
| 348 |
+
be parsed into a built-in type but were not formatted appropriately. Finally,
|
| 349 |
+
any fields that are expected to appear only once but are repeated are
|
| 350 |
+
included in this dict.
|
| 351 |
+
|
| 352 |
+
"""
|
| 353 |
+
raw: dict[str, str | list[str] | dict[str, str]] = {}
|
| 354 |
+
unparsed: dict[str, list[str]] = {}
|
| 355 |
+
|
| 356 |
+
if isinstance(data, str):
|
| 357 |
+
parsed = email.parser.Parser(policy=email.policy.compat32).parsestr(data)
|
| 358 |
+
else:
|
| 359 |
+
parsed = email.parser.BytesParser(policy=email.policy.compat32).parsebytes(data)
|
| 360 |
+
|
| 361 |
+
# We have to wrap parsed.keys() in a set, because in the case of multiple
|
| 362 |
+
# values for a key (a list), the key will appear multiple times in the
|
| 363 |
+
# list of keys, but we're avoiding that by using get_all().
|
| 364 |
+
for name_with_case in frozenset(parsed.keys()):
|
| 365 |
+
# Header names in RFC are case insensitive, so we'll normalize to all
|
| 366 |
+
# lower case to make comparisons easier.
|
| 367 |
+
name = name_with_case.lower()
|
| 368 |
+
|
| 369 |
+
# We use get_all() here, even for fields that aren't multiple use,
|
| 370 |
+
# because otherwise someone could have e.g. two Name fields, and we
|
| 371 |
+
# would just silently ignore it rather than doing something about it.
|
| 372 |
+
headers = parsed.get_all(name) or []
|
| 373 |
+
|
| 374 |
+
# The way the email module works when parsing bytes is that it
|
| 375 |
+
# unconditionally decodes the bytes as ascii using the surrogateescape
|
| 376 |
+
# handler. When you pull that data back out (such as with get_all() ),
|
| 377 |
+
# it looks to see if the str has any surrogate escapes, and if it does
|
| 378 |
+
# it wraps it in a Header object instead of returning the string.
|
| 379 |
+
#
|
| 380 |
+
# As such, we'll look for those Header objects, and fix up the encoding.
|
| 381 |
+
value = []
|
| 382 |
+
# Flag if we have run into any issues processing the headers, thus
|
| 383 |
+
# signalling that the data belongs in 'unparsed'.
|
| 384 |
+
valid_encoding = True
|
| 385 |
+
for h in headers:
|
| 386 |
+
# It's unclear if this can return more types than just a Header or
|
| 387 |
+
# a str, so we'll just assert here to make sure.
|
| 388 |
+
assert isinstance(h, (email.header.Header, str))
|
| 389 |
+
|
| 390 |
+
# If it's a header object, we need to do our little dance to get
|
| 391 |
+
# the real data out of it. In cases where there is invalid data
|
| 392 |
+
# we're going to end up with mojibake, but there's no obvious, good
|
| 393 |
+
# way around that without reimplementing parts of the Header object
|
| 394 |
+
# ourselves.
|
| 395 |
+
#
|
| 396 |
+
# That should be fine since, if mojibacked happens, this key is
|
| 397 |
+
# going into the unparsed dict anyways.
|
| 398 |
+
if isinstance(h, email.header.Header):
|
| 399 |
+
# The Header object stores it's data as chunks, and each chunk
|
| 400 |
+
# can be independently encoded, so we'll need to check each
|
| 401 |
+
# of them.
|
| 402 |
+
chunks: list[tuple[bytes, str | None]] = []
|
| 403 |
+
for binary, _encoding in email.header.decode_header(h):
|
| 404 |
+
try:
|
| 405 |
+
binary.decode("utf8", "strict")
|
| 406 |
+
except UnicodeDecodeError:
|
| 407 |
+
# Enable mojibake.
|
| 408 |
+
encoding = "latin1"
|
| 409 |
+
valid_encoding = False
|
| 410 |
+
else:
|
| 411 |
+
encoding = "utf8"
|
| 412 |
+
chunks.append((binary, encoding))
|
| 413 |
+
|
| 414 |
+
# Turn our chunks back into a Header object, then let that
|
| 415 |
+
# Header object do the right thing to turn them into a
|
| 416 |
+
# string for us.
|
| 417 |
+
value.append(str(email.header.make_header(chunks)))
|
| 418 |
+
# This is already a string, so just add it.
|
| 419 |
+
else:
|
| 420 |
+
value.append(h)
|
| 421 |
+
|
| 422 |
+
# We've processed all of our values to get them into a list of str,
|
| 423 |
+
# but we may have mojibake data, in which case this is an unparsed
|
| 424 |
+
# field.
|
| 425 |
+
if not valid_encoding:
|
| 426 |
+
unparsed[name] = value
|
| 427 |
+
continue
|
| 428 |
+
|
| 429 |
+
raw_name = _EMAIL_TO_RAW_MAPPING.get(name)
|
| 430 |
+
if raw_name is None:
|
| 431 |
+
# This is a bit of a weird situation, we've encountered a key that
|
| 432 |
+
# we don't know what it means, so we don't know whether it's meant
|
| 433 |
+
# to be a list or not.
|
| 434 |
+
#
|
| 435 |
+
# Since we can't really tell one way or another, we'll just leave it
|
| 436 |
+
# as a list, even though it may be a single item list, because that's
|
| 437 |
+
# what makes the most sense for email headers.
|
| 438 |
+
unparsed[name] = value
|
| 439 |
+
continue
|
| 440 |
+
|
| 441 |
+
# If this is one of our string fields, then we'll check to see if our
|
| 442 |
+
# value is a list of a single item. If it is then we'll assume that
|
| 443 |
+
# it was emitted as a single string, and unwrap the str from inside
|
| 444 |
+
# the list.
|
| 445 |
+
#
|
| 446 |
+
# If it's any other kind of data, then we haven't the faintest clue
|
| 447 |
+
# what we should parse it as, and we have to just add it to our list
|
| 448 |
+
# of unparsed stuff.
|
| 449 |
+
if raw_name in _STRING_FIELDS and len(value) == 1:
|
| 450 |
+
raw[raw_name] = value[0]
|
| 451 |
+
# If this is import_names, we need to special case the empty field
|
| 452 |
+
# case, which converts to an empty list instead of None. We can't let
|
| 453 |
+
# the empty case slip through, as it will fail validation.
|
| 454 |
+
elif raw_name == "import_names" and value == [""]:
|
| 455 |
+
raw[raw_name] = []
|
| 456 |
+
# If this is one of our list of string fields, then we can just assign
|
| 457 |
+
# the value, since email *only* has strings, and our get_all() call
|
| 458 |
+
# above ensures that this is a list.
|
| 459 |
+
elif raw_name in _LIST_FIELDS:
|
| 460 |
+
raw[raw_name] = value
|
| 461 |
+
# Special Case: Keywords
|
| 462 |
+
# The keywords field is implemented in the metadata spec as a str,
|
| 463 |
+
# but it conceptually is a list of strings, and is serialized using
|
| 464 |
+
# ", ".join(keywords), so we'll do some light data massaging to turn
|
| 465 |
+
# this into what it logically is.
|
| 466 |
+
elif raw_name == "keywords" and len(value) == 1:
|
| 467 |
+
raw[raw_name] = _parse_keywords(value[0])
|
| 468 |
+
# Special Case: Project-URL
|
| 469 |
+
# The project urls is implemented in the metadata spec as a list of
|
| 470 |
+
# specially-formatted strings that represent a key and a value, which
|
| 471 |
+
# is fundamentally a mapping, however the email format doesn't support
|
| 472 |
+
# mappings in a sane way, so it was crammed into a list of strings
|
| 473 |
+
# instead.
|
| 474 |
+
#
|
| 475 |
+
# We will do a little light data massaging to turn this into a map as
|
| 476 |
+
# it logically should be.
|
| 477 |
+
elif raw_name == "project_urls":
|
| 478 |
+
try:
|
| 479 |
+
raw[raw_name] = _parse_project_urls(value)
|
| 480 |
+
except KeyError:
|
| 481 |
+
unparsed[name] = value
|
| 482 |
+
# Nothing that we've done has managed to parse this, so it'll just
|
| 483 |
+
# throw it in our unparsable data and move on.
|
| 484 |
+
else:
|
| 485 |
+
unparsed[name] = value
|
| 486 |
+
|
| 487 |
+
# We need to support getting the Description from the message payload in
|
| 488 |
+
# addition to getting it from the the headers. This does mean, though, there
|
| 489 |
+
# is the possibility of it being set both ways, in which case we put both
|
| 490 |
+
# in 'unparsed' since we don't know which is right.
|
| 491 |
+
try:
|
| 492 |
+
payload = _get_payload(parsed, data)
|
| 493 |
+
except ValueError:
|
| 494 |
+
unparsed.setdefault("description", []).append(
|
| 495 |
+
parsed.get_payload(decode=isinstance(data, bytes)) # type: ignore[call-overload]
|
| 496 |
+
)
|
| 497 |
+
else:
|
| 498 |
+
if payload:
|
| 499 |
+
# Check to see if we've already got a description, if so then both
|
| 500 |
+
# it, and this body move to unparsable.
|
| 501 |
+
if "description" in raw:
|
| 502 |
+
description_header = cast("str", raw.pop("description"))
|
| 503 |
+
unparsed.setdefault("description", []).extend(
|
| 504 |
+
[description_header, payload]
|
| 505 |
+
)
|
| 506 |
+
elif "description" in unparsed:
|
| 507 |
+
unparsed["description"].append(payload)
|
| 508 |
+
else:
|
| 509 |
+
raw["description"] = payload
|
| 510 |
+
|
| 511 |
+
# We need to cast our `raw` to a metadata, because a TypedDict only support
|
| 512 |
+
# literal key names, but we're computing our key names on purpose, but the
|
| 513 |
+
# way this function is implemented, our `TypedDict` can only have valid key
|
| 514 |
+
# names.
|
| 515 |
+
return cast("RawMetadata", raw), unparsed
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
_NOT_FOUND = object()
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
# Keep the two values in sync.
|
| 522 |
+
_VALID_METADATA_VERSIONS = ["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4", "2.5"]
|
| 523 |
+
_MetadataVersion = Literal["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4", "2.5"]
|
| 524 |
+
|
| 525 |
+
_REQUIRED_ATTRS = frozenset(["metadata_version", "name", "version"])
|
| 526 |
+
|
| 527 |
+
|
| 528 |
+
class _Validator(Generic[T]):
|
| 529 |
+
"""Validate a metadata field.
|
| 530 |
+
|
| 531 |
+
All _process_*() methods correspond to a core metadata field. The method is
|
| 532 |
+
called with the field's raw value. If the raw value is valid it is returned
|
| 533 |
+
in its "enriched" form (e.g. ``version.Version`` for the ``Version`` field).
|
| 534 |
+
If the raw value is invalid, :exc:`InvalidMetadata` is raised (with a cause
|
| 535 |
+
as appropriate).
|
| 536 |
+
"""
|
| 537 |
+
|
| 538 |
+
name: str
|
| 539 |
+
raw_name: str
|
| 540 |
+
added: _MetadataVersion
|
| 541 |
+
|
| 542 |
+
def __init__(
|
| 543 |
+
self,
|
| 544 |
+
*,
|
| 545 |
+
added: _MetadataVersion = "1.0",
|
| 546 |
+
) -> None:
|
| 547 |
+
self.added = added
|
| 548 |
+
|
| 549 |
+
def __set_name__(self, _owner: Metadata, name: str) -> None:
|
| 550 |
+
self.name = name
|
| 551 |
+
self.raw_name = _RAW_TO_EMAIL_MAPPING[name]
|
| 552 |
+
|
| 553 |
+
def __get__(self, instance: Metadata, _owner: type[Metadata]) -> T:
|
| 554 |
+
# With Python 3.8, the caching can be replaced with functools.cached_property().
|
| 555 |
+
# No need to check the cache as attribute lookup will resolve into the
|
| 556 |
+
# instance's __dict__ before __get__ is called.
|
| 557 |
+
cache = instance.__dict__
|
| 558 |
+
value = instance._raw.get(self.name)
|
| 559 |
+
|
| 560 |
+
# To make the _process_* methods easier, we'll check if the value is None
|
| 561 |
+
# and if this field is NOT a required attribute, and if both of those
|
| 562 |
+
# things are true, we'll skip the the converter. This will mean that the
|
| 563 |
+
# converters never have to deal with the None union.
|
| 564 |
+
if self.name in _REQUIRED_ATTRS or value is not None:
|
| 565 |
+
try:
|
| 566 |
+
converter: Callable[[Any], T] = getattr(self, f"_process_{self.name}")
|
| 567 |
+
except AttributeError:
|
| 568 |
+
pass
|
| 569 |
+
else:
|
| 570 |
+
value = converter(value)
|
| 571 |
+
|
| 572 |
+
cache[self.name] = value
|
| 573 |
+
try:
|
| 574 |
+
del instance._raw[self.name] # type: ignore[misc]
|
| 575 |
+
except KeyError:
|
| 576 |
+
pass
|
| 577 |
+
|
| 578 |
+
return cast("T", value)
|
| 579 |
+
|
| 580 |
+
def _invalid_metadata(
|
| 581 |
+
self, msg: str, cause: Exception | None = None
|
| 582 |
+
) -> InvalidMetadata:
|
| 583 |
+
exc = InvalidMetadata(
|
| 584 |
+
self.raw_name, msg.format_map({"field": repr(self.raw_name)})
|
| 585 |
+
)
|
| 586 |
+
exc.__cause__ = cause
|
| 587 |
+
return exc
|
| 588 |
+
|
| 589 |
+
def _process_metadata_version(self, value: str) -> _MetadataVersion:
|
| 590 |
+
# Implicitly makes Metadata-Version required.
|
| 591 |
+
if value not in _VALID_METADATA_VERSIONS:
|
| 592 |
+
raise self._invalid_metadata(f"{value!r} is not a valid metadata version")
|
| 593 |
+
return cast("_MetadataVersion", value)
|
| 594 |
+
|
| 595 |
+
def _process_name(self, value: str) -> str:
|
| 596 |
+
if not value:
|
| 597 |
+
raise self._invalid_metadata("{field} is a required field")
|
| 598 |
+
# Validate the name as a side-effect.
|
| 599 |
+
try:
|
| 600 |
+
utils.canonicalize_name(value, validate=True)
|
| 601 |
+
except utils.InvalidName as exc:
|
| 602 |
+
raise self._invalid_metadata(
|
| 603 |
+
f"{value!r} is invalid for {{field}}", cause=exc
|
| 604 |
+
) from exc
|
| 605 |
+
else:
|
| 606 |
+
return value
|
| 607 |
+
|
| 608 |
+
def _process_version(self, value: str) -> version_module.Version:
|
| 609 |
+
if not value:
|
| 610 |
+
raise self._invalid_metadata("{field} is a required field")
|
| 611 |
+
try:
|
| 612 |
+
return version_module.parse(value)
|
| 613 |
+
except version_module.InvalidVersion as exc:
|
| 614 |
+
raise self._invalid_metadata(
|
| 615 |
+
f"{value!r} is invalid for {{field}}", cause=exc
|
| 616 |
+
) from exc
|
| 617 |
+
|
| 618 |
+
def _process_summary(self, value: str) -> str:
|
| 619 |
+
"""Check the field contains no newlines."""
|
| 620 |
+
if "\n" in value:
|
| 621 |
+
raise self._invalid_metadata("{field} must be a single line")
|
| 622 |
+
return value
|
| 623 |
+
|
| 624 |
+
def _process_description_content_type(self, value: str) -> str:
|
| 625 |
+
content_types = {"text/plain", "text/x-rst", "text/markdown"}
|
| 626 |
+
message = email.message.EmailMessage()
|
| 627 |
+
message["content-type"] = value
|
| 628 |
+
|
| 629 |
+
content_type, parameters = (
|
| 630 |
+
# Defaults to `text/plain` if parsing failed.
|
| 631 |
+
message.get_content_type().lower(),
|
| 632 |
+
message["content-type"].params,
|
| 633 |
+
)
|
| 634 |
+
# Check if content-type is valid or defaulted to `text/plain` and thus was
|
| 635 |
+
# not parseable.
|
| 636 |
+
if content_type not in content_types or content_type not in value.lower():
|
| 637 |
+
raise self._invalid_metadata(
|
| 638 |
+
f"{{field}} must be one of {list(content_types)}, not {value!r}"
|
| 639 |
+
)
|
| 640 |
+
|
| 641 |
+
charset = parameters.get("charset", "UTF-8")
|
| 642 |
+
if charset != "UTF-8":
|
| 643 |
+
raise self._invalid_metadata(
|
| 644 |
+
f"{{field}} can only specify the UTF-8 charset, not {list(charset)}"
|
| 645 |
+
)
|
| 646 |
+
|
| 647 |
+
markdown_variants = {"GFM", "CommonMark"}
|
| 648 |
+
variant = parameters.get("variant", "GFM") # Use an acceptable default.
|
| 649 |
+
if content_type == "text/markdown" and variant not in markdown_variants:
|
| 650 |
+
raise self._invalid_metadata(
|
| 651 |
+
f"valid Markdown variants for {{field}} are {list(markdown_variants)}, "
|
| 652 |
+
f"not {variant!r}",
|
| 653 |
+
)
|
| 654 |
+
return value
|
| 655 |
+
|
| 656 |
+
def _process_dynamic(self, value: list[str]) -> list[str]:
|
| 657 |
+
for dynamic_field in map(str.lower, value):
|
| 658 |
+
if dynamic_field in {"name", "version", "metadata-version"}:
|
| 659 |
+
raise self._invalid_metadata(
|
| 660 |
+
f"{dynamic_field!r} is not allowed as a dynamic field"
|
| 661 |
+
)
|
| 662 |
+
elif dynamic_field not in _EMAIL_TO_RAW_MAPPING:
|
| 663 |
+
raise self._invalid_metadata(
|
| 664 |
+
f"{dynamic_field!r} is not a valid dynamic field"
|
| 665 |
+
)
|
| 666 |
+
return list(map(str.lower, value))
|
| 667 |
+
|
| 668 |
+
def _process_provides_extra(
|
| 669 |
+
self,
|
| 670 |
+
value: list[str],
|
| 671 |
+
) -> list[utils.NormalizedName]:
|
| 672 |
+
normalized_names = []
|
| 673 |
+
try:
|
| 674 |
+
for name in value:
|
| 675 |
+
normalized_names.append(utils.canonicalize_name(name, validate=True))
|
| 676 |
+
except utils.InvalidName as exc:
|
| 677 |
+
raise self._invalid_metadata(
|
| 678 |
+
f"{name!r} is invalid for {{field}}", cause=exc
|
| 679 |
+
) from exc
|
| 680 |
+
else:
|
| 681 |
+
return normalized_names
|
| 682 |
+
|
| 683 |
+
def _process_requires_python(self, value: str) -> specifiers.SpecifierSet:
|
| 684 |
+
try:
|
| 685 |
+
return specifiers.SpecifierSet(value)
|
| 686 |
+
except specifiers.InvalidSpecifier as exc:
|
| 687 |
+
raise self._invalid_metadata(
|
| 688 |
+
f"{value!r} is invalid for {{field}}", cause=exc
|
| 689 |
+
) from exc
|
| 690 |
+
|
| 691 |
+
def _process_requires_dist(
|
| 692 |
+
self,
|
| 693 |
+
value: list[str],
|
| 694 |
+
) -> list[requirements.Requirement]:
|
| 695 |
+
reqs = []
|
| 696 |
+
try:
|
| 697 |
+
for req in value:
|
| 698 |
+
reqs.append(requirements.Requirement(req))
|
| 699 |
+
except requirements.InvalidRequirement as exc:
|
| 700 |
+
raise self._invalid_metadata(
|
| 701 |
+
f"{req!r} is invalid for {{field}}", cause=exc
|
| 702 |
+
) from exc
|
| 703 |
+
else:
|
| 704 |
+
return reqs
|
| 705 |
+
|
| 706 |
+
def _process_license_expression(self, value: str) -> NormalizedLicenseExpression:
|
| 707 |
+
try:
|
| 708 |
+
return licenses.canonicalize_license_expression(value)
|
| 709 |
+
except ValueError as exc:
|
| 710 |
+
raise self._invalid_metadata(
|
| 711 |
+
f"{value!r} is invalid for {{field}}", cause=exc
|
| 712 |
+
) from exc
|
| 713 |
+
|
| 714 |
+
def _process_license_files(self, value: list[str]) -> list[str]:
|
| 715 |
+
paths = []
|
| 716 |
+
for path in value:
|
| 717 |
+
if ".." in path:
|
| 718 |
+
raise self._invalid_metadata(
|
| 719 |
+
f"{path!r} is invalid for {{field}}, "
|
| 720 |
+
"parent directory indicators are not allowed"
|
| 721 |
+
)
|
| 722 |
+
if "*" in path:
|
| 723 |
+
raise self._invalid_metadata(
|
| 724 |
+
f"{path!r} is invalid for {{field}}, paths must be resolved"
|
| 725 |
+
)
|
| 726 |
+
if (
|
| 727 |
+
pathlib.PurePosixPath(path).is_absolute()
|
| 728 |
+
or pathlib.PureWindowsPath(path).is_absolute()
|
| 729 |
+
):
|
| 730 |
+
raise self._invalid_metadata(
|
| 731 |
+
f"{path!r} is invalid for {{field}}, paths must be relative"
|
| 732 |
+
)
|
| 733 |
+
if pathlib.PureWindowsPath(path).as_posix() != path:
|
| 734 |
+
raise self._invalid_metadata(
|
| 735 |
+
f"{path!r} is invalid for {{field}}, paths must use '/' delimiter"
|
| 736 |
+
)
|
| 737 |
+
paths.append(path)
|
| 738 |
+
return paths
|
| 739 |
+
|
| 740 |
+
def _process_import_names(self, value: list[str]) -> list[str]:
|
| 741 |
+
for import_name in value:
|
| 742 |
+
name, semicolon, private = import_name.partition(";")
|
| 743 |
+
name = name.rstrip()
|
| 744 |
+
for identifier in name.split("."):
|
| 745 |
+
if not identifier.isidentifier():
|
| 746 |
+
raise self._invalid_metadata(
|
| 747 |
+
f"{name!r} is invalid for {{field}}; "
|
| 748 |
+
f"{identifier!r} is not a valid identifier"
|
| 749 |
+
)
|
| 750 |
+
elif keyword.iskeyword(identifier):
|
| 751 |
+
raise self._invalid_metadata(
|
| 752 |
+
f"{name!r} is invalid for {{field}}; "
|
| 753 |
+
f"{identifier!r} is a keyword"
|
| 754 |
+
)
|
| 755 |
+
if semicolon and private.lstrip() != "private":
|
| 756 |
+
raise self._invalid_metadata(
|
| 757 |
+
f"{import_name!r} is invalid for {{field}}; "
|
| 758 |
+
"the only valid option is 'private'"
|
| 759 |
+
)
|
| 760 |
+
return value
|
| 761 |
+
|
| 762 |
+
_process_import_namespaces = _process_import_names
|
| 763 |
+
|
| 764 |
+
|
| 765 |
+
class Metadata:
|
| 766 |
+
"""Representation of distribution metadata.
|
| 767 |
+
|
| 768 |
+
Compared to :class:`RawMetadata`, this class provides objects representing
|
| 769 |
+
metadata fields instead of only using built-in types. Any invalid metadata
|
| 770 |
+
will cause :exc:`InvalidMetadata` to be raised (with a
|
| 771 |
+
:py:attr:`~BaseException.__cause__` attribute as appropriate).
|
| 772 |
+
"""
|
| 773 |
+
|
| 774 |
+
_raw: RawMetadata
|
| 775 |
+
|
| 776 |
+
@classmethod
|
| 777 |
+
def from_raw(cls, data: RawMetadata, *, validate: bool = True) -> Metadata:
|
| 778 |
+
"""Create an instance from :class:`RawMetadata`.
|
| 779 |
+
|
| 780 |
+
If *validate* is true, all metadata will be validated. All exceptions
|
| 781 |
+
related to validation will be gathered and raised as an :class:`ExceptionGroup`.
|
| 782 |
+
"""
|
| 783 |
+
ins = cls()
|
| 784 |
+
ins._raw = data.copy() # Mutations occur due to caching enriched values.
|
| 785 |
+
|
| 786 |
+
if validate:
|
| 787 |
+
exceptions: list[Exception] = []
|
| 788 |
+
try:
|
| 789 |
+
metadata_version = ins.metadata_version
|
| 790 |
+
metadata_age = _VALID_METADATA_VERSIONS.index(metadata_version)
|
| 791 |
+
except InvalidMetadata as metadata_version_exc:
|
| 792 |
+
exceptions.append(metadata_version_exc)
|
| 793 |
+
metadata_version = None
|
| 794 |
+
|
| 795 |
+
# Make sure to check for the fields that are present, the required
|
| 796 |
+
# fields (so their absence can be reported).
|
| 797 |
+
fields_to_check = frozenset(ins._raw) | _REQUIRED_ATTRS
|
| 798 |
+
# Remove fields that have already been checked.
|
| 799 |
+
fields_to_check -= {"metadata_version"}
|
| 800 |
+
|
| 801 |
+
for key in fields_to_check:
|
| 802 |
+
try:
|
| 803 |
+
if metadata_version:
|
| 804 |
+
# Can't use getattr() as that triggers descriptor protocol which
|
| 805 |
+
# will fail due to no value for the instance argument.
|
| 806 |
+
try:
|
| 807 |
+
field_metadata_version = cls.__dict__[key].added
|
| 808 |
+
except KeyError:
|
| 809 |
+
exc = InvalidMetadata(key, f"unrecognized field: {key!r}")
|
| 810 |
+
exceptions.append(exc)
|
| 811 |
+
continue
|
| 812 |
+
field_age = _VALID_METADATA_VERSIONS.index(
|
| 813 |
+
field_metadata_version
|
| 814 |
+
)
|
| 815 |
+
if field_age > metadata_age:
|
| 816 |
+
field = _RAW_TO_EMAIL_MAPPING[key]
|
| 817 |
+
exc = InvalidMetadata(
|
| 818 |
+
field,
|
| 819 |
+
f"{field} introduced in metadata version "
|
| 820 |
+
f"{field_metadata_version}, not {metadata_version}",
|
| 821 |
+
)
|
| 822 |
+
exceptions.append(exc)
|
| 823 |
+
continue
|
| 824 |
+
getattr(ins, key)
|
| 825 |
+
except InvalidMetadata as exc:
|
| 826 |
+
exceptions.append(exc)
|
| 827 |
+
|
| 828 |
+
if exceptions:
|
| 829 |
+
raise ExceptionGroup("invalid metadata", exceptions)
|
| 830 |
+
|
| 831 |
+
return ins
|
| 832 |
+
|
| 833 |
+
@classmethod
|
| 834 |
+
def from_email(cls, data: bytes | str, *, validate: bool = True) -> Metadata:
|
| 835 |
+
"""Parse metadata from email headers.
|
| 836 |
+
|
| 837 |
+
If *validate* is true, the metadata will be validated. All exceptions
|
| 838 |
+
related to validation will be gathered and raised as an :class:`ExceptionGroup`.
|
| 839 |
+
"""
|
| 840 |
+
raw, unparsed = parse_email(data)
|
| 841 |
+
|
| 842 |
+
if validate:
|
| 843 |
+
exceptions: list[Exception] = []
|
| 844 |
+
for unparsed_key in unparsed:
|
| 845 |
+
if unparsed_key in _EMAIL_TO_RAW_MAPPING:
|
| 846 |
+
message = f"{unparsed_key!r} has invalid data"
|
| 847 |
+
else:
|
| 848 |
+
message = f"unrecognized field: {unparsed_key!r}"
|
| 849 |
+
exceptions.append(InvalidMetadata(unparsed_key, message))
|
| 850 |
+
|
| 851 |
+
if exceptions:
|
| 852 |
+
raise ExceptionGroup("unparsed", exceptions)
|
| 853 |
+
|
| 854 |
+
try:
|
| 855 |
+
return cls.from_raw(raw, validate=validate)
|
| 856 |
+
except ExceptionGroup as exc_group:
|
| 857 |
+
raise ExceptionGroup(
|
| 858 |
+
"invalid or unparsed metadata", exc_group.exceptions
|
| 859 |
+
) from None
|
| 860 |
+
|
| 861 |
+
metadata_version: _Validator[_MetadataVersion] = _Validator()
|
| 862 |
+
""":external:ref:`core-metadata-metadata-version`
|
| 863 |
+
(required; validated to be a valid metadata version)"""
|
| 864 |
+
# `name` is not normalized/typed to NormalizedName so as to provide access to
|
| 865 |
+
# the original/raw name.
|
| 866 |
+
name: _Validator[str] = _Validator()
|
| 867 |
+
""":external:ref:`core-metadata-name`
|
| 868 |
+
(required; validated using :func:`~packaging.utils.canonicalize_name` and its
|
| 869 |
+
*validate* parameter)"""
|
| 870 |
+
version: _Validator[version_module.Version] = _Validator()
|
| 871 |
+
""":external:ref:`core-metadata-version` (required)"""
|
| 872 |
+
dynamic: _Validator[list[str] | None] = _Validator(
|
| 873 |
+
added="2.2",
|
| 874 |
+
)
|
| 875 |
+
""":external:ref:`core-metadata-dynamic`
|
| 876 |
+
(validated against core metadata field names and lowercased)"""
|
| 877 |
+
platforms: _Validator[list[str] | None] = _Validator()
|
| 878 |
+
""":external:ref:`core-metadata-platform`"""
|
| 879 |
+
supported_platforms: _Validator[list[str] | None] = _Validator(added="1.1")
|
| 880 |
+
""":external:ref:`core-metadata-supported-platform`"""
|
| 881 |
+
summary: _Validator[str | None] = _Validator()
|
| 882 |
+
""":external:ref:`core-metadata-summary` (validated to contain no newlines)"""
|
| 883 |
+
description: _Validator[str | None] = _Validator() # TODO 2.1: can be in body
|
| 884 |
+
""":external:ref:`core-metadata-description`"""
|
| 885 |
+
description_content_type: _Validator[str | None] = _Validator(added="2.1")
|
| 886 |
+
""":external:ref:`core-metadata-description-content-type` (validated)"""
|
| 887 |
+
keywords: _Validator[list[str] | None] = _Validator()
|
| 888 |
+
""":external:ref:`core-metadata-keywords`"""
|
| 889 |
+
home_page: _Validator[str | None] = _Validator()
|
| 890 |
+
""":external:ref:`core-metadata-home-page`"""
|
| 891 |
+
download_url: _Validator[str | None] = _Validator(added="1.1")
|
| 892 |
+
""":external:ref:`core-metadata-download-url`"""
|
| 893 |
+
author: _Validator[str | None] = _Validator()
|
| 894 |
+
""":external:ref:`core-metadata-author`"""
|
| 895 |
+
author_email: _Validator[str | None] = _Validator()
|
| 896 |
+
""":external:ref:`core-metadata-author-email`"""
|
| 897 |
+
maintainer: _Validator[str | None] = _Validator(added="1.2")
|
| 898 |
+
""":external:ref:`core-metadata-maintainer`"""
|
| 899 |
+
maintainer_email: _Validator[str | None] = _Validator(added="1.2")
|
| 900 |
+
""":external:ref:`core-metadata-maintainer-email`"""
|
| 901 |
+
license: _Validator[str | None] = _Validator()
|
| 902 |
+
""":external:ref:`core-metadata-license`"""
|
| 903 |
+
license_expression: _Validator[NormalizedLicenseExpression | None] = _Validator(
|
| 904 |
+
added="2.4"
|
| 905 |
+
)
|
| 906 |
+
""":external:ref:`core-metadata-license-expression`"""
|
| 907 |
+
license_files: _Validator[list[str] | None] = _Validator(added="2.4")
|
| 908 |
+
""":external:ref:`core-metadata-license-file`"""
|
| 909 |
+
classifiers: _Validator[list[str] | None] = _Validator(added="1.1")
|
| 910 |
+
""":external:ref:`core-metadata-classifier`"""
|
| 911 |
+
requires_dist: _Validator[list[requirements.Requirement] | None] = _Validator(
|
| 912 |
+
added="1.2"
|
| 913 |
+
)
|
| 914 |
+
""":external:ref:`core-metadata-requires-dist`"""
|
| 915 |
+
requires_python: _Validator[specifiers.SpecifierSet | None] = _Validator(
|
| 916 |
+
added="1.2"
|
| 917 |
+
)
|
| 918 |
+
""":external:ref:`core-metadata-requires-python`"""
|
| 919 |
+
# Because `Requires-External` allows for non-PEP 440 version specifiers, we
|
| 920 |
+
# don't do any processing on the values.
|
| 921 |
+
requires_external: _Validator[list[str] | None] = _Validator(added="1.2")
|
| 922 |
+
""":external:ref:`core-metadata-requires-external`"""
|
| 923 |
+
project_urls: _Validator[dict[str, str] | None] = _Validator(added="1.2")
|
| 924 |
+
""":external:ref:`core-metadata-project-url`"""
|
| 925 |
+
# PEP 685 lets us raise an error if an extra doesn't pass `Name` validation
|
| 926 |
+
# regardless of metadata version.
|
| 927 |
+
provides_extra: _Validator[list[utils.NormalizedName] | None] = _Validator(
|
| 928 |
+
added="2.1",
|
| 929 |
+
)
|
| 930 |
+
""":external:ref:`core-metadata-provides-extra`"""
|
| 931 |
+
provides_dist: _Validator[list[str] | None] = _Validator(added="1.2")
|
| 932 |
+
""":external:ref:`core-metadata-provides-dist`"""
|
| 933 |
+
obsoletes_dist: _Validator[list[str] | None] = _Validator(added="1.2")
|
| 934 |
+
""":external:ref:`core-metadata-obsoletes-dist`"""
|
| 935 |
+
import_names: _Validator[list[str] | None] = _Validator(added="2.5")
|
| 936 |
+
""":external:ref:`core-metadata-import-name`"""
|
| 937 |
+
import_namespaces: _Validator[list[str] | None] = _Validator(added="2.5")
|
| 938 |
+
""":external:ref:`core-metadata-import-namespace`"""
|
| 939 |
+
requires: _Validator[list[str] | None] = _Validator(added="1.1")
|
| 940 |
+
"""``Requires`` (deprecated)"""
|
| 941 |
+
provides: _Validator[list[str] | None] = _Validator(added="1.1")
|
| 942 |
+
"""``Provides`` (deprecated)"""
|
| 943 |
+
obsoletes: _Validator[list[str] | None] = _Validator(added="1.1")
|
| 944 |
+
"""``Obsoletes`` (deprecated)"""
|
| 945 |
+
|
| 946 |
+
def as_rfc822(self) -> RFC822Message:
|
| 947 |
+
"""
|
| 948 |
+
Return an RFC822 message with the metadata.
|
| 949 |
+
"""
|
| 950 |
+
message = RFC822Message()
|
| 951 |
+
self._write_metadata(message)
|
| 952 |
+
return message
|
| 953 |
+
|
| 954 |
+
def _write_metadata(self, message: RFC822Message) -> None:
|
| 955 |
+
"""
|
| 956 |
+
Return an RFC822 message with the metadata.
|
| 957 |
+
"""
|
| 958 |
+
for name, validator in self.__class__.__dict__.items():
|
| 959 |
+
if isinstance(validator, _Validator) and name != "description":
|
| 960 |
+
value = getattr(self, name)
|
| 961 |
+
email_name = _RAW_TO_EMAIL_MAPPING[name]
|
| 962 |
+
if value is not None:
|
| 963 |
+
if email_name == "project-url":
|
| 964 |
+
for label, url in value.items():
|
| 965 |
+
message[email_name] = f"{label}, {url}"
|
| 966 |
+
elif email_name == "keywords":
|
| 967 |
+
message[email_name] = ",".join(value)
|
| 968 |
+
elif email_name == "import-name" and value == []:
|
| 969 |
+
message[email_name] = ""
|
| 970 |
+
elif isinstance(value, list):
|
| 971 |
+
for item in value:
|
| 972 |
+
message[email_name] = str(item)
|
| 973 |
+
else:
|
| 974 |
+
message[email_name] = str(value)
|
| 975 |
+
|
| 976 |
+
# The description is a special case because it is in the body of the message.
|
| 977 |
+
if self.description is not None:
|
| 978 |
+
message.set_payload(self.description)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/py.typed
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/pylock.py
ADDED
|
@@ -0,0 +1,635 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import dataclasses
|
| 4 |
+
import logging
|
| 5 |
+
import re
|
| 6 |
+
from collections.abc import Mapping, Sequence
|
| 7 |
+
from dataclasses import dataclass
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
from typing import (
|
| 10 |
+
TYPE_CHECKING,
|
| 11 |
+
Any,
|
| 12 |
+
Callable,
|
| 13 |
+
Protocol,
|
| 14 |
+
TypeVar,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
from .markers import Marker
|
| 18 |
+
from .specifiers import SpecifierSet
|
| 19 |
+
from .utils import NormalizedName, is_normalized_name
|
| 20 |
+
from .version import Version
|
| 21 |
+
|
| 22 |
+
if TYPE_CHECKING: # pragma: no cover
|
| 23 |
+
from pathlib import Path
|
| 24 |
+
|
| 25 |
+
from typing_extensions import Self
|
| 26 |
+
|
| 27 |
+
_logger = logging.getLogger(__name__)
|
| 28 |
+
|
| 29 |
+
__all__ = [
|
| 30 |
+
"Package",
|
| 31 |
+
"PackageArchive",
|
| 32 |
+
"PackageDirectory",
|
| 33 |
+
"PackageSdist",
|
| 34 |
+
"PackageVcs",
|
| 35 |
+
"PackageWheel",
|
| 36 |
+
"Pylock",
|
| 37 |
+
"PylockUnsupportedVersionError",
|
| 38 |
+
"PylockValidationError",
|
| 39 |
+
"is_valid_pylock_path",
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
_T = TypeVar("_T")
|
| 43 |
+
_T2 = TypeVar("_T2")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class _FromMappingProtocol(Protocol): # pragma: no cover
|
| 47 |
+
@classmethod
|
| 48 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self: ...
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
_FromMappingProtocolT = TypeVar("_FromMappingProtocolT", bound=_FromMappingProtocol)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
_PYLOCK_FILE_NAME_RE = re.compile(r"^pylock\.([^.]+)\.toml$")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def is_valid_pylock_path(path: Path) -> bool:
|
| 58 |
+
"""Check if the given path is a valid pylock file path."""
|
| 59 |
+
return path.name == "pylock.toml" or bool(_PYLOCK_FILE_NAME_RE.match(path.name))
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _toml_key(key: str) -> str:
|
| 63 |
+
return key.replace("_", "-")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def _toml_value(key: str, value: Any) -> Any: # noqa: ANN401
|
| 67 |
+
if isinstance(value, (Version, Marker, SpecifierSet)):
|
| 68 |
+
return str(value)
|
| 69 |
+
if isinstance(value, Sequence) and key == "environments":
|
| 70 |
+
return [str(v) for v in value]
|
| 71 |
+
return value
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _toml_dict_factory(data: list[tuple[str, Any]]) -> dict[str, Any]:
|
| 75 |
+
return {
|
| 76 |
+
_toml_key(key): _toml_value(key, value)
|
| 77 |
+
for key, value in data
|
| 78 |
+
if value is not None
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _get(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T | None:
|
| 83 |
+
"""Get a value from the dictionary and verify it's the expected type."""
|
| 84 |
+
if (value := d.get(key)) is None:
|
| 85 |
+
return None
|
| 86 |
+
if not isinstance(value, expected_type):
|
| 87 |
+
raise PylockValidationError(
|
| 88 |
+
f"Unexpected type {type(value).__name__} "
|
| 89 |
+
f"(expected {expected_type.__name__})",
|
| 90 |
+
context=key,
|
| 91 |
+
)
|
| 92 |
+
return value
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def _get_required(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T:
|
| 96 |
+
"""Get a required value from the dictionary and verify it's the expected type."""
|
| 97 |
+
if (value := _get(d, expected_type, key)) is None:
|
| 98 |
+
raise _PylockRequiredKeyError(key)
|
| 99 |
+
return value
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _get_sequence(
|
| 103 |
+
d: Mapping[str, Any], expected_item_type: type[_T], key: str
|
| 104 |
+
) -> Sequence[_T] | None:
|
| 105 |
+
"""Get a list value from the dictionary and verify it's the expected items type."""
|
| 106 |
+
if (value := _get(d, Sequence, key)) is None: # type: ignore[type-abstract]
|
| 107 |
+
return None
|
| 108 |
+
if isinstance(value, (str, bytes)):
|
| 109 |
+
# special case: str and bytes are Sequences, but we want to reject it
|
| 110 |
+
raise PylockValidationError(
|
| 111 |
+
f"Unexpected type {type(value).__name__} (expected Sequence)",
|
| 112 |
+
context=key,
|
| 113 |
+
)
|
| 114 |
+
for i, item in enumerate(value):
|
| 115 |
+
if not isinstance(item, expected_item_type):
|
| 116 |
+
raise PylockValidationError(
|
| 117 |
+
f"Unexpected type {type(item).__name__} "
|
| 118 |
+
f"(expected {expected_item_type.__name__})",
|
| 119 |
+
context=f"{key}[{i}]",
|
| 120 |
+
)
|
| 121 |
+
return value
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _get_as(
|
| 125 |
+
d: Mapping[str, Any],
|
| 126 |
+
expected_type: type[_T],
|
| 127 |
+
target_type: Callable[[_T], _T2],
|
| 128 |
+
key: str,
|
| 129 |
+
) -> _T2 | None:
|
| 130 |
+
"""Get a value from the dictionary, verify it's the expected type,
|
| 131 |
+
and convert to the target type.
|
| 132 |
+
|
| 133 |
+
This assumes the target_type constructor accepts the value.
|
| 134 |
+
"""
|
| 135 |
+
if (value := _get(d, expected_type, key)) is None:
|
| 136 |
+
return None
|
| 137 |
+
try:
|
| 138 |
+
return target_type(value)
|
| 139 |
+
except Exception as e:
|
| 140 |
+
raise PylockValidationError(e, context=key) from e
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def _get_required_as(
|
| 144 |
+
d: Mapping[str, Any],
|
| 145 |
+
expected_type: type[_T],
|
| 146 |
+
target_type: Callable[[_T], _T2],
|
| 147 |
+
key: str,
|
| 148 |
+
) -> _T2:
|
| 149 |
+
"""Get a required value from the dict, verify it's the expected type,
|
| 150 |
+
and convert to the target type."""
|
| 151 |
+
if (value := _get_as(d, expected_type, target_type, key)) is None:
|
| 152 |
+
raise _PylockRequiredKeyError(key)
|
| 153 |
+
return value
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def _get_sequence_as(
|
| 157 |
+
d: Mapping[str, Any],
|
| 158 |
+
expected_item_type: type[_T],
|
| 159 |
+
target_item_type: Callable[[_T], _T2],
|
| 160 |
+
key: str,
|
| 161 |
+
) -> list[_T2] | None:
|
| 162 |
+
"""Get list value from dictionary and verify expected items type."""
|
| 163 |
+
if (value := _get_sequence(d, expected_item_type, key)) is None:
|
| 164 |
+
return None
|
| 165 |
+
result = []
|
| 166 |
+
try:
|
| 167 |
+
for item in value:
|
| 168 |
+
typed_item = target_item_type(item)
|
| 169 |
+
result.append(typed_item)
|
| 170 |
+
except Exception as e:
|
| 171 |
+
raise PylockValidationError(e, context=f"{key}[{len(result)}]") from e
|
| 172 |
+
return result
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def _get_object(
|
| 176 |
+
d: Mapping[str, Any], target_type: type[_FromMappingProtocolT], key: str
|
| 177 |
+
) -> _FromMappingProtocolT | None:
|
| 178 |
+
"""Get a dictionary value from the dictionary and convert it to a dataclass."""
|
| 179 |
+
if (value := _get(d, Mapping, key)) is None: # type: ignore[type-abstract]
|
| 180 |
+
return None
|
| 181 |
+
try:
|
| 182 |
+
return target_type._from_dict(value)
|
| 183 |
+
except Exception as e:
|
| 184 |
+
raise PylockValidationError(e, context=key) from e
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def _get_sequence_of_objects(
|
| 188 |
+
d: Mapping[str, Any], target_item_type: type[_FromMappingProtocolT], key: str
|
| 189 |
+
) -> list[_FromMappingProtocolT] | None:
|
| 190 |
+
"""Get a list value from the dictionary and convert its items to a dataclass."""
|
| 191 |
+
if (value := _get_sequence(d, Mapping, key)) is None: # type: ignore[type-abstract]
|
| 192 |
+
return None
|
| 193 |
+
result: list[_FromMappingProtocolT] = []
|
| 194 |
+
try:
|
| 195 |
+
for item in value:
|
| 196 |
+
typed_item = target_item_type._from_dict(item)
|
| 197 |
+
result.append(typed_item)
|
| 198 |
+
except Exception as e:
|
| 199 |
+
raise PylockValidationError(e, context=f"{key}[{len(result)}]") from e
|
| 200 |
+
return result
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def _get_required_sequence_of_objects(
|
| 204 |
+
d: Mapping[str, Any], target_item_type: type[_FromMappingProtocolT], key: str
|
| 205 |
+
) -> Sequence[_FromMappingProtocolT]:
|
| 206 |
+
"""Get a required list value from the dictionary and convert its items to a
|
| 207 |
+
dataclass."""
|
| 208 |
+
if (result := _get_sequence_of_objects(d, target_item_type, key)) is None:
|
| 209 |
+
raise _PylockRequiredKeyError(key)
|
| 210 |
+
return result
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def _validate_normalized_name(name: str) -> NormalizedName:
|
| 214 |
+
"""Validate that a string is a NormalizedName."""
|
| 215 |
+
if not is_normalized_name(name):
|
| 216 |
+
raise PylockValidationError(f"Name {name!r} is not normalized")
|
| 217 |
+
return NormalizedName(name)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def _validate_path_url(path: str | None, url: str | None) -> None:
|
| 221 |
+
if not path and not url:
|
| 222 |
+
raise PylockValidationError("path or url must be provided")
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def _validate_hashes(hashes: Mapping[str, Any]) -> Mapping[str, Any]:
|
| 226 |
+
if not hashes:
|
| 227 |
+
raise PylockValidationError("At least one hash must be provided")
|
| 228 |
+
if not all(isinstance(hash_val, str) for hash_val in hashes.values()):
|
| 229 |
+
raise PylockValidationError("Hash values must be strings")
|
| 230 |
+
return hashes
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
class PylockValidationError(Exception):
|
| 234 |
+
"""Raised when when input data is not spec-compliant."""
|
| 235 |
+
|
| 236 |
+
context: str | None = None
|
| 237 |
+
message: str
|
| 238 |
+
|
| 239 |
+
def __init__(
|
| 240 |
+
self,
|
| 241 |
+
cause: str | Exception,
|
| 242 |
+
*,
|
| 243 |
+
context: str | None = None,
|
| 244 |
+
) -> None:
|
| 245 |
+
if isinstance(cause, PylockValidationError):
|
| 246 |
+
if cause.context:
|
| 247 |
+
self.context = (
|
| 248 |
+
f"{context}.{cause.context}" if context else cause.context
|
| 249 |
+
)
|
| 250 |
+
else:
|
| 251 |
+
self.context = context
|
| 252 |
+
self.message = cause.message
|
| 253 |
+
else:
|
| 254 |
+
self.context = context
|
| 255 |
+
self.message = str(cause)
|
| 256 |
+
|
| 257 |
+
def __str__(self) -> str:
|
| 258 |
+
if self.context:
|
| 259 |
+
return f"{self.message} in {self.context!r}"
|
| 260 |
+
return self.message
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
class _PylockRequiredKeyError(PylockValidationError):
|
| 264 |
+
def __init__(self, key: str) -> None:
|
| 265 |
+
super().__init__("Missing required value", context=key)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
class PylockUnsupportedVersionError(PylockValidationError):
|
| 269 |
+
"""Raised when encountering an unsupported `lock_version`."""
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
@dataclass(frozen=True, init=False)
|
| 273 |
+
class PackageVcs:
|
| 274 |
+
type: str
|
| 275 |
+
url: str | None = None
|
| 276 |
+
path: str | None = None
|
| 277 |
+
requested_revision: str | None = None
|
| 278 |
+
commit_id: str # type: ignore[misc]
|
| 279 |
+
subdirectory: str | None = None
|
| 280 |
+
|
| 281 |
+
def __init__(
|
| 282 |
+
self,
|
| 283 |
+
*,
|
| 284 |
+
type: str,
|
| 285 |
+
url: str | None = None,
|
| 286 |
+
path: str | None = None,
|
| 287 |
+
requested_revision: str | None = None,
|
| 288 |
+
commit_id: str,
|
| 289 |
+
subdirectory: str | None = None,
|
| 290 |
+
) -> None:
|
| 291 |
+
# In Python 3.10+ make dataclass kw_only=True and remove __init__
|
| 292 |
+
object.__setattr__(self, "type", type)
|
| 293 |
+
object.__setattr__(self, "url", url)
|
| 294 |
+
object.__setattr__(self, "path", path)
|
| 295 |
+
object.__setattr__(self, "requested_revision", requested_revision)
|
| 296 |
+
object.__setattr__(self, "commit_id", commit_id)
|
| 297 |
+
object.__setattr__(self, "subdirectory", subdirectory)
|
| 298 |
+
|
| 299 |
+
@classmethod
|
| 300 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self:
|
| 301 |
+
package_vcs = cls(
|
| 302 |
+
type=_get_required(d, str, "type"),
|
| 303 |
+
url=_get(d, str, "url"),
|
| 304 |
+
path=_get(d, str, "path"),
|
| 305 |
+
requested_revision=_get(d, str, "requested-revision"),
|
| 306 |
+
commit_id=_get_required(d, str, "commit-id"),
|
| 307 |
+
subdirectory=_get(d, str, "subdirectory"),
|
| 308 |
+
)
|
| 309 |
+
_validate_path_url(package_vcs.path, package_vcs.url)
|
| 310 |
+
return package_vcs
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
@dataclass(frozen=True, init=False)
|
| 314 |
+
class PackageDirectory:
|
| 315 |
+
path: str
|
| 316 |
+
editable: bool | None = None
|
| 317 |
+
subdirectory: str | None = None
|
| 318 |
+
|
| 319 |
+
def __init__(
|
| 320 |
+
self,
|
| 321 |
+
*,
|
| 322 |
+
path: str,
|
| 323 |
+
editable: bool | None = None,
|
| 324 |
+
subdirectory: str | None = None,
|
| 325 |
+
) -> None:
|
| 326 |
+
# In Python 3.10+ make dataclass kw_only=True and remove __init__
|
| 327 |
+
object.__setattr__(self, "path", path)
|
| 328 |
+
object.__setattr__(self, "editable", editable)
|
| 329 |
+
object.__setattr__(self, "subdirectory", subdirectory)
|
| 330 |
+
|
| 331 |
+
@classmethod
|
| 332 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self:
|
| 333 |
+
return cls(
|
| 334 |
+
path=_get_required(d, str, "path"),
|
| 335 |
+
editable=_get(d, bool, "editable"),
|
| 336 |
+
subdirectory=_get(d, str, "subdirectory"),
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
@dataclass(frozen=True, init=False)
|
| 341 |
+
class PackageArchive:
|
| 342 |
+
url: str | None = None
|
| 343 |
+
path: str | None = None
|
| 344 |
+
size: int | None = None
|
| 345 |
+
upload_time: datetime | None = None
|
| 346 |
+
hashes: Mapping[str, str] # type: ignore[misc]
|
| 347 |
+
subdirectory: str | None = None
|
| 348 |
+
|
| 349 |
+
def __init__(
|
| 350 |
+
self,
|
| 351 |
+
*,
|
| 352 |
+
url: str | None = None,
|
| 353 |
+
path: str | None = None,
|
| 354 |
+
size: int | None = None,
|
| 355 |
+
upload_time: datetime | None = None,
|
| 356 |
+
hashes: Mapping[str, str],
|
| 357 |
+
subdirectory: str | None = None,
|
| 358 |
+
) -> None:
|
| 359 |
+
# In Python 3.10+ make dataclass kw_only=True and remove __init__
|
| 360 |
+
object.__setattr__(self, "url", url)
|
| 361 |
+
object.__setattr__(self, "path", path)
|
| 362 |
+
object.__setattr__(self, "size", size)
|
| 363 |
+
object.__setattr__(self, "upload_time", upload_time)
|
| 364 |
+
object.__setattr__(self, "hashes", hashes)
|
| 365 |
+
object.__setattr__(self, "subdirectory", subdirectory)
|
| 366 |
+
|
| 367 |
+
@classmethod
|
| 368 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self:
|
| 369 |
+
package_archive = cls(
|
| 370 |
+
url=_get(d, str, "url"),
|
| 371 |
+
path=_get(d, str, "path"),
|
| 372 |
+
size=_get(d, int, "size"),
|
| 373 |
+
upload_time=_get(d, datetime, "upload-time"),
|
| 374 |
+
hashes=_get_required_as(d, Mapping, _validate_hashes, "hashes"), # type: ignore[type-abstract]
|
| 375 |
+
subdirectory=_get(d, str, "subdirectory"),
|
| 376 |
+
)
|
| 377 |
+
_validate_path_url(package_archive.path, package_archive.url)
|
| 378 |
+
return package_archive
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
@dataclass(frozen=True, init=False)
|
| 382 |
+
class PackageSdist:
|
| 383 |
+
name: str | None = None
|
| 384 |
+
upload_time: datetime | None = None
|
| 385 |
+
url: str | None = None
|
| 386 |
+
path: str | None = None
|
| 387 |
+
size: int | None = None
|
| 388 |
+
hashes: Mapping[str, str] # type: ignore[misc]
|
| 389 |
+
|
| 390 |
+
def __init__(
|
| 391 |
+
self,
|
| 392 |
+
*,
|
| 393 |
+
name: str | None = None,
|
| 394 |
+
upload_time: datetime | None = None,
|
| 395 |
+
url: str | None = None,
|
| 396 |
+
path: str | None = None,
|
| 397 |
+
size: int | None = None,
|
| 398 |
+
hashes: Mapping[str, str],
|
| 399 |
+
) -> None:
|
| 400 |
+
# In Python 3.10+ make dataclass kw_only=True and remove __init__
|
| 401 |
+
object.__setattr__(self, "name", name)
|
| 402 |
+
object.__setattr__(self, "upload_time", upload_time)
|
| 403 |
+
object.__setattr__(self, "url", url)
|
| 404 |
+
object.__setattr__(self, "path", path)
|
| 405 |
+
object.__setattr__(self, "size", size)
|
| 406 |
+
object.__setattr__(self, "hashes", hashes)
|
| 407 |
+
|
| 408 |
+
@classmethod
|
| 409 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self:
|
| 410 |
+
package_sdist = cls(
|
| 411 |
+
name=_get(d, str, "name"),
|
| 412 |
+
upload_time=_get(d, datetime, "upload-time"),
|
| 413 |
+
url=_get(d, str, "url"),
|
| 414 |
+
path=_get(d, str, "path"),
|
| 415 |
+
size=_get(d, int, "size"),
|
| 416 |
+
hashes=_get_required_as(d, Mapping, _validate_hashes, "hashes"), # type: ignore[type-abstract]
|
| 417 |
+
)
|
| 418 |
+
_validate_path_url(package_sdist.path, package_sdist.url)
|
| 419 |
+
return package_sdist
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
@dataclass(frozen=True, init=False)
|
| 423 |
+
class PackageWheel:
|
| 424 |
+
name: str | None = None
|
| 425 |
+
upload_time: datetime | None = None
|
| 426 |
+
url: str | None = None
|
| 427 |
+
path: str | None = None
|
| 428 |
+
size: int | None = None
|
| 429 |
+
hashes: Mapping[str, str] # type: ignore[misc]
|
| 430 |
+
|
| 431 |
+
def __init__(
|
| 432 |
+
self,
|
| 433 |
+
*,
|
| 434 |
+
name: str | None = None,
|
| 435 |
+
upload_time: datetime | None = None,
|
| 436 |
+
url: str | None = None,
|
| 437 |
+
path: str | None = None,
|
| 438 |
+
size: int | None = None,
|
| 439 |
+
hashes: Mapping[str, str],
|
| 440 |
+
) -> None:
|
| 441 |
+
# In Python 3.10+ make dataclass kw_only=True and remove __init__
|
| 442 |
+
object.__setattr__(self, "name", name)
|
| 443 |
+
object.__setattr__(self, "upload_time", upload_time)
|
| 444 |
+
object.__setattr__(self, "url", url)
|
| 445 |
+
object.__setattr__(self, "path", path)
|
| 446 |
+
object.__setattr__(self, "size", size)
|
| 447 |
+
object.__setattr__(self, "hashes", hashes)
|
| 448 |
+
|
| 449 |
+
@classmethod
|
| 450 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self:
|
| 451 |
+
package_wheel = cls(
|
| 452 |
+
name=_get(d, str, "name"),
|
| 453 |
+
upload_time=_get(d, datetime, "upload-time"),
|
| 454 |
+
url=_get(d, str, "url"),
|
| 455 |
+
path=_get(d, str, "path"),
|
| 456 |
+
size=_get(d, int, "size"),
|
| 457 |
+
hashes=_get_required_as(d, Mapping, _validate_hashes, "hashes"), # type: ignore[type-abstract]
|
| 458 |
+
)
|
| 459 |
+
_validate_path_url(package_wheel.path, package_wheel.url)
|
| 460 |
+
return package_wheel
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
@dataclass(frozen=True, init=False)
|
| 464 |
+
class Package:
|
| 465 |
+
name: NormalizedName
|
| 466 |
+
version: Version | None = None
|
| 467 |
+
marker: Marker | None = None
|
| 468 |
+
requires_python: SpecifierSet | None = None
|
| 469 |
+
dependencies: Sequence[Mapping[str, Any]] | None = None
|
| 470 |
+
vcs: PackageVcs | None = None
|
| 471 |
+
directory: PackageDirectory | None = None
|
| 472 |
+
archive: PackageArchive | None = None
|
| 473 |
+
index: str | None = None
|
| 474 |
+
sdist: PackageSdist | None = None
|
| 475 |
+
wheels: Sequence[PackageWheel] | None = None
|
| 476 |
+
attestation_identities: Sequence[Mapping[str, Any]] | None = None
|
| 477 |
+
tool: Mapping[str, Any] | None = None
|
| 478 |
+
|
| 479 |
+
def __init__(
|
| 480 |
+
self,
|
| 481 |
+
*,
|
| 482 |
+
name: NormalizedName,
|
| 483 |
+
version: Version | None = None,
|
| 484 |
+
marker: Marker | None = None,
|
| 485 |
+
requires_python: SpecifierSet | None = None,
|
| 486 |
+
dependencies: Sequence[Mapping[str, Any]] | None = None,
|
| 487 |
+
vcs: PackageVcs | None = None,
|
| 488 |
+
directory: PackageDirectory | None = None,
|
| 489 |
+
archive: PackageArchive | None = None,
|
| 490 |
+
index: str | None = None,
|
| 491 |
+
sdist: PackageSdist | None = None,
|
| 492 |
+
wheels: Sequence[PackageWheel] | None = None,
|
| 493 |
+
attestation_identities: Sequence[Mapping[str, Any]] | None = None,
|
| 494 |
+
tool: Mapping[str, Any] | None = None,
|
| 495 |
+
) -> None:
|
| 496 |
+
# In Python 3.10+ make dataclass kw_only=True and remove __init__
|
| 497 |
+
object.__setattr__(self, "name", name)
|
| 498 |
+
object.__setattr__(self, "version", version)
|
| 499 |
+
object.__setattr__(self, "marker", marker)
|
| 500 |
+
object.__setattr__(self, "requires_python", requires_python)
|
| 501 |
+
object.__setattr__(self, "dependencies", dependencies)
|
| 502 |
+
object.__setattr__(self, "vcs", vcs)
|
| 503 |
+
object.__setattr__(self, "directory", directory)
|
| 504 |
+
object.__setattr__(self, "archive", archive)
|
| 505 |
+
object.__setattr__(self, "index", index)
|
| 506 |
+
object.__setattr__(self, "sdist", sdist)
|
| 507 |
+
object.__setattr__(self, "wheels", wheels)
|
| 508 |
+
object.__setattr__(self, "attestation_identities", attestation_identities)
|
| 509 |
+
object.__setattr__(self, "tool", tool)
|
| 510 |
+
|
| 511 |
+
@classmethod
|
| 512 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self:
|
| 513 |
+
package = cls(
|
| 514 |
+
name=_get_required_as(d, str, _validate_normalized_name, "name"),
|
| 515 |
+
version=_get_as(d, str, Version, "version"),
|
| 516 |
+
requires_python=_get_as(d, str, SpecifierSet, "requires-python"),
|
| 517 |
+
dependencies=_get_sequence(d, Mapping, "dependencies"), # type: ignore[type-abstract]
|
| 518 |
+
marker=_get_as(d, str, Marker, "marker"),
|
| 519 |
+
vcs=_get_object(d, PackageVcs, "vcs"),
|
| 520 |
+
directory=_get_object(d, PackageDirectory, "directory"),
|
| 521 |
+
archive=_get_object(d, PackageArchive, "archive"),
|
| 522 |
+
index=_get(d, str, "index"),
|
| 523 |
+
sdist=_get_object(d, PackageSdist, "sdist"),
|
| 524 |
+
wheels=_get_sequence_of_objects(d, PackageWheel, "wheels"),
|
| 525 |
+
attestation_identities=_get_sequence(d, Mapping, "attestation-identities"), # type: ignore[type-abstract]
|
| 526 |
+
tool=_get(d, Mapping, "tool"), # type: ignore[type-abstract]
|
| 527 |
+
)
|
| 528 |
+
distributions = bool(package.sdist) + len(package.wheels or [])
|
| 529 |
+
direct_urls = (
|
| 530 |
+
bool(package.vcs) + bool(package.directory) + bool(package.archive)
|
| 531 |
+
)
|
| 532 |
+
if distributions > 0 and direct_urls > 0:
|
| 533 |
+
raise PylockValidationError(
|
| 534 |
+
"None of vcs, directory, archive must be set if sdist or wheels are set"
|
| 535 |
+
)
|
| 536 |
+
if distributions == 0 and direct_urls != 1:
|
| 537 |
+
raise PylockValidationError(
|
| 538 |
+
"Exactly one of vcs, directory, archive must be set "
|
| 539 |
+
"if sdist and wheels are not set"
|
| 540 |
+
)
|
| 541 |
+
try:
|
| 542 |
+
for i, attestation_identity in enumerate( # noqa: B007
|
| 543 |
+
package.attestation_identities or []
|
| 544 |
+
):
|
| 545 |
+
_get_required(attestation_identity, str, "kind")
|
| 546 |
+
except Exception as e:
|
| 547 |
+
raise PylockValidationError(
|
| 548 |
+
e, context=f"attestation-identities[{i}]"
|
| 549 |
+
) from e
|
| 550 |
+
return package
|
| 551 |
+
|
| 552 |
+
@property
|
| 553 |
+
def is_direct(self) -> bool:
|
| 554 |
+
return not (self.sdist or self.wheels)
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
@dataclass(frozen=True, init=False)
|
| 558 |
+
class Pylock:
|
| 559 |
+
"""A class representing a pylock file."""
|
| 560 |
+
|
| 561 |
+
lock_version: Version
|
| 562 |
+
environments: Sequence[Marker] | None = None
|
| 563 |
+
requires_python: SpecifierSet | None = None
|
| 564 |
+
extras: Sequence[NormalizedName] | None = None
|
| 565 |
+
dependency_groups: Sequence[str] | None = None
|
| 566 |
+
default_groups: Sequence[str] | None = None
|
| 567 |
+
created_by: str # type: ignore[misc]
|
| 568 |
+
packages: Sequence[Package] # type: ignore[misc]
|
| 569 |
+
tool: Mapping[str, Any] | None = None
|
| 570 |
+
|
| 571 |
+
def __init__(
|
| 572 |
+
self,
|
| 573 |
+
*,
|
| 574 |
+
lock_version: Version,
|
| 575 |
+
environments: Sequence[Marker] | None = None,
|
| 576 |
+
requires_python: SpecifierSet | None = None,
|
| 577 |
+
extras: Sequence[NormalizedName] | None = None,
|
| 578 |
+
dependency_groups: Sequence[str] | None = None,
|
| 579 |
+
default_groups: Sequence[str] | None = None,
|
| 580 |
+
created_by: str,
|
| 581 |
+
packages: Sequence[Package],
|
| 582 |
+
tool: Mapping[str, Any] | None = None,
|
| 583 |
+
) -> None:
|
| 584 |
+
# In Python 3.10+ make dataclass kw_only=True and remove __init__
|
| 585 |
+
object.__setattr__(self, "lock_version", lock_version)
|
| 586 |
+
object.__setattr__(self, "environments", environments)
|
| 587 |
+
object.__setattr__(self, "requires_python", requires_python)
|
| 588 |
+
object.__setattr__(self, "extras", extras)
|
| 589 |
+
object.__setattr__(self, "dependency_groups", dependency_groups)
|
| 590 |
+
object.__setattr__(self, "default_groups", default_groups)
|
| 591 |
+
object.__setattr__(self, "created_by", created_by)
|
| 592 |
+
object.__setattr__(self, "packages", packages)
|
| 593 |
+
object.__setattr__(self, "tool", tool)
|
| 594 |
+
|
| 595 |
+
@classmethod
|
| 596 |
+
def _from_dict(cls, d: Mapping[str, Any]) -> Self:
|
| 597 |
+
pylock = cls(
|
| 598 |
+
lock_version=_get_required_as(d, str, Version, "lock-version"),
|
| 599 |
+
environments=_get_sequence_as(d, str, Marker, "environments"),
|
| 600 |
+
extras=_get_sequence_as(d, str, _validate_normalized_name, "extras"),
|
| 601 |
+
dependency_groups=_get_sequence(d, str, "dependency-groups"),
|
| 602 |
+
default_groups=_get_sequence(d, str, "default-groups"),
|
| 603 |
+
created_by=_get_required(d, str, "created-by"),
|
| 604 |
+
requires_python=_get_as(d, str, SpecifierSet, "requires-python"),
|
| 605 |
+
packages=_get_required_sequence_of_objects(d, Package, "packages"),
|
| 606 |
+
tool=_get(d, Mapping, "tool"), # type: ignore[type-abstract]
|
| 607 |
+
)
|
| 608 |
+
if not Version("1") <= pylock.lock_version < Version("2"):
|
| 609 |
+
raise PylockUnsupportedVersionError(
|
| 610 |
+
f"pylock version {pylock.lock_version} is not supported"
|
| 611 |
+
)
|
| 612 |
+
if pylock.lock_version > Version("1.0"):
|
| 613 |
+
_logger.warning(
|
| 614 |
+
"pylock minor version %s is not supported", pylock.lock_version
|
| 615 |
+
)
|
| 616 |
+
return pylock
|
| 617 |
+
|
| 618 |
+
@classmethod
|
| 619 |
+
def from_dict(cls, d: Mapping[str, Any], /) -> Self:
|
| 620 |
+
"""Create and validate a Pylock instance from a TOML dictionary.
|
| 621 |
+
|
| 622 |
+
Raises :class:`PylockValidationError` if the input data is not
|
| 623 |
+
spec-compliant.
|
| 624 |
+
"""
|
| 625 |
+
return cls._from_dict(d)
|
| 626 |
+
|
| 627 |
+
def to_dict(self) -> Mapping[str, Any]:
|
| 628 |
+
"""Convert the Pylock instance to a TOML dictionary."""
|
| 629 |
+
return dataclasses.asdict(self, dict_factory=_toml_dict_factory)
|
| 630 |
+
|
| 631 |
+
def validate(self) -> None:
|
| 632 |
+
"""Validate the Pylock instance against the specification.
|
| 633 |
+
|
| 634 |
+
Raises :class:`PylockValidationError` otherwise."""
|
| 635 |
+
self.from_dict(self.to_dict())
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/requirements.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
from typing import Iterator
|
| 7 |
+
|
| 8 |
+
from ._parser import parse_requirement as _parse_requirement
|
| 9 |
+
from ._tokenizer import ParserSyntaxError
|
| 10 |
+
from .markers import Marker, _normalize_extra_values
|
| 11 |
+
from .specifiers import SpecifierSet
|
| 12 |
+
from .utils import canonicalize_name
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class InvalidRequirement(ValueError):
|
| 16 |
+
"""
|
| 17 |
+
An invalid requirement was found, users should refer to PEP 508.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Requirement:
|
| 22 |
+
"""Parse a requirement.
|
| 23 |
+
|
| 24 |
+
Parse a given requirement string into its parts, such as name, specifier,
|
| 25 |
+
URL, and extras. Raises InvalidRequirement on a badly-formed requirement
|
| 26 |
+
string.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
# TODO: Can we test whether something is contained within a requirement?
|
| 30 |
+
# If so how do we do that? Do we need to test against the _name_ of
|
| 31 |
+
# the thing as well as the version? What about the markers?
|
| 32 |
+
# TODO: Can we normalize the name and extra name?
|
| 33 |
+
|
| 34 |
+
def __init__(self, requirement_string: str) -> None:
|
| 35 |
+
try:
|
| 36 |
+
parsed = _parse_requirement(requirement_string)
|
| 37 |
+
except ParserSyntaxError as e:
|
| 38 |
+
raise InvalidRequirement(str(e)) from e
|
| 39 |
+
|
| 40 |
+
self.name: str = parsed.name
|
| 41 |
+
self.url: str | None = parsed.url or None
|
| 42 |
+
self.extras: set[str] = set(parsed.extras or [])
|
| 43 |
+
self.specifier: SpecifierSet = SpecifierSet(parsed.specifier)
|
| 44 |
+
self.marker: Marker | None = None
|
| 45 |
+
if parsed.marker is not None:
|
| 46 |
+
self.marker = Marker.__new__(Marker)
|
| 47 |
+
self.marker._markers = _normalize_extra_values(parsed.marker)
|
| 48 |
+
|
| 49 |
+
def _iter_parts(self, name: str) -> Iterator[str]:
|
| 50 |
+
yield name
|
| 51 |
+
|
| 52 |
+
if self.extras:
|
| 53 |
+
formatted_extras = ",".join(sorted(self.extras))
|
| 54 |
+
yield f"[{formatted_extras}]"
|
| 55 |
+
|
| 56 |
+
if self.specifier:
|
| 57 |
+
yield str(self.specifier)
|
| 58 |
+
|
| 59 |
+
if self.url:
|
| 60 |
+
yield f" @ {self.url}"
|
| 61 |
+
if self.marker:
|
| 62 |
+
yield " "
|
| 63 |
+
|
| 64 |
+
if self.marker:
|
| 65 |
+
yield f"; {self.marker}"
|
| 66 |
+
|
| 67 |
+
def __str__(self) -> str:
|
| 68 |
+
return "".join(self._iter_parts(self.name))
|
| 69 |
+
|
| 70 |
+
def __repr__(self) -> str:
|
| 71 |
+
return f"<{self.__class__.__name__}('{self}')>"
|
| 72 |
+
|
| 73 |
+
def __hash__(self) -> int:
|
| 74 |
+
return hash(tuple(self._iter_parts(canonicalize_name(self.name))))
|
| 75 |
+
|
| 76 |
+
def __eq__(self, other: object) -> bool:
|
| 77 |
+
if not isinstance(other, Requirement):
|
| 78 |
+
return NotImplemented
|
| 79 |
+
|
| 80 |
+
return (
|
| 81 |
+
canonicalize_name(self.name) == canonicalize_name(other.name)
|
| 82 |
+
and self.extras == other.extras
|
| 83 |
+
and self.specifier == other.specifier
|
| 84 |
+
and self.url == other.url
|
| 85 |
+
and self.marker == other.marker
|
| 86 |
+
)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/packaging/specifiers.py
ADDED
|
@@ -0,0 +1,1068 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is dual licensed under the terms of the Apache License, Version
|
| 2 |
+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
| 3 |
+
# for complete details.
|
| 4 |
+
"""
|
| 5 |
+
.. testsetup::
|
| 6 |
+
|
| 7 |
+
from packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier
|
| 8 |
+
from packaging.version import Version
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import abc
|
| 14 |
+
import itertools
|
| 15 |
+
import re
|
| 16 |
+
from typing import Callable, Final, Iterable, Iterator, TypeVar, Union
|
| 17 |
+
|
| 18 |
+
from .utils import canonicalize_version
|
| 19 |
+
from .version import InvalidVersion, Version
|
| 20 |
+
|
| 21 |
+
UnparsedVersion = Union[Version, str]
|
| 22 |
+
UnparsedVersionVar = TypeVar("UnparsedVersionVar", bound=UnparsedVersion)
|
| 23 |
+
CallableOperator = Callable[[Version, str], bool]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _coerce_version(version: UnparsedVersion) -> Version | None:
|
| 27 |
+
if not isinstance(version, Version):
|
| 28 |
+
try:
|
| 29 |
+
version = Version(version)
|
| 30 |
+
except InvalidVersion:
|
| 31 |
+
return None
|
| 32 |
+
return version
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _public_version(version: Version) -> Version:
|
| 36 |
+
return version.__replace__(local=None)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _base_version(version: Version) -> Version:
|
| 40 |
+
return version.__replace__(pre=None, post=None, dev=None, local=None)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class InvalidSpecifier(ValueError):
|
| 44 |
+
"""
|
| 45 |
+
Raised when attempting to create a :class:`Specifier` with a specifier
|
| 46 |
+
string that is invalid.
|
| 47 |
+
|
| 48 |
+
>>> Specifier("lolwat")
|
| 49 |
+
Traceback (most recent call last):
|
| 50 |
+
...
|
| 51 |
+
packaging.specifiers.InvalidSpecifier: Invalid specifier: 'lolwat'
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class BaseSpecifier(metaclass=abc.ABCMeta):
|
| 56 |
+
__slots__ = ()
|
| 57 |
+
__match_args__ = ("_str",)
|
| 58 |
+
|
| 59 |
+
@property
|
| 60 |
+
def _str(self) -> str:
|
| 61 |
+
"""Internal property for match_args"""
|
| 62 |
+
return str(self)
|
| 63 |
+
|
| 64 |
+
@abc.abstractmethod
|
| 65 |
+
def __str__(self) -> str:
|
| 66 |
+
"""
|
| 67 |
+
Returns the str representation of this Specifier-like object. This
|
| 68 |
+
should be representative of the Specifier itself.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
@abc.abstractmethod
|
| 72 |
+
def __hash__(self) -> int:
|
| 73 |
+
"""
|
| 74 |
+
Returns a hash value for this Specifier-like object.
|
| 75 |
+
"""
|
| 76 |
+
|
| 77 |
+
@abc.abstractmethod
|
| 78 |
+
def __eq__(self, other: object) -> bool:
|
| 79 |
+
"""
|
| 80 |
+
Returns a boolean representing whether or not the two Specifier-like
|
| 81 |
+
objects are equal.
|
| 82 |
+
|
| 83 |
+
:param other: The other object to check against.
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
@property
|
| 87 |
+
@abc.abstractmethod
|
| 88 |
+
def prereleases(self) -> bool | None:
|
| 89 |
+
"""Whether or not pre-releases as a whole are allowed.
|
| 90 |
+
|
| 91 |
+
This can be set to either ``True`` or ``False`` to explicitly enable or disable
|
| 92 |
+
prereleases or it can be set to ``None`` (the default) to use default semantics.
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
@prereleases.setter # noqa: B027
|
| 96 |
+
def prereleases(self, value: bool) -> None:
|
| 97 |
+
"""Setter for :attr:`prereleases`.
|
| 98 |
+
|
| 99 |
+
:param value: The value to set.
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
@abc.abstractmethod
|
| 103 |
+
def contains(self, item: str, prereleases: bool | None = None) -> bool:
|
| 104 |
+
"""
|
| 105 |
+
Determines if the given item is contained within this specifier.
|
| 106 |
+
"""
|
| 107 |
+
|
| 108 |
+
@abc.abstractmethod
|
| 109 |
+
def filter(
|
| 110 |
+
self, iterable: Iterable[UnparsedVersionVar], prereleases: bool | None = None
|
| 111 |
+
) -> Iterator[UnparsedVersionVar]:
|
| 112 |
+
"""
|
| 113 |
+
Takes an iterable of items and filters them so that only items which
|
| 114 |
+
are contained within this specifier are allowed in it.
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class Specifier(BaseSpecifier):
|
| 119 |
+
"""This class abstracts handling of version specifiers.
|
| 120 |
+
|
| 121 |
+
.. tip::
|
| 122 |
+
|
| 123 |
+
It is generally not required to instantiate this manually. You should instead
|
| 124 |
+
prefer to work with :class:`SpecifierSet` instead, which can parse
|
| 125 |
+
comma-separated version specifiers (which is what package metadata contains).
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
__slots__ = ("_prereleases", "_spec", "_spec_version")
|
| 129 |
+
|
| 130 |
+
_operator_regex_str = r"""
|
| 131 |
+
(?P<operator>(~=|==|!=|<=|>=|<|>|===))
|
| 132 |
+
"""
|
| 133 |
+
_version_regex_str = r"""
|
| 134 |
+
(?P<version>
|
| 135 |
+
(?:
|
| 136 |
+
# The identity operators allow for an escape hatch that will
|
| 137 |
+
# do an exact string match of the version you wish to install.
|
| 138 |
+
# This will not be parsed by PEP 440 and we cannot determine
|
| 139 |
+
# any semantic meaning from it. This operator is discouraged
|
| 140 |
+
# but included entirely as an escape hatch.
|
| 141 |
+
(?<====) # Only match for the identity operator
|
| 142 |
+
\s*
|
| 143 |
+
[^\s;)]* # The arbitrary version can be just about anything,
|
| 144 |
+
# we match everything except for whitespace, a
|
| 145 |
+
# semi-colon for marker support, and a closing paren
|
| 146 |
+
# since versions can be enclosed in them.
|
| 147 |
+
)
|
| 148 |
+
|
|
| 149 |
+
(?:
|
| 150 |
+
# The (non)equality operators allow for wild card and local
|
| 151 |
+
# versions to be specified so we have to define these two
|
| 152 |
+
# operators separately to enable that.
|
| 153 |
+
(?<===|!=) # Only match for equals and not equals
|
| 154 |
+
|
| 155 |
+
\s*
|
| 156 |
+
v?
|
| 157 |
+
(?:[0-9]+!)? # epoch
|
| 158 |
+
[0-9]+(?:\.[0-9]+)* # release
|
| 159 |
+
|
| 160 |
+
# You cannot use a wild card and a pre-release, post-release, a dev or
|
| 161 |
+
# local version together so group them with a | and make them optional.
|
| 162 |
+
(?:
|
| 163 |
+
\.\* # Wild card syntax of .*
|
| 164 |
+
|
|
| 165 |
+
(?: # pre release
|
| 166 |
+
[-_\.]?
|
| 167 |
+
(alpha|beta|preview|pre|a|b|c|rc)
|
| 168 |
+
[-_\.]?
|
| 169 |
+
[0-9]*
|
| 170 |
+
)?
|
| 171 |
+
(?: # post release
|
| 172 |
+
(?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
|
| 173 |
+
)?
|
| 174 |
+
(?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
|
| 175 |
+
(?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local
|
| 176 |
+
)?
|
| 177 |
+
)
|
| 178 |
+
|
|
| 179 |
+
(?:
|
| 180 |
+
# The compatible operator requires at least two digits in the
|
| 181 |
+
# release segment.
|
| 182 |
+
(?<=~=) # Only match for the compatible operator
|
| 183 |
+
|
| 184 |
+
\s*
|
| 185 |
+
v?
|
| 186 |
+
(?:[0-9]+!)? # epoch
|
| 187 |
+
[0-9]+(?:\.[0-9]+)+ # release (We have a + instead of a *)
|
| 188 |
+
(?: # pre release
|
| 189 |
+
[-_\.]?
|
| 190 |
+
(alpha|beta|preview|pre|a|b|c|rc)
|
| 191 |
+
[-_\.]?
|
| 192 |
+
[0-9]*
|
| 193 |
+
)?
|
| 194 |
+
(?: # post release
|
| 195 |
+
(?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
|
| 196 |
+
)?
|
| 197 |
+
(?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
|
| 198 |
+
)
|
| 199 |
+
|
|
| 200 |
+
(?:
|
| 201 |
+
# All other operators only allow a sub set of what the
|
| 202 |
+
# (non)equality operators do. Specifically they do not allow
|
| 203 |
+
# local versions to be specified nor do they allow the prefix
|
| 204 |
+
# matching wild cards.
|
| 205 |
+
(?<!==|!=|~=) # We have special cases for these
|
| 206 |
+
# operators so we want to make sure they
|
| 207 |
+
# don't match here.
|
| 208 |
+
|
| 209 |
+
\s*
|
| 210 |
+
v?
|
| 211 |
+
(?:[0-9]+!)? # epoch
|
| 212 |
+
[0-9]+(?:\.[0-9]+)* # release
|
| 213 |
+
(?: # pre release
|
| 214 |
+
[-_\.]?
|
| 215 |
+
(alpha|beta|preview|pre|a|b|c|rc)
|
| 216 |
+
[-_\.]?
|
| 217 |
+
[0-9]*
|
| 218 |
+
)?
|
| 219 |
+
(?: # post release
|
| 220 |
+
(?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
|
| 221 |
+
)?
|
| 222 |
+
(?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
|
| 223 |
+
)
|
| 224 |
+
)
|
| 225 |
+
"""
|
| 226 |
+
|
| 227 |
+
_regex = re.compile(
|
| 228 |
+
r"\s*" + _operator_regex_str + _version_regex_str + r"\s*",
|
| 229 |
+
re.VERBOSE | re.IGNORECASE,
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
_operators: Final = {
|
| 233 |
+
"~=": "compatible",
|
| 234 |
+
"==": "equal",
|
| 235 |
+
"!=": "not_equal",
|
| 236 |
+
"<=": "less_than_equal",
|
| 237 |
+
">=": "greater_than_equal",
|
| 238 |
+
"<": "less_than",
|
| 239 |
+
">": "greater_than",
|
| 240 |
+
"===": "arbitrary",
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
def __init__(self, spec: str = "", prereleases: bool | None = None) -> None:
|
| 244 |
+
"""Initialize a Specifier instance.
|
| 245 |
+
|
| 246 |
+
:param spec:
|
| 247 |
+
The string representation of a specifier which will be parsed and
|
| 248 |
+
normalized before use.
|
| 249 |
+
:param prereleases:
|
| 250 |
+
This tells the specifier if it should accept prerelease versions if
|
| 251 |
+
applicable or not. The default of ``None`` will autodetect it from the
|
| 252 |
+
given specifiers.
|
| 253 |
+
:raises InvalidSpecifier:
|
| 254 |
+
If the given specifier is invalid (i.e. bad syntax).
|
| 255 |
+
"""
|
| 256 |
+
match = self._regex.fullmatch(spec)
|
| 257 |
+
if not match:
|
| 258 |
+
raise InvalidSpecifier(f"Invalid specifier: {spec!r}")
|
| 259 |
+
|
| 260 |
+
self._spec: tuple[str, str] = (
|
| 261 |
+
match.group("operator").strip(),
|
| 262 |
+
match.group("version").strip(),
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
# Store whether or not this Specifier should accept prereleases
|
| 266 |
+
self._prereleases = prereleases
|
| 267 |
+
|
| 268 |
+
# Specifier version cache
|
| 269 |
+
self._spec_version: tuple[str, Version] | None = None
|
| 270 |
+
|
| 271 |
+
def _get_spec_version(self, version: str) -> Version | None:
|
| 272 |
+
"""One element cache, as only one spec Version is needed per Specifier."""
|
| 273 |
+
if self._spec_version is not None and self._spec_version[0] == version:
|
| 274 |
+
return self._spec_version[1]
|
| 275 |
+
|
| 276 |
+
version_specifier = _coerce_version(version)
|
| 277 |
+
if version_specifier is None:
|
| 278 |
+
return None
|
| 279 |
+
|
| 280 |
+
self._spec_version = (version, version_specifier)
|
| 281 |
+
return version_specifier
|
| 282 |
+
|
| 283 |
+
def _require_spec_version(self, version: str) -> Version:
|
| 284 |
+
"""Get spec version, asserting it's valid (not for === operator).
|
| 285 |
+
|
| 286 |
+
This method should only be called for operators where version
|
| 287 |
+
strings are guaranteed to be valid PEP 440 versions (not ===).
|
| 288 |
+
"""
|
| 289 |
+
spec_version = self._get_spec_version(version)
|
| 290 |
+
assert spec_version is not None
|
| 291 |
+
return spec_version
|
| 292 |
+
|
| 293 |
+
@property
|
| 294 |
+
def prereleases(self) -> bool | None:
|
| 295 |
+
# If there is an explicit prereleases set for this, then we'll just
|
| 296 |
+
# blindly use that.
|
| 297 |
+
if self._prereleases is not None:
|
| 298 |
+
return self._prereleases
|
| 299 |
+
|
| 300 |
+
# Only the "!=" operator does not imply prereleases when
|
| 301 |
+
# the version in the specifier is a prerelease.
|
| 302 |
+
operator, version_str = self._spec
|
| 303 |
+
if operator != "!=":
|
| 304 |
+
# The == specifier with trailing .* cannot include prereleases
|
| 305 |
+
# e.g. "==1.0a1.*" is not valid.
|
| 306 |
+
if operator == "==" and version_str.endswith(".*"):
|
| 307 |
+
return False
|
| 308 |
+
|
| 309 |
+
# "===" can have arbitrary string versions, so we cannot parse
|
| 310 |
+
# those, we take prereleases as unknown (None) for those.
|
| 311 |
+
version = self._get_spec_version(version_str)
|
| 312 |
+
if version is None:
|
| 313 |
+
return None
|
| 314 |
+
|
| 315 |
+
# For all other operators, use the check if spec Version
|
| 316 |
+
# object implies pre-releases.
|
| 317 |
+
if version.is_prerelease:
|
| 318 |
+
return True
|
| 319 |
+
|
| 320 |
+
return False
|
| 321 |
+
|
| 322 |
+
@prereleases.setter
|
| 323 |
+
def prereleases(self, value: bool | None) -> None:
|
| 324 |
+
self._prereleases = value
|
| 325 |
+
|
| 326 |
+
@property
|
| 327 |
+
def operator(self) -> str:
|
| 328 |
+
"""The operator of this specifier.
|
| 329 |
+
|
| 330 |
+
>>> Specifier("==1.2.3").operator
|
| 331 |
+
'=='
|
| 332 |
+
"""
|
| 333 |
+
return self._spec[0]
|
| 334 |
+
|
| 335 |
+
@property
|
| 336 |
+
def version(self) -> str:
|
| 337 |
+
"""The version of this specifier.
|
| 338 |
+
|
| 339 |
+
>>> Specifier("==1.2.3").version
|
| 340 |
+
'1.2.3'
|
| 341 |
+
"""
|
| 342 |
+
return self._spec[1]
|
| 343 |
+
|
| 344 |
+
def __repr__(self) -> str:
|
| 345 |
+
"""A representation of the Specifier that shows all internal state.
|
| 346 |
+
|
| 347 |
+
>>> Specifier('>=1.0.0')
|
| 348 |
+
<Specifier('>=1.0.0')>
|
| 349 |
+
>>> Specifier('>=1.0.0', prereleases=False)
|
| 350 |
+
<Specifier('>=1.0.0', prereleases=False)>
|
| 351 |
+
>>> Specifier('>=1.0.0', prereleases=True)
|
| 352 |
+
<Specifier('>=1.0.0', prereleases=True)>
|
| 353 |
+
"""
|
| 354 |
+
pre = (
|
| 355 |
+
f", prereleases={self.prereleases!r}"
|
| 356 |
+
if self._prereleases is not None
|
| 357 |
+
else ""
|
| 358 |
+
)
|
| 359 |
+
|
| 360 |
+
return f"<{self.__class__.__name__}({str(self)!r}{pre})>"
|
| 361 |
+
|
| 362 |
+
def __str__(self) -> str:
|
| 363 |
+
"""A string representation of the Specifier that can be round-tripped.
|
| 364 |
+
|
| 365 |
+
>>> str(Specifier('>=1.0.0'))
|
| 366 |
+
'>=1.0.0'
|
| 367 |
+
>>> str(Specifier('>=1.0.0', prereleases=False))
|
| 368 |
+
'>=1.0.0'
|
| 369 |
+
"""
|
| 370 |
+
return "{}{}".format(*self._spec)
|
| 371 |
+
|
| 372 |
+
@property
|
| 373 |
+
def _canonical_spec(self) -> tuple[str, str]:
|
| 374 |
+
operator, version = self._spec
|
| 375 |
+
if operator == "===" or version.endswith(".*"):
|
| 376 |
+
return operator, version
|
| 377 |
+
|
| 378 |
+
spec_version = self._require_spec_version(version)
|
| 379 |
+
|
| 380 |
+
canonical_version = canonicalize_version(
|
| 381 |
+
spec_version, strip_trailing_zero=(operator != "~=")
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
return operator, canonical_version
|
| 385 |
+
|
| 386 |
+
def __hash__(self) -> int:
|
| 387 |
+
return hash(self._canonical_spec)
|
| 388 |
+
|
| 389 |
+
def __eq__(self, other: object) -> bool:
|
| 390 |
+
"""Whether or not the two Specifier-like objects are equal.
|
| 391 |
+
|
| 392 |
+
:param other: The other object to check against.
|
| 393 |
+
|
| 394 |
+
The value of :attr:`prereleases` is ignored.
|
| 395 |
+
|
| 396 |
+
>>> Specifier("==1.2.3") == Specifier("== 1.2.3.0")
|
| 397 |
+
True
|
| 398 |
+
>>> (Specifier("==1.2.3", prereleases=False) ==
|
| 399 |
+
... Specifier("==1.2.3", prereleases=True))
|
| 400 |
+
True
|
| 401 |
+
>>> Specifier("==1.2.3") == "==1.2.3"
|
| 402 |
+
True
|
| 403 |
+
>>> Specifier("==1.2.3") == Specifier("==1.2.4")
|
| 404 |
+
False
|
| 405 |
+
>>> Specifier("==1.2.3") == Specifier("~=1.2.3")
|
| 406 |
+
False
|
| 407 |
+
"""
|
| 408 |
+
if isinstance(other, str):
|
| 409 |
+
try:
|
| 410 |
+
other = self.__class__(str(other))
|
| 411 |
+
except InvalidSpecifier:
|
| 412 |
+
return NotImplemented
|
| 413 |
+
elif not isinstance(other, self.__class__):
|
| 414 |
+
return NotImplemented
|
| 415 |
+
|
| 416 |
+
return self._canonical_spec == other._canonical_spec
|
| 417 |
+
|
| 418 |
+
def _get_operator(self, op: str) -> CallableOperator:
|
| 419 |
+
operator_callable: CallableOperator = getattr(
|
| 420 |
+
self, f"_compare_{self._operators[op]}"
|
| 421 |
+
)
|
| 422 |
+
return operator_callable
|
| 423 |
+
|
| 424 |
+
def _compare_compatible(self, prospective: Version, spec: str) -> bool:
|
| 425 |
+
# Compatible releases have an equivalent combination of >= and ==. That
|
| 426 |
+
# is that ~=2.2 is equivalent to >=2.2,==2.*. This allows us to
|
| 427 |
+
# implement this in terms of the other specifiers instead of
|
| 428 |
+
# implementing it ourselves. The only thing we need to do is construct
|
| 429 |
+
# the other specifiers.
|
| 430 |
+
|
| 431 |
+
# We want everything but the last item in the version, but we want to
|
| 432 |
+
# ignore suffix segments.
|
| 433 |
+
prefix = _version_join(
|
| 434 |
+
list(itertools.takewhile(_is_not_suffix, _version_split(spec)))[:-1]
|
| 435 |
+
)
|
| 436 |
+
|
| 437 |
+
# Add the prefix notation to the end of our string
|
| 438 |
+
prefix += ".*"
|
| 439 |
+
|
| 440 |
+
return self._get_operator(">=")(prospective, spec) and self._get_operator("==")(
|
| 441 |
+
prospective, prefix
|
| 442 |
+
)
|
| 443 |
+
|
| 444 |
+
def _compare_equal(self, prospective: Version, spec: str) -> bool:
|
| 445 |
+
# We need special logic to handle prefix matching
|
| 446 |
+
if spec.endswith(".*"):
|
| 447 |
+
# In the case of prefix matching we want to ignore local segment.
|
| 448 |
+
normalized_prospective = canonicalize_version(
|
| 449 |
+
_public_version(prospective), strip_trailing_zero=False
|
| 450 |
+
)
|
| 451 |
+
# Get the normalized version string ignoring the trailing .*
|
| 452 |
+
normalized_spec = canonicalize_version(spec[:-2], strip_trailing_zero=False)
|
| 453 |
+
# Split the spec out by bangs and dots, and pretend that there is
|
| 454 |
+
# an implicit dot in between a release segment and a pre-release segment.
|
| 455 |
+
split_spec = _version_split(normalized_spec)
|
| 456 |
+
|
| 457 |
+
# Split the prospective version out by bangs and dots, and pretend
|
| 458 |
+
# that there is an implicit dot in between a release segment and
|
| 459 |
+
# a pre-release segment.
|
| 460 |
+
split_prospective = _version_split(normalized_prospective)
|
| 461 |
+
|
| 462 |
+
# 0-pad the prospective version before shortening it to get the correct
|
| 463 |
+
# shortened version.
|
| 464 |
+
padded_prospective, _ = _pad_version(split_prospective, split_spec)
|
| 465 |
+
|
| 466 |
+
# Shorten the prospective version to be the same length as the spec
|
| 467 |
+
# so that we can determine if the specifier is a prefix of the
|
| 468 |
+
# prospective version or not.
|
| 469 |
+
shortened_prospective = padded_prospective[: len(split_spec)]
|
| 470 |
+
|
| 471 |
+
return shortened_prospective == split_spec
|
| 472 |
+
else:
|
| 473 |
+
# Convert our spec string into a Version
|
| 474 |
+
spec_version = self._require_spec_version(spec)
|
| 475 |
+
|
| 476 |
+
# If the specifier does not have a local segment, then we want to
|
| 477 |
+
# act as if the prospective version also does not have a local
|
| 478 |
+
# segment.
|
| 479 |
+
if not spec_version.local:
|
| 480 |
+
prospective = _public_version(prospective)
|
| 481 |
+
|
| 482 |
+
return prospective == spec_version
|
| 483 |
+
|
| 484 |
+
def _compare_not_equal(self, prospective: Version, spec: str) -> bool:
|
| 485 |
+
return not self._compare_equal(prospective, spec)
|
| 486 |
+
|
| 487 |
+
def _compare_less_than_equal(self, prospective: Version, spec: str) -> bool:
|
| 488 |
+
# NB: Local version identifiers are NOT permitted in the version
|
| 489 |
+
# specifier, so local version labels can be universally removed from
|
| 490 |
+
# the prospective version.
|
| 491 |
+
return _public_version(prospective) <= self._require_spec_version(spec)
|
| 492 |
+
|
| 493 |
+
def _compare_greater_than_equal(self, prospective: Version, spec: str) -> bool:
|
| 494 |
+
# NB: Local version identifiers are NOT permitted in the version
|
| 495 |
+
# specifier, so local version labels can be universally removed from
|
| 496 |
+
# the prospective version.
|
| 497 |
+
return _public_version(prospective) >= self._require_spec_version(spec)
|
| 498 |
+
|
| 499 |
+
def _compare_less_than(self, prospective: Version, spec_str: str) -> bool:
|
| 500 |
+
# Convert our spec to a Version instance, since we'll want to work with
|
| 501 |
+
# it as a version.
|
| 502 |
+
spec = self._require_spec_version(spec_str)
|
| 503 |
+
|
| 504 |
+
# Check to see if the prospective version is less than the spec
|
| 505 |
+
# version. If it's not we can short circuit and just return False now
|
| 506 |
+
# instead of doing extra unneeded work.
|
| 507 |
+
if not prospective < spec:
|
| 508 |
+
return False
|
| 509 |
+
|
| 510 |
+
# This special case is here so that, unless the specifier itself
|
| 511 |
+
# includes is a pre-release version, that we do not accept pre-release
|
| 512 |
+
# versions for the version mentioned in the specifier (e.g. <3.1 should
|
| 513 |
+
# not match 3.1.dev0, but should match 3.0.dev0).
|
| 514 |
+
if (
|
| 515 |
+
not spec.is_prerelease
|
| 516 |
+
and prospective.is_prerelease
|
| 517 |
+
and _base_version(prospective) == _base_version(spec)
|
| 518 |
+
):
|
| 519 |
+
return False
|
| 520 |
+
|
| 521 |
+
# If we've gotten to here, it means that prospective version is both
|
| 522 |
+
# less than the spec version *and* it's not a pre-release of the same
|
| 523 |
+
# version in the spec.
|
| 524 |
+
return True
|
| 525 |
+
|
| 526 |
+
def _compare_greater_than(self, prospective: Version, spec_str: str) -> bool:
|
| 527 |
+
# Convert our spec to a Version instance, since we'll want to work with
|
| 528 |
+
# it as a version.
|
| 529 |
+
spec = self._require_spec_version(spec_str)
|
| 530 |
+
|
| 531 |
+
# Check to see if the prospective version is greater than the spec
|
| 532 |
+
# version. If it's not we can short circuit and just return False now
|
| 533 |
+
# instead of doing extra unneeded work.
|
| 534 |
+
if not prospective > spec:
|
| 535 |
+
return False
|
| 536 |
+
|
| 537 |
+
# This special case is here so that, unless the specifier itself
|
| 538 |
+
# includes is a post-release version, that we do not accept
|
| 539 |
+
# post-release versions for the version mentioned in the specifier
|
| 540 |
+
# (e.g. >3.1 should not match 3.0.post0, but should match 3.2.post0).
|
| 541 |
+
if (
|
| 542 |
+
not spec.is_postrelease
|
| 543 |
+
and prospective.is_postrelease
|
| 544 |
+
and _base_version(prospective) == _base_version(spec)
|
| 545 |
+
):
|
| 546 |
+
return False
|
| 547 |
+
|
| 548 |
+
# Ensure that we do not allow a local version of the version mentioned
|
| 549 |
+
# in the specifier, which is technically greater than, to match.
|
| 550 |
+
if prospective.local is not None and _base_version(
|
| 551 |
+
prospective
|
| 552 |
+
) == _base_version(spec):
|
| 553 |
+
return False
|
| 554 |
+
|
| 555 |
+
# If we've gotten to here, it means that prospective version is both
|
| 556 |
+
# greater than the spec version *and* it's not a pre-release of the
|
| 557 |
+
# same version in the spec.
|
| 558 |
+
return True
|
| 559 |
+
|
| 560 |
+
def _compare_arbitrary(self, prospective: Version | str, spec: str) -> bool:
|
| 561 |
+
return str(prospective).lower() == str(spec).lower()
|
| 562 |
+
|
| 563 |
+
def __contains__(self, item: str | Version) -> bool:
|
| 564 |
+
"""Return whether or not the item is contained in this specifier.
|
| 565 |
+
|
| 566 |
+
:param item: The item to check for.
|
| 567 |
+
|
| 568 |
+
This is used for the ``in`` operator and behaves the same as
|
| 569 |
+
:meth:`contains` with no ``prereleases`` argument passed.
|
| 570 |
+
|
| 571 |
+
>>> "1.2.3" in Specifier(">=1.2.3")
|
| 572 |
+
True
|
| 573 |
+
>>> Version("1.2.3") in Specifier(">=1.2.3")
|
| 574 |
+
True
|
| 575 |
+
>>> "1.0.0" in Specifier(">=1.2.3")
|
| 576 |
+
False
|
| 577 |
+
>>> "1.3.0a1" in Specifier(">=1.2.3")
|
| 578 |
+
True
|
| 579 |
+
>>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True)
|
| 580 |
+
True
|
| 581 |
+
"""
|
| 582 |
+
return self.contains(item)
|
| 583 |
+
|
| 584 |
+
def contains(self, item: UnparsedVersion, prereleases: bool | None = None) -> bool:
|
| 585 |
+
"""Return whether or not the item is contained in this specifier.
|
| 586 |
+
|
| 587 |
+
:param item:
|
| 588 |
+
The item to check for, which can be a version string or a
|
| 589 |
+
:class:`Version` instance.
|
| 590 |
+
:param prereleases:
|
| 591 |
+
Whether or not to match prereleases with this Specifier. If set to
|
| 592 |
+
``None`` (the default), it will follow the recommendation from
|
| 593 |
+
:pep:`440` and match prereleases, as there are no other versions.
|
| 594 |
+
|
| 595 |
+
>>> Specifier(">=1.2.3").contains("1.2.3")
|
| 596 |
+
True
|
| 597 |
+
>>> Specifier(">=1.2.3").contains(Version("1.2.3"))
|
| 598 |
+
True
|
| 599 |
+
>>> Specifier(">=1.2.3").contains("1.0.0")
|
| 600 |
+
False
|
| 601 |
+
>>> Specifier(">=1.2.3").contains("1.3.0a1")
|
| 602 |
+
True
|
| 603 |
+
>>> Specifier(">=1.2.3", prereleases=False).contains("1.3.0a1")
|
| 604 |
+
False
|
| 605 |
+
>>> Specifier(">=1.2.3").contains("1.3.0a1")
|
| 606 |
+
True
|
| 607 |
+
"""
|
| 608 |
+
|
| 609 |
+
return bool(list(self.filter([item], prereleases=prereleases)))
|
| 610 |
+
|
| 611 |
+
def filter(
|
| 612 |
+
self, iterable: Iterable[UnparsedVersionVar], prereleases: bool | None = None
|
| 613 |
+
) -> Iterator[UnparsedVersionVar]:
|
| 614 |
+
"""Filter items in the given iterable, that match the specifier.
|
| 615 |
+
|
| 616 |
+
:param iterable:
|
| 617 |
+
An iterable that can contain version strings and :class:`Version` instances.
|
| 618 |
+
The items in the iterable will be filtered according to the specifier.
|
| 619 |
+
:param prereleases:
|
| 620 |
+
Whether or not to allow prereleases in the returned iterator. If set to
|
| 621 |
+
``None`` (the default), it will follow the recommendation from :pep:`440`
|
| 622 |
+
and match prereleases if there are no other versions.
|
| 623 |
+
|
| 624 |
+
>>> list(Specifier(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
|
| 625 |
+
['1.3']
|
| 626 |
+
>>> list(Specifier(">=1.2.3").filter(["1.2", "1.2.3", "1.3", Version("1.4")]))
|
| 627 |
+
['1.2.3', '1.3', <Version('1.4')>]
|
| 628 |
+
>>> list(Specifier(">=1.2.3").filter(["1.2", "1.5a1"]))
|
| 629 |
+
['1.5a1']
|
| 630 |
+
>>> list(Specifier(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
|
| 631 |
+
['1.3', '1.5a1']
|
| 632 |
+
>>> list(Specifier(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
|
| 633 |
+
['1.3', '1.5a1']
|
| 634 |
+
"""
|
| 635 |
+
prereleases_versions = []
|
| 636 |
+
found_non_prereleases = False
|
| 637 |
+
|
| 638 |
+
# Determine if to include prereleases by default
|
| 639 |
+
include_prereleases = (
|
| 640 |
+
prereleases if prereleases is not None else self.prereleases
|
| 641 |
+
)
|
| 642 |
+
|
| 643 |
+
# Get the matching operator
|
| 644 |
+
operator_callable = self._get_operator(self.operator)
|
| 645 |
+
|
| 646 |
+
# Filter versions
|
| 647 |
+
for version in iterable:
|
| 648 |
+
parsed_version = _coerce_version(version)
|
| 649 |
+
if parsed_version is None:
|
| 650 |
+
# === operator can match arbitrary (non-version) strings
|
| 651 |
+
if self.operator == "===" and self._compare_arbitrary(
|
| 652 |
+
version, self.version
|
| 653 |
+
):
|
| 654 |
+
yield version
|
| 655 |
+
elif operator_callable(parsed_version, self.version):
|
| 656 |
+
# If it's not a prerelease or prereleases are allowed, yield it directly
|
| 657 |
+
if not parsed_version.is_prerelease or include_prereleases:
|
| 658 |
+
found_non_prereleases = True
|
| 659 |
+
yield version
|
| 660 |
+
# Otherwise collect prereleases for potential later use
|
| 661 |
+
elif prereleases is None and self._prereleases is not False:
|
| 662 |
+
prereleases_versions.append(version)
|
| 663 |
+
|
| 664 |
+
# If no non-prereleases were found and prereleases weren't
|
| 665 |
+
# explicitly forbidden, yield the collected prereleases
|
| 666 |
+
if (
|
| 667 |
+
not found_non_prereleases
|
| 668 |
+
and prereleases is None
|
| 669 |
+
and self._prereleases is not False
|
| 670 |
+
):
|
| 671 |
+
yield from prereleases_versions
|
| 672 |
+
|
| 673 |
+
|
| 674 |
+
_prefix_regex = re.compile(r"([0-9]+)((?:a|b|c|rc)[0-9]+)")
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
def _version_split(version: str) -> list[str]:
|
| 678 |
+
"""Split version into components.
|
| 679 |
+
|
| 680 |
+
The split components are intended for version comparison. The logic does
|
| 681 |
+
not attempt to retain the original version string, so joining the
|
| 682 |
+
components back with :func:`_version_join` may not produce the original
|
| 683 |
+
version string.
|
| 684 |
+
"""
|
| 685 |
+
result: list[str] = []
|
| 686 |
+
|
| 687 |
+
epoch, _, rest = version.rpartition("!")
|
| 688 |
+
result.append(epoch or "0")
|
| 689 |
+
|
| 690 |
+
for item in rest.split("."):
|
| 691 |
+
match = _prefix_regex.fullmatch(item)
|
| 692 |
+
if match:
|
| 693 |
+
result.extend(match.groups())
|
| 694 |
+
else:
|
| 695 |
+
result.append(item)
|
| 696 |
+
return result
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
def _version_join(components: list[str]) -> str:
|
| 700 |
+
"""Join split version components into a version string.
|
| 701 |
+
|
| 702 |
+
This function assumes the input came from :func:`_version_split`, where the
|
| 703 |
+
first component must be the epoch (either empty or numeric), and all other
|
| 704 |
+
components numeric.
|
| 705 |
+
"""
|
| 706 |
+
epoch, *rest = components
|
| 707 |
+
return f"{epoch}!{'.'.join(rest)}"
|
| 708 |
+
|
| 709 |
+
|
| 710 |
+
def _is_not_suffix(segment: str) -> bool:
|
| 711 |
+
return not any(
|
| 712 |
+
segment.startswith(prefix) for prefix in ("dev", "a", "b", "rc", "post")
|
| 713 |
+
)
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
def _pad_version(left: list[str], right: list[str]) -> tuple[list[str], list[str]]:
|
| 717 |
+
left_split, right_split = [], []
|
| 718 |
+
|
| 719 |
+
# Get the release segment of our versions
|
| 720 |
+
left_split.append(list(itertools.takewhile(lambda x: x.isdigit(), left)))
|
| 721 |
+
right_split.append(list(itertools.takewhile(lambda x: x.isdigit(), right)))
|
| 722 |
+
|
| 723 |
+
# Get the rest of our versions
|
| 724 |
+
left_split.append(left[len(left_split[0]) :])
|
| 725 |
+
right_split.append(right[len(right_split[0]) :])
|
| 726 |
+
|
| 727 |
+
# Insert our padding
|
| 728 |
+
left_split.insert(1, ["0"] * max(0, len(right_split[0]) - len(left_split[0])))
|
| 729 |
+
right_split.insert(1, ["0"] * max(0, len(left_split[0]) - len(right_split[0])))
|
| 730 |
+
|
| 731 |
+
return (
|
| 732 |
+
list(itertools.chain.from_iterable(left_split)),
|
| 733 |
+
list(itertools.chain.from_iterable(right_split)),
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
class SpecifierSet(BaseSpecifier):
|
| 738 |
+
"""This class abstracts handling of a set of version specifiers.
|
| 739 |
+
|
| 740 |
+
It can be passed a single specifier (``>=3.0``), a comma-separated list of
|
| 741 |
+
specifiers (``>=3.0,!=3.1``), or no specifier at all.
|
| 742 |
+
"""
|
| 743 |
+
|
| 744 |
+
__slots__ = ("_prereleases", "_specs")
|
| 745 |
+
|
| 746 |
+
def __init__(
|
| 747 |
+
self,
|
| 748 |
+
specifiers: str | Iterable[Specifier] = "",
|
| 749 |
+
prereleases: bool | None = None,
|
| 750 |
+
) -> None:
|
| 751 |
+
"""Initialize a SpecifierSet instance.
|
| 752 |
+
|
| 753 |
+
:param specifiers:
|
| 754 |
+
The string representation of a specifier or a comma-separated list of
|
| 755 |
+
specifiers which will be parsed and normalized before use.
|
| 756 |
+
May also be an iterable of ``Specifier`` instances, which will be used
|
| 757 |
+
as is.
|
| 758 |
+
:param prereleases:
|
| 759 |
+
This tells the SpecifierSet if it should accept prerelease versions if
|
| 760 |
+
applicable or not. The default of ``None`` will autodetect it from the
|
| 761 |
+
given specifiers.
|
| 762 |
+
|
| 763 |
+
:raises InvalidSpecifier:
|
| 764 |
+
If the given ``specifiers`` are not parseable than this exception will be
|
| 765 |
+
raised.
|
| 766 |
+
"""
|
| 767 |
+
|
| 768 |
+
if isinstance(specifiers, str):
|
| 769 |
+
# Split on `,` to break each individual specifier into its own item, and
|
| 770 |
+
# strip each item to remove leading/trailing whitespace.
|
| 771 |
+
split_specifiers = [s.strip() for s in specifiers.split(",") if s.strip()]
|
| 772 |
+
|
| 773 |
+
# Make each individual specifier a Specifier and save in a frozen set
|
| 774 |
+
# for later.
|
| 775 |
+
self._specs = frozenset(map(Specifier, split_specifiers))
|
| 776 |
+
else:
|
| 777 |
+
# Save the supplied specifiers in a frozen set.
|
| 778 |
+
self._specs = frozenset(specifiers)
|
| 779 |
+
|
| 780 |
+
# Store our prereleases value so we can use it later to determine if
|
| 781 |
+
# we accept prereleases or not.
|
| 782 |
+
self._prereleases = prereleases
|
| 783 |
+
|
| 784 |
+
@property
|
| 785 |
+
def prereleases(self) -> bool | None:
|
| 786 |
+
# If we have been given an explicit prerelease modifier, then we'll
|
| 787 |
+
# pass that through here.
|
| 788 |
+
if self._prereleases is not None:
|
| 789 |
+
return self._prereleases
|
| 790 |
+
|
| 791 |
+
# If we don't have any specifiers, and we don't have a forced value,
|
| 792 |
+
# then we'll just return None since we don't know if this should have
|
| 793 |
+
# pre-releases or not.
|
| 794 |
+
if not self._specs:
|
| 795 |
+
return None
|
| 796 |
+
|
| 797 |
+
# Otherwise we'll see if any of the given specifiers accept
|
| 798 |
+
# prereleases, if any of them do we'll return True, otherwise False.
|
| 799 |
+
if any(s.prereleases for s in self._specs):
|
| 800 |
+
return True
|
| 801 |
+
|
| 802 |
+
return None
|
| 803 |
+
|
| 804 |
+
@prereleases.setter
|
| 805 |
+
def prereleases(self, value: bool | None) -> None:
|
| 806 |
+
self._prereleases = value
|
| 807 |
+
|
| 808 |
+
def __repr__(self) -> str:
|
| 809 |
+
"""A representation of the specifier set that shows all internal state.
|
| 810 |
+
|
| 811 |
+
Note that the ordering of the individual specifiers within the set may not
|
| 812 |
+
match the input string.
|
| 813 |
+
|
| 814 |
+
>>> SpecifierSet('>=1.0.0,!=2.0.0')
|
| 815 |
+
<SpecifierSet('!=2.0.0,>=1.0.0')>
|
| 816 |
+
>>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=False)
|
| 817 |
+
<SpecifierSet('!=2.0.0,>=1.0.0', prereleases=False)>
|
| 818 |
+
>>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=True)
|
| 819 |
+
<SpecifierSet('!=2.0.0,>=1.0.0', prereleases=True)>
|
| 820 |
+
"""
|
| 821 |
+
pre = (
|
| 822 |
+
f", prereleases={self.prereleases!r}"
|
| 823 |
+
if self._prereleases is not None
|
| 824 |
+
else ""
|
| 825 |
+
)
|
| 826 |
+
|
| 827 |
+
return f"<SpecifierSet({str(self)!r}{pre})>"
|
| 828 |
+
|
| 829 |
+
def __str__(self) -> str:
|
| 830 |
+
"""A string representation of the specifier set that can be round-tripped.
|
| 831 |
+
|
| 832 |
+
Note that the ordering of the individual specifiers within the set may not
|
| 833 |
+
match the input string.
|
| 834 |
+
|
| 835 |
+
>>> str(SpecifierSet(">=1.0.0,!=1.0.1"))
|
| 836 |
+
'!=1.0.1,>=1.0.0'
|
| 837 |
+
>>> str(SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False))
|
| 838 |
+
'!=1.0.1,>=1.0.0'
|
| 839 |
+
"""
|
| 840 |
+
return ",".join(sorted(str(s) for s in self._specs))
|
| 841 |
+
|
| 842 |
+
def __hash__(self) -> int:
|
| 843 |
+
return hash(self._specs)
|
| 844 |
+
|
| 845 |
+
def __and__(self, other: SpecifierSet | str) -> SpecifierSet:
|
| 846 |
+
"""Return a SpecifierSet which is a combination of the two sets.
|
| 847 |
+
|
| 848 |
+
:param other: The other object to combine with.
|
| 849 |
+
|
| 850 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1") & '<=2.0.0,!=2.0.1'
|
| 851 |
+
<SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
|
| 852 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1") & SpecifierSet('<=2.0.0,!=2.0.1')
|
| 853 |
+
<SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
|
| 854 |
+
"""
|
| 855 |
+
if isinstance(other, str):
|
| 856 |
+
other = SpecifierSet(other)
|
| 857 |
+
elif not isinstance(other, SpecifierSet):
|
| 858 |
+
return NotImplemented
|
| 859 |
+
|
| 860 |
+
specifier = SpecifierSet()
|
| 861 |
+
specifier._specs = frozenset(self._specs | other._specs)
|
| 862 |
+
|
| 863 |
+
if self._prereleases is None and other._prereleases is not None:
|
| 864 |
+
specifier._prereleases = other._prereleases
|
| 865 |
+
elif (
|
| 866 |
+
self._prereleases is not None and other._prereleases is None
|
| 867 |
+
) or self._prereleases == other._prereleases:
|
| 868 |
+
specifier._prereleases = self._prereleases
|
| 869 |
+
else:
|
| 870 |
+
raise ValueError(
|
| 871 |
+
"Cannot combine SpecifierSets with True and False prerelease overrides."
|
| 872 |
+
)
|
| 873 |
+
|
| 874 |
+
return specifier
|
| 875 |
+
|
| 876 |
+
def __eq__(self, other: object) -> bool:
|
| 877 |
+
"""Whether or not the two SpecifierSet-like objects are equal.
|
| 878 |
+
|
| 879 |
+
:param other: The other object to check against.
|
| 880 |
+
|
| 881 |
+
The value of :attr:`prereleases` is ignored.
|
| 882 |
+
|
| 883 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.1")
|
| 884 |
+
True
|
| 885 |
+
>>> (SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False) ==
|
| 886 |
+
... SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True))
|
| 887 |
+
True
|
| 888 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1") == ">=1.0.0,!=1.0.1"
|
| 889 |
+
True
|
| 890 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0")
|
| 891 |
+
False
|
| 892 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.2")
|
| 893 |
+
False
|
| 894 |
+
"""
|
| 895 |
+
if isinstance(other, (str, Specifier)):
|
| 896 |
+
other = SpecifierSet(str(other))
|
| 897 |
+
elif not isinstance(other, SpecifierSet):
|
| 898 |
+
return NotImplemented
|
| 899 |
+
|
| 900 |
+
return self._specs == other._specs
|
| 901 |
+
|
| 902 |
+
def __len__(self) -> int:
|
| 903 |
+
"""Returns the number of specifiers in this specifier set."""
|
| 904 |
+
return len(self._specs)
|
| 905 |
+
|
| 906 |
+
def __iter__(self) -> Iterator[Specifier]:
|
| 907 |
+
"""
|
| 908 |
+
Returns an iterator over all the underlying :class:`Specifier` instances
|
| 909 |
+
in this specifier set.
|
| 910 |
+
|
| 911 |
+
>>> sorted(SpecifierSet(">=1.0.0,!=1.0.1"), key=str)
|
| 912 |
+
[<Specifier('!=1.0.1')>, <Specifier('>=1.0.0')>]
|
| 913 |
+
"""
|
| 914 |
+
return iter(self._specs)
|
| 915 |
+
|
| 916 |
+
def __contains__(self, item: UnparsedVersion) -> bool:
|
| 917 |
+
"""Return whether or not the item is contained in this specifier.
|
| 918 |
+
|
| 919 |
+
:param item: The item to check for.
|
| 920 |
+
|
| 921 |
+
This is used for the ``in`` operator and behaves the same as
|
| 922 |
+
:meth:`contains` with no ``prereleases`` argument passed.
|
| 923 |
+
|
| 924 |
+
>>> "1.2.3" in SpecifierSet(">=1.0.0,!=1.0.1")
|
| 925 |
+
True
|
| 926 |
+
>>> Version("1.2.3") in SpecifierSet(">=1.0.0,!=1.0.1")
|
| 927 |
+
True
|
| 928 |
+
>>> "1.0.1" in SpecifierSet(">=1.0.0,!=1.0.1")
|
| 929 |
+
False
|
| 930 |
+
>>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1")
|
| 931 |
+
True
|
| 932 |
+
>>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True)
|
| 933 |
+
True
|
| 934 |
+
"""
|
| 935 |
+
return self.contains(item)
|
| 936 |
+
|
| 937 |
+
def contains(
|
| 938 |
+
self,
|
| 939 |
+
item: UnparsedVersion,
|
| 940 |
+
prereleases: bool | None = None,
|
| 941 |
+
installed: bool | None = None,
|
| 942 |
+
) -> bool:
|
| 943 |
+
"""Return whether or not the item is contained in this SpecifierSet.
|
| 944 |
+
|
| 945 |
+
:param item:
|
| 946 |
+
The item to check for, which can be a version string or a
|
| 947 |
+
:class:`Version` instance.
|
| 948 |
+
:param prereleases:
|
| 949 |
+
Whether or not to match prereleases with this SpecifierSet. If set to
|
| 950 |
+
``None`` (the default), it will follow the recommendation from :pep:`440`
|
| 951 |
+
and match prereleases, as there are no other versions.
|
| 952 |
+
:param installed:
|
| 953 |
+
Whether or not the item is installed. If set to ``True``, it will
|
| 954 |
+
accept prerelease versions even if the specifier does not allow them.
|
| 955 |
+
|
| 956 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.2.3")
|
| 957 |
+
True
|
| 958 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1").contains(Version("1.2.3"))
|
| 959 |
+
True
|
| 960 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.0.1")
|
| 961 |
+
False
|
| 962 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1")
|
| 963 |
+
True
|
| 964 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False).contains("1.3.0a1")
|
| 965 |
+
False
|
| 966 |
+
>>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1", prereleases=True)
|
| 967 |
+
True
|
| 968 |
+
"""
|
| 969 |
+
version = _coerce_version(item)
|
| 970 |
+
|
| 971 |
+
if version is not None and installed and version.is_prerelease:
|
| 972 |
+
prereleases = True
|
| 973 |
+
|
| 974 |
+
check_item = item if version is None else version
|
| 975 |
+
return bool(list(self.filter([check_item], prereleases=prereleases)))
|
| 976 |
+
|
| 977 |
+
def filter(
|
| 978 |
+
self, iterable: Iterable[UnparsedVersionVar], prereleases: bool | None = None
|
| 979 |
+
) -> Iterator[UnparsedVersionVar]:
|
| 980 |
+
"""Filter items in the given iterable, that match the specifiers in this set.
|
| 981 |
+
|
| 982 |
+
:param iterable:
|
| 983 |
+
An iterable that can contain version strings and :class:`Version` instances.
|
| 984 |
+
The items in the iterable will be filtered according to the specifier.
|
| 985 |
+
:param prereleases:
|
| 986 |
+
Whether or not to allow prereleases in the returned iterator. If set to
|
| 987 |
+
``None`` (the default), it will follow the recommendation from :pep:`440`
|
| 988 |
+
and match prereleases if there are no other versions.
|
| 989 |
+
|
| 990 |
+
>>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
|
| 991 |
+
['1.3']
|
| 992 |
+
>>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.3", Version("1.4")]))
|
| 993 |
+
['1.3', <Version('1.4')>]
|
| 994 |
+
>>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.5a1"]))
|
| 995 |
+
['1.5a1']
|
| 996 |
+
>>> list(SpecifierSet(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
|
| 997 |
+
['1.3', '1.5a1']
|
| 998 |
+
>>> list(SpecifierSet(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
|
| 999 |
+
['1.3', '1.5a1']
|
| 1000 |
+
|
| 1001 |
+
An "empty" SpecifierSet will filter items based on the presence of prerelease
|
| 1002 |
+
versions in the set.
|
| 1003 |
+
|
| 1004 |
+
>>> list(SpecifierSet("").filter(["1.3", "1.5a1"]))
|
| 1005 |
+
['1.3']
|
| 1006 |
+
>>> list(SpecifierSet("").filter(["1.5a1"]))
|
| 1007 |
+
['1.5a1']
|
| 1008 |
+
>>> list(SpecifierSet("", prereleases=True).filter(["1.3", "1.5a1"]))
|
| 1009 |
+
['1.3', '1.5a1']
|
| 1010 |
+
>>> list(SpecifierSet("").filter(["1.3", "1.5a1"], prereleases=True))
|
| 1011 |
+
['1.3', '1.5a1']
|
| 1012 |
+
"""
|
| 1013 |
+
# Determine if we're forcing a prerelease or not, if we're not forcing
|
| 1014 |
+
# one for this particular filter call, then we'll use whatever the
|
| 1015 |
+
# SpecifierSet thinks for whether or not we should support prereleases.
|
| 1016 |
+
if prereleases is None and self.prereleases is not None:
|
| 1017 |
+
prereleases = self.prereleases
|
| 1018 |
+
|
| 1019 |
+
# If we have any specifiers, then we want to wrap our iterable in the
|
| 1020 |
+
# filter method for each one, this will act as a logical AND amongst
|
| 1021 |
+
# each specifier.
|
| 1022 |
+
if self._specs:
|
| 1023 |
+
# When prereleases is None, we need to let all versions through
|
| 1024 |
+
# the individual filters, then decide about prereleases at the end
|
| 1025 |
+
# based on whether any non-prereleases matched ALL specs.
|
| 1026 |
+
for spec in self._specs:
|
| 1027 |
+
iterable = spec.filter(
|
| 1028 |
+
iterable, prereleases=True if prereleases is None else prereleases
|
| 1029 |
+
)
|
| 1030 |
+
|
| 1031 |
+
if prereleases is not None:
|
| 1032 |
+
# If we have a forced prereleases value,
|
| 1033 |
+
# we can immediately return the iterator.
|
| 1034 |
+
return iter(iterable)
|
| 1035 |
+
else:
|
| 1036 |
+
# Handle empty SpecifierSet cases where prereleases is not None.
|
| 1037 |
+
if prereleases is True:
|
| 1038 |
+
return iter(iterable)
|
| 1039 |
+
|
| 1040 |
+
if prereleases is False:
|
| 1041 |
+
return (
|
| 1042 |
+
item
|
| 1043 |
+
for item in iterable
|
| 1044 |
+
if (version := _coerce_version(item)) is None
|
| 1045 |
+
or not version.is_prerelease
|
| 1046 |
+
)
|
| 1047 |
+
|
| 1048 |
+
# Finally if prereleases is None, apply PEP 440 logic:
|
| 1049 |
+
# exclude prereleases unless there are no final releases that matched.
|
| 1050 |
+
filtered_items: list[UnparsedVersionVar] = []
|
| 1051 |
+
found_prereleases: list[UnparsedVersionVar] = []
|
| 1052 |
+
found_final_release = False
|
| 1053 |
+
|
| 1054 |
+
for item in iterable:
|
| 1055 |
+
parsed_version = _coerce_version(item)
|
| 1056 |
+
# Arbitrary strings are always included as it is not
|
| 1057 |
+
# possible to determine if they are prereleases,
|
| 1058 |
+
# and they have already passed all specifiers.
|
| 1059 |
+
if parsed_version is None:
|
| 1060 |
+
filtered_items.append(item)
|
| 1061 |
+
found_prereleases.append(item)
|
| 1062 |
+
elif parsed_version.is_prerelease:
|
| 1063 |
+
found_prereleases.append(item)
|
| 1064 |
+
else:
|
| 1065 |
+
filtered_items.append(item)
|
| 1066 |
+
found_final_release = True
|
| 1067 |
+
|
| 1068 |
+
return iter(filtered_items if found_final_release else found_prereleases)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The following files include code from opensource projects
|
| 2 |
+
(either as direct copies or modified versions):
|
| 3 |
+
|
| 4 |
+
- `setuptools.schema.json`, `distutils.schema.json`:
|
| 5 |
+
- project: `validate-pyproject` - licensed under MPL-2.0
|
| 6 |
+
(https://github.com/abravalheri/validate-pyproject):
|
| 7 |
+
|
| 8 |
+
This Source Code Form is subject to the terms of the Mozilla Public
|
| 9 |
+
License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
| 10 |
+
You can obtain one at https://mozilla.org/MPL/2.0/.
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/__init__.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""For backward compatibility, expose main functions from
|
| 2 |
+
``setuptools.config.setupcfg``
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from collections.abc import Callable
|
| 6 |
+
from functools import wraps
|
| 7 |
+
from typing import TypeVar, cast
|
| 8 |
+
|
| 9 |
+
from ..warnings import SetuptoolsDeprecationWarning
|
| 10 |
+
from . import setupcfg
|
| 11 |
+
|
| 12 |
+
Fn = TypeVar("Fn", bound=Callable)
|
| 13 |
+
|
| 14 |
+
__all__ = ('parse_configuration', 'read_configuration')
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _deprecation_notice(fn: Fn) -> Fn:
|
| 18 |
+
@wraps(fn)
|
| 19 |
+
def _wrapper(*args, **kwargs):
|
| 20 |
+
SetuptoolsDeprecationWarning.emit(
|
| 21 |
+
"Deprecated API usage.",
|
| 22 |
+
f"""
|
| 23 |
+
As setuptools moves its configuration towards `pyproject.toml`,
|
| 24 |
+
`{__name__}.{fn.__name__}` became deprecated.
|
| 25 |
+
|
| 26 |
+
For the time being, you can use the `{setupcfg.__name__}` module
|
| 27 |
+
to access a backward compatible API, but this module is provisional
|
| 28 |
+
and might be removed in the future.
|
| 29 |
+
|
| 30 |
+
To read project metadata, consider using
|
| 31 |
+
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
|
| 32 |
+
For simple scenarios, you can also try parsing the file directly
|
| 33 |
+
with the help of ``configparser``.
|
| 34 |
+
""",
|
| 35 |
+
# due_date not defined yet, because the community still heavily relies on it
|
| 36 |
+
# Warning introduced in 24 Mar 2022
|
| 37 |
+
)
|
| 38 |
+
return fn(*args, **kwargs)
|
| 39 |
+
|
| 40 |
+
return cast(Fn, _wrapper)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
read_configuration = _deprecation_notice(setupcfg.read_configuration)
|
| 44 |
+
parse_configuration = _deprecation_notice(setupcfg.parse_configuration)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_apply_pyprojecttoml.py
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Translation layer between pyproject config and setuptools distribution and
|
| 2 |
+
metadata objects.
|
| 3 |
+
|
| 4 |
+
The distribution and metadata objects are modeled after (an old version of)
|
| 5 |
+
core metadata, therefore configs in the format specified for ``pyproject.toml``
|
| 6 |
+
need to be processed before being applied.
|
| 7 |
+
|
| 8 |
+
**PRIVATE MODULE**: API reserved for setuptools internal usage only.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import logging
|
| 14 |
+
import os
|
| 15 |
+
from collections.abc import Callable, Mapping
|
| 16 |
+
from email.headerregistry import Address
|
| 17 |
+
from functools import partial, reduce
|
| 18 |
+
from inspect import cleandoc
|
| 19 |
+
from itertools import chain
|
| 20 |
+
from types import MappingProxyType
|
| 21 |
+
from typing import TYPE_CHECKING, Any, TypeVar
|
| 22 |
+
|
| 23 |
+
from .. import _static
|
| 24 |
+
from .._path import StrPath
|
| 25 |
+
from ..errors import InvalidConfigError, RemovedConfigError
|
| 26 |
+
from ..extension import Extension
|
| 27 |
+
from ..warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning
|
| 28 |
+
|
| 29 |
+
if TYPE_CHECKING:
|
| 30 |
+
from typing import TypeAlias
|
| 31 |
+
|
| 32 |
+
from setuptools._importlib import metadata
|
| 33 |
+
from setuptools.dist import Distribution
|
| 34 |
+
|
| 35 |
+
from distutils.dist import _OptionsList # Comes from typeshed
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
EMPTY: Mapping = MappingProxyType({}) # Immutable dict-like
|
| 39 |
+
_ProjectReadmeValue: TypeAlias = str | dict[str, str]
|
| 40 |
+
_Correspondence: TypeAlias = Callable[["Distribution", Any, StrPath | None], None]
|
| 41 |
+
_T = TypeVar("_T")
|
| 42 |
+
|
| 43 |
+
_logger = logging.getLogger(__name__)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def apply(dist: Distribution, config: dict, filename: StrPath) -> Distribution:
|
| 47 |
+
"""Apply configuration dict read with :func:`read_configuration`"""
|
| 48 |
+
|
| 49 |
+
if not config:
|
| 50 |
+
return dist # short-circuit unrelated pyproject.toml file
|
| 51 |
+
|
| 52 |
+
root_dir = os.path.dirname(filename) or "."
|
| 53 |
+
|
| 54 |
+
_apply_project_table(dist, config, root_dir)
|
| 55 |
+
_apply_tool_table(dist, config, filename)
|
| 56 |
+
|
| 57 |
+
current_directory = os.getcwd()
|
| 58 |
+
os.chdir(root_dir)
|
| 59 |
+
try:
|
| 60 |
+
dist._finalize_requires()
|
| 61 |
+
dist._finalize_license_expression()
|
| 62 |
+
dist._finalize_license_files()
|
| 63 |
+
finally:
|
| 64 |
+
os.chdir(current_directory)
|
| 65 |
+
|
| 66 |
+
return dist
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _apply_project_table(dist: Distribution, config: dict, root_dir: StrPath):
|
| 70 |
+
orig_config = config.get("project", {})
|
| 71 |
+
if not orig_config:
|
| 72 |
+
return # short-circuit
|
| 73 |
+
|
| 74 |
+
project_table = {k: _static.attempt_conversion(v) for k, v in orig_config.items()}
|
| 75 |
+
_handle_missing_dynamic(dist, project_table)
|
| 76 |
+
_unify_entry_points(project_table)
|
| 77 |
+
|
| 78 |
+
for field, value in project_table.items():
|
| 79 |
+
norm_key = json_compatible_key(field)
|
| 80 |
+
corresp = PYPROJECT_CORRESPONDENCE.get(norm_key, norm_key)
|
| 81 |
+
if callable(corresp):
|
| 82 |
+
corresp(dist, value, root_dir)
|
| 83 |
+
else:
|
| 84 |
+
_set_config(dist, corresp, value)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def _apply_tool_table(dist: Distribution, config: dict, filename: StrPath):
|
| 88 |
+
tool_table = config.get("tool", {}).get("setuptools", {})
|
| 89 |
+
if not tool_table:
|
| 90 |
+
return # short-circuit
|
| 91 |
+
|
| 92 |
+
if "license-files" in tool_table:
|
| 93 |
+
if "license-files" in config.get("project", {}):
|
| 94 |
+
# https://github.com/pypa/setuptools/pull/4837#discussion_r2004983349
|
| 95 |
+
raise InvalidConfigError(
|
| 96 |
+
"'project.license-files' is defined already. "
|
| 97 |
+
"Remove 'tool.setuptools.license-files'."
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
pypa_guides = "guides/writing-pyproject-toml/#license-files"
|
| 101 |
+
SetuptoolsDeprecationWarning.emit(
|
| 102 |
+
"'tool.setuptools.license-files' is deprecated in favor of "
|
| 103 |
+
"'project.license-files' (available on setuptools>=77.0.0).",
|
| 104 |
+
see_url=f"https://packaging.python.org/en/latest/{pypa_guides}",
|
| 105 |
+
due_date=(2027, 2, 18), # Warning introduced on 2025-02-18
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
for field, value in tool_table.items():
|
| 109 |
+
norm_key = json_compatible_key(field)
|
| 110 |
+
|
| 111 |
+
if norm_key in TOOL_TABLE_REMOVALS:
|
| 112 |
+
suggestion = cleandoc(TOOL_TABLE_REMOVALS[norm_key])
|
| 113 |
+
msg = f"""
|
| 114 |
+
The parameter `tool.setuptools.{field}` was long deprecated
|
| 115 |
+
and has been removed from `pyproject.toml`.
|
| 116 |
+
"""
|
| 117 |
+
raise RemovedConfigError("\n".join([cleandoc(msg), suggestion]))
|
| 118 |
+
|
| 119 |
+
norm_key = TOOL_TABLE_RENAMES.get(norm_key, norm_key)
|
| 120 |
+
corresp = TOOL_TABLE_CORRESPONDENCE.get(norm_key, norm_key)
|
| 121 |
+
if callable(corresp):
|
| 122 |
+
corresp(dist, value)
|
| 123 |
+
else:
|
| 124 |
+
_set_config(dist, corresp, value)
|
| 125 |
+
|
| 126 |
+
_copy_command_options(config, dist, filename)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _handle_missing_dynamic(dist: Distribution, project_table: dict):
|
| 130 |
+
"""Be temporarily forgiving with ``dynamic`` fields not listed in ``dynamic``"""
|
| 131 |
+
dynamic = set(project_table.get("dynamic", []))
|
| 132 |
+
for field, getter in _PREVIOUSLY_DEFINED.items():
|
| 133 |
+
if not (field in project_table or field in dynamic):
|
| 134 |
+
value = getter(dist)
|
| 135 |
+
if value:
|
| 136 |
+
_MissingDynamic.emit(field=field, value=value)
|
| 137 |
+
project_table[field] = _RESET_PREVIOUSLY_DEFINED.get(field)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def json_compatible_key(key: str) -> str:
|
| 141 |
+
"""As defined in :pep:`566#json-compatible-metadata`"""
|
| 142 |
+
return key.lower().replace("-", "_")
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _set_config(dist: Distribution, field: str, value: Any):
|
| 146 |
+
val = _PREPROCESS.get(field, _noop)(dist, value)
|
| 147 |
+
setter = getattr(dist.metadata, f"set_{field}", None)
|
| 148 |
+
if setter:
|
| 149 |
+
setter(val)
|
| 150 |
+
elif hasattr(dist.metadata, field) or field in SETUPTOOLS_PATCHES:
|
| 151 |
+
setattr(dist.metadata, field, val)
|
| 152 |
+
else:
|
| 153 |
+
setattr(dist, field, val)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
_CONTENT_TYPES = {
|
| 157 |
+
".md": "text/markdown",
|
| 158 |
+
".rst": "text/x-rst",
|
| 159 |
+
".txt": "text/plain",
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def _guess_content_type(file: str) -> str | None:
|
| 164 |
+
_, ext = os.path.splitext(file.lower())
|
| 165 |
+
if not ext:
|
| 166 |
+
return None
|
| 167 |
+
|
| 168 |
+
if ext in _CONTENT_TYPES:
|
| 169 |
+
return _static.Str(_CONTENT_TYPES[ext])
|
| 170 |
+
|
| 171 |
+
valid = ", ".join(f"{k} ({v})" for k, v in _CONTENT_TYPES.items())
|
| 172 |
+
msg = f"only the following file extensions are recognized: {valid}."
|
| 173 |
+
raise ValueError(f"Undefined content type for {file}, {msg}")
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def _long_description(
|
| 177 |
+
dist: Distribution, val: _ProjectReadmeValue, root_dir: StrPath | None
|
| 178 |
+
):
|
| 179 |
+
from setuptools.config import expand
|
| 180 |
+
|
| 181 |
+
file: str | tuple[()]
|
| 182 |
+
if isinstance(val, str):
|
| 183 |
+
file = val
|
| 184 |
+
text = expand.read_files(file, root_dir)
|
| 185 |
+
ctype = _guess_content_type(file)
|
| 186 |
+
else:
|
| 187 |
+
file = val.get("file") or ()
|
| 188 |
+
text = val.get("text") or expand.read_files(file, root_dir)
|
| 189 |
+
ctype = val["content-type"]
|
| 190 |
+
|
| 191 |
+
# XXX: Is it completely safe to assume static?
|
| 192 |
+
_set_config(dist, "long_description", _static.Str(text))
|
| 193 |
+
|
| 194 |
+
if ctype:
|
| 195 |
+
_set_config(dist, "long_description_content_type", _static.Str(ctype))
|
| 196 |
+
|
| 197 |
+
if file:
|
| 198 |
+
dist._referenced_files.add(file)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def _license(dist: Distribution, val: str | dict, root_dir: StrPath | None):
|
| 202 |
+
from setuptools.config import expand
|
| 203 |
+
|
| 204 |
+
if isinstance(val, str):
|
| 205 |
+
if getattr(dist.metadata, "license", None):
|
| 206 |
+
SetuptoolsWarning.emit("`license` overwritten by `pyproject.toml`")
|
| 207 |
+
dist.metadata.license = None
|
| 208 |
+
_set_config(dist, "license_expression", _static.Str(val))
|
| 209 |
+
else:
|
| 210 |
+
pypa_guides = "guides/writing-pyproject-toml/#license"
|
| 211 |
+
SetuptoolsDeprecationWarning.emit(
|
| 212 |
+
"`project.license` as a TOML table is deprecated",
|
| 213 |
+
"Please use a simple string containing a SPDX expression for "
|
| 214 |
+
"`project.license`. You can also use `project.license-files`. "
|
| 215 |
+
"(Both options available on setuptools>=77.0.0).",
|
| 216 |
+
see_url=f"https://packaging.python.org/en/latest/{pypa_guides}",
|
| 217 |
+
due_date=(2027, 2, 18), # Introduced on 2025-02-18
|
| 218 |
+
)
|
| 219 |
+
if "file" in val:
|
| 220 |
+
# XXX: Is it completely safe to assume static?
|
| 221 |
+
value = expand.read_files([val["file"]], root_dir)
|
| 222 |
+
_set_config(dist, "license", _static.Str(value))
|
| 223 |
+
dist._referenced_files.add(val["file"])
|
| 224 |
+
else:
|
| 225 |
+
_set_config(dist, "license", _static.Str(val["text"]))
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def _people(dist: Distribution, val: list[dict], _root_dir: StrPath | None, kind: str):
|
| 229 |
+
field = []
|
| 230 |
+
email_field = []
|
| 231 |
+
for person in val:
|
| 232 |
+
if "name" not in person:
|
| 233 |
+
email_field.append(person["email"])
|
| 234 |
+
elif "email" not in person:
|
| 235 |
+
field.append(person["name"])
|
| 236 |
+
else:
|
| 237 |
+
addr = Address(display_name=person["name"], addr_spec=person["email"])
|
| 238 |
+
email_field.append(str(addr))
|
| 239 |
+
|
| 240 |
+
if field:
|
| 241 |
+
_set_config(dist, kind, _static.Str(", ".join(field)))
|
| 242 |
+
if email_field:
|
| 243 |
+
_set_config(dist, f"{kind}_email", _static.Str(", ".join(email_field)))
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def _project_urls(dist: Distribution, val: dict, _root_dir: StrPath | None):
|
| 247 |
+
_set_config(dist, "project_urls", val)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def _python_requires(dist: Distribution, val: str, _root_dir: StrPath | None):
|
| 251 |
+
_set_config(dist, "python_requires", _static.SpecifierSet(val))
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def _dependencies(dist: Distribution, val: list, _root_dir: StrPath | None):
|
| 255 |
+
if getattr(dist, "install_requires", []):
|
| 256 |
+
msg = "`install_requires` overwritten in `pyproject.toml` (dependencies)"
|
| 257 |
+
SetuptoolsWarning.emit(msg)
|
| 258 |
+
dist.install_requires = val
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def _optional_dependencies(dist: Distribution, val: dict, _root_dir: StrPath | None):
|
| 262 |
+
if getattr(dist, "extras_require", None):
|
| 263 |
+
msg = "`extras_require` overwritten in `pyproject.toml` (optional-dependencies)"
|
| 264 |
+
SetuptoolsWarning.emit(msg)
|
| 265 |
+
dist.extras_require = val
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def _ext_modules(dist: Distribution, val: list[dict]) -> list[Extension]:
|
| 269 |
+
existing = dist.ext_modules or []
|
| 270 |
+
args = ({k.replace("-", "_"): v for k, v in x.items()} for x in val)
|
| 271 |
+
new = (Extension(**_adjust_ext_attrs(kw)) for kw in args)
|
| 272 |
+
return [*existing, *new]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def _adjust_ext_attrs(attrs: dict) -> dict:
|
| 276 |
+
# https://github.com/pypa/setuptools/issues/4810
|
| 277 |
+
# In TOML there is no differentiation between tuples and lists,
|
| 278 |
+
# and distutils requires tuples...
|
| 279 |
+
attrs["define_macros"] = list(map(tuple, attrs.get("define_macros") or []))
|
| 280 |
+
return attrs
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def _noop(_dist: Distribution, val: _T) -> _T:
|
| 284 |
+
return val
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def _identity(val: _T) -> _T:
|
| 288 |
+
return val
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def _unify_entry_points(project_table: dict):
|
| 292 |
+
project = project_table
|
| 293 |
+
given = project.pop("entry-points", project.pop("entry_points", {}))
|
| 294 |
+
entry_points = dict(given) # Avoid problems with static
|
| 295 |
+
renaming = {"scripts": "console_scripts", "gui_scripts": "gui_scripts"}
|
| 296 |
+
for key, value in list(project.items()): # eager to allow modifications
|
| 297 |
+
norm_key = json_compatible_key(key)
|
| 298 |
+
if norm_key in renaming:
|
| 299 |
+
# Don't skip even if value is empty (reason: reset missing `dynamic`)
|
| 300 |
+
entry_points[renaming[norm_key]] = project.pop(key)
|
| 301 |
+
|
| 302 |
+
if entry_points:
|
| 303 |
+
project["entry-points"] = {
|
| 304 |
+
name: [f"{k} = {v}" for k, v in group.items()]
|
| 305 |
+
for name, group in entry_points.items()
|
| 306 |
+
if group # now we can skip empty groups
|
| 307 |
+
}
|
| 308 |
+
# Sometimes this will set `project["entry-points"] = {}`, and that is
|
| 309 |
+
# intentional (for resetting configurations that are missing `dynamic`).
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def _copy_command_options(pyproject: dict, dist: Distribution, filename: StrPath):
|
| 313 |
+
tool_table = pyproject.get("tool", {})
|
| 314 |
+
cmdclass = tool_table.get("setuptools", {}).get("cmdclass", {})
|
| 315 |
+
valid_options = _valid_command_options(cmdclass)
|
| 316 |
+
|
| 317 |
+
cmd_opts = dist.command_options
|
| 318 |
+
for cmd, config in pyproject.get("tool", {}).get("distutils", {}).items():
|
| 319 |
+
cmd = json_compatible_key(cmd)
|
| 320 |
+
valid = valid_options.get(cmd, set())
|
| 321 |
+
cmd_opts.setdefault(cmd, {})
|
| 322 |
+
for key, value in config.items():
|
| 323 |
+
key = json_compatible_key(key)
|
| 324 |
+
cmd_opts[cmd][key] = (str(filename), value)
|
| 325 |
+
if key not in valid:
|
| 326 |
+
# To avoid removing options that are specified dynamically we
|
| 327 |
+
# just log a warn...
|
| 328 |
+
_logger.warning(f"Command option {cmd}.{key} is not defined")
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def _valid_command_options(cmdclass: Mapping = EMPTY) -> dict[str, set[str]]:
|
| 332 |
+
from setuptools.dist import Distribution
|
| 333 |
+
|
| 334 |
+
from .._importlib import metadata
|
| 335 |
+
|
| 336 |
+
valid_options = {"global": _normalise_cmd_options(Distribution.global_options)}
|
| 337 |
+
|
| 338 |
+
unloaded_entry_points = metadata.entry_points(group='distutils.commands')
|
| 339 |
+
loaded_entry_points = (_load_ep(ep) for ep in unloaded_entry_points)
|
| 340 |
+
entry_points = (ep for ep in loaded_entry_points if ep)
|
| 341 |
+
for cmd, cmd_class in chain(entry_points, cmdclass.items()):
|
| 342 |
+
opts = valid_options.get(cmd, set())
|
| 343 |
+
opts = opts | _normalise_cmd_options(getattr(cmd_class, "user_options", []))
|
| 344 |
+
valid_options[cmd] = opts
|
| 345 |
+
|
| 346 |
+
return valid_options
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def _load_ep(ep: metadata.EntryPoint) -> tuple[str, type] | None:
|
| 350 |
+
if ep.value.startswith("wheel.bdist_wheel"):
|
| 351 |
+
# Ignore deprecated entrypoint from wheel and avoid warning pypa/wheel#631
|
| 352 |
+
# TODO: remove check when `bdist_wheel` has been fully removed from pypa/wheel
|
| 353 |
+
return None
|
| 354 |
+
|
| 355 |
+
# Ignore all the errors
|
| 356 |
+
try:
|
| 357 |
+
return (ep.name, ep.load())
|
| 358 |
+
except Exception as ex:
|
| 359 |
+
msg = f"{ex.__class__.__name__} while trying to load entry-point {ep.name}"
|
| 360 |
+
_logger.warning(f"{msg}: {ex}")
|
| 361 |
+
return None
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def _normalise_cmd_option_key(name: str) -> str:
|
| 365 |
+
return json_compatible_key(name).strip("_=")
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def _normalise_cmd_options(desc: _OptionsList) -> set[str]:
|
| 369 |
+
return {_normalise_cmd_option_key(fancy_option[0]) for fancy_option in desc}
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def _get_previous_entrypoints(dist: Distribution) -> dict[str, list]:
|
| 373 |
+
ignore = ("console_scripts", "gui_scripts")
|
| 374 |
+
value = getattr(dist, "entry_points", None) or {}
|
| 375 |
+
return {k: v for k, v in value.items() if k not in ignore}
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
def _get_previous_scripts(dist: Distribution) -> list | None:
|
| 379 |
+
value = getattr(dist, "entry_points", None) or {}
|
| 380 |
+
return value.get("console_scripts")
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def _get_previous_gui_scripts(dist: Distribution) -> list | None:
|
| 384 |
+
value = getattr(dist, "entry_points", None) or {}
|
| 385 |
+
return value.get("gui_scripts")
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
def _set_static_list_metadata(attr: str, dist: Distribution, val: list) -> None:
|
| 389 |
+
"""Apply distutils metadata validation but preserve "static" behaviour"""
|
| 390 |
+
meta = dist.metadata
|
| 391 |
+
setter, getter = getattr(meta, f"set_{attr}"), getattr(meta, f"get_{attr}")
|
| 392 |
+
setter(val)
|
| 393 |
+
setattr(meta, attr, _static.List(getter()))
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
def _attrgetter(attr):
|
| 397 |
+
"""
|
| 398 |
+
Similar to ``operator.attrgetter`` but returns None if ``attr`` is not found
|
| 399 |
+
>>> from types import SimpleNamespace
|
| 400 |
+
>>> obj = SimpleNamespace(a=42, b=SimpleNamespace(c=13))
|
| 401 |
+
>>> _attrgetter("a")(obj)
|
| 402 |
+
42
|
| 403 |
+
>>> _attrgetter("b.c")(obj)
|
| 404 |
+
13
|
| 405 |
+
>>> _attrgetter("d")(obj) is None
|
| 406 |
+
True
|
| 407 |
+
"""
|
| 408 |
+
return partial(reduce, lambda acc, x: getattr(acc, x, None), attr.split("."))
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def _some_attrgetter(*items):
|
| 412 |
+
"""
|
| 413 |
+
Return the first "truth-y" attribute or None
|
| 414 |
+
>>> from types import SimpleNamespace
|
| 415 |
+
>>> obj = SimpleNamespace(a=42, b=SimpleNamespace(c=13))
|
| 416 |
+
>>> _some_attrgetter("d", "a", "b.c")(obj)
|
| 417 |
+
42
|
| 418 |
+
>>> _some_attrgetter("d", "e", "b.c", "a")(obj)
|
| 419 |
+
13
|
| 420 |
+
>>> _some_attrgetter("d", "e", "f")(obj) is None
|
| 421 |
+
True
|
| 422 |
+
"""
|
| 423 |
+
|
| 424 |
+
def _acessor(obj):
|
| 425 |
+
values = (_attrgetter(i)(obj) for i in items)
|
| 426 |
+
return next((i for i in values if i is not None), None)
|
| 427 |
+
|
| 428 |
+
return _acessor
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
PYPROJECT_CORRESPONDENCE: dict[str, _Correspondence] = {
|
| 432 |
+
"readme": _long_description,
|
| 433 |
+
"license": _license,
|
| 434 |
+
"authors": partial(_people, kind="author"),
|
| 435 |
+
"maintainers": partial(_people, kind="maintainer"),
|
| 436 |
+
"urls": _project_urls,
|
| 437 |
+
"dependencies": _dependencies,
|
| 438 |
+
"optional_dependencies": _optional_dependencies,
|
| 439 |
+
"requires_python": _python_requires,
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
TOOL_TABLE_RENAMES = {"script_files": "scripts"}
|
| 443 |
+
TOOL_TABLE_REMOVALS = {
|
| 444 |
+
"namespace_packages": """
|
| 445 |
+
Please migrate to implicit native namespaces instead.
|
| 446 |
+
See https://packaging.python.org/en/latest/guides/packaging-namespace-packages/.
|
| 447 |
+
""",
|
| 448 |
+
}
|
| 449 |
+
TOOL_TABLE_CORRESPONDENCE = {
|
| 450 |
+
# Fields with corresponding core metadata need to be marked as static:
|
| 451 |
+
"obsoletes": partial(_set_static_list_metadata, "obsoletes"),
|
| 452 |
+
"provides": partial(_set_static_list_metadata, "provides"),
|
| 453 |
+
"platforms": partial(_set_static_list_metadata, "platforms"),
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
SETUPTOOLS_PATCHES = {
|
| 457 |
+
"long_description_content_type",
|
| 458 |
+
"project_urls",
|
| 459 |
+
"provides_extras",
|
| 460 |
+
"license_file",
|
| 461 |
+
"license_files",
|
| 462 |
+
"license_expression",
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
_PREPROCESS = {
|
| 466 |
+
"ext_modules": _ext_modules,
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
_PREVIOUSLY_DEFINED = {
|
| 470 |
+
"name": _attrgetter("metadata.name"),
|
| 471 |
+
"version": _attrgetter("metadata.version"),
|
| 472 |
+
"description": _attrgetter("metadata.description"),
|
| 473 |
+
"readme": _attrgetter("metadata.long_description"),
|
| 474 |
+
"requires-python": _some_attrgetter("python_requires", "metadata.python_requires"),
|
| 475 |
+
"license": _some_attrgetter("metadata.license_expression", "metadata.license"),
|
| 476 |
+
# XXX: `license-file` is currently not considered in the context of `dynamic`.
|
| 477 |
+
# See TestPresetField.test_license_files_exempt_from_dynamic
|
| 478 |
+
"authors": _some_attrgetter("metadata.author", "metadata.author_email"),
|
| 479 |
+
"maintainers": _some_attrgetter("metadata.maintainer", "metadata.maintainer_email"),
|
| 480 |
+
"keywords": _attrgetter("metadata.keywords"),
|
| 481 |
+
"classifiers": _attrgetter("metadata.classifiers"),
|
| 482 |
+
"urls": _attrgetter("metadata.project_urls"),
|
| 483 |
+
"entry-points": _get_previous_entrypoints,
|
| 484 |
+
"scripts": _get_previous_scripts,
|
| 485 |
+
"gui-scripts": _get_previous_gui_scripts,
|
| 486 |
+
"dependencies": _attrgetter("install_requires"),
|
| 487 |
+
"optional-dependencies": _attrgetter("extras_require"),
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
_RESET_PREVIOUSLY_DEFINED: dict = {
|
| 492 |
+
# Fix improper setting: given in `setup.py`, but not listed in `dynamic`
|
| 493 |
+
# Use "immutable" data structures to avoid in-place modification.
|
| 494 |
+
# dict: pyproject name => value to which reset
|
| 495 |
+
"license": "",
|
| 496 |
+
# XXX: `license-file` is currently not considered in the context of `dynamic`.
|
| 497 |
+
# See TestPresetField.test_license_files_exempt_from_dynamic
|
| 498 |
+
"authors": _static.EMPTY_LIST,
|
| 499 |
+
"maintainers": _static.EMPTY_LIST,
|
| 500 |
+
"keywords": _static.EMPTY_LIST,
|
| 501 |
+
"classifiers": _static.EMPTY_LIST,
|
| 502 |
+
"urls": _static.EMPTY_DICT,
|
| 503 |
+
"entry-points": _static.EMPTY_DICT,
|
| 504 |
+
"scripts": _static.EMPTY_DICT,
|
| 505 |
+
"gui-scripts": _static.EMPTY_DICT,
|
| 506 |
+
"dependencies": _static.EMPTY_LIST,
|
| 507 |
+
"optional-dependencies": _static.EMPTY_DICT,
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
class _MissingDynamic(SetuptoolsWarning):
|
| 512 |
+
_SUMMARY = "`{field}` defined outside of `pyproject.toml` is ignored."
|
| 513 |
+
|
| 514 |
+
_DETAILS = """
|
| 515 |
+
The following seems to be defined outside of `pyproject.toml`:
|
| 516 |
+
|
| 517 |
+
`{field} = {value!r}`
|
| 518 |
+
|
| 519 |
+
According to the spec (see the link below), however, setuptools CANNOT
|
| 520 |
+
consider this value unless `{field}` is listed as `dynamic`.
|
| 521 |
+
|
| 522 |
+
https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table
|
| 523 |
+
|
| 524 |
+
To prevent this problem, you can list `{field}` under `dynamic` or alternatively
|
| 525 |
+
remove the `[project]` table from your file and rely entirely on other means of
|
| 526 |
+
configuration.
|
| 527 |
+
"""
|
| 528 |
+
# TODO: Consider removing this check in the future?
|
| 529 |
+
# There is a trade-off here between improving "debug-ability" and the cost
|
| 530 |
+
# of running/testing/maintaining these unnecessary checks...
|
| 531 |
+
|
| 532 |
+
@classmethod
|
| 533 |
+
def details(cls, field: str, value: Any) -> str:
|
| 534 |
+
return cls._DETAILS.format(field=field, value=value)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/NOTICE
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The code contained in this directory was automatically generated using the
|
| 2 |
+
following command:
|
| 3 |
+
|
| 4 |
+
python -m validate_pyproject.pre_compile --output-dir=setuptools/config/_validate_pyproject --enable-plugins setuptools distutils --very-verbose -t distutils=setuptools/config/distutils.schema.json -t setuptools=setuptools/config/setuptools.schema.json
|
| 5 |
+
|
| 6 |
+
Please avoid changing it manually.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
You can report issues or suggest changes directly to `validate-pyproject`
|
| 10 |
+
(or to the relevant plugin repository)
|
| 11 |
+
|
| 12 |
+
- https://github.com/abravalheri/validate-pyproject/issues
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
***
|
| 16 |
+
|
| 17 |
+
The following files include code from opensource projects
|
| 18 |
+
(either as direct copies or modified versions):
|
| 19 |
+
|
| 20 |
+
- `fastjsonschema_exceptions.py`:
|
| 21 |
+
- project: `fastjsonschema` - licensed under BSD-3-Clause
|
| 22 |
+
(https://github.com/horejsek/python-fastjsonschema)
|
| 23 |
+
- `extra_validations.py` and `format.py`, `error_reporting.py`:
|
| 24 |
+
- project: `validate-pyproject` - licensed under MPL-2.0
|
| 25 |
+
(https://github.com/abravalheri/validate-pyproject)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Additionally the following files are automatically generated by tools provided
|
| 29 |
+
by the same projects:
|
| 30 |
+
|
| 31 |
+
- `__init__.py`
|
| 32 |
+
- `fastjsonschema_validations.py`
|
| 33 |
+
|
| 34 |
+
The relevant copyright notes and licenses are included below.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
***
|
| 38 |
+
|
| 39 |
+
`fastjsonschema`
|
| 40 |
+
================
|
| 41 |
+
|
| 42 |
+
Copyright (c) 2018, Michal Horejsek
|
| 43 |
+
All rights reserved.
|
| 44 |
+
|
| 45 |
+
Redistribution and use in source and binary forms, with or without modification,
|
| 46 |
+
are permitted provided that the following conditions are met:
|
| 47 |
+
|
| 48 |
+
Redistributions of source code must retain the above copyright notice, this
|
| 49 |
+
list of conditions and the following disclaimer.
|
| 50 |
+
|
| 51 |
+
Redistributions in binary form must reproduce the above copyright notice, this
|
| 52 |
+
list of conditions and the following disclaimer in the documentation and/or
|
| 53 |
+
other materials provided with the distribution.
|
| 54 |
+
|
| 55 |
+
Neither the name of the {organization} nor the names of its
|
| 56 |
+
contributors may be used to endorse or promote products derived from
|
| 57 |
+
this software without specific prior written permission.
|
| 58 |
+
|
| 59 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 60 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 61 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 62 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
| 63 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 64 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 65 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 66 |
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 67 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 68 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
***
|
| 73 |
+
|
| 74 |
+
`validate-pyproject`
|
| 75 |
+
====================
|
| 76 |
+
|
| 77 |
+
Mozilla Public License, version 2.0
|
| 78 |
+
|
| 79 |
+
1. Definitions
|
| 80 |
+
|
| 81 |
+
1.1. "Contributor"
|
| 82 |
+
|
| 83 |
+
means each individual or legal entity that creates, contributes to the
|
| 84 |
+
creation of, or owns Covered Software.
|
| 85 |
+
|
| 86 |
+
1.2. "Contributor Version"
|
| 87 |
+
|
| 88 |
+
means the combination of the Contributions of others (if any) used by a
|
| 89 |
+
Contributor and that particular Contributor's Contribution.
|
| 90 |
+
|
| 91 |
+
1.3. "Contribution"
|
| 92 |
+
|
| 93 |
+
means Covered Software of a particular Contributor.
|
| 94 |
+
|
| 95 |
+
1.4. "Covered Software"
|
| 96 |
+
|
| 97 |
+
means Source Code Form to which the initial Contributor has attached the
|
| 98 |
+
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
| 99 |
+
Modifications of such Source Code Form, in each case including portions
|
| 100 |
+
thereof.
|
| 101 |
+
|
| 102 |
+
1.5. "Incompatible With Secondary Licenses"
|
| 103 |
+
means
|
| 104 |
+
|
| 105 |
+
a. that the initial Contributor has attached the notice described in
|
| 106 |
+
Exhibit B to the Covered Software; or
|
| 107 |
+
|
| 108 |
+
b. that the Covered Software was made available under the terms of
|
| 109 |
+
version 1.1 or earlier of the License, but not also under the terms of
|
| 110 |
+
a Secondary License.
|
| 111 |
+
|
| 112 |
+
1.6. "Executable Form"
|
| 113 |
+
|
| 114 |
+
means any form of the work other than Source Code Form.
|
| 115 |
+
|
| 116 |
+
1.7. "Larger Work"
|
| 117 |
+
|
| 118 |
+
means a work that combines Covered Software with other material, in a
|
| 119 |
+
separate file or files, that is not Covered Software.
|
| 120 |
+
|
| 121 |
+
1.8. "License"
|
| 122 |
+
|
| 123 |
+
means this document.
|
| 124 |
+
|
| 125 |
+
1.9. "Licensable"
|
| 126 |
+
|
| 127 |
+
means having the right to grant, to the maximum extent possible, whether
|
| 128 |
+
at the time of the initial grant or subsequently, any and all of the
|
| 129 |
+
rights conveyed by this License.
|
| 130 |
+
|
| 131 |
+
1.10. "Modifications"
|
| 132 |
+
|
| 133 |
+
means any of the following:
|
| 134 |
+
|
| 135 |
+
a. any file in Source Code Form that results from an addition to,
|
| 136 |
+
deletion from, or modification of the contents of Covered Software; or
|
| 137 |
+
|
| 138 |
+
b. any new file in Source Code Form that contains any Covered Software.
|
| 139 |
+
|
| 140 |
+
1.11. "Patent Claims" of a Contributor
|
| 141 |
+
|
| 142 |
+
means any patent claim(s), including without limitation, method,
|
| 143 |
+
process, and apparatus claims, in any patent Licensable by such
|
| 144 |
+
Contributor that would be infringed, but for the grant of the License,
|
| 145 |
+
by the making, using, selling, offering for sale, having made, import,
|
| 146 |
+
or transfer of either its Contributions or its Contributor Version.
|
| 147 |
+
|
| 148 |
+
1.12. "Secondary License"
|
| 149 |
+
|
| 150 |
+
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
| 151 |
+
General Public License, Version 2.1, the GNU Affero General Public
|
| 152 |
+
License, Version 3.0, or any later versions of those licenses.
|
| 153 |
+
|
| 154 |
+
1.13. "Source Code Form"
|
| 155 |
+
|
| 156 |
+
means the form of the work preferred for making modifications.
|
| 157 |
+
|
| 158 |
+
1.14. "You" (or "Your")
|
| 159 |
+
|
| 160 |
+
means an individual or a legal entity exercising rights under this
|
| 161 |
+
License. For legal entities, "You" includes any entity that controls, is
|
| 162 |
+
controlled by, or is under common control with You. For purposes of this
|
| 163 |
+
definition, "control" means (a) the power, direct or indirect, to cause
|
| 164 |
+
the direction or management of such entity, whether by contract or
|
| 165 |
+
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
| 166 |
+
outstanding shares or beneficial ownership of such entity.
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
2. License Grants and Conditions
|
| 170 |
+
|
| 171 |
+
2.1. Grants
|
| 172 |
+
|
| 173 |
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
| 174 |
+
non-exclusive license:
|
| 175 |
+
|
| 176 |
+
a. under intellectual property rights (other than patent or trademark)
|
| 177 |
+
Licensable by such Contributor to use, reproduce, make available,
|
| 178 |
+
modify, display, perform, distribute, and otherwise exploit its
|
| 179 |
+
Contributions, either on an unmodified basis, with Modifications, or
|
| 180 |
+
as part of a Larger Work; and
|
| 181 |
+
|
| 182 |
+
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
| 183 |
+
sale, have made, import, and otherwise transfer either its
|
| 184 |
+
Contributions or its Contributor Version.
|
| 185 |
+
|
| 186 |
+
2.2. Effective Date
|
| 187 |
+
|
| 188 |
+
The licenses granted in Section 2.1 with respect to any Contribution
|
| 189 |
+
become effective for each Contribution on the date the Contributor first
|
| 190 |
+
distributes such Contribution.
|
| 191 |
+
|
| 192 |
+
2.3. Limitations on Grant Scope
|
| 193 |
+
|
| 194 |
+
The licenses granted in this Section 2 are the only rights granted under
|
| 195 |
+
this License. No additional rights or licenses will be implied from the
|
| 196 |
+
distribution or licensing of Covered Software under this License.
|
| 197 |
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
| 198 |
+
Contributor:
|
| 199 |
+
|
| 200 |
+
a. for any code that a Contributor has removed from Covered Software; or
|
| 201 |
+
|
| 202 |
+
b. for infringements caused by: (i) Your and any other third party's
|
| 203 |
+
modifications of Covered Software, or (ii) the combination of its
|
| 204 |
+
Contributions with other software (except as part of its Contributor
|
| 205 |
+
Version); or
|
| 206 |
+
|
| 207 |
+
c. under Patent Claims infringed by Covered Software in the absence of
|
| 208 |
+
its Contributions.
|
| 209 |
+
|
| 210 |
+
This License does not grant any rights in the trademarks, service marks,
|
| 211 |
+
or logos of any Contributor (except as may be necessary to comply with
|
| 212 |
+
the notice requirements in Section 3.4).
|
| 213 |
+
|
| 214 |
+
2.4. Subsequent Licenses
|
| 215 |
+
|
| 216 |
+
No Contributor makes additional grants as a result of Your choice to
|
| 217 |
+
distribute the Covered Software under a subsequent version of this
|
| 218 |
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
| 219 |
+
permitted under the terms of Section 3.3).
|
| 220 |
+
|
| 221 |
+
2.5. Representation
|
| 222 |
+
|
| 223 |
+
Each Contributor represents that the Contributor believes its
|
| 224 |
+
Contributions are its original creation(s) or it has sufficient rights to
|
| 225 |
+
grant the rights to its Contributions conveyed by this License.
|
| 226 |
+
|
| 227 |
+
2.6. Fair Use
|
| 228 |
+
|
| 229 |
+
This License is not intended to limit any rights You have under
|
| 230 |
+
applicable copyright doctrines of fair use, fair dealing, or other
|
| 231 |
+
equivalents.
|
| 232 |
+
|
| 233 |
+
2.7. Conditions
|
| 234 |
+
|
| 235 |
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
| 236 |
+
Section 2.1.
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
3. Responsibilities
|
| 240 |
+
|
| 241 |
+
3.1. Distribution of Source Form
|
| 242 |
+
|
| 243 |
+
All distribution of Covered Software in Source Code Form, including any
|
| 244 |
+
Modifications that You create or to which You contribute, must be under
|
| 245 |
+
the terms of this License. You must inform recipients that the Source
|
| 246 |
+
Code Form of the Covered Software is governed by the terms of this
|
| 247 |
+
License, and how they can obtain a copy of this License. You may not
|
| 248 |
+
attempt to alter or restrict the recipients' rights in the Source Code
|
| 249 |
+
Form.
|
| 250 |
+
|
| 251 |
+
3.2. Distribution of Executable Form
|
| 252 |
+
|
| 253 |
+
If You distribute Covered Software in Executable Form then:
|
| 254 |
+
|
| 255 |
+
a. such Covered Software must also be made available in Source Code Form,
|
| 256 |
+
as described in Section 3.1, and You must inform recipients of the
|
| 257 |
+
Executable Form how they can obtain a copy of such Source Code Form by
|
| 258 |
+
reasonable means in a timely manner, at a charge no more than the cost
|
| 259 |
+
of distribution to the recipient; and
|
| 260 |
+
|
| 261 |
+
b. You may distribute such Executable Form under the terms of this
|
| 262 |
+
License, or sublicense it under different terms, provided that the
|
| 263 |
+
license for the Executable Form does not attempt to limit or alter the
|
| 264 |
+
recipients' rights in the Source Code Form under this License.
|
| 265 |
+
|
| 266 |
+
3.3. Distribution of a Larger Work
|
| 267 |
+
|
| 268 |
+
You may create and distribute a Larger Work under terms of Your choice,
|
| 269 |
+
provided that You also comply with the requirements of this License for
|
| 270 |
+
the Covered Software. If the Larger Work is a combination of Covered
|
| 271 |
+
Software with a work governed by one or more Secondary Licenses, and the
|
| 272 |
+
Covered Software is not Incompatible With Secondary Licenses, this
|
| 273 |
+
License permits You to additionally distribute such Covered Software
|
| 274 |
+
under the terms of such Secondary License(s), so that the recipient of
|
| 275 |
+
the Larger Work may, at their option, further distribute the Covered
|
| 276 |
+
Software under the terms of either this License or such Secondary
|
| 277 |
+
License(s).
|
| 278 |
+
|
| 279 |
+
3.4. Notices
|
| 280 |
+
|
| 281 |
+
You may not remove or alter the substance of any license notices
|
| 282 |
+
(including copyright notices, patent notices, disclaimers of warranty, or
|
| 283 |
+
limitations of liability) contained within the Source Code Form of the
|
| 284 |
+
Covered Software, except that You may alter any license notices to the
|
| 285 |
+
extent required to remedy known factual inaccuracies.
|
| 286 |
+
|
| 287 |
+
3.5. Application of Additional Terms
|
| 288 |
+
|
| 289 |
+
You may choose to offer, and to charge a fee for, warranty, support,
|
| 290 |
+
indemnity or liability obligations to one or more recipients of Covered
|
| 291 |
+
Software. However, You may do so only on Your own behalf, and not on
|
| 292 |
+
behalf of any Contributor. You must make it absolutely clear that any
|
| 293 |
+
such warranty, support, indemnity, or liability obligation is offered by
|
| 294 |
+
You alone, and You hereby agree to indemnify every Contributor for any
|
| 295 |
+
liability incurred by such Contributor as a result of warranty, support,
|
| 296 |
+
indemnity or liability terms You offer. You may include additional
|
| 297 |
+
disclaimers of warranty and limitations of liability specific to any
|
| 298 |
+
jurisdiction.
|
| 299 |
+
|
| 300 |
+
4. Inability to Comply Due to Statute or Regulation
|
| 301 |
+
|
| 302 |
+
If it is impossible for You to comply with any of the terms of this License
|
| 303 |
+
with respect to some or all of the Covered Software due to statute,
|
| 304 |
+
judicial order, or regulation then You must: (a) comply with the terms of
|
| 305 |
+
this License to the maximum extent possible; and (b) describe the
|
| 306 |
+
limitations and the code they affect. Such description must be placed in a
|
| 307 |
+
text file included with all distributions of the Covered Software under
|
| 308 |
+
this License. Except to the extent prohibited by statute or regulation,
|
| 309 |
+
such description must be sufficiently detailed for a recipient of ordinary
|
| 310 |
+
skill to be able to understand it.
|
| 311 |
+
|
| 312 |
+
5. Termination
|
| 313 |
+
|
| 314 |
+
5.1. The rights granted under this License will terminate automatically if You
|
| 315 |
+
fail to comply with any of its terms. However, if You become compliant,
|
| 316 |
+
then the rights granted under this License from a particular Contributor
|
| 317 |
+
are reinstated (a) provisionally, unless and until such Contributor
|
| 318 |
+
explicitly and finally terminates Your grants, and (b) on an ongoing
|
| 319 |
+
basis, if such Contributor fails to notify You of the non-compliance by
|
| 320 |
+
some reasonable means prior to 60 days after You have come back into
|
| 321 |
+
compliance. Moreover, Your grants from a particular Contributor are
|
| 322 |
+
reinstated on an ongoing basis if such Contributor notifies You of the
|
| 323 |
+
non-compliance by some reasonable means, this is the first time You have
|
| 324 |
+
received notice of non-compliance with this License from such
|
| 325 |
+
Contributor, and You become compliant prior to 30 days after Your receipt
|
| 326 |
+
of the notice.
|
| 327 |
+
|
| 328 |
+
5.2. If You initiate litigation against any entity by asserting a patent
|
| 329 |
+
infringement claim (excluding declaratory judgment actions,
|
| 330 |
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
| 331 |
+
directly or indirectly infringes any patent, then the rights granted to
|
| 332 |
+
You by any and all Contributors for the Covered Software under Section
|
| 333 |
+
2.1 of this License shall terminate.
|
| 334 |
+
|
| 335 |
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
| 336 |
+
license agreements (excluding distributors and resellers) which have been
|
| 337 |
+
validly granted by You or Your distributors under this License prior to
|
| 338 |
+
termination shall survive termination.
|
| 339 |
+
|
| 340 |
+
6. Disclaimer of Warranty
|
| 341 |
+
|
| 342 |
+
Covered Software is provided under this License on an "as is" basis,
|
| 343 |
+
without warranty of any kind, either expressed, implied, or statutory,
|
| 344 |
+
including, without limitation, warranties that the Covered Software is free
|
| 345 |
+
of defects, merchantable, fit for a particular purpose or non-infringing.
|
| 346 |
+
The entire risk as to the quality and performance of the Covered Software
|
| 347 |
+
is with You. Should any Covered Software prove defective in any respect,
|
| 348 |
+
You (not any Contributor) assume the cost of any necessary servicing,
|
| 349 |
+
repair, or correction. This disclaimer of warranty constitutes an essential
|
| 350 |
+
part of this License. No use of any Covered Software is authorized under
|
| 351 |
+
this License except under this disclaimer.
|
| 352 |
+
|
| 353 |
+
7. Limitation of Liability
|
| 354 |
+
|
| 355 |
+
Under no circumstances and under no legal theory, whether tort (including
|
| 356 |
+
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
| 357 |
+
distributes Covered Software as permitted above, be liable to You for any
|
| 358 |
+
direct, indirect, special, incidental, or consequential damages of any
|
| 359 |
+
character including, without limitation, damages for lost profits, loss of
|
| 360 |
+
goodwill, work stoppage, computer failure or malfunction, or any and all
|
| 361 |
+
other commercial damages or losses, even if such party shall have been
|
| 362 |
+
informed of the possibility of such damages. This limitation of liability
|
| 363 |
+
shall not apply to liability for death or personal injury resulting from
|
| 364 |
+
such party's negligence to the extent applicable law prohibits such
|
| 365 |
+
limitation. Some jurisdictions do not allow the exclusion or limitation of
|
| 366 |
+
incidental or consequential damages, so this exclusion and limitation may
|
| 367 |
+
not apply to You.
|
| 368 |
+
|
| 369 |
+
8. Litigation
|
| 370 |
+
|
| 371 |
+
Any litigation relating to this License may be brought only in the courts
|
| 372 |
+
of a jurisdiction where the defendant maintains its principal place of
|
| 373 |
+
business and such litigation shall be governed by laws of that
|
| 374 |
+
jurisdiction, without reference to its conflict-of-law provisions. Nothing
|
| 375 |
+
in this Section shall prevent a party's ability to bring cross-claims or
|
| 376 |
+
counter-claims.
|
| 377 |
+
|
| 378 |
+
9. Miscellaneous
|
| 379 |
+
|
| 380 |
+
This License represents the complete agreement concerning the subject
|
| 381 |
+
matter hereof. If any provision of this License is held to be
|
| 382 |
+
unenforceable, such provision shall be reformed only to the extent
|
| 383 |
+
necessary to make it enforceable. Any law or regulation which provides that
|
| 384 |
+
the language of a contract shall be construed against the drafter shall not
|
| 385 |
+
be used to construe this License against a Contributor.
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
10. Versions of the License
|
| 389 |
+
|
| 390 |
+
10.1. New Versions
|
| 391 |
+
|
| 392 |
+
Mozilla Foundation is the license steward. Except as provided in Section
|
| 393 |
+
10.3, no one other than the license steward has the right to modify or
|
| 394 |
+
publish new versions of this License. Each version will be given a
|
| 395 |
+
distinguishing version number.
|
| 396 |
+
|
| 397 |
+
10.2. Effect of New Versions
|
| 398 |
+
|
| 399 |
+
You may distribute the Covered Software under the terms of the version
|
| 400 |
+
of the License under which You originally received the Covered Software,
|
| 401 |
+
or under the terms of any subsequent version published by the license
|
| 402 |
+
steward.
|
| 403 |
+
|
| 404 |
+
10.3. Modified Versions
|
| 405 |
+
|
| 406 |
+
If you create software not governed by this License, and you want to
|
| 407 |
+
create a new license for such software, you may create and use a
|
| 408 |
+
modified version of this License if you rename the license and remove
|
| 409 |
+
any references to the name of the license steward (except to note that
|
| 410 |
+
such modified license differs from this License).
|
| 411 |
+
|
| 412 |
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
| 413 |
+
Licenses If You choose to distribute Source Code Form that is
|
| 414 |
+
Incompatible With Secondary Licenses under the terms of this version of
|
| 415 |
+
the License, the notice described in Exhibit B of this License must be
|
| 416 |
+
attached.
|
| 417 |
+
|
| 418 |
+
Exhibit A - Source Code Form License Notice
|
| 419 |
+
|
| 420 |
+
This Source Code Form is subject to the
|
| 421 |
+
terms of the Mozilla Public License, v.
|
| 422 |
+
2.0. If a copy of the MPL was not
|
| 423 |
+
distributed with this file, You can
|
| 424 |
+
obtain one at
|
| 425 |
+
https://mozilla.org/MPL/2.0/.
|
| 426 |
+
|
| 427 |
+
If it is not possible or desirable to put the notice in a particular file,
|
| 428 |
+
then You may include the notice in a location (such as a LICENSE file in a
|
| 429 |
+
relevant directory) where a recipient would be likely to look for such a
|
| 430 |
+
notice.
|
| 431 |
+
|
| 432 |
+
You may add additional accurate notices of copyright ownership.
|
| 433 |
+
|
| 434 |
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
| 435 |
+
|
| 436 |
+
This Source Code Form is "Incompatible
|
| 437 |
+
With Secondary Licenses", as defined by
|
| 438 |
+
the Mozilla Public License, v. 2.0.
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import reduce
|
| 2 |
+
from typing import Any, Callable, Dict
|
| 3 |
+
|
| 4 |
+
from . import formats
|
| 5 |
+
from .error_reporting import detailed_errors, ValidationError
|
| 6 |
+
from .extra_validations import EXTRA_VALIDATIONS
|
| 7 |
+
from .fastjsonschema_exceptions import JsonSchemaException, JsonSchemaValueException
|
| 8 |
+
from .fastjsonschema_validations import validate as _validate
|
| 9 |
+
|
| 10 |
+
__all__ = [
|
| 11 |
+
"validate",
|
| 12 |
+
"FORMAT_FUNCTIONS",
|
| 13 |
+
"EXTRA_VALIDATIONS",
|
| 14 |
+
"ValidationError",
|
| 15 |
+
"JsonSchemaException",
|
| 16 |
+
"JsonSchemaValueException",
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
FORMAT_FUNCTIONS: Dict[str, Callable[[str], bool]] = {
|
| 21 |
+
fn.__name__.replace("_", "-"): fn
|
| 22 |
+
for fn in formats.__dict__.values()
|
| 23 |
+
if callable(fn) and not fn.__name__.startswith("_")
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def validate(data: Any) -> bool:
|
| 28 |
+
"""Validate the given ``data`` object using JSON Schema
|
| 29 |
+
This function raises ``ValidationError`` if ``data`` is invalid.
|
| 30 |
+
"""
|
| 31 |
+
with detailed_errors():
|
| 32 |
+
_validate(data, custom_formats=FORMAT_FUNCTIONS)
|
| 33 |
+
reduce(lambda acc, fn: fn(acc), EXTRA_VALIDATIONS, data)
|
| 34 |
+
return True
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/error_reporting.py
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
import os
|
| 7 |
+
import re
|
| 8 |
+
import typing
|
| 9 |
+
from contextlib import contextmanager
|
| 10 |
+
from textwrap import indent, wrap
|
| 11 |
+
from typing import Any, Generator, Iterator, Sequence
|
| 12 |
+
|
| 13 |
+
from .fastjsonschema_exceptions import JsonSchemaValueException
|
| 14 |
+
|
| 15 |
+
if typing.TYPE_CHECKING:
|
| 16 |
+
import sys
|
| 17 |
+
|
| 18 |
+
if sys.version_info < (3, 11):
|
| 19 |
+
from typing_extensions import Self
|
| 20 |
+
else:
|
| 21 |
+
from typing import Self
|
| 22 |
+
|
| 23 |
+
_logger = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
_MESSAGE_REPLACEMENTS = {
|
| 26 |
+
"must be named by propertyName definition": "keys must be named by",
|
| 27 |
+
"one of contains definition": "at least one item that matches",
|
| 28 |
+
" same as const definition:": "",
|
| 29 |
+
"only specified items": "only items matching the definition",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
_SKIP_DETAILS = (
|
| 33 |
+
"must not be empty",
|
| 34 |
+
"is always invalid",
|
| 35 |
+
"must not be there",
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
_NEED_DETAILS = {"anyOf", "oneOf", "allOf", "contains", "propertyNames", "not", "items"}
|
| 39 |
+
|
| 40 |
+
_CAMEL_CASE_SPLITTER = re.compile(r"\W+|([A-Z][^A-Z\W]*)")
|
| 41 |
+
_IDENTIFIER = re.compile(r"^[\w_]+$", re.IGNORECASE)
|
| 42 |
+
|
| 43 |
+
_TOML_JARGON = {
|
| 44 |
+
"object": "table",
|
| 45 |
+
"property": "key",
|
| 46 |
+
"properties": "keys",
|
| 47 |
+
"property names": "keys",
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
_FORMATS_HELP = """
|
| 51 |
+
For more details about `format` see
|
| 52 |
+
https://validate-pyproject.readthedocs.io/en/latest/api/validate_pyproject.formats.html
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class ValidationError(JsonSchemaValueException):
|
| 57 |
+
"""Report violations of a given JSON schema.
|
| 58 |
+
|
| 59 |
+
This class extends :exc:`~fastjsonschema.JsonSchemaValueException`
|
| 60 |
+
by adding the following properties:
|
| 61 |
+
|
| 62 |
+
- ``summary``: an improved version of the ``JsonSchemaValueException`` error message
|
| 63 |
+
with only the necessary information)
|
| 64 |
+
|
| 65 |
+
- ``details``: more contextual information about the error like the failing schema
|
| 66 |
+
itself and the value that violates the schema.
|
| 67 |
+
|
| 68 |
+
Depending on the level of the verbosity of the ``logging`` configuration
|
| 69 |
+
the exception message will be only ``summary`` (default) or a combination of
|
| 70 |
+
``summary`` and ``details`` (when the logging level is set to :obj:`logging.DEBUG`).
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
summary = ""
|
| 74 |
+
details = ""
|
| 75 |
+
_original_message = ""
|
| 76 |
+
|
| 77 |
+
@classmethod
|
| 78 |
+
def _from_jsonschema(cls, ex: JsonSchemaValueException) -> Self:
|
| 79 |
+
formatter = _ErrorFormatting(ex)
|
| 80 |
+
obj = cls(str(formatter), ex.value, formatter.name, ex.definition, ex.rule)
|
| 81 |
+
debug_code = os.getenv("JSONSCHEMA_DEBUG_CODE_GENERATION", "false").lower()
|
| 82 |
+
if debug_code != "false": # pragma: no cover
|
| 83 |
+
obj.__cause__, obj.__traceback__ = ex.__cause__, ex.__traceback__
|
| 84 |
+
obj._original_message = ex.message
|
| 85 |
+
obj.summary = formatter.summary
|
| 86 |
+
obj.details = formatter.details
|
| 87 |
+
return obj
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
@contextmanager
|
| 91 |
+
def detailed_errors() -> Generator[None, None, None]:
|
| 92 |
+
try:
|
| 93 |
+
yield
|
| 94 |
+
except JsonSchemaValueException as ex:
|
| 95 |
+
raise ValidationError._from_jsonschema(ex) from None
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class _ErrorFormatting:
|
| 99 |
+
def __init__(self, ex: JsonSchemaValueException):
|
| 100 |
+
self.ex = ex
|
| 101 |
+
self.name = f"`{self._simplify_name(ex.name)}`"
|
| 102 |
+
self._original_message: str = self.ex.message.replace(ex.name, self.name)
|
| 103 |
+
self._summary = ""
|
| 104 |
+
self._details = ""
|
| 105 |
+
|
| 106 |
+
def __str__(self) -> str:
|
| 107 |
+
if _logger.getEffectiveLevel() <= logging.DEBUG and self.details:
|
| 108 |
+
return f"{self.summary}\n\n{self.details}"
|
| 109 |
+
|
| 110 |
+
return self.summary
|
| 111 |
+
|
| 112 |
+
@property
|
| 113 |
+
def summary(self) -> str:
|
| 114 |
+
if not self._summary:
|
| 115 |
+
self._summary = self._expand_summary()
|
| 116 |
+
|
| 117 |
+
return self._summary
|
| 118 |
+
|
| 119 |
+
@property
|
| 120 |
+
def details(self) -> str:
|
| 121 |
+
if not self._details:
|
| 122 |
+
self._details = self._expand_details()
|
| 123 |
+
|
| 124 |
+
return self._details
|
| 125 |
+
|
| 126 |
+
@staticmethod
|
| 127 |
+
def _simplify_name(name: str) -> str:
|
| 128 |
+
x = len("data.")
|
| 129 |
+
return name[x:] if name.startswith("data.") else name
|
| 130 |
+
|
| 131 |
+
def _expand_summary(self) -> str:
|
| 132 |
+
msg = self._original_message
|
| 133 |
+
|
| 134 |
+
for bad, repl in _MESSAGE_REPLACEMENTS.items():
|
| 135 |
+
msg = msg.replace(bad, repl)
|
| 136 |
+
|
| 137 |
+
if any(substring in msg for substring in _SKIP_DETAILS):
|
| 138 |
+
return msg
|
| 139 |
+
|
| 140 |
+
schema = self.ex.rule_definition
|
| 141 |
+
if self.ex.rule in _NEED_DETAILS and schema:
|
| 142 |
+
summary = _SummaryWriter(_TOML_JARGON)
|
| 143 |
+
return f"{msg}:\n\n{indent(summary(schema), ' ')}"
|
| 144 |
+
|
| 145 |
+
return msg
|
| 146 |
+
|
| 147 |
+
def _expand_details(self) -> str:
|
| 148 |
+
optional = []
|
| 149 |
+
definition = self.ex.definition or {}
|
| 150 |
+
desc_lines = definition.pop("$$description", [])
|
| 151 |
+
desc = definition.pop("description", None) or " ".join(desc_lines)
|
| 152 |
+
if desc:
|
| 153 |
+
description = "\n".join(
|
| 154 |
+
wrap(
|
| 155 |
+
desc,
|
| 156 |
+
width=80,
|
| 157 |
+
initial_indent=" ",
|
| 158 |
+
subsequent_indent=" ",
|
| 159 |
+
break_long_words=False,
|
| 160 |
+
)
|
| 161 |
+
)
|
| 162 |
+
optional.append(f"DESCRIPTION:\n{description}")
|
| 163 |
+
schema = json.dumps(definition, indent=4)
|
| 164 |
+
value = json.dumps(self.ex.value, indent=4)
|
| 165 |
+
defaults = [
|
| 166 |
+
f"GIVEN VALUE:\n{indent(value, ' ')}",
|
| 167 |
+
f"OFFENDING RULE: {self.ex.rule!r}",
|
| 168 |
+
f"DEFINITION:\n{indent(schema, ' ')}",
|
| 169 |
+
]
|
| 170 |
+
msg = "\n\n".join(optional + defaults)
|
| 171 |
+
epilog = f"\n{_FORMATS_HELP}" if "format" in msg.lower() else ""
|
| 172 |
+
return msg + epilog
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class _SummaryWriter:
|
| 176 |
+
_IGNORE = frozenset(("description", "default", "title", "examples"))
|
| 177 |
+
|
| 178 |
+
def __init__(self, jargon: dict[str, str] | None = None):
|
| 179 |
+
self.jargon: dict[str, str] = jargon or {}
|
| 180 |
+
# Clarify confusing terms
|
| 181 |
+
self._terms = {
|
| 182 |
+
"anyOf": "at least one of the following",
|
| 183 |
+
"oneOf": "exactly one of the following",
|
| 184 |
+
"allOf": "all of the following",
|
| 185 |
+
"not": "(*NOT* the following)",
|
| 186 |
+
"prefixItems": f"{self._jargon('items')} (in order)",
|
| 187 |
+
"items": "items",
|
| 188 |
+
"contains": "contains at least one of",
|
| 189 |
+
"propertyNames": (
|
| 190 |
+
f"non-predefined acceptable {self._jargon('property names')}"
|
| 191 |
+
),
|
| 192 |
+
"patternProperties": f"{self._jargon('properties')} named via pattern",
|
| 193 |
+
"const": "predefined value",
|
| 194 |
+
"enum": "one of",
|
| 195 |
+
}
|
| 196 |
+
# Attributes that indicate that the definition is easy and can be done
|
| 197 |
+
# inline (e.g. string and number)
|
| 198 |
+
self._guess_inline_defs = [
|
| 199 |
+
"enum",
|
| 200 |
+
"const",
|
| 201 |
+
"maxLength",
|
| 202 |
+
"minLength",
|
| 203 |
+
"pattern",
|
| 204 |
+
"format",
|
| 205 |
+
"minimum",
|
| 206 |
+
"maximum",
|
| 207 |
+
"exclusiveMinimum",
|
| 208 |
+
"exclusiveMaximum",
|
| 209 |
+
"multipleOf",
|
| 210 |
+
]
|
| 211 |
+
|
| 212 |
+
def _jargon(self, term: str | list[str]) -> str | list[str]:
|
| 213 |
+
if isinstance(term, list):
|
| 214 |
+
return [self.jargon.get(t, t) for t in term]
|
| 215 |
+
return self.jargon.get(term, term)
|
| 216 |
+
|
| 217 |
+
def __call__(
|
| 218 |
+
self,
|
| 219 |
+
schema: dict | list[dict],
|
| 220 |
+
prefix: str = "",
|
| 221 |
+
*,
|
| 222 |
+
_path: Sequence[str] = (),
|
| 223 |
+
) -> str:
|
| 224 |
+
if isinstance(schema, list):
|
| 225 |
+
return self._handle_list(schema, prefix, _path)
|
| 226 |
+
|
| 227 |
+
filtered = self._filter_unecessary(schema, _path)
|
| 228 |
+
simple = self._handle_simple_dict(filtered, _path)
|
| 229 |
+
if simple:
|
| 230 |
+
return f"{prefix}{simple}"
|
| 231 |
+
|
| 232 |
+
child_prefix = self._child_prefix(prefix, " ")
|
| 233 |
+
item_prefix = self._child_prefix(prefix, "- ")
|
| 234 |
+
indent = len(prefix) * " "
|
| 235 |
+
with io.StringIO() as buffer:
|
| 236 |
+
for i, (key, value) in enumerate(filtered.items()):
|
| 237 |
+
child_path = [*_path, key]
|
| 238 |
+
line_prefix = prefix if i == 0 else indent
|
| 239 |
+
buffer.write(f"{line_prefix}{self._label(child_path)}:")
|
| 240 |
+
# ^ just the first item should receive the complete prefix
|
| 241 |
+
if isinstance(value, dict):
|
| 242 |
+
filtered = self._filter_unecessary(value, child_path)
|
| 243 |
+
simple = self._handle_simple_dict(filtered, child_path)
|
| 244 |
+
buffer.write(
|
| 245 |
+
f" {simple}"
|
| 246 |
+
if simple
|
| 247 |
+
else f"\n{self(value, child_prefix, _path=child_path)}"
|
| 248 |
+
)
|
| 249 |
+
elif isinstance(value, list) and (
|
| 250 |
+
key != "type" or self._is_property(child_path)
|
| 251 |
+
):
|
| 252 |
+
children = self._handle_list(value, item_prefix, child_path)
|
| 253 |
+
sep = " " if children.startswith("[") else "\n"
|
| 254 |
+
buffer.write(f"{sep}{children}")
|
| 255 |
+
else:
|
| 256 |
+
buffer.write(f" {self._value(value, child_path)}\n")
|
| 257 |
+
return buffer.getvalue()
|
| 258 |
+
|
| 259 |
+
def _is_unecessary(self, path: Sequence[str]) -> bool:
|
| 260 |
+
if self._is_property(path) or not path: # empty path => instruction @ root
|
| 261 |
+
return False
|
| 262 |
+
key = path[-1]
|
| 263 |
+
return any(key.startswith(k) for k in "$_") or key in self._IGNORE
|
| 264 |
+
|
| 265 |
+
def _filter_unecessary(
|
| 266 |
+
self, schema: dict[str, Any], path: Sequence[str]
|
| 267 |
+
) -> dict[str, Any]:
|
| 268 |
+
return {
|
| 269 |
+
key: value
|
| 270 |
+
for key, value in schema.items()
|
| 271 |
+
if not self._is_unecessary([*path, key])
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
def _handle_simple_dict(self, value: dict, path: Sequence[str]) -> str | None:
|
| 275 |
+
inline = any(p in value for p in self._guess_inline_defs)
|
| 276 |
+
simple = not any(isinstance(v, (list, dict)) for v in value.values())
|
| 277 |
+
if inline or simple:
|
| 278 |
+
return f"{{{', '.join(self._inline_attrs(value, path))}}}\n"
|
| 279 |
+
return None
|
| 280 |
+
|
| 281 |
+
def _handle_list(
|
| 282 |
+
self, schemas: list, prefix: str = "", path: Sequence[str] = ()
|
| 283 |
+
) -> str:
|
| 284 |
+
if self._is_unecessary(path):
|
| 285 |
+
return ""
|
| 286 |
+
|
| 287 |
+
repr_ = repr(schemas)
|
| 288 |
+
if all(not isinstance(e, (dict, list)) for e in schemas) and len(repr_) < 60:
|
| 289 |
+
return f"{repr_}\n"
|
| 290 |
+
|
| 291 |
+
item_prefix = self._child_prefix(prefix, "- ")
|
| 292 |
+
return "".join(
|
| 293 |
+
self(v, item_prefix, _path=[*path, f"[{i}]"]) for i, v in enumerate(schemas)
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
def _is_property(self, path: Sequence[str]) -> bool:
|
| 297 |
+
"""Check if the given path can correspond to an arbitrarily named property"""
|
| 298 |
+
counter = 0
|
| 299 |
+
for key in path[-2::-1]:
|
| 300 |
+
if key not in {"properties", "patternProperties"}:
|
| 301 |
+
break
|
| 302 |
+
counter += 1
|
| 303 |
+
|
| 304 |
+
# If the counter if even, the path correspond to a JSON Schema keyword
|
| 305 |
+
# otherwise it can be any arbitrary string naming a property
|
| 306 |
+
return counter % 2 == 1
|
| 307 |
+
|
| 308 |
+
def _label(self, path: Sequence[str]) -> str:
|
| 309 |
+
*parents, key = path
|
| 310 |
+
if not self._is_property(path):
|
| 311 |
+
norm_key = _separate_terms(key)
|
| 312 |
+
return self._terms.get(key) or " ".join(self._jargon(norm_key))
|
| 313 |
+
|
| 314 |
+
if parents[-1] == "patternProperties":
|
| 315 |
+
return f"(regex {key!r})"
|
| 316 |
+
return repr(key) # property name
|
| 317 |
+
|
| 318 |
+
def _value(self, value: Any, path: Sequence[str]) -> str:
|
| 319 |
+
if path[-1] == "type" and not self._is_property(path):
|
| 320 |
+
type_ = self._jargon(value)
|
| 321 |
+
return f"[{', '.join(type_)}]" if isinstance(type_, list) else type_
|
| 322 |
+
return repr(value)
|
| 323 |
+
|
| 324 |
+
def _inline_attrs(self, schema: dict, path: Sequence[str]) -> Iterator[str]:
|
| 325 |
+
for key, value in schema.items():
|
| 326 |
+
child_path = [*path, key]
|
| 327 |
+
yield f"{self._label(child_path)}: {self._value(value, child_path)}"
|
| 328 |
+
|
| 329 |
+
def _child_prefix(self, parent_prefix: str, child_prefix: str) -> str:
|
| 330 |
+
return len(parent_prefix) * " " + child_prefix
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def _separate_terms(word: str) -> list[str]:
|
| 334 |
+
"""
|
| 335 |
+
>>> _separate_terms("FooBar-foo")
|
| 336 |
+
['foo', 'bar', 'foo']
|
| 337 |
+
"""
|
| 338 |
+
return [w.lower() for w in _CAMEL_CASE_SPLITTER.split(word) if w]
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/extra_validations.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The purpose of this module is implement PEP 621 validations that are
|
| 2 |
+
difficult to express as a JSON Schema (or that are not supported by the current
|
| 3 |
+
JSON Schema library).
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import collections
|
| 7 |
+
import itertools
|
| 8 |
+
from inspect import cleandoc
|
| 9 |
+
from typing import Generator, Iterable, Mapping, TypeVar
|
| 10 |
+
|
| 11 |
+
from .error_reporting import ValidationError
|
| 12 |
+
|
| 13 |
+
T = TypeVar("T", bound=Mapping)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class RedefiningStaticFieldAsDynamic(ValidationError):
|
| 17 |
+
_DESC = """According to PEP 621:
|
| 18 |
+
|
| 19 |
+
Build back-ends MUST raise an error if the metadata specifies a field
|
| 20 |
+
statically as well as being listed in dynamic.
|
| 21 |
+
"""
|
| 22 |
+
__doc__ = _DESC
|
| 23 |
+
_URL = (
|
| 24 |
+
"https://packaging.python.org/en/latest/specifications/pyproject-toml/#dynamic"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class IncludedDependencyGroupMustExist(ValidationError):
|
| 29 |
+
_DESC = """An included dependency group must exist and must not be cyclic.
|
| 30 |
+
"""
|
| 31 |
+
__doc__ = _DESC
|
| 32 |
+
_URL = "https://peps.python.org/pep-0735/"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class ImportNameCollision(ValidationError):
|
| 36 |
+
_DESC = """According to PEP 794:
|
| 37 |
+
|
| 38 |
+
All import-names and import-namespaces items must be unique.
|
| 39 |
+
"""
|
| 40 |
+
__doc__ = _DESC
|
| 41 |
+
_URL = "https://peps.python.org/pep-0794/"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class ImportNameMissing(ValidationError):
|
| 45 |
+
_DESC = """According to PEP 794:
|
| 46 |
+
|
| 47 |
+
An import name must have all parents listed.
|
| 48 |
+
"""
|
| 49 |
+
__doc__ = _DESC
|
| 50 |
+
_URL = "https://peps.python.org/pep-0794/"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def validate_project_dynamic(pyproject: T) -> T:
|
| 54 |
+
project_table = pyproject.get("project", {})
|
| 55 |
+
dynamic = project_table.get("dynamic", [])
|
| 56 |
+
|
| 57 |
+
for field in dynamic:
|
| 58 |
+
if field in project_table:
|
| 59 |
+
raise RedefiningStaticFieldAsDynamic(
|
| 60 |
+
message=f"You cannot provide a value for `project.{field}` and "
|
| 61 |
+
"list it under `project.dynamic` at the same time",
|
| 62 |
+
value={
|
| 63 |
+
field: project_table[field],
|
| 64 |
+
"...": " # ...",
|
| 65 |
+
"dynamic": dynamic,
|
| 66 |
+
},
|
| 67 |
+
name=f"data.project.{field}",
|
| 68 |
+
definition={
|
| 69 |
+
"description": cleandoc(RedefiningStaticFieldAsDynamic._DESC),
|
| 70 |
+
"see": RedefiningStaticFieldAsDynamic._URL,
|
| 71 |
+
},
|
| 72 |
+
rule="PEP 621",
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
return pyproject
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def validate_include_depenency(pyproject: T) -> T:
|
| 79 |
+
dependency_groups = pyproject.get("dependency-groups", {})
|
| 80 |
+
for key, value in dependency_groups.items():
|
| 81 |
+
for each in value:
|
| 82 |
+
if (
|
| 83 |
+
isinstance(each, dict)
|
| 84 |
+
and (include_group := each.get("include-group"))
|
| 85 |
+
and include_group not in dependency_groups
|
| 86 |
+
):
|
| 87 |
+
raise IncludedDependencyGroupMustExist(
|
| 88 |
+
message=f"The included dependency group {include_group} doesn't exist",
|
| 89 |
+
value=each,
|
| 90 |
+
name=f"data.dependency_groups.{key}",
|
| 91 |
+
definition={
|
| 92 |
+
"description": cleandoc(IncludedDependencyGroupMustExist._DESC),
|
| 93 |
+
"see": IncludedDependencyGroupMustExist._URL,
|
| 94 |
+
},
|
| 95 |
+
rule="PEP 735",
|
| 96 |
+
)
|
| 97 |
+
# TODO: check for `include-group` cycles (can be conditional to graphlib)
|
| 98 |
+
return pyproject
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def _remove_private(items: Iterable[str]) -> Generator[str, None, None]:
|
| 102 |
+
for item in items:
|
| 103 |
+
yield item.partition(";")[0].rstrip()
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def validate_import_name_issues(pyproject: T) -> T:
|
| 107 |
+
project = pyproject.get("project", {})
|
| 108 |
+
import_names = collections.Counter(_remove_private(project.get("import-names", [])))
|
| 109 |
+
import_namespaces = collections.Counter(
|
| 110 |
+
_remove_private(project.get("import-namespaces", []))
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
duplicated = [k for k, v in (import_names + import_namespaces).items() if v > 1]
|
| 114 |
+
|
| 115 |
+
if duplicated:
|
| 116 |
+
raise ImportNameCollision(
|
| 117 |
+
message="Duplicated names are not allowed in import-names/import-namespaces",
|
| 118 |
+
value=duplicated,
|
| 119 |
+
name="data.project.importnames(paces)",
|
| 120 |
+
definition={
|
| 121 |
+
"description": cleandoc(ImportNameCollision._DESC),
|
| 122 |
+
"see": ImportNameCollision._URL,
|
| 123 |
+
},
|
| 124 |
+
rule="PEP 794",
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
names = frozenset(import_names + import_namespaces)
|
| 128 |
+
for name in names:
|
| 129 |
+
for parent in itertools.accumulate(
|
| 130 |
+
name.split(".")[:-1], lambda a, b: f"{a}.{b}"
|
| 131 |
+
):
|
| 132 |
+
if parent not in names:
|
| 133 |
+
raise ImportNameMissing(
|
| 134 |
+
message="All parents of an import name must also be listed in import-namespace/import-names",
|
| 135 |
+
value=name,
|
| 136 |
+
name="data.project.importnames(paces)",
|
| 137 |
+
definition={
|
| 138 |
+
"description": cleandoc(ImportNameMissing._DESC),
|
| 139 |
+
"see": ImportNameMissing._URL,
|
| 140 |
+
},
|
| 141 |
+
rule="PEP 794",
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
return pyproject
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
EXTRA_VALIDATIONS = (
|
| 148 |
+
validate_project_dynamic,
|
| 149 |
+
validate_include_depenency,
|
| 150 |
+
validate_import_name_issues,
|
| 151 |
+
)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_exceptions.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
SPLIT_RE = re.compile(r'[\.\[\]]+')
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class JsonSchemaException(ValueError):
|
| 8 |
+
"""
|
| 9 |
+
Base exception of ``fastjsonschema`` library.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class JsonSchemaValueException(JsonSchemaException):
|
| 14 |
+
"""
|
| 15 |
+
Exception raised by validation function. Available properties:
|
| 16 |
+
|
| 17 |
+
* ``message`` containing human-readable information what is wrong (e.g. ``data.property[index] must be smaller than or equal to 42``),
|
| 18 |
+
* invalid ``value`` (e.g. ``60``),
|
| 19 |
+
* ``name`` of a path in the data structure (e.g. ``data.property[index]``),
|
| 20 |
+
* ``path`` as an array in the data structure (e.g. ``['data', 'property', 'index']``),
|
| 21 |
+
* the whole ``definition`` which the ``value`` has to fulfil (e.g. ``{'type': 'number', 'maximum': 42}``),
|
| 22 |
+
* ``rule`` which the ``value`` is breaking (e.g. ``maximum``)
|
| 23 |
+
* and ``rule_definition`` (e.g. ``42``).
|
| 24 |
+
|
| 25 |
+
.. versionchanged:: 2.14.0
|
| 26 |
+
Added all extra properties.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
def __init__(self, message, value=None, name=None, definition=None, rule=None):
|
| 30 |
+
super().__init__(message)
|
| 31 |
+
self.message = message
|
| 32 |
+
self.value = value
|
| 33 |
+
self.name = name
|
| 34 |
+
self.definition = definition
|
| 35 |
+
self.rule = rule
|
| 36 |
+
|
| 37 |
+
@property
|
| 38 |
+
def path(self):
|
| 39 |
+
return [item for item in SPLIT_RE.split(self.name) if item != '']
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def rule_definition(self):
|
| 43 |
+
if not self.rule or not self.definition:
|
| 44 |
+
return None
|
| 45 |
+
return self.definition.get(self.rule)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class JsonSchemaDefinitionException(JsonSchemaException):
|
| 49 |
+
"""
|
| 50 |
+
Exception raised by generator of validation function.
|
| 51 |
+
"""
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_validations.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/_validate_pyproject/formats.py
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
The functions in this module are used to validate schemas with the
|
| 3 |
+
`format JSON Schema keyword
|
| 4 |
+
<https://json-schema.org/understanding-json-schema/reference/string#format>`_.
|
| 5 |
+
|
| 6 |
+
The correspondence is given by replacing the ``_`` character in the name of the
|
| 7 |
+
function with a ``-`` to obtain the format name and vice versa.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import keyword
|
| 13 |
+
import logging
|
| 14 |
+
import os
|
| 15 |
+
import re
|
| 16 |
+
import string
|
| 17 |
+
import typing
|
| 18 |
+
from itertools import chain as _chain
|
| 19 |
+
|
| 20 |
+
if typing.TYPE_CHECKING:
|
| 21 |
+
import builtins
|
| 22 |
+
|
| 23 |
+
from typing_extensions import Literal
|
| 24 |
+
|
| 25 |
+
_logger = logging.getLogger(__name__)
|
| 26 |
+
|
| 27 |
+
# -------------------------------------------------------------------------------------
|
| 28 |
+
# PEP 440
|
| 29 |
+
|
| 30 |
+
VERSION_PATTERN = r"""
|
| 31 |
+
v?
|
| 32 |
+
(?:
|
| 33 |
+
(?:(?P<epoch>[0-9]+)!)? # epoch
|
| 34 |
+
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
|
| 35 |
+
(?P<pre> # pre-release
|
| 36 |
+
[-_\.]?
|
| 37 |
+
(?P<pre_l>alpha|a|beta|b|preview|pre|c|rc)
|
| 38 |
+
[-_\.]?
|
| 39 |
+
(?P<pre_n>[0-9]+)?
|
| 40 |
+
)?
|
| 41 |
+
(?P<post> # post release
|
| 42 |
+
(?:-(?P<post_n1>[0-9]+))
|
| 43 |
+
|
|
| 44 |
+
(?:
|
| 45 |
+
[-_\.]?
|
| 46 |
+
(?P<post_l>post|rev|r)
|
| 47 |
+
[-_\.]?
|
| 48 |
+
(?P<post_n2>[0-9]+)?
|
| 49 |
+
)
|
| 50 |
+
)?
|
| 51 |
+
(?P<dev> # dev release
|
| 52 |
+
[-_\.]?
|
| 53 |
+
(?P<dev_l>dev)
|
| 54 |
+
[-_\.]?
|
| 55 |
+
(?P<dev_n>[0-9]+)?
|
| 56 |
+
)?
|
| 57 |
+
)
|
| 58 |
+
(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
VERSION_REGEX = re.compile(
|
| 62 |
+
r"^\s*" + VERSION_PATTERN + r"\s*$", re.VERBOSE | re.IGNORECASE
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def pep440(version: str) -> bool:
|
| 67 |
+
"""See :ref:`PyPA's version specification <pypa:version-specifiers>`
|
| 68 |
+
(initially introduced in :pep:`440`).
|
| 69 |
+
"""
|
| 70 |
+
return VERSION_REGEX.match(version) is not None
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# -------------------------------------------------------------------------------------
|
| 74 |
+
# PEP 508
|
| 75 |
+
|
| 76 |
+
PEP508_IDENTIFIER_PATTERN = r"([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])"
|
| 77 |
+
PEP508_IDENTIFIER_REGEX = re.compile(f"^{PEP508_IDENTIFIER_PATTERN}$", re.IGNORECASE)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def pep508_identifier(name: str) -> bool:
|
| 81 |
+
"""See :ref:`PyPA's name specification <pypa:name-format>`
|
| 82 |
+
(initially introduced in :pep:`508#names`).
|
| 83 |
+
"""
|
| 84 |
+
return PEP508_IDENTIFIER_REGEX.match(name) is not None
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
try:
|
| 88 |
+
try:
|
| 89 |
+
from packaging import requirements as _req
|
| 90 |
+
except ImportError: # pragma: no cover
|
| 91 |
+
# let's try setuptools vendored version
|
| 92 |
+
from setuptools._vendor.packaging import ( # type: ignore[no-redef]
|
| 93 |
+
requirements as _req,
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
def pep508(value: str) -> bool:
|
| 97 |
+
"""See :ref:`PyPA's dependency specifiers <pypa:dependency-specifiers>`
|
| 98 |
+
(initially introduced in :pep:`508`).
|
| 99 |
+
"""
|
| 100 |
+
try:
|
| 101 |
+
_req.Requirement(value)
|
| 102 |
+
except _req.InvalidRequirement:
|
| 103 |
+
return False
|
| 104 |
+
return True
|
| 105 |
+
|
| 106 |
+
except ImportError: # pragma: no cover
|
| 107 |
+
_logger.warning(
|
| 108 |
+
"Could not find an installation of `packaging`. Requirements, dependencies and "
|
| 109 |
+
"versions might not be validated. "
|
| 110 |
+
"To enforce validation, please install `packaging`."
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
def pep508(value: str) -> bool: # noqa: ARG001
|
| 114 |
+
return True
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def pep508_versionspec(value: str) -> bool:
|
| 118 |
+
"""Expression that can be used to specify/lock versions (including ranges)
|
| 119 |
+
See ``versionspec`` in :ref:`PyPA's dependency specifiers
|
| 120 |
+
<pypa:dependency-specifiers>` (initially introduced in :pep:`508`).
|
| 121 |
+
"""
|
| 122 |
+
if any(c in value for c in (";", "]", "@")):
|
| 123 |
+
# In PEP 508:
|
| 124 |
+
# conditional markers, extras and URL specs are not included in the
|
| 125 |
+
# versionspec
|
| 126 |
+
return False
|
| 127 |
+
# Let's pretend we have a dependency called `requirement` with the given
|
| 128 |
+
# version spec, then we can reuse the pep508 function for validation:
|
| 129 |
+
return pep508(f"requirement{value}")
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
# -------------------------------------------------------------------------------------
|
| 133 |
+
# PEP 517
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def pep517_backend_reference(value: str) -> bool:
|
| 137 |
+
"""See PyPA's specification for defining build-backend references
|
| 138 |
+
introduced in :pep:`517#source-trees`.
|
| 139 |
+
|
| 140 |
+
This is similar to an entry-point reference (e.g., ``package.module:object``).
|
| 141 |
+
"""
|
| 142 |
+
module, _, obj = value.partition(":")
|
| 143 |
+
identifiers = (i.strip() for i in _chain(module.split("."), obj.split(".")))
|
| 144 |
+
return all(python_identifier(i) for i in identifiers if i)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
# -------------------------------------------------------------------------------------
|
| 148 |
+
# Classifiers - PEP 301
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def _download_classifiers() -> str:
|
| 152 |
+
import ssl
|
| 153 |
+
from email.message import Message
|
| 154 |
+
from urllib.request import urlopen
|
| 155 |
+
|
| 156 |
+
url = "https://pypi.org/pypi?:action=list_classifiers"
|
| 157 |
+
context = ssl.create_default_context()
|
| 158 |
+
with urlopen(url, context=context) as response: # noqa: S310 (audit URLs)
|
| 159 |
+
headers = Message()
|
| 160 |
+
headers["content_type"] = response.getheader("content-type", "text/plain")
|
| 161 |
+
return response.read().decode(headers.get_param("charset", "utf-8")) # type: ignore[no-any-return]
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
class _TroveClassifier:
|
| 165 |
+
"""The ``trove_classifiers`` package is the official way of validating classifiers,
|
| 166 |
+
however this package might not be always available.
|
| 167 |
+
As a workaround we can still download a list from PyPI.
|
| 168 |
+
We also don't want to be over strict about it, so simply skipping silently is an
|
| 169 |
+
option (classifiers will be validated anyway during the upload to PyPI).
|
| 170 |
+
"""
|
| 171 |
+
|
| 172 |
+
downloaded: None | Literal[False] | set[str]
|
| 173 |
+
"""
|
| 174 |
+
None => not cached yet
|
| 175 |
+
False => unavailable
|
| 176 |
+
set => cached values
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
def __init__(self) -> None:
|
| 180 |
+
self.downloaded = None
|
| 181 |
+
self._skip_download = False
|
| 182 |
+
self.__name__ = "trove_classifier" # Emulate a public function
|
| 183 |
+
|
| 184 |
+
def _disable_download(self) -> None:
|
| 185 |
+
# This is a private API. Only setuptools has the consent of using it.
|
| 186 |
+
self._skip_download = True
|
| 187 |
+
|
| 188 |
+
def __call__(self, value: str) -> bool:
|
| 189 |
+
if self.downloaded is False or self._skip_download is True:
|
| 190 |
+
return True
|
| 191 |
+
|
| 192 |
+
if os.getenv("NO_NETWORK") or os.getenv("VALIDATE_PYPROJECT_NO_NETWORK"):
|
| 193 |
+
self.downloaded = False
|
| 194 |
+
msg = (
|
| 195 |
+
"Install ``trove-classifiers`` to ensure proper validation. "
|
| 196 |
+
"Skipping download of classifiers list from PyPI (NO_NETWORK)."
|
| 197 |
+
)
|
| 198 |
+
_logger.debug(msg)
|
| 199 |
+
return True
|
| 200 |
+
|
| 201 |
+
if self.downloaded is None:
|
| 202 |
+
msg = (
|
| 203 |
+
"Install ``trove-classifiers`` to ensure proper validation. "
|
| 204 |
+
"Meanwhile a list of classifiers will be downloaded from PyPI."
|
| 205 |
+
)
|
| 206 |
+
_logger.debug(msg)
|
| 207 |
+
try:
|
| 208 |
+
self.downloaded = set(_download_classifiers().splitlines())
|
| 209 |
+
except Exception: # noqa: BLE001
|
| 210 |
+
self.downloaded = False
|
| 211 |
+
_logger.debug("Problem with download, skipping validation")
|
| 212 |
+
return True
|
| 213 |
+
|
| 214 |
+
return value in self.downloaded or value.lower().startswith("private ::")
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
try:
|
| 218 |
+
from trove_classifiers import classifiers as _trove_classifiers
|
| 219 |
+
|
| 220 |
+
def trove_classifier(value: str) -> bool:
|
| 221 |
+
"""See https://pypi.org/classifiers/"""
|
| 222 |
+
return value in _trove_classifiers or value.lower().startswith("private ::")
|
| 223 |
+
|
| 224 |
+
except ImportError: # pragma: no cover
|
| 225 |
+
trove_classifier = _TroveClassifier()
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
# -------------------------------------------------------------------------------------
|
| 229 |
+
# Stub packages - PEP 561
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def pep561_stub_name(value: str) -> bool:
|
| 233 |
+
"""Name of a directory containing type stubs.
|
| 234 |
+
It must follow the name scheme ``<package>-stubs`` as defined in
|
| 235 |
+
:pep:`561#stub-only-packages`.
|
| 236 |
+
"""
|
| 237 |
+
top, *children = value.split(".")
|
| 238 |
+
if not top.endswith("-stubs"):
|
| 239 |
+
return False
|
| 240 |
+
return python_module_name(".".join([top[: -len("-stubs")], *children]))
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
# -------------------------------------------------------------------------------------
|
| 244 |
+
# Non-PEP related
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def url(value: str) -> bool:
|
| 248 |
+
"""Valid URL (validation uses :obj:`urllib.parse`).
|
| 249 |
+
For maximum compatibility please make sure to include a ``scheme`` prefix
|
| 250 |
+
in your URL (e.g. ``http://``).
|
| 251 |
+
"""
|
| 252 |
+
from urllib.parse import urlparse
|
| 253 |
+
|
| 254 |
+
try:
|
| 255 |
+
parts = urlparse(value)
|
| 256 |
+
if not parts.scheme:
|
| 257 |
+
_logger.warning(
|
| 258 |
+
"For maximum compatibility please make sure to include a "
|
| 259 |
+
"`scheme` prefix in your URL (e.g. 'http://'). "
|
| 260 |
+
f"Given value: {value}"
|
| 261 |
+
)
|
| 262 |
+
if not (value.startswith(("/", "\\")) or "@" in value):
|
| 263 |
+
parts = urlparse(f"http://{value}")
|
| 264 |
+
|
| 265 |
+
return bool(parts.scheme and parts.netloc)
|
| 266 |
+
except Exception: # noqa: BLE001
|
| 267 |
+
return False
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
# https://packaging.python.org/specifications/entry-points/
|
| 271 |
+
ENTRYPOINT_PATTERN = r"[^\[\s=]([^=]*[^\s=])?"
|
| 272 |
+
ENTRYPOINT_REGEX = re.compile(f"^{ENTRYPOINT_PATTERN}$", re.IGNORECASE)
|
| 273 |
+
RECOMMEDED_ENTRYPOINT_PATTERN = r"[\w.-]+"
|
| 274 |
+
RECOMMEDED_ENTRYPOINT_REGEX = re.compile(
|
| 275 |
+
f"^{RECOMMEDED_ENTRYPOINT_PATTERN}$", re.IGNORECASE
|
| 276 |
+
)
|
| 277 |
+
ENTRYPOINT_GROUP_PATTERN = r"\w+(\.\w+)*"
|
| 278 |
+
ENTRYPOINT_GROUP_REGEX = re.compile(f"^{ENTRYPOINT_GROUP_PATTERN}$", re.IGNORECASE)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def python_identifier(value: str) -> bool:
|
| 282 |
+
"""Can be used as identifier in Python.
|
| 283 |
+
(Validation uses :obj:`str.isidentifier`).
|
| 284 |
+
"""
|
| 285 |
+
return value.isidentifier()
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
def python_qualified_identifier(value: str) -> bool:
|
| 289 |
+
"""
|
| 290 |
+
Python "dotted identifier", i.e. a sequence of :obj:`python_identifier`
|
| 291 |
+
concatenated with ``"."`` (e.g.: ``package.module.submodule``).
|
| 292 |
+
"""
|
| 293 |
+
if value.startswith(".") or value.endswith("."):
|
| 294 |
+
return False
|
| 295 |
+
return all(python_identifier(m) for m in value.split("."))
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def python_module_name(value: str) -> bool:
|
| 299 |
+
"""Module name that can be used in an ``import``-statement in Python.
|
| 300 |
+
See :obj:`python_qualified_identifier`.
|
| 301 |
+
"""
|
| 302 |
+
return python_qualified_identifier(value)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def python_module_name_relaxed(value: str) -> bool:
|
| 306 |
+
"""Similar to :obj:`python_module_name`, but relaxed to also accept
|
| 307 |
+
dash characters (``-``) and cover special cases like ``pip-run``.
|
| 308 |
+
|
| 309 |
+
It is recommended, however, that beginners avoid dash characters,
|
| 310 |
+
as they require advanced knowledge about Python internals.
|
| 311 |
+
|
| 312 |
+
The following are disallowed:
|
| 313 |
+
|
| 314 |
+
* names starting/ending in dashes,
|
| 315 |
+
* names ending in ``-stubs`` (potentially collide with :obj:`pep561_stub_name`).
|
| 316 |
+
"""
|
| 317 |
+
if value.startswith("-") or value.endswith("-"):
|
| 318 |
+
return False
|
| 319 |
+
if value.endswith("-stubs"):
|
| 320 |
+
return False # Avoid collision with PEP 561
|
| 321 |
+
return python_module_name(value.replace("-", "_"))
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def python_entrypoint_group(value: str) -> bool:
|
| 325 |
+
"""See ``Data model > group`` in the :ref:`PyPA's entry-points specification
|
| 326 |
+
<pypa:entry-points>`.
|
| 327 |
+
"""
|
| 328 |
+
return ENTRYPOINT_GROUP_REGEX.match(value) is not None
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def python_entrypoint_name(value: str) -> bool:
|
| 332 |
+
"""See ``Data model > name`` in the :ref:`PyPA's entry-points specification
|
| 333 |
+
<pypa:entry-points>`.
|
| 334 |
+
"""
|
| 335 |
+
if not ENTRYPOINT_REGEX.match(value):
|
| 336 |
+
return False
|
| 337 |
+
if not RECOMMEDED_ENTRYPOINT_REGEX.match(value):
|
| 338 |
+
msg = f"Entry point `{value}` does not follow recommended pattern: "
|
| 339 |
+
msg += RECOMMEDED_ENTRYPOINT_PATTERN
|
| 340 |
+
_logger.warning(msg)
|
| 341 |
+
return True
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def python_entrypoint_reference(value: str) -> bool:
|
| 345 |
+
"""Reference to a Python object using in the format::
|
| 346 |
+
|
| 347 |
+
importable.module:object.attr
|
| 348 |
+
|
| 349 |
+
See ``Data model >object reference`` in the :ref:`PyPA's entry-points specification
|
| 350 |
+
<pypa:entry-points>`.
|
| 351 |
+
"""
|
| 352 |
+
module, _, rest = value.partition(":")
|
| 353 |
+
if "[" in rest:
|
| 354 |
+
obj, _, extras_ = rest.partition("[")
|
| 355 |
+
if extras_.strip()[-1] != "]":
|
| 356 |
+
return False
|
| 357 |
+
extras = (x.strip() for x in extras_.strip(string.whitespace + "[]").split(","))
|
| 358 |
+
if not all(pep508_identifier(e) for e in extras):
|
| 359 |
+
return False
|
| 360 |
+
_logger.warning(f"`{value}` - using extras for entry points is not recommended")
|
| 361 |
+
else:
|
| 362 |
+
obj = rest
|
| 363 |
+
|
| 364 |
+
module_parts = module.split(".")
|
| 365 |
+
identifiers = _chain(module_parts, obj.split(".")) if rest else iter(module_parts)
|
| 366 |
+
return all(python_identifier(i.strip()) for i in identifiers)
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def uint8(value: builtins.int) -> bool:
|
| 370 |
+
r"""Unsigned 8-bit integer (:math:`0 \leq x < 2^8`)"""
|
| 371 |
+
return 0 <= value < 2**8
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
def uint16(value: builtins.int) -> bool:
|
| 375 |
+
r"""Unsigned 16-bit integer (:math:`0 \leq x < 2^{16}`)"""
|
| 376 |
+
return 0 <= value < 2**16
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def uint32(value: builtins.int) -> bool:
|
| 380 |
+
r"""Unsigned 32-bit integer (:math:`0 \leq x < 2^{32}`)"""
|
| 381 |
+
return 0 <= value < 2**32
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
def uint64(value: builtins.int) -> bool:
|
| 385 |
+
r"""Unsigned 64-bit integer (:math:`0 \leq x < 2^{64}`)"""
|
| 386 |
+
return 0 <= value < 2**64
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
def uint(value: builtins.int) -> bool:
|
| 390 |
+
r"""Signed 64-bit integer (:math:`0 \leq x < 2^{64}`)"""
|
| 391 |
+
return 0 <= value < 2**64
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
def int8(value: builtins.int) -> bool:
|
| 395 |
+
r"""Signed 8-bit integer (:math:`-2^{7} \leq x < 2^{7}`)"""
|
| 396 |
+
return -(2**7) <= value < 2**7
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def int16(value: builtins.int) -> bool:
|
| 400 |
+
r"""Signed 16-bit integer (:math:`-2^{15} \leq x < 2^{15}`)"""
|
| 401 |
+
return -(2**15) <= value < 2**15
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
def int32(value: builtins.int) -> bool:
|
| 405 |
+
r"""Signed 32-bit integer (:math:`-2^{31} \leq x < 2^{31}`)"""
|
| 406 |
+
return -(2**31) <= value < 2**31
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
def int64(value: builtins.int) -> bool:
|
| 410 |
+
r"""Signed 64-bit integer (:math:`-2^{63} \leq x < 2^{63}`)"""
|
| 411 |
+
return -(2**63) <= value < 2**63
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def int(value: builtins.int) -> bool:
|
| 415 |
+
r"""Signed 64-bit integer (:math:`-2^{63} \leq x < 2^{63}`)"""
|
| 416 |
+
return -(2**63) <= value < 2**63
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
try:
|
| 420 |
+
from packaging import licenses as _licenses
|
| 421 |
+
|
| 422 |
+
def SPDX(value: str) -> bool:
|
| 423 |
+
"""See :ref:`PyPA's License-Expression specification
|
| 424 |
+
<pypa:core-metadata-license-expression>` (added in :pep:`639`).
|
| 425 |
+
"""
|
| 426 |
+
try:
|
| 427 |
+
_licenses.canonicalize_license_expression(value)
|
| 428 |
+
except _licenses.InvalidLicenseExpression:
|
| 429 |
+
return False
|
| 430 |
+
return True
|
| 431 |
+
|
| 432 |
+
except ImportError: # pragma: no cover
|
| 433 |
+
_logger.warning(
|
| 434 |
+
"Could not find an up-to-date installation of `packaging`. "
|
| 435 |
+
"License expressions might not be validated. "
|
| 436 |
+
"To enforce validation, please install `packaging>=24.2`."
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
def SPDX(value: str) -> bool: # noqa: ARG001
|
| 440 |
+
return True
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
VALID_IMPORT_NAME = re.compile(
|
| 444 |
+
r"""
|
| 445 |
+
^ # start of string
|
| 446 |
+
[A-Za-z_][A-Za-z_0-9]+ # a valid Python identifier
|
| 447 |
+
(?:\.[A-Za-z_][A-Za-z_0-9]*)* # optionally followed by .identifier's
|
| 448 |
+
(?:\s*;\s*private)? # optionally followed by ; private
|
| 449 |
+
$ # end of string
|
| 450 |
+
""",
|
| 451 |
+
re.VERBOSE,
|
| 452 |
+
)
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
def import_name(value: str) -> bool:
|
| 456 |
+
"""This is a valid import name. It has to be series of python identifiers
|
| 457 |
+
(not keywords), separated by dots, optionally followed by a semicolon and
|
| 458 |
+
the keyword "private".
|
| 459 |
+
"""
|
| 460 |
+
if VALID_IMPORT_NAME.match(value) is None:
|
| 461 |
+
return False
|
| 462 |
+
|
| 463 |
+
idents, _, _ = value.partition(";")
|
| 464 |
+
return all(not keyword.iskeyword(ident) for ident in idents.rstrip().split("."))
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/distutils.schema.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 3 |
+
|
| 4 |
+
"$id": "https://setuptools.pypa.io/en/latest/deprecated/distutils/configfile.html",
|
| 5 |
+
"title": "``tool.distutils`` table",
|
| 6 |
+
"$$description": [
|
| 7 |
+
"**EXPERIMENTAL** (NOT OFFICIALLY SUPPORTED): Use ``tool.distutils``",
|
| 8 |
+
"subtables to configure arguments for ``distutils`` commands.",
|
| 9 |
+
"Originally, ``distutils`` allowed developers to configure arguments for",
|
| 10 |
+
"``setup.py`` commands via `distutils configuration files",
|
| 11 |
+
"<https://setuptools.pypa.io/en/latest/deprecated/distutils/configfile.html>`_.",
|
| 12 |
+
"See also `the old Python docs <https://docs.python.org/3.11/install/>_`."
|
| 13 |
+
],
|
| 14 |
+
|
| 15 |
+
"type": "object",
|
| 16 |
+
"properties": {
|
| 17 |
+
"global": {
|
| 18 |
+
"type": "object",
|
| 19 |
+
"description": "Global options applied to all ``distutils`` commands"
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"patternProperties": {
|
| 23 |
+
".+": {"type": "object"}
|
| 24 |
+
},
|
| 25 |
+
"$comment": "TODO: Is there a practical way of making this schema more specific?"
|
| 26 |
+
}
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/expand.py
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utility functions to expand configuration directives or special values
|
| 2 |
+
(such glob patterns).
|
| 3 |
+
|
| 4 |
+
We can split the process of interpreting configuration files into 2 steps:
|
| 5 |
+
|
| 6 |
+
1. The parsing the file contents from strings to value objects
|
| 7 |
+
that can be understand by Python (for example a string with a comma
|
| 8 |
+
separated list of keywords into an actual Python list of strings).
|
| 9 |
+
|
| 10 |
+
2. The expansion (or post-processing) of these values according to the
|
| 11 |
+
semantics ``setuptools`` assign to them (for example a configuration field
|
| 12 |
+
with the ``file:`` directive should be expanded from a list of file paths to
|
| 13 |
+
a single string with the contents of those files concatenated)
|
| 14 |
+
|
| 15 |
+
This module focus on the second step, and therefore allow sharing the expansion
|
| 16 |
+
functions among several configuration file formats.
|
| 17 |
+
|
| 18 |
+
**PRIVATE MODULE**: API reserved for setuptools internal usage only.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
from __future__ import annotations
|
| 22 |
+
|
| 23 |
+
import ast
|
| 24 |
+
import importlib
|
| 25 |
+
import os
|
| 26 |
+
import pathlib
|
| 27 |
+
import sys
|
| 28 |
+
from collections.abc import Callable, Iterable, Iterator, Mapping
|
| 29 |
+
from configparser import ConfigParser
|
| 30 |
+
from glob import iglob
|
| 31 |
+
from importlib.machinery import ModuleSpec, all_suffixes
|
| 32 |
+
from itertools import chain
|
| 33 |
+
from pathlib import Path
|
| 34 |
+
from types import ModuleType, TracebackType
|
| 35 |
+
from typing import TYPE_CHECKING, Any, TypeVar
|
| 36 |
+
|
| 37 |
+
from .. import _static
|
| 38 |
+
from .._path import StrPath, same_path as _same_path
|
| 39 |
+
from ..discovery import find_package_path
|
| 40 |
+
from ..warnings import SetuptoolsWarning
|
| 41 |
+
|
| 42 |
+
from distutils.errors import DistutilsOptionError
|
| 43 |
+
|
| 44 |
+
if TYPE_CHECKING:
|
| 45 |
+
from typing_extensions import Self
|
| 46 |
+
|
| 47 |
+
from setuptools.dist import Distribution
|
| 48 |
+
|
| 49 |
+
_K = TypeVar("_K")
|
| 50 |
+
_V_co = TypeVar("_V_co", covariant=True)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class StaticModule:
|
| 54 |
+
"""Proxy to a module object that avoids executing arbitrary code."""
|
| 55 |
+
|
| 56 |
+
def __init__(self, name: str, spec: ModuleSpec) -> None:
|
| 57 |
+
module = ast.parse(pathlib.Path(spec.origin).read_bytes()) # type: ignore[arg-type] # Let it raise an error on None
|
| 58 |
+
vars(self).update(locals())
|
| 59 |
+
del self.self
|
| 60 |
+
|
| 61 |
+
def _find_assignments(self) -> Iterator[tuple[ast.AST, ast.AST]]:
|
| 62 |
+
for statement in self.module.body:
|
| 63 |
+
if isinstance(statement, ast.Assign):
|
| 64 |
+
yield from ((target, statement.value) for target in statement.targets)
|
| 65 |
+
elif isinstance(statement, ast.AnnAssign) and statement.value:
|
| 66 |
+
yield (statement.target, statement.value)
|
| 67 |
+
|
| 68 |
+
def __getattr__(self, attr: str) -> Any:
|
| 69 |
+
"""Attempt to load an attribute "statically", via :func:`ast.literal_eval`."""
|
| 70 |
+
try:
|
| 71 |
+
return next(
|
| 72 |
+
ast.literal_eval(value)
|
| 73 |
+
for target, value in self._find_assignments()
|
| 74 |
+
if isinstance(target, ast.Name) and target.id == attr
|
| 75 |
+
)
|
| 76 |
+
except Exception as e:
|
| 77 |
+
raise AttributeError(f"{self.name} has no attribute {attr}") from e
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def glob_relative(
|
| 81 |
+
patterns: Iterable[str], root_dir: StrPath | None = None
|
| 82 |
+
) -> list[str]:
|
| 83 |
+
"""Expand the list of glob patterns, but preserving relative paths.
|
| 84 |
+
|
| 85 |
+
:param list[str] patterns: List of glob patterns
|
| 86 |
+
:param str root_dir: Path to which globs should be relative
|
| 87 |
+
(current directory by default)
|
| 88 |
+
:rtype: list
|
| 89 |
+
"""
|
| 90 |
+
glob_characters = {'*', '?', '[', ']', '{', '}'}
|
| 91 |
+
expanded_values = []
|
| 92 |
+
root_dir = root_dir or os.getcwd()
|
| 93 |
+
for value in patterns:
|
| 94 |
+
# Has globby characters?
|
| 95 |
+
if any(char in value for char in glob_characters):
|
| 96 |
+
# then expand the glob pattern while keeping paths *relative*:
|
| 97 |
+
glob_path = os.path.abspath(os.path.join(root_dir, value))
|
| 98 |
+
expanded_values.extend(
|
| 99 |
+
sorted(
|
| 100 |
+
os.path.relpath(path, root_dir).replace(os.sep, "/")
|
| 101 |
+
for path in iglob(glob_path, recursive=True)
|
| 102 |
+
)
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
else:
|
| 106 |
+
# take the value as-is
|
| 107 |
+
path = os.path.relpath(value, root_dir).replace(os.sep, "/")
|
| 108 |
+
expanded_values.append(path)
|
| 109 |
+
|
| 110 |
+
return expanded_values
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def read_files(
|
| 114 |
+
filepaths: StrPath | Iterable[StrPath], root_dir: StrPath | None = None
|
| 115 |
+
) -> str:
|
| 116 |
+
"""Return the content of the files concatenated using ``\n`` as str
|
| 117 |
+
|
| 118 |
+
This function is sandboxed and won't reach anything outside ``root_dir``
|
| 119 |
+
|
| 120 |
+
(By default ``root_dir`` is the current directory).
|
| 121 |
+
"""
|
| 122 |
+
from more_itertools import always_iterable
|
| 123 |
+
|
| 124 |
+
root_dir = os.path.abspath(root_dir or os.getcwd())
|
| 125 |
+
_filepaths = (os.path.join(root_dir, path) for path in always_iterable(filepaths))
|
| 126 |
+
return '\n'.join(
|
| 127 |
+
_read_file(path)
|
| 128 |
+
for path in _filter_existing_files(_filepaths)
|
| 129 |
+
if _assert_local(path, root_dir)
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def _filter_existing_files(filepaths: Iterable[StrPath]) -> Iterator[StrPath]:
|
| 134 |
+
for path in filepaths:
|
| 135 |
+
if os.path.isfile(path):
|
| 136 |
+
yield path
|
| 137 |
+
else:
|
| 138 |
+
SetuptoolsWarning.emit(f"File {path!r} cannot be found")
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _read_file(filepath: bytes | StrPath) -> str:
|
| 142 |
+
with open(filepath, encoding='utf-8') as f:
|
| 143 |
+
return f.read()
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def _assert_local(filepath: StrPath, root_dir: str):
|
| 147 |
+
if Path(os.path.abspath(root_dir)) not in Path(os.path.abspath(filepath)).parents:
|
| 148 |
+
msg = f"Cannot access {filepath!r} (or anything outside {root_dir!r})"
|
| 149 |
+
raise DistutilsOptionError(msg)
|
| 150 |
+
|
| 151 |
+
return True
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def read_attr(
|
| 155 |
+
attr_desc: str,
|
| 156 |
+
package_dir: Mapping[str, str] | None = None,
|
| 157 |
+
root_dir: StrPath | None = None,
|
| 158 |
+
) -> Any:
|
| 159 |
+
"""Reads the value of an attribute from a module.
|
| 160 |
+
|
| 161 |
+
This function will try to read the attributed statically first
|
| 162 |
+
(via :func:`ast.literal_eval`), and only evaluate the module if it fails.
|
| 163 |
+
|
| 164 |
+
Examples:
|
| 165 |
+
read_attr("package.attr")
|
| 166 |
+
read_attr("package.module.attr")
|
| 167 |
+
|
| 168 |
+
:param str attr_desc: Dot-separated string describing how to reach the
|
| 169 |
+
attribute (see examples above)
|
| 170 |
+
:param dict[str, str] package_dir: Mapping of package names to their
|
| 171 |
+
location in disk (represented by paths relative to ``root_dir``).
|
| 172 |
+
:param str root_dir: Path to directory containing all the packages in
|
| 173 |
+
``package_dir`` (current directory by default).
|
| 174 |
+
:rtype: str
|
| 175 |
+
"""
|
| 176 |
+
root_dir = root_dir or os.getcwd()
|
| 177 |
+
attrs_path = attr_desc.strip().split('.')
|
| 178 |
+
attr_name = attrs_path.pop()
|
| 179 |
+
module_name = '.'.join(attrs_path)
|
| 180 |
+
module_name = module_name or '__init__'
|
| 181 |
+
path = _find_module(module_name, package_dir, root_dir)
|
| 182 |
+
spec = _find_spec(module_name, path)
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
value = getattr(StaticModule(module_name, spec), attr_name)
|
| 186 |
+
# XXX: Is marking as static contents coming from modules too optimistic?
|
| 187 |
+
return _static.attempt_conversion(value)
|
| 188 |
+
except Exception:
|
| 189 |
+
# fallback to evaluate module
|
| 190 |
+
module = _load_spec(spec, module_name)
|
| 191 |
+
return getattr(module, attr_name)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def _find_spec(module_name: str, module_path: StrPath | None) -> ModuleSpec:
|
| 195 |
+
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
| 196 |
+
spec = spec or importlib.util.find_spec(module_name)
|
| 197 |
+
|
| 198 |
+
if spec is None:
|
| 199 |
+
raise ModuleNotFoundError(module_name)
|
| 200 |
+
|
| 201 |
+
return spec
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _load_spec(spec: ModuleSpec, module_name: str) -> ModuleType:
|
| 205 |
+
name = getattr(spec, "__name__", module_name)
|
| 206 |
+
if name in sys.modules:
|
| 207 |
+
return sys.modules[name]
|
| 208 |
+
module = importlib.util.module_from_spec(spec)
|
| 209 |
+
sys.modules[name] = module # cache (it also ensures `==` works on loaded items)
|
| 210 |
+
assert spec.loader is not None
|
| 211 |
+
spec.loader.exec_module(module)
|
| 212 |
+
return module
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def _find_module(
|
| 216 |
+
module_name: str, package_dir: Mapping[str, str] | None, root_dir: StrPath
|
| 217 |
+
) -> str | None:
|
| 218 |
+
"""Find the path to the module named ``module_name``,
|
| 219 |
+
considering the ``package_dir`` in the build configuration and ``root_dir``.
|
| 220 |
+
|
| 221 |
+
>>> tmp = getfixture('tmpdir')
|
| 222 |
+
>>> _ = tmp.ensure("a/b/c.py")
|
| 223 |
+
>>> _ = tmp.ensure("a/b/d/__init__.py")
|
| 224 |
+
>>> r = lambda x: x.replace(str(tmp), "tmp").replace(os.sep, "/")
|
| 225 |
+
>>> r(_find_module("a.b.c", None, tmp))
|
| 226 |
+
'tmp/a/b/c.py'
|
| 227 |
+
>>> r(_find_module("f.g.h", {"": "1", "f": "2", "f.g": "3", "f.g.h": "a/b/d"}, tmp))
|
| 228 |
+
'tmp/a/b/d/__init__.py'
|
| 229 |
+
"""
|
| 230 |
+
path_start = find_package_path(module_name, package_dir or {}, root_dir)
|
| 231 |
+
candidates = chain.from_iterable(
|
| 232 |
+
(f"{path_start}{ext}", os.path.join(path_start, f"__init__{ext}"))
|
| 233 |
+
for ext in all_suffixes()
|
| 234 |
+
)
|
| 235 |
+
return next((x for x in candidates if os.path.isfile(x)), None)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def resolve_class(
|
| 239 |
+
qualified_class_name: str,
|
| 240 |
+
package_dir: Mapping[str, str] | None = None,
|
| 241 |
+
root_dir: StrPath | None = None,
|
| 242 |
+
) -> Callable:
|
| 243 |
+
"""Given a qualified class name, return the associated class object"""
|
| 244 |
+
root_dir = root_dir or os.getcwd()
|
| 245 |
+
idx = qualified_class_name.rfind('.')
|
| 246 |
+
class_name = qualified_class_name[idx + 1 :]
|
| 247 |
+
pkg_name = qualified_class_name[:idx]
|
| 248 |
+
|
| 249 |
+
path = _find_module(pkg_name, package_dir, root_dir)
|
| 250 |
+
module = _load_spec(_find_spec(pkg_name, path), pkg_name)
|
| 251 |
+
return getattr(module, class_name)
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def cmdclass(
|
| 255 |
+
values: dict[str, str],
|
| 256 |
+
package_dir: Mapping[str, str] | None = None,
|
| 257 |
+
root_dir: StrPath | None = None,
|
| 258 |
+
) -> dict[str, Callable]:
|
| 259 |
+
"""Given a dictionary mapping command names to strings for qualified class
|
| 260 |
+
names, apply :func:`resolve_class` to the dict values.
|
| 261 |
+
"""
|
| 262 |
+
return {k: resolve_class(v, package_dir, root_dir) for k, v in values.items()}
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def find_packages(
|
| 266 |
+
*,
|
| 267 |
+
namespaces=True,
|
| 268 |
+
fill_package_dir: dict[str, str] | None = None,
|
| 269 |
+
root_dir: StrPath | None = None,
|
| 270 |
+
**kwargs,
|
| 271 |
+
) -> list[str]:
|
| 272 |
+
"""Works similarly to :func:`setuptools.find_packages`, but with all
|
| 273 |
+
arguments given as keyword arguments. Moreover, ``where`` can be given
|
| 274 |
+
as a list (the results will be simply concatenated).
|
| 275 |
+
|
| 276 |
+
When the additional keyword argument ``namespaces`` is ``True``, it will
|
| 277 |
+
behave like :func:`setuptools.find_namespace_packages`` (i.e. include
|
| 278 |
+
implicit namespaces as per :pep:`420`).
|
| 279 |
+
|
| 280 |
+
The ``where`` argument will be considered relative to ``root_dir`` (or the current
|
| 281 |
+
working directory when ``root_dir`` is not given).
|
| 282 |
+
|
| 283 |
+
If the ``fill_package_dir`` argument is passed, this function will consider it as a
|
| 284 |
+
similar data structure to the ``package_dir`` configuration parameter add fill-in
|
| 285 |
+
any missing package location.
|
| 286 |
+
|
| 287 |
+
:rtype: list
|
| 288 |
+
"""
|
| 289 |
+
from more_itertools import always_iterable, unique_everseen
|
| 290 |
+
|
| 291 |
+
from setuptools.discovery import construct_package_dir
|
| 292 |
+
|
| 293 |
+
# check "not namespaces" first due to python/mypy#6232
|
| 294 |
+
if not namespaces:
|
| 295 |
+
from setuptools.discovery import PackageFinder
|
| 296 |
+
else:
|
| 297 |
+
from setuptools.discovery import PEP420PackageFinder as PackageFinder
|
| 298 |
+
|
| 299 |
+
root_dir = root_dir or os.curdir
|
| 300 |
+
where = kwargs.pop('where', ['.'])
|
| 301 |
+
packages: list[str] = []
|
| 302 |
+
fill_package_dir = {} if fill_package_dir is None else fill_package_dir
|
| 303 |
+
search = list(unique_everseen(always_iterable(where)))
|
| 304 |
+
|
| 305 |
+
if len(search) == 1 and all(not _same_path(search[0], x) for x in (".", root_dir)):
|
| 306 |
+
fill_package_dir.setdefault("", search[0])
|
| 307 |
+
|
| 308 |
+
for path in search:
|
| 309 |
+
package_path = _nest_path(root_dir, path)
|
| 310 |
+
pkgs = PackageFinder.find(package_path, **kwargs)
|
| 311 |
+
packages.extend(pkgs)
|
| 312 |
+
if pkgs and not (
|
| 313 |
+
fill_package_dir.get("") == path or os.path.samefile(package_path, root_dir)
|
| 314 |
+
):
|
| 315 |
+
fill_package_dir.update(construct_package_dir(pkgs, path))
|
| 316 |
+
|
| 317 |
+
return packages
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def _nest_path(parent: StrPath, path: StrPath) -> str:
|
| 321 |
+
path = parent if path in {".", ""} else os.path.join(parent, path)
|
| 322 |
+
return os.path.normpath(path)
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def version(value: Callable | Iterable[str | int] | str) -> str:
|
| 326 |
+
"""When getting the version directly from an attribute,
|
| 327 |
+
it should be normalised to string.
|
| 328 |
+
"""
|
| 329 |
+
_value = value() if callable(value) else value
|
| 330 |
+
|
| 331 |
+
if isinstance(_value, str):
|
| 332 |
+
return _value
|
| 333 |
+
if hasattr(_value, '__iter__'):
|
| 334 |
+
return '.'.join(map(str, _value))
|
| 335 |
+
return f'{_value}'
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def canonic_package_data(package_data: dict) -> dict:
|
| 339 |
+
if "*" in package_data:
|
| 340 |
+
package_data[""] = package_data.pop("*")
|
| 341 |
+
return package_data
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def canonic_data_files(
|
| 345 |
+
data_files: list | dict, root_dir: StrPath | None = None
|
| 346 |
+
) -> list[tuple[str, list[str]]]:
|
| 347 |
+
"""For compatibility with ``setup.py``, ``data_files`` should be a list
|
| 348 |
+
of pairs instead of a dict.
|
| 349 |
+
|
| 350 |
+
This function also expands glob patterns.
|
| 351 |
+
"""
|
| 352 |
+
if isinstance(data_files, list):
|
| 353 |
+
return data_files
|
| 354 |
+
|
| 355 |
+
return [
|
| 356 |
+
(dest, glob_relative(patterns, root_dir))
|
| 357 |
+
for dest, patterns in data_files.items()
|
| 358 |
+
]
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def entry_points(
|
| 362 |
+
text: str, text_source: str = "entry-points"
|
| 363 |
+
) -> dict[str, dict[str, str]]:
|
| 364 |
+
"""Given the contents of entry-points file,
|
| 365 |
+
process it into a 2-level dictionary (``dict[str, dict[str, str]]``).
|
| 366 |
+
The first level keys are entry-point groups, the second level keys are
|
| 367 |
+
entry-point names, and the second level values are references to objects
|
| 368 |
+
(that correspond to the entry-point value).
|
| 369 |
+
"""
|
| 370 |
+
# Using undocumented behaviour, see python/typeshed#12700
|
| 371 |
+
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore[call-overload]
|
| 372 |
+
parser.optionxform = str # case sensitive
|
| 373 |
+
parser.read_string(text, text_source)
|
| 374 |
+
groups = {k: dict(v.items()) for k, v in parser.items()}
|
| 375 |
+
groups.pop(parser.default_section, None)
|
| 376 |
+
return groups
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
class EnsurePackagesDiscovered:
|
| 380 |
+
"""Some expand functions require all the packages to already be discovered before
|
| 381 |
+
they run, e.g. :func:`read_attr`, :func:`resolve_class`, :func:`cmdclass`.
|
| 382 |
+
|
| 383 |
+
Therefore in some cases we will need to run autodiscovery during the evaluation of
|
| 384 |
+
the configuration. However, it is better to postpone calling package discovery as
|
| 385 |
+
much as possible, because some parameters can influence it (e.g. ``package_dir``),
|
| 386 |
+
and those might not have been processed yet.
|
| 387 |
+
"""
|
| 388 |
+
|
| 389 |
+
def __init__(self, distribution: Distribution) -> None:
|
| 390 |
+
self._dist = distribution
|
| 391 |
+
self._called = False
|
| 392 |
+
|
| 393 |
+
def __call__(self) -> None:
|
| 394 |
+
"""Trigger the automatic package discovery, if it is still necessary."""
|
| 395 |
+
if not self._called:
|
| 396 |
+
self._called = True
|
| 397 |
+
self._dist.set_defaults(name=False) # Skip name, we can still be parsing
|
| 398 |
+
|
| 399 |
+
def __enter__(self) -> Self:
|
| 400 |
+
return self
|
| 401 |
+
|
| 402 |
+
def __exit__(
|
| 403 |
+
self,
|
| 404 |
+
exc_type: type[BaseException] | None,
|
| 405 |
+
exc_value: BaseException | None,
|
| 406 |
+
traceback: TracebackType | None,
|
| 407 |
+
) -> None:
|
| 408 |
+
if self._called:
|
| 409 |
+
self._dist.set_defaults.analyse_name() # Now we can set a default name
|
| 410 |
+
|
| 411 |
+
def _get_package_dir(self) -> Mapping[str, str]:
|
| 412 |
+
self()
|
| 413 |
+
pkg_dir = self._dist.package_dir
|
| 414 |
+
return {} if pkg_dir is None else pkg_dir
|
| 415 |
+
|
| 416 |
+
@property
|
| 417 |
+
def package_dir(self) -> Mapping[str, str]:
|
| 418 |
+
"""Proxy to ``package_dir`` that may trigger auto-discovery when used."""
|
| 419 |
+
return LazyMappingProxy(self._get_package_dir)
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
class LazyMappingProxy(Mapping[_K, _V_co]):
|
| 423 |
+
"""Mapping proxy that delays resolving the target object, until really needed.
|
| 424 |
+
|
| 425 |
+
>>> def obtain_mapping():
|
| 426 |
+
... print("Running expensive function!")
|
| 427 |
+
... return {"key": "value", "other key": "other value"}
|
| 428 |
+
>>> mapping = LazyMappingProxy(obtain_mapping)
|
| 429 |
+
>>> mapping["key"]
|
| 430 |
+
Running expensive function!
|
| 431 |
+
'value'
|
| 432 |
+
>>> mapping["other key"]
|
| 433 |
+
'other value'
|
| 434 |
+
"""
|
| 435 |
+
|
| 436 |
+
def __init__(self, obtain_mapping_value: Callable[[], Mapping[_K, _V_co]]) -> None:
|
| 437 |
+
self._obtain = obtain_mapping_value
|
| 438 |
+
self._value: Mapping[_K, _V_co] | None = None
|
| 439 |
+
|
| 440 |
+
def _target(self) -> Mapping[_K, _V_co]:
|
| 441 |
+
if self._value is None:
|
| 442 |
+
self._value = self._obtain()
|
| 443 |
+
return self._value
|
| 444 |
+
|
| 445 |
+
def __getitem__(self, key: _K) -> _V_co:
|
| 446 |
+
return self._target()[key]
|
| 447 |
+
|
| 448 |
+
def __len__(self) -> int:
|
| 449 |
+
return len(self._target())
|
| 450 |
+
|
| 451 |
+
def __iter__(self) -> Iterator[_K]:
|
| 452 |
+
return iter(self._target())
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/pyprojecttoml.py
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Load setuptools configuration from ``pyproject.toml`` files.
|
| 3 |
+
|
| 4 |
+
**PRIVATE MODULE**: API reserved for setuptools internal usage only.
|
| 5 |
+
|
| 6 |
+
To read project metadata, consider using
|
| 7 |
+
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
|
| 8 |
+
For simple scenarios, you can also try parsing the file directly
|
| 9 |
+
with the help of ``tomllib`` or ``tomli``.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import annotations
|
| 13 |
+
|
| 14 |
+
import logging
|
| 15 |
+
import os
|
| 16 |
+
from collections.abc import Callable, Mapping
|
| 17 |
+
from contextlib import contextmanager
|
| 18 |
+
from functools import partial
|
| 19 |
+
from types import TracebackType
|
| 20 |
+
from typing import TYPE_CHECKING, Any
|
| 21 |
+
|
| 22 |
+
from .._path import StrPath
|
| 23 |
+
from ..errors import FileError, InvalidConfigError
|
| 24 |
+
from ..warnings import SetuptoolsWarning
|
| 25 |
+
from . import expand as _expand
|
| 26 |
+
from ._apply_pyprojecttoml import _PREVIOUSLY_DEFINED, _MissingDynamic, apply as _apply
|
| 27 |
+
|
| 28 |
+
if TYPE_CHECKING:
|
| 29 |
+
from typing_extensions import Self
|
| 30 |
+
|
| 31 |
+
from setuptools.dist import Distribution
|
| 32 |
+
|
| 33 |
+
_logger = logging.getLogger(__name__)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def load_file(filepath: StrPath) -> dict:
|
| 37 |
+
from ..compat.py310 import tomllib
|
| 38 |
+
|
| 39 |
+
with open(filepath, "rb") as file:
|
| 40 |
+
return tomllib.load(file)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def validate(config: dict, filepath: StrPath) -> bool:
|
| 44 |
+
from . import _validate_pyproject as validator
|
| 45 |
+
|
| 46 |
+
trove_classifier = validator.FORMAT_FUNCTIONS.get("trove-classifier")
|
| 47 |
+
if hasattr(trove_classifier, "_disable_download"):
|
| 48 |
+
# Improve reproducibility by default. See abravalheri/validate-pyproject#31
|
| 49 |
+
trove_classifier._disable_download() # type: ignore[union-attr]
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
return validator.validate(config)
|
| 53 |
+
except validator.ValidationError as ex:
|
| 54 |
+
summary = f"configuration error: {ex.summary}"
|
| 55 |
+
if ex.name.strip("`") != "project":
|
| 56 |
+
# Probably it is just a field missing/misnamed, not worthy the verbosity...
|
| 57 |
+
_logger.debug(summary)
|
| 58 |
+
_logger.debug(ex.details)
|
| 59 |
+
|
| 60 |
+
error = f"invalid pyproject.toml config: {ex.name}."
|
| 61 |
+
raise ValueError(f"{error}\n{summary}") from None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def apply_configuration(
|
| 65 |
+
dist: Distribution,
|
| 66 |
+
filepath: StrPath,
|
| 67 |
+
ignore_option_errors: bool = False,
|
| 68 |
+
) -> Distribution:
|
| 69 |
+
"""Apply the configuration from a ``pyproject.toml`` file into an existing
|
| 70 |
+
distribution object.
|
| 71 |
+
"""
|
| 72 |
+
config = read_configuration(filepath, True, ignore_option_errors, dist)
|
| 73 |
+
return _apply(dist, config, filepath)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def read_configuration(
|
| 77 |
+
filepath: StrPath,
|
| 78 |
+
expand: bool = True,
|
| 79 |
+
ignore_option_errors: bool = False,
|
| 80 |
+
dist: Distribution | None = None,
|
| 81 |
+
) -> dict[str, Any]:
|
| 82 |
+
"""Read given configuration file and returns options from it as a dict.
|
| 83 |
+
|
| 84 |
+
:param str|unicode filepath: Path to configuration file in the ``pyproject.toml``
|
| 85 |
+
format.
|
| 86 |
+
|
| 87 |
+
:param bool expand: Whether to expand directives and other computed values
|
| 88 |
+
(i.e. post-process the given configuration)
|
| 89 |
+
|
| 90 |
+
:param bool ignore_option_errors: Whether to silently ignore
|
| 91 |
+
options, values of which could not be resolved (e.g. due to exceptions
|
| 92 |
+
in directives such as file:, attr:, etc.).
|
| 93 |
+
If False exceptions are propagated as expected.
|
| 94 |
+
|
| 95 |
+
:param Distribution|None: Distribution object to which the configuration refers.
|
| 96 |
+
If not given a dummy object will be created and discarded after the
|
| 97 |
+
configuration is read. This is used for auto-discovery of packages and in the
|
| 98 |
+
case a dynamic configuration (e.g. ``attr`` or ``cmdclass``) is expanded.
|
| 99 |
+
When ``expand=False`` this object is simply ignored.
|
| 100 |
+
|
| 101 |
+
:rtype: dict
|
| 102 |
+
"""
|
| 103 |
+
filepath = os.path.abspath(filepath)
|
| 104 |
+
|
| 105 |
+
if not os.path.isfile(filepath):
|
| 106 |
+
raise FileError(f"Configuration file {filepath!r} does not exist.")
|
| 107 |
+
|
| 108 |
+
asdict = load_file(filepath) or {}
|
| 109 |
+
project_table = asdict.get("project", {})
|
| 110 |
+
tool_table = asdict.get("tool", {})
|
| 111 |
+
setuptools_table = tool_table.get("setuptools", {})
|
| 112 |
+
if not asdict or not (project_table or setuptools_table):
|
| 113 |
+
return {} # User is not using pyproject to configure setuptools
|
| 114 |
+
|
| 115 |
+
if "setuptools" in asdict.get("tools", {}):
|
| 116 |
+
# let the user know they probably have a typo in their metadata
|
| 117 |
+
_ToolsTypoInMetadata.emit()
|
| 118 |
+
|
| 119 |
+
if "distutils" in tool_table:
|
| 120 |
+
_ExperimentalConfiguration.emit(subject="[tool.distutils]")
|
| 121 |
+
|
| 122 |
+
# There is an overall sense in the community that making include_package_data=True
|
| 123 |
+
# the default would be an improvement.
|
| 124 |
+
# `ini2toml` backfills include_package_data=False when nothing is explicitly given,
|
| 125 |
+
# therefore setting a default here is backwards compatible.
|
| 126 |
+
if dist and dist.include_package_data is not None:
|
| 127 |
+
setuptools_table.setdefault("include-package-data", dist.include_package_data)
|
| 128 |
+
else:
|
| 129 |
+
setuptools_table.setdefault("include-package-data", True)
|
| 130 |
+
# Persist changes:
|
| 131 |
+
asdict["tool"] = tool_table
|
| 132 |
+
tool_table["setuptools"] = setuptools_table
|
| 133 |
+
|
| 134 |
+
if "ext-modules" in setuptools_table:
|
| 135 |
+
_ExperimentalConfiguration.emit(subject="[tool.setuptools.ext-modules]")
|
| 136 |
+
|
| 137 |
+
fields = ("import-names", "import-namespaces")
|
| 138 |
+
places = (project_table, project_table.get("dynamic", []))
|
| 139 |
+
if any(field in place for field in fields for place in places):
|
| 140 |
+
raise NotImplementedError(
|
| 141 |
+
"Setuptools does not support `import-names` and `import-namespaces`"
|
| 142 |
+
" in `pyproject.toml` yet. If your are interested in this feature, "
|
| 143 |
+
" please consider submitting a contribution via pull requests."
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
with _ignore_errors(ignore_option_errors):
|
| 147 |
+
# Don't complain about unrelated errors (e.g. tools not using the "tool" table)
|
| 148 |
+
subset = {"project": project_table, "tool": {"setuptools": setuptools_table}}
|
| 149 |
+
validate(subset, filepath)
|
| 150 |
+
|
| 151 |
+
if expand:
|
| 152 |
+
root_dir = os.path.dirname(filepath)
|
| 153 |
+
return expand_configuration(asdict, root_dir, ignore_option_errors, dist)
|
| 154 |
+
|
| 155 |
+
return asdict
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def expand_configuration(
|
| 159 |
+
config: dict,
|
| 160 |
+
root_dir: StrPath | None = None,
|
| 161 |
+
ignore_option_errors: bool = False,
|
| 162 |
+
dist: Distribution | None = None,
|
| 163 |
+
) -> dict:
|
| 164 |
+
"""Given a configuration with unresolved fields (e.g. dynamic, cmdclass, ...)
|
| 165 |
+
find their final values.
|
| 166 |
+
|
| 167 |
+
:param dict config: Dict containing the configuration for the distribution
|
| 168 |
+
:param str root_dir: Top-level directory for the distribution/project
|
| 169 |
+
(the same directory where ``pyproject.toml`` is place)
|
| 170 |
+
:param bool ignore_option_errors: see :func:`read_configuration`
|
| 171 |
+
:param Distribution|None: Distribution object to which the configuration refers.
|
| 172 |
+
If not given a dummy object will be created and discarded after the
|
| 173 |
+
configuration is read. Used in the case a dynamic configuration
|
| 174 |
+
(e.g. ``attr`` or ``cmdclass``).
|
| 175 |
+
|
| 176 |
+
:rtype: dict
|
| 177 |
+
"""
|
| 178 |
+
return _ConfigExpander(config, root_dir, ignore_option_errors, dist).expand()
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class _ConfigExpander:
|
| 182 |
+
def __init__(
|
| 183 |
+
self,
|
| 184 |
+
config: dict,
|
| 185 |
+
root_dir: StrPath | None = None,
|
| 186 |
+
ignore_option_errors: bool = False,
|
| 187 |
+
dist: Distribution | None = None,
|
| 188 |
+
) -> None:
|
| 189 |
+
self.config = config
|
| 190 |
+
self.root_dir = root_dir or os.getcwd()
|
| 191 |
+
self.project_cfg = config.get("project", {})
|
| 192 |
+
self.dynamic = self.project_cfg.get("dynamic", [])
|
| 193 |
+
self.setuptools_cfg = config.get("tool", {}).get("setuptools", {})
|
| 194 |
+
self.dynamic_cfg = self.setuptools_cfg.get("dynamic", {})
|
| 195 |
+
self.ignore_option_errors = ignore_option_errors
|
| 196 |
+
self._dist = dist
|
| 197 |
+
self._referenced_files = set[str]()
|
| 198 |
+
|
| 199 |
+
def _ensure_dist(self) -> Distribution:
|
| 200 |
+
from setuptools.dist import Distribution
|
| 201 |
+
|
| 202 |
+
attrs = {"src_root": self.root_dir, "name": self.project_cfg.get("name", None)}
|
| 203 |
+
return self._dist or Distribution(attrs)
|
| 204 |
+
|
| 205 |
+
def _process_field(self, container: dict, field: str, fn: Callable):
|
| 206 |
+
if field in container:
|
| 207 |
+
with _ignore_errors(self.ignore_option_errors):
|
| 208 |
+
container[field] = fn(container[field])
|
| 209 |
+
|
| 210 |
+
def _canonic_package_data(self, field="package-data"):
|
| 211 |
+
package_data = self.setuptools_cfg.get(field, {})
|
| 212 |
+
return _expand.canonic_package_data(package_data)
|
| 213 |
+
|
| 214 |
+
def expand(self):
|
| 215 |
+
self._expand_packages()
|
| 216 |
+
self._canonic_package_data()
|
| 217 |
+
self._canonic_package_data("exclude-package-data")
|
| 218 |
+
|
| 219 |
+
# A distribution object is required for discovering the correct package_dir
|
| 220 |
+
dist = self._ensure_dist()
|
| 221 |
+
ctx = _EnsurePackagesDiscovered(dist, self.project_cfg, self.setuptools_cfg)
|
| 222 |
+
with ctx as ensure_discovered:
|
| 223 |
+
package_dir = ensure_discovered.package_dir
|
| 224 |
+
self._expand_data_files()
|
| 225 |
+
self._expand_cmdclass(package_dir)
|
| 226 |
+
self._expand_all_dynamic(dist, package_dir)
|
| 227 |
+
|
| 228 |
+
dist._referenced_files.update(self._referenced_files)
|
| 229 |
+
return self.config
|
| 230 |
+
|
| 231 |
+
def _expand_packages(self):
|
| 232 |
+
packages = self.setuptools_cfg.get("packages")
|
| 233 |
+
if packages is None or isinstance(packages, (list, tuple)):
|
| 234 |
+
return
|
| 235 |
+
|
| 236 |
+
find = packages.get("find")
|
| 237 |
+
if isinstance(find, dict):
|
| 238 |
+
find["root_dir"] = self.root_dir
|
| 239 |
+
find["fill_package_dir"] = self.setuptools_cfg.setdefault("package-dir", {})
|
| 240 |
+
with _ignore_errors(self.ignore_option_errors):
|
| 241 |
+
self.setuptools_cfg["packages"] = _expand.find_packages(**find)
|
| 242 |
+
|
| 243 |
+
def _expand_data_files(self):
|
| 244 |
+
data_files = partial(_expand.canonic_data_files, root_dir=self.root_dir)
|
| 245 |
+
self._process_field(self.setuptools_cfg, "data-files", data_files)
|
| 246 |
+
|
| 247 |
+
def _expand_cmdclass(self, package_dir: Mapping[str, str]):
|
| 248 |
+
root_dir = self.root_dir
|
| 249 |
+
cmdclass = partial(_expand.cmdclass, package_dir=package_dir, root_dir=root_dir)
|
| 250 |
+
self._process_field(self.setuptools_cfg, "cmdclass", cmdclass)
|
| 251 |
+
|
| 252 |
+
def _expand_all_dynamic(self, dist: Distribution, package_dir: Mapping[str, str]):
|
| 253 |
+
special = ( # need special handling
|
| 254 |
+
"version",
|
| 255 |
+
"readme",
|
| 256 |
+
"entry-points",
|
| 257 |
+
"scripts",
|
| 258 |
+
"gui-scripts",
|
| 259 |
+
"classifiers",
|
| 260 |
+
"dependencies",
|
| 261 |
+
"optional-dependencies",
|
| 262 |
+
)
|
| 263 |
+
# `_obtain` functions are assumed to raise appropriate exceptions/warnings.
|
| 264 |
+
obtained_dynamic = {
|
| 265 |
+
field: self._obtain(dist, field, package_dir)
|
| 266 |
+
for field in self.dynamic
|
| 267 |
+
if field not in special
|
| 268 |
+
}
|
| 269 |
+
obtained_dynamic.update(
|
| 270 |
+
self._obtain_entry_points(dist, package_dir) or {},
|
| 271 |
+
version=self._obtain_version(dist, package_dir),
|
| 272 |
+
readme=self._obtain_readme(dist),
|
| 273 |
+
classifiers=self._obtain_classifiers(dist),
|
| 274 |
+
dependencies=self._obtain_dependencies(dist),
|
| 275 |
+
optional_dependencies=self._obtain_optional_dependencies(dist),
|
| 276 |
+
)
|
| 277 |
+
# `None` indicates there is nothing in `tool.setuptools.dynamic` but the value
|
| 278 |
+
# might have already been set by setup.py/extensions, so avoid overwriting.
|
| 279 |
+
updates = {k: v for k, v in obtained_dynamic.items() if v is not None}
|
| 280 |
+
self.project_cfg.update(updates)
|
| 281 |
+
|
| 282 |
+
def _ensure_previously_set(self, dist: Distribution, field: str):
|
| 283 |
+
previous = _PREVIOUSLY_DEFINED[field](dist)
|
| 284 |
+
if previous is None and not self.ignore_option_errors:
|
| 285 |
+
msg = (
|
| 286 |
+
f"No configuration found for dynamic {field!r}.\n"
|
| 287 |
+
"Some dynamic fields need to be specified via `tool.setuptools.dynamic`"
|
| 288 |
+
"\nothers must be specified via the equivalent attribute in `setup.py`."
|
| 289 |
+
)
|
| 290 |
+
raise InvalidConfigError(msg)
|
| 291 |
+
|
| 292 |
+
def _expand_directive(
|
| 293 |
+
self, specifier: str, directive, package_dir: Mapping[str, str]
|
| 294 |
+
):
|
| 295 |
+
from more_itertools import always_iterable
|
| 296 |
+
|
| 297 |
+
with _ignore_errors(self.ignore_option_errors):
|
| 298 |
+
root_dir = self.root_dir
|
| 299 |
+
if "file" in directive:
|
| 300 |
+
self._referenced_files.update(always_iterable(directive["file"]))
|
| 301 |
+
return _expand.read_files(directive["file"], root_dir)
|
| 302 |
+
if "attr" in directive:
|
| 303 |
+
return _expand.read_attr(directive["attr"], package_dir, root_dir)
|
| 304 |
+
raise ValueError(f"invalid `{specifier}`: {directive!r}")
|
| 305 |
+
return None
|
| 306 |
+
|
| 307 |
+
def _obtain(self, dist: Distribution, field: str, package_dir: Mapping[str, str]):
|
| 308 |
+
if field in self.dynamic_cfg:
|
| 309 |
+
return self._expand_directive(
|
| 310 |
+
f"tool.setuptools.dynamic.{field}",
|
| 311 |
+
self.dynamic_cfg[field],
|
| 312 |
+
package_dir,
|
| 313 |
+
)
|
| 314 |
+
self._ensure_previously_set(dist, field)
|
| 315 |
+
return None
|
| 316 |
+
|
| 317 |
+
def _obtain_version(self, dist: Distribution, package_dir: Mapping[str, str]):
|
| 318 |
+
# Since plugins can set version, let's silently skip if it cannot be obtained
|
| 319 |
+
if "version" in self.dynamic and "version" in self.dynamic_cfg:
|
| 320 |
+
return _expand.version(
|
| 321 |
+
# We already do an early check for the presence of "version"
|
| 322 |
+
self._obtain(dist, "version", package_dir) # pyright: ignore[reportArgumentType]
|
| 323 |
+
)
|
| 324 |
+
return None
|
| 325 |
+
|
| 326 |
+
def _obtain_readme(self, dist: Distribution) -> dict[str, str] | None:
|
| 327 |
+
if "readme" not in self.dynamic:
|
| 328 |
+
return None
|
| 329 |
+
|
| 330 |
+
dynamic_cfg = self.dynamic_cfg
|
| 331 |
+
if "readme" in dynamic_cfg:
|
| 332 |
+
return {
|
| 333 |
+
# We already do an early check for the presence of "readme"
|
| 334 |
+
"text": self._obtain(dist, "readme", {}),
|
| 335 |
+
"content-type": dynamic_cfg["readme"].get("content-type", "text/x-rst"),
|
| 336 |
+
} # pyright: ignore[reportReturnType]
|
| 337 |
+
|
| 338 |
+
self._ensure_previously_set(dist, "readme")
|
| 339 |
+
return None
|
| 340 |
+
|
| 341 |
+
def _obtain_entry_points(
|
| 342 |
+
self, dist: Distribution, package_dir: Mapping[str, str]
|
| 343 |
+
) -> dict[str, dict[str, Any]] | None:
|
| 344 |
+
fields = ("entry-points", "scripts", "gui-scripts")
|
| 345 |
+
if not any(field in self.dynamic for field in fields):
|
| 346 |
+
return None
|
| 347 |
+
|
| 348 |
+
text = self._obtain(dist, "entry-points", package_dir)
|
| 349 |
+
if text is None:
|
| 350 |
+
return None
|
| 351 |
+
|
| 352 |
+
groups = _expand.entry_points(text)
|
| 353 |
+
# Any is str | dict[str, str], but causes variance issues
|
| 354 |
+
expanded: dict[str, dict[str, Any]] = {"entry-points": groups}
|
| 355 |
+
|
| 356 |
+
def _set_scripts(field: str, group: str):
|
| 357 |
+
if group in groups:
|
| 358 |
+
value = groups.pop(group)
|
| 359 |
+
if field not in self.dynamic:
|
| 360 |
+
raise InvalidConfigError(_MissingDynamic.details(field, value))
|
| 361 |
+
expanded[field] = value
|
| 362 |
+
|
| 363 |
+
_set_scripts("scripts", "console_scripts")
|
| 364 |
+
_set_scripts("gui-scripts", "gui_scripts")
|
| 365 |
+
|
| 366 |
+
return expanded
|
| 367 |
+
|
| 368 |
+
def _obtain_classifiers(self, dist: Distribution):
|
| 369 |
+
if "classifiers" in self.dynamic:
|
| 370 |
+
value = self._obtain(dist, "classifiers", {})
|
| 371 |
+
if value:
|
| 372 |
+
return value.splitlines()
|
| 373 |
+
return None
|
| 374 |
+
|
| 375 |
+
def _obtain_dependencies(self, dist: Distribution):
|
| 376 |
+
if "dependencies" in self.dynamic:
|
| 377 |
+
value = self._obtain(dist, "dependencies", {})
|
| 378 |
+
if value:
|
| 379 |
+
return _parse_requirements_list(value)
|
| 380 |
+
return None
|
| 381 |
+
|
| 382 |
+
def _obtain_optional_dependencies(self, dist: Distribution):
|
| 383 |
+
if "optional-dependencies" not in self.dynamic:
|
| 384 |
+
return None
|
| 385 |
+
if "optional-dependencies" in self.dynamic_cfg:
|
| 386 |
+
optional_dependencies_map = self.dynamic_cfg["optional-dependencies"]
|
| 387 |
+
assert isinstance(optional_dependencies_map, dict)
|
| 388 |
+
return {
|
| 389 |
+
group: _parse_requirements_list(
|
| 390 |
+
self._expand_directive(
|
| 391 |
+
f"tool.setuptools.dynamic.optional-dependencies.{group}",
|
| 392 |
+
directive,
|
| 393 |
+
{},
|
| 394 |
+
)
|
| 395 |
+
)
|
| 396 |
+
for group, directive in optional_dependencies_map.items()
|
| 397 |
+
}
|
| 398 |
+
self._ensure_previously_set(dist, "optional-dependencies")
|
| 399 |
+
return None
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
def _parse_requirements_list(value):
|
| 403 |
+
return [
|
| 404 |
+
line
|
| 405 |
+
for line in value.splitlines()
|
| 406 |
+
if line.strip() and not line.strip().startswith("#")
|
| 407 |
+
]
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
@contextmanager
|
| 411 |
+
def _ignore_errors(ignore_option_errors: bool):
|
| 412 |
+
if not ignore_option_errors:
|
| 413 |
+
yield
|
| 414 |
+
return
|
| 415 |
+
|
| 416 |
+
try:
|
| 417 |
+
yield
|
| 418 |
+
except Exception as ex:
|
| 419 |
+
_logger.debug(f"ignored error: {ex.__class__.__name__} - {ex}")
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
class _EnsurePackagesDiscovered(_expand.EnsurePackagesDiscovered):
|
| 423 |
+
def __init__(
|
| 424 |
+
self, distribution: Distribution, project_cfg: dict, setuptools_cfg: dict
|
| 425 |
+
) -> None:
|
| 426 |
+
super().__init__(distribution)
|
| 427 |
+
self._project_cfg = project_cfg
|
| 428 |
+
self._setuptools_cfg = setuptools_cfg
|
| 429 |
+
|
| 430 |
+
def __enter__(self) -> Self:
|
| 431 |
+
"""When entering the context, the values of ``packages``, ``py_modules`` and
|
| 432 |
+
``package_dir`` that are missing in ``dist`` are copied from ``setuptools_cfg``.
|
| 433 |
+
"""
|
| 434 |
+
dist, cfg = self._dist, self._setuptools_cfg
|
| 435 |
+
package_dir: dict[str, str] = cfg.setdefault("package-dir", {})
|
| 436 |
+
package_dir.update(dist.package_dir or {})
|
| 437 |
+
dist.package_dir = package_dir # needs to be the same object
|
| 438 |
+
|
| 439 |
+
dist.set_defaults._ignore_ext_modules() # pyproject.toml-specific behaviour
|
| 440 |
+
|
| 441 |
+
# Set `name`, `py_modules` and `packages` in dist to short-circuit
|
| 442 |
+
# auto-discovery, but avoid overwriting empty lists purposefully set by users.
|
| 443 |
+
if dist.metadata.name is None:
|
| 444 |
+
dist.metadata.name = self._project_cfg.get("name")
|
| 445 |
+
if dist.py_modules is None:
|
| 446 |
+
dist.py_modules = cfg.get("py-modules")
|
| 447 |
+
if dist.packages is None:
|
| 448 |
+
dist.packages = cfg.get("packages")
|
| 449 |
+
|
| 450 |
+
return super().__enter__()
|
| 451 |
+
|
| 452 |
+
def __exit__(
|
| 453 |
+
self,
|
| 454 |
+
exc_type: type[BaseException] | None,
|
| 455 |
+
exc_value: BaseException | None,
|
| 456 |
+
traceback: TracebackType | None,
|
| 457 |
+
) -> None:
|
| 458 |
+
"""When exiting the context, if values of ``packages``, ``py_modules`` and
|
| 459 |
+
``package_dir`` are missing in ``setuptools_cfg``, copy from ``dist``.
|
| 460 |
+
"""
|
| 461 |
+
# If anything was discovered set them back, so they count in the final config.
|
| 462 |
+
self._setuptools_cfg.setdefault("packages", self._dist.packages)
|
| 463 |
+
self._setuptools_cfg.setdefault("py-modules", self._dist.py_modules)
|
| 464 |
+
return super().__exit__(exc_type, exc_value, traceback)
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
class _ExperimentalConfiguration(SetuptoolsWarning):
|
| 468 |
+
_SUMMARY = (
|
| 469 |
+
"`{subject}` in `pyproject.toml` is still *experimental* "
|
| 470 |
+
"and likely to change in future releases."
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
class _ToolsTypoInMetadata(SetuptoolsWarning):
|
| 475 |
+
_SUMMARY = (
|
| 476 |
+
"Ignoring [tools.setuptools] in pyproject.toml, did you mean [tool.setuptools]?"
|
| 477 |
+
)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/setupcfg.py
ADDED
|
@@ -0,0 +1,782 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Load setuptools configuration from ``setup.cfg`` files.
|
| 3 |
+
|
| 4 |
+
**API will be made private in the future**
|
| 5 |
+
|
| 6 |
+
To read project metadata, consider using
|
| 7 |
+
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
|
| 8 |
+
For simple scenarios, you can also try parsing the file directly
|
| 9 |
+
with the help of ``configparser``.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import annotations
|
| 13 |
+
|
| 14 |
+
import contextlib
|
| 15 |
+
import functools
|
| 16 |
+
import os
|
| 17 |
+
from abc import abstractmethod
|
| 18 |
+
from collections import defaultdict
|
| 19 |
+
from collections.abc import Callable, Iterable, Iterator
|
| 20 |
+
from functools import partial, wraps
|
| 21 |
+
from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeVar, cast
|
| 22 |
+
|
| 23 |
+
from packaging.markers import default_environment as marker_env
|
| 24 |
+
from packaging.requirements import InvalidRequirement, Requirement
|
| 25 |
+
from packaging.version import InvalidVersion, Version
|
| 26 |
+
|
| 27 |
+
from .. import _static
|
| 28 |
+
from .._path import StrPath
|
| 29 |
+
from ..errors import FileError, OptionError
|
| 30 |
+
from ..warnings import SetuptoolsDeprecationWarning
|
| 31 |
+
from . import expand
|
| 32 |
+
|
| 33 |
+
if TYPE_CHECKING:
|
| 34 |
+
from typing import TypeAlias
|
| 35 |
+
|
| 36 |
+
from setuptools.dist import Distribution
|
| 37 |
+
|
| 38 |
+
from distutils.dist import DistributionMetadata
|
| 39 |
+
|
| 40 |
+
SingleCommandOptions: TypeAlias = dict[str, tuple[str, Any]]
|
| 41 |
+
"""Dict that associate the name of the options of a particular command to a
|
| 42 |
+
tuple. The first element of the tuple indicates the origin of the option value
|
| 43 |
+
(e.g. the name of the configuration file where it was read from),
|
| 44 |
+
while the second element of the tuple is the option value itself
|
| 45 |
+
"""
|
| 46 |
+
AllCommandOptions: TypeAlias = dict[str, SingleCommandOptions]
|
| 47 |
+
"""cmd name => its options"""
|
| 48 |
+
Target = TypeVar("Target", "Distribution", "DistributionMetadata")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def read_configuration(
|
| 52 |
+
filepath: StrPath, find_others: bool = False, ignore_option_errors: bool = False
|
| 53 |
+
) -> dict:
|
| 54 |
+
"""Read given configuration file and returns options from it as a dict.
|
| 55 |
+
|
| 56 |
+
:param str|unicode filepath: Path to configuration file
|
| 57 |
+
to get options from.
|
| 58 |
+
|
| 59 |
+
:param bool find_others: Whether to search for other configuration files
|
| 60 |
+
which could be on in various places.
|
| 61 |
+
|
| 62 |
+
:param bool ignore_option_errors: Whether to silently ignore
|
| 63 |
+
options, values of which could not be resolved (e.g. due to exceptions
|
| 64 |
+
in directives such as file:, attr:, etc.).
|
| 65 |
+
If False exceptions are propagated as expected.
|
| 66 |
+
|
| 67 |
+
:rtype: dict
|
| 68 |
+
"""
|
| 69 |
+
from setuptools.dist import Distribution
|
| 70 |
+
|
| 71 |
+
dist = Distribution()
|
| 72 |
+
filenames = dist.find_config_files() if find_others else []
|
| 73 |
+
handlers = _apply(dist, filepath, filenames, ignore_option_errors)
|
| 74 |
+
return configuration_to_dict(handlers)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def apply_configuration(dist: Distribution, filepath: StrPath) -> Distribution:
|
| 78 |
+
"""Apply the configuration from a ``setup.cfg`` file into an existing
|
| 79 |
+
distribution object.
|
| 80 |
+
"""
|
| 81 |
+
_apply(dist, filepath)
|
| 82 |
+
dist._finalize_requires()
|
| 83 |
+
return dist
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _apply(
|
| 87 |
+
dist: Distribution,
|
| 88 |
+
filepath: StrPath,
|
| 89 |
+
other_files: Iterable[StrPath] = (),
|
| 90 |
+
ignore_option_errors: bool = False,
|
| 91 |
+
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]:
|
| 92 |
+
"""Read configuration from ``filepath`` and applies to the ``dist`` object."""
|
| 93 |
+
from setuptools.dist import _Distribution
|
| 94 |
+
|
| 95 |
+
filepath = os.path.abspath(filepath)
|
| 96 |
+
|
| 97 |
+
if not os.path.isfile(filepath):
|
| 98 |
+
raise FileError(f'Configuration file {filepath} does not exist.')
|
| 99 |
+
|
| 100 |
+
current_directory = os.getcwd()
|
| 101 |
+
os.chdir(os.path.dirname(filepath))
|
| 102 |
+
filenames = [*other_files, filepath]
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
# TODO: Temporary cast until mypy 1.12 is released with upstream fixes from typeshed
|
| 106 |
+
_Distribution.parse_config_files(dist, filenames=cast(list[str], filenames))
|
| 107 |
+
handlers = parse_configuration(
|
| 108 |
+
dist, dist.command_options, ignore_option_errors=ignore_option_errors
|
| 109 |
+
)
|
| 110 |
+
dist._finalize_license_files()
|
| 111 |
+
finally:
|
| 112 |
+
os.chdir(current_directory)
|
| 113 |
+
|
| 114 |
+
return handlers
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def _get_option(target_obj: Distribution | DistributionMetadata, key: str):
|
| 118 |
+
"""
|
| 119 |
+
Given a target object and option key, get that option from
|
| 120 |
+
the target object, either through a get_{key} method or
|
| 121 |
+
from an attribute directly.
|
| 122 |
+
"""
|
| 123 |
+
getter_name = f'get_{key}'
|
| 124 |
+
by_attribute = functools.partial(getattr, target_obj, key)
|
| 125 |
+
getter = getattr(target_obj, getter_name, by_attribute)
|
| 126 |
+
return getter()
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def configuration_to_dict(
|
| 130 |
+
handlers: Iterable[
|
| 131 |
+
ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]
|
| 132 |
+
],
|
| 133 |
+
) -> dict:
|
| 134 |
+
"""Returns configuration data gathered by given handlers as a dict.
|
| 135 |
+
|
| 136 |
+
:param Iterable[ConfigHandler] handlers: Handlers list,
|
| 137 |
+
usually from parse_configuration()
|
| 138 |
+
|
| 139 |
+
:rtype: dict
|
| 140 |
+
"""
|
| 141 |
+
config_dict: dict = defaultdict(dict)
|
| 142 |
+
|
| 143 |
+
for handler in handlers:
|
| 144 |
+
for option in handler.set_options:
|
| 145 |
+
value = _get_option(handler.target_obj, option)
|
| 146 |
+
config_dict[handler.section_prefix][option] = value
|
| 147 |
+
|
| 148 |
+
return config_dict
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def parse_configuration(
|
| 152 |
+
distribution: Distribution,
|
| 153 |
+
command_options: AllCommandOptions,
|
| 154 |
+
ignore_option_errors: bool = False,
|
| 155 |
+
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]:
|
| 156 |
+
"""Performs additional parsing of configuration options
|
| 157 |
+
for a distribution.
|
| 158 |
+
|
| 159 |
+
Returns a list of used option handlers.
|
| 160 |
+
|
| 161 |
+
:param Distribution distribution:
|
| 162 |
+
:param dict command_options:
|
| 163 |
+
:param bool ignore_option_errors: Whether to silently ignore
|
| 164 |
+
options, values of which could not be resolved (e.g. due to exceptions
|
| 165 |
+
in directives such as file:, attr:, etc.).
|
| 166 |
+
If False exceptions are propagated as expected.
|
| 167 |
+
:rtype: list
|
| 168 |
+
"""
|
| 169 |
+
with expand.EnsurePackagesDiscovered(distribution) as ensure_discovered:
|
| 170 |
+
options = ConfigOptionsHandler(
|
| 171 |
+
distribution,
|
| 172 |
+
command_options,
|
| 173 |
+
ignore_option_errors,
|
| 174 |
+
ensure_discovered,
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
options.parse()
|
| 178 |
+
if not distribution.package_dir:
|
| 179 |
+
distribution.package_dir = options.package_dir # Filled by `find_packages`
|
| 180 |
+
|
| 181 |
+
meta = ConfigMetadataHandler(
|
| 182 |
+
distribution.metadata,
|
| 183 |
+
command_options,
|
| 184 |
+
ignore_option_errors,
|
| 185 |
+
ensure_discovered,
|
| 186 |
+
distribution.package_dir,
|
| 187 |
+
distribution.src_root,
|
| 188 |
+
)
|
| 189 |
+
meta.parse()
|
| 190 |
+
distribution._referenced_files.update(
|
| 191 |
+
options._referenced_files, meta._referenced_files
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
return meta, options
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def _warn_accidental_env_marker_misconfig(label: str, orig_value: str, parsed: list):
|
| 198 |
+
"""Because users sometimes misinterpret this configuration:
|
| 199 |
+
|
| 200 |
+
[options.extras_require]
|
| 201 |
+
foo = bar;python_version<"4"
|
| 202 |
+
|
| 203 |
+
It looks like one requirement with an environment marker
|
| 204 |
+
but because there is no newline, it's parsed as two requirements
|
| 205 |
+
with a semicolon as separator.
|
| 206 |
+
|
| 207 |
+
Therefore, if:
|
| 208 |
+
* input string does not contain a newline AND
|
| 209 |
+
* parsed result contains two requirements AND
|
| 210 |
+
* parsing of the two parts from the result ("<first>;<second>")
|
| 211 |
+
leads in a valid Requirement with a valid marker
|
| 212 |
+
a UserWarning is shown to inform the user about the possible problem.
|
| 213 |
+
"""
|
| 214 |
+
if "\n" in orig_value or len(parsed) != 2:
|
| 215 |
+
return
|
| 216 |
+
|
| 217 |
+
markers = marker_env().keys()
|
| 218 |
+
|
| 219 |
+
try:
|
| 220 |
+
req = Requirement(parsed[1])
|
| 221 |
+
if req.name in markers:
|
| 222 |
+
_AmbiguousMarker.emit(field=label, req=parsed[1])
|
| 223 |
+
except InvalidRequirement as ex:
|
| 224 |
+
if any(parsed[1].startswith(marker) for marker in markers):
|
| 225 |
+
msg = _AmbiguousMarker.message(field=label, req=parsed[1])
|
| 226 |
+
raise InvalidRequirement(msg) from ex
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
class ConfigHandler(Generic[Target]):
|
| 230 |
+
"""Handles metadata supplied in configuration files."""
|
| 231 |
+
|
| 232 |
+
section_prefix: str
|
| 233 |
+
"""Prefix for config sections handled by this handler.
|
| 234 |
+
Must be provided by class heirs.
|
| 235 |
+
|
| 236 |
+
"""
|
| 237 |
+
|
| 238 |
+
aliases: ClassVar[dict[str, str]] = {}
|
| 239 |
+
"""Options aliases.
|
| 240 |
+
For compatibility with various packages. E.g.: d2to1 and pbr.
|
| 241 |
+
Note: `-` in keys is replaced with `_` by config parser.
|
| 242 |
+
|
| 243 |
+
"""
|
| 244 |
+
|
| 245 |
+
def __init__(
|
| 246 |
+
self,
|
| 247 |
+
target_obj: Target,
|
| 248 |
+
options: AllCommandOptions,
|
| 249 |
+
ignore_option_errors,
|
| 250 |
+
ensure_discovered: expand.EnsurePackagesDiscovered,
|
| 251 |
+
) -> None:
|
| 252 |
+
self.ignore_option_errors = ignore_option_errors
|
| 253 |
+
self.target_obj: Target = target_obj
|
| 254 |
+
self.sections = dict(self._section_options(options))
|
| 255 |
+
self.set_options: list[str] = []
|
| 256 |
+
self.ensure_discovered = ensure_discovered
|
| 257 |
+
self._referenced_files = set[str]()
|
| 258 |
+
"""After parsing configurations, this property will enumerate
|
| 259 |
+
all files referenced by the "file:" directive. Private API for setuptools only.
|
| 260 |
+
"""
|
| 261 |
+
|
| 262 |
+
@classmethod
|
| 263 |
+
def _section_options(
|
| 264 |
+
cls, options: AllCommandOptions
|
| 265 |
+
) -> Iterator[tuple[str, SingleCommandOptions]]:
|
| 266 |
+
for full_name, value in options.items():
|
| 267 |
+
pre, _sep, name = full_name.partition(cls.section_prefix)
|
| 268 |
+
if pre:
|
| 269 |
+
continue
|
| 270 |
+
yield name.lstrip('.'), value
|
| 271 |
+
|
| 272 |
+
@property
|
| 273 |
+
@abstractmethod
|
| 274 |
+
def parsers(self) -> dict[str, Callable]:
|
| 275 |
+
"""Metadata item name to parser function mapping."""
|
| 276 |
+
raise NotImplementedError(
|
| 277 |
+
f'{self.__class__.__name__} must provide .parsers property'
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
def __setitem__(self, option_name, value) -> None:
|
| 281 |
+
target_obj = self.target_obj
|
| 282 |
+
|
| 283 |
+
# Translate alias into real name.
|
| 284 |
+
option_name = self.aliases.get(option_name, option_name)
|
| 285 |
+
|
| 286 |
+
try:
|
| 287 |
+
current_value = getattr(target_obj, option_name)
|
| 288 |
+
except AttributeError as e:
|
| 289 |
+
raise KeyError(option_name) from e
|
| 290 |
+
|
| 291 |
+
if current_value:
|
| 292 |
+
# Already inhabited. Skipping.
|
| 293 |
+
return
|
| 294 |
+
|
| 295 |
+
try:
|
| 296 |
+
parsed = self.parsers.get(option_name, lambda x: x)(value)
|
| 297 |
+
except (Exception,) * self.ignore_option_errors:
|
| 298 |
+
return
|
| 299 |
+
|
| 300 |
+
simple_setter = functools.partial(target_obj.__setattr__, option_name)
|
| 301 |
+
setter = getattr(target_obj, f"set_{option_name}", simple_setter)
|
| 302 |
+
setter(parsed)
|
| 303 |
+
|
| 304 |
+
self.set_options.append(option_name)
|
| 305 |
+
|
| 306 |
+
@classmethod
|
| 307 |
+
def _parse_list(cls, value, separator=','):
|
| 308 |
+
"""Represents value as a list.
|
| 309 |
+
|
| 310 |
+
Value is split either by separator (defaults to comma) or by lines.
|
| 311 |
+
|
| 312 |
+
:param value:
|
| 313 |
+
:param separator: List items separator character.
|
| 314 |
+
:rtype: list
|
| 315 |
+
"""
|
| 316 |
+
if isinstance(value, list): # _get_parser_compound case
|
| 317 |
+
return value
|
| 318 |
+
|
| 319 |
+
if '\n' in value:
|
| 320 |
+
value = value.splitlines()
|
| 321 |
+
else:
|
| 322 |
+
value = value.split(separator)
|
| 323 |
+
|
| 324 |
+
return [chunk.strip() for chunk in value if chunk.strip()]
|
| 325 |
+
|
| 326 |
+
@classmethod
|
| 327 |
+
def _parse_dict(cls, value):
|
| 328 |
+
"""Represents value as a dict.
|
| 329 |
+
|
| 330 |
+
:param value:
|
| 331 |
+
:rtype: dict
|
| 332 |
+
"""
|
| 333 |
+
separator = '='
|
| 334 |
+
result = {}
|
| 335 |
+
for line in cls._parse_list(value):
|
| 336 |
+
key, sep, val = line.partition(separator)
|
| 337 |
+
if sep != separator:
|
| 338 |
+
raise OptionError(f"Unable to parse option value to dict: {value}")
|
| 339 |
+
result[key.strip()] = val.strip()
|
| 340 |
+
|
| 341 |
+
return result
|
| 342 |
+
|
| 343 |
+
@classmethod
|
| 344 |
+
def _parse_bool(cls, value):
|
| 345 |
+
"""Represents value as boolean.
|
| 346 |
+
|
| 347 |
+
:param value:
|
| 348 |
+
:rtype: bool
|
| 349 |
+
"""
|
| 350 |
+
value = value.lower()
|
| 351 |
+
return value in ('1', 'true', 'yes')
|
| 352 |
+
|
| 353 |
+
@classmethod
|
| 354 |
+
def _exclude_files_parser(cls, key):
|
| 355 |
+
"""Returns a parser function to make sure field inputs
|
| 356 |
+
are not files.
|
| 357 |
+
|
| 358 |
+
Parses a value after getting the key so error messages are
|
| 359 |
+
more informative.
|
| 360 |
+
|
| 361 |
+
:param key:
|
| 362 |
+
:rtype: callable
|
| 363 |
+
"""
|
| 364 |
+
|
| 365 |
+
def parser(value):
|
| 366 |
+
exclude_directive = 'file:'
|
| 367 |
+
if value.startswith(exclude_directive):
|
| 368 |
+
raise ValueError(
|
| 369 |
+
f'Only strings are accepted for the {key} field, '
|
| 370 |
+
'files are not accepted'
|
| 371 |
+
)
|
| 372 |
+
return _static.Str(value)
|
| 373 |
+
|
| 374 |
+
return parser
|
| 375 |
+
|
| 376 |
+
def _parse_file(self, value, root_dir: StrPath | None):
|
| 377 |
+
"""Represents value as a string, allowing including text
|
| 378 |
+
from nearest files using `file:` directive.
|
| 379 |
+
|
| 380 |
+
Directive is sandboxed and won't reach anything outside
|
| 381 |
+
directory with setup.py.
|
| 382 |
+
|
| 383 |
+
Examples:
|
| 384 |
+
file: README.rst, CHANGELOG.md, src/file.txt
|
| 385 |
+
|
| 386 |
+
:param str value:
|
| 387 |
+
:rtype: str
|
| 388 |
+
"""
|
| 389 |
+
include_directive = 'file:'
|
| 390 |
+
|
| 391 |
+
if not isinstance(value, str):
|
| 392 |
+
return value
|
| 393 |
+
|
| 394 |
+
if not value.startswith(include_directive):
|
| 395 |
+
return _static.Str(value)
|
| 396 |
+
|
| 397 |
+
spec = value[len(include_directive) :]
|
| 398 |
+
filepaths = [path.strip() for path in spec.split(',')]
|
| 399 |
+
self._referenced_files.update(filepaths)
|
| 400 |
+
# XXX: Is marking as static contents coming from files too optimistic?
|
| 401 |
+
return _static.Str(expand.read_files(filepaths, root_dir))
|
| 402 |
+
|
| 403 |
+
def _parse_attr(self, value, package_dir, root_dir: StrPath):
|
| 404 |
+
"""Represents value as a module attribute.
|
| 405 |
+
|
| 406 |
+
Examples:
|
| 407 |
+
attr: package.attr
|
| 408 |
+
attr: package.module.attr
|
| 409 |
+
|
| 410 |
+
:param str value:
|
| 411 |
+
:rtype: str
|
| 412 |
+
"""
|
| 413 |
+
attr_directive = 'attr:'
|
| 414 |
+
if not value.startswith(attr_directive):
|
| 415 |
+
return _static.Str(value)
|
| 416 |
+
|
| 417 |
+
attr_desc = value.replace(attr_directive, '')
|
| 418 |
+
|
| 419 |
+
# Make sure package_dir is populated correctly, so `attr:` directives can work
|
| 420 |
+
package_dir.update(self.ensure_discovered.package_dir)
|
| 421 |
+
return expand.read_attr(attr_desc, package_dir, root_dir)
|
| 422 |
+
|
| 423 |
+
@classmethod
|
| 424 |
+
def _get_parser_compound(cls, *parse_methods):
|
| 425 |
+
"""Returns parser function to represents value as a list.
|
| 426 |
+
|
| 427 |
+
Parses a value applying given methods one after another.
|
| 428 |
+
|
| 429 |
+
:param parse_methods:
|
| 430 |
+
:rtype: callable
|
| 431 |
+
"""
|
| 432 |
+
|
| 433 |
+
def parse(value):
|
| 434 |
+
parsed = value
|
| 435 |
+
|
| 436 |
+
for method in parse_methods:
|
| 437 |
+
parsed = method(parsed)
|
| 438 |
+
|
| 439 |
+
return parsed
|
| 440 |
+
|
| 441 |
+
return parse
|
| 442 |
+
|
| 443 |
+
@classmethod
|
| 444 |
+
def _parse_section_to_dict_with_key(cls, section_options, values_parser):
|
| 445 |
+
"""Parses section options into a dictionary.
|
| 446 |
+
|
| 447 |
+
Applies a given parser to each option in a section.
|
| 448 |
+
|
| 449 |
+
:param dict section_options:
|
| 450 |
+
:param callable values_parser: function with 2 args corresponding to key, value
|
| 451 |
+
:rtype: dict
|
| 452 |
+
"""
|
| 453 |
+
value = {}
|
| 454 |
+
for key, (_, val) in section_options.items():
|
| 455 |
+
value[key] = values_parser(key, val)
|
| 456 |
+
return value
|
| 457 |
+
|
| 458 |
+
@classmethod
|
| 459 |
+
def _parse_section_to_dict(cls, section_options, values_parser=None):
|
| 460 |
+
"""Parses section options into a dictionary.
|
| 461 |
+
|
| 462 |
+
Optionally applies a given parser to each value.
|
| 463 |
+
|
| 464 |
+
:param dict section_options:
|
| 465 |
+
:param callable values_parser: function with 1 arg corresponding to option value
|
| 466 |
+
:rtype: dict
|
| 467 |
+
"""
|
| 468 |
+
parser = (lambda _, v: values_parser(v)) if values_parser else (lambda _, v: v)
|
| 469 |
+
return cls._parse_section_to_dict_with_key(section_options, parser)
|
| 470 |
+
|
| 471 |
+
def parse_section(self, section_options) -> None:
|
| 472 |
+
"""Parses configuration file section.
|
| 473 |
+
|
| 474 |
+
:param dict section_options:
|
| 475 |
+
"""
|
| 476 |
+
for name, (_, value) in section_options.items():
|
| 477 |
+
with contextlib.suppress(KeyError):
|
| 478 |
+
# Keep silent for a new option may appear anytime.
|
| 479 |
+
self[name] = value
|
| 480 |
+
|
| 481 |
+
def parse(self) -> None:
|
| 482 |
+
"""Parses configuration file items from one
|
| 483 |
+
or more related sections.
|
| 484 |
+
|
| 485 |
+
"""
|
| 486 |
+
for section_name, section_options in self.sections.items():
|
| 487 |
+
method_postfix = ''
|
| 488 |
+
if section_name: # [section.option] variant
|
| 489 |
+
method_postfix = f"_{section_name}"
|
| 490 |
+
|
| 491 |
+
section_parser_method: Callable | None = getattr(
|
| 492 |
+
self,
|
| 493 |
+
# Dots in section names are translated into dunderscores.
|
| 494 |
+
f'parse_section{method_postfix}'.replace('.', '__'),
|
| 495 |
+
None,
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
if section_parser_method is None:
|
| 499 |
+
raise OptionError(
|
| 500 |
+
"Unsupported distribution option section: "
|
| 501 |
+
f"[{self.section_prefix}.{section_name}]"
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
section_parser_method(section_options)
|
| 505 |
+
|
| 506 |
+
def _deprecated_config_handler(self, func, msg, **kw):
|
| 507 |
+
"""this function will wrap around parameters that are deprecated
|
| 508 |
+
|
| 509 |
+
:param msg: deprecation message
|
| 510 |
+
:param func: function to be wrapped around
|
| 511 |
+
"""
|
| 512 |
+
|
| 513 |
+
@wraps(func)
|
| 514 |
+
def config_handler(*args, **kwargs):
|
| 515 |
+
kw.setdefault("stacklevel", 2)
|
| 516 |
+
_DeprecatedConfig.emit("Deprecated config in `setup.cfg`", msg, **kw)
|
| 517 |
+
return func(*args, **kwargs)
|
| 518 |
+
|
| 519 |
+
return config_handler
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
class ConfigMetadataHandler(ConfigHandler["DistributionMetadata"]):
|
| 523 |
+
section_prefix = 'metadata'
|
| 524 |
+
|
| 525 |
+
aliases = {
|
| 526 |
+
'home_page': 'url',
|
| 527 |
+
'summary': 'description',
|
| 528 |
+
'classifier': 'classifiers',
|
| 529 |
+
'platform': 'platforms',
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
strict_mode = False
|
| 533 |
+
"""We need to keep it loose, to be partially compatible with
|
| 534 |
+
`pbr` and `d2to1` packages which also uses `metadata` section.
|
| 535 |
+
|
| 536 |
+
"""
|
| 537 |
+
|
| 538 |
+
def __init__(
|
| 539 |
+
self,
|
| 540 |
+
target_obj: DistributionMetadata,
|
| 541 |
+
options: AllCommandOptions,
|
| 542 |
+
ignore_option_errors: bool,
|
| 543 |
+
ensure_discovered: expand.EnsurePackagesDiscovered,
|
| 544 |
+
package_dir: dict | None = None,
|
| 545 |
+
root_dir: StrPath | None = os.curdir,
|
| 546 |
+
) -> None:
|
| 547 |
+
super().__init__(target_obj, options, ignore_option_errors, ensure_discovered)
|
| 548 |
+
self.package_dir = package_dir
|
| 549 |
+
self.root_dir = root_dir
|
| 550 |
+
|
| 551 |
+
@property
|
| 552 |
+
def parsers(self) -> dict[str, Callable]:
|
| 553 |
+
"""Metadata item name to parser function mapping."""
|
| 554 |
+
parse_list_static = self._get_parser_compound(self._parse_list, _static.List)
|
| 555 |
+
parse_dict_static = self._get_parser_compound(self._parse_dict, _static.Dict)
|
| 556 |
+
parse_file = partial(self._parse_file, root_dir=self.root_dir)
|
| 557 |
+
exclude_files_parser = self._exclude_files_parser
|
| 558 |
+
|
| 559 |
+
return {
|
| 560 |
+
'author': _static.Str,
|
| 561 |
+
'author_email': _static.Str,
|
| 562 |
+
'maintainer': _static.Str,
|
| 563 |
+
'maintainer_email': _static.Str,
|
| 564 |
+
'platforms': parse_list_static,
|
| 565 |
+
'keywords': parse_list_static,
|
| 566 |
+
'provides': parse_list_static,
|
| 567 |
+
'obsoletes': parse_list_static,
|
| 568 |
+
'classifiers': self._get_parser_compound(parse_file, parse_list_static),
|
| 569 |
+
'license': exclude_files_parser('license'),
|
| 570 |
+
'license_files': parse_list_static,
|
| 571 |
+
'description': parse_file,
|
| 572 |
+
'long_description': parse_file,
|
| 573 |
+
'long_description_content_type': _static.Str,
|
| 574 |
+
'version': self._parse_version, # Cannot be marked as dynamic
|
| 575 |
+
'url': _static.Str,
|
| 576 |
+
'project_urls': parse_dict_static,
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
def _parse_version(self, value):
|
| 580 |
+
"""Parses `version` option value.
|
| 581 |
+
|
| 582 |
+
:param value:
|
| 583 |
+
:rtype: str
|
| 584 |
+
|
| 585 |
+
"""
|
| 586 |
+
version = self._parse_file(value, self.root_dir)
|
| 587 |
+
|
| 588 |
+
if version != value:
|
| 589 |
+
version = version.strip()
|
| 590 |
+
# Be strict about versions loaded from file because it's easy to
|
| 591 |
+
# accidentally include newlines and other unintended content
|
| 592 |
+
try:
|
| 593 |
+
Version(version)
|
| 594 |
+
except InvalidVersion as e:
|
| 595 |
+
raise OptionError(
|
| 596 |
+
f'Version loaded from {value} does not '
|
| 597 |
+
f'comply with PEP 440: {version}'
|
| 598 |
+
) from e
|
| 599 |
+
|
| 600 |
+
return version
|
| 601 |
+
|
| 602 |
+
return expand.version(self._parse_attr(value, self.package_dir, self.root_dir))
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
class ConfigOptionsHandler(ConfigHandler["Distribution"]):
|
| 606 |
+
section_prefix = 'options'
|
| 607 |
+
|
| 608 |
+
def __init__(
|
| 609 |
+
self,
|
| 610 |
+
target_obj: Distribution,
|
| 611 |
+
options: AllCommandOptions,
|
| 612 |
+
ignore_option_errors: bool,
|
| 613 |
+
ensure_discovered: expand.EnsurePackagesDiscovered,
|
| 614 |
+
) -> None:
|
| 615 |
+
super().__init__(target_obj, options, ignore_option_errors, ensure_discovered)
|
| 616 |
+
self.root_dir = target_obj.src_root
|
| 617 |
+
self.package_dir: dict[str, str] = {} # To be filled by `find_packages`
|
| 618 |
+
|
| 619 |
+
@classmethod
|
| 620 |
+
def _parse_list_semicolon(cls, value):
|
| 621 |
+
return cls._parse_list(value, separator=';')
|
| 622 |
+
|
| 623 |
+
def _parse_file_in_root(self, value):
|
| 624 |
+
return self._parse_file(value, root_dir=self.root_dir)
|
| 625 |
+
|
| 626 |
+
def _parse_requirements_list(self, label: str, value: str):
|
| 627 |
+
# Parse a requirements list, either by reading in a `file:`, or a list.
|
| 628 |
+
parsed = self._parse_list_semicolon(self._parse_file_in_root(value))
|
| 629 |
+
_warn_accidental_env_marker_misconfig(label, value, parsed)
|
| 630 |
+
# Filter it to only include lines that are not comments. `parse_list`
|
| 631 |
+
# will have stripped each line and filtered out empties.
|
| 632 |
+
return _static.List(line for line in parsed if not line.startswith("#"))
|
| 633 |
+
# ^-- Use `_static.List` to mark a non-`Dynamic` Core Metadata
|
| 634 |
+
|
| 635 |
+
@property
|
| 636 |
+
def parsers(self) -> dict[str, Callable]:
|
| 637 |
+
"""Metadata item name to parser function mapping."""
|
| 638 |
+
parse_list = self._parse_list
|
| 639 |
+
parse_bool = self._parse_bool
|
| 640 |
+
parse_cmdclass = self._parse_cmdclass
|
| 641 |
+
|
| 642 |
+
return {
|
| 643 |
+
'zip_safe': parse_bool,
|
| 644 |
+
'include_package_data': parse_bool,
|
| 645 |
+
'package_dir': self._parse_dict,
|
| 646 |
+
'scripts': parse_list,
|
| 647 |
+
'eager_resources': parse_list,
|
| 648 |
+
'dependency_links': parse_list,
|
| 649 |
+
'namespace_packages': self._deprecated_config_handler(
|
| 650 |
+
parse_list,
|
| 651 |
+
"The namespace_packages parameter is deprecated, "
|
| 652 |
+
"consider using implicit namespaces instead (PEP 420).",
|
| 653 |
+
# TODO: define due date, see setuptools.dist:check_nsp.
|
| 654 |
+
),
|
| 655 |
+
'install_requires': partial( # Core Metadata
|
| 656 |
+
self._parse_requirements_list, "install_requires"
|
| 657 |
+
),
|
| 658 |
+
'setup_requires': self._parse_list_semicolon,
|
| 659 |
+
'packages': self._parse_packages,
|
| 660 |
+
'entry_points': self._parse_file_in_root,
|
| 661 |
+
'py_modules': parse_list,
|
| 662 |
+
'python_requires': _static.SpecifierSet, # Core Metadata
|
| 663 |
+
'cmdclass': parse_cmdclass,
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
def _parse_cmdclass(self, value):
|
| 667 |
+
package_dir = self.ensure_discovered.package_dir
|
| 668 |
+
return expand.cmdclass(self._parse_dict(value), package_dir, self.root_dir)
|
| 669 |
+
|
| 670 |
+
def _parse_packages(self, value):
|
| 671 |
+
"""Parses `packages` option value.
|
| 672 |
+
|
| 673 |
+
:param value:
|
| 674 |
+
:rtype: list
|
| 675 |
+
"""
|
| 676 |
+
find_directives = ['find:', 'find_namespace:']
|
| 677 |
+
trimmed_value = value.strip()
|
| 678 |
+
|
| 679 |
+
if trimmed_value not in find_directives:
|
| 680 |
+
return self._parse_list(value)
|
| 681 |
+
|
| 682 |
+
# Read function arguments from a dedicated section.
|
| 683 |
+
find_kwargs = self.parse_section_packages__find(
|
| 684 |
+
self.sections.get('packages.find', {})
|
| 685 |
+
)
|
| 686 |
+
|
| 687 |
+
find_kwargs.update(
|
| 688 |
+
namespaces=(trimmed_value == find_directives[1]),
|
| 689 |
+
root_dir=self.root_dir,
|
| 690 |
+
fill_package_dir=self.package_dir,
|
| 691 |
+
)
|
| 692 |
+
|
| 693 |
+
return expand.find_packages(**find_kwargs)
|
| 694 |
+
|
| 695 |
+
def parse_section_packages__find(self, section_options):
|
| 696 |
+
"""Parses `packages.find` configuration file section.
|
| 697 |
+
|
| 698 |
+
To be used in conjunction with _parse_packages().
|
| 699 |
+
|
| 700 |
+
:param dict section_options:
|
| 701 |
+
"""
|
| 702 |
+
section_data = self._parse_section_to_dict(section_options, self._parse_list)
|
| 703 |
+
|
| 704 |
+
valid_keys = ['where', 'include', 'exclude']
|
| 705 |
+
find_kwargs = {k: v for k, v in section_data.items() if k in valid_keys and v}
|
| 706 |
+
|
| 707 |
+
where = find_kwargs.get('where')
|
| 708 |
+
if where is not None:
|
| 709 |
+
find_kwargs['where'] = where[0] # cast list to single val
|
| 710 |
+
|
| 711 |
+
return find_kwargs
|
| 712 |
+
|
| 713 |
+
def parse_section_entry_points(self, section_options) -> None:
|
| 714 |
+
"""Parses `entry_points` configuration file section.
|
| 715 |
+
|
| 716 |
+
:param dict section_options:
|
| 717 |
+
"""
|
| 718 |
+
parsed = self._parse_section_to_dict(section_options, self._parse_list)
|
| 719 |
+
self['entry_points'] = parsed
|
| 720 |
+
|
| 721 |
+
def _parse_package_data(self, section_options):
|
| 722 |
+
package_data = self._parse_section_to_dict(section_options, self._parse_list)
|
| 723 |
+
return expand.canonic_package_data(package_data)
|
| 724 |
+
|
| 725 |
+
def parse_section_package_data(self, section_options) -> None:
|
| 726 |
+
"""Parses `package_data` configuration file section.
|
| 727 |
+
|
| 728 |
+
:param dict section_options:
|
| 729 |
+
"""
|
| 730 |
+
self['package_data'] = self._parse_package_data(section_options)
|
| 731 |
+
|
| 732 |
+
def parse_section_exclude_package_data(self, section_options) -> None:
|
| 733 |
+
"""Parses `exclude_package_data` configuration file section.
|
| 734 |
+
|
| 735 |
+
:param dict section_options:
|
| 736 |
+
"""
|
| 737 |
+
self['exclude_package_data'] = self._parse_package_data(section_options)
|
| 738 |
+
|
| 739 |
+
def parse_section_extras_require(self, section_options) -> None: # Core Metadata
|
| 740 |
+
"""Parses `extras_require` configuration file section.
|
| 741 |
+
|
| 742 |
+
:param dict section_options:
|
| 743 |
+
"""
|
| 744 |
+
parsed = self._parse_section_to_dict_with_key(
|
| 745 |
+
section_options,
|
| 746 |
+
lambda k, v: self._parse_requirements_list(f"extras_require[{k}]", v),
|
| 747 |
+
)
|
| 748 |
+
|
| 749 |
+
self['extras_require'] = _static.Dict(parsed)
|
| 750 |
+
# ^-- Use `_static.Dict` to mark a non-`Dynamic` Core Metadata
|
| 751 |
+
|
| 752 |
+
def parse_section_data_files(self, section_options) -> None:
|
| 753 |
+
"""Parses `data_files` configuration file section.
|
| 754 |
+
|
| 755 |
+
:param dict section_options:
|
| 756 |
+
"""
|
| 757 |
+
parsed = self._parse_section_to_dict(section_options, self._parse_list)
|
| 758 |
+
self['data_files'] = expand.canonic_data_files(parsed, self.root_dir)
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
class _AmbiguousMarker(SetuptoolsDeprecationWarning):
|
| 762 |
+
_SUMMARY = "Ambiguous requirement marker."
|
| 763 |
+
_DETAILS = """
|
| 764 |
+
One of the parsed requirements in `{field}` looks like a valid environment marker:
|
| 765 |
+
|
| 766 |
+
{req!r}
|
| 767 |
+
|
| 768 |
+
Please make sure that the configuration file is correct.
|
| 769 |
+
You can use dangling lines to avoid this problem.
|
| 770 |
+
"""
|
| 771 |
+
_SEE_DOCS = "userguide/declarative_config.html#opt-2"
|
| 772 |
+
# TODO: should we include due_date here? Initially introduced in 6 Aug 2022.
|
| 773 |
+
# Does this make sense with latest version of packaging?
|
| 774 |
+
|
| 775 |
+
@classmethod
|
| 776 |
+
def message(cls, **kw):
|
| 777 |
+
docs = f"https://setuptools.pypa.io/en/latest/{cls._SEE_DOCS}"
|
| 778 |
+
return cls._format(cls._SUMMARY, cls._DETAILS, see_url=docs, format_args=kw)
|
| 779 |
+
|
| 780 |
+
|
| 781 |
+
class _DeprecatedConfig(SetuptoolsDeprecationWarning):
|
| 782 |
+
_SEE_DOCS = "userguide/declarative_config.html"
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/config/setuptools.schema.json
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 3 |
+
|
| 4 |
+
"$id": "https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html",
|
| 5 |
+
"title": "``tool.setuptools`` table",
|
| 6 |
+
"$$description": [
|
| 7 |
+
"``setuptools``-specific configurations that can be set by users that require",
|
| 8 |
+
"customization.",
|
| 9 |
+
"These configurations are completely optional and probably can be skipped when",
|
| 10 |
+
"creating simple packages. They are equivalent to some of the `Keywords",
|
| 11 |
+
"<https://setuptools.pypa.io/en/latest/references/keywords.html>`_",
|
| 12 |
+
"used by the ``setup.py`` file, and can be set via the ``tool.setuptools`` table.",
|
| 13 |
+
"It considers only ``setuptools`` `parameters",
|
| 14 |
+
"<https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration>`_",
|
| 15 |
+
"that are not covered by :pep:`621`; and intentionally excludes ``dependency_links``",
|
| 16 |
+
"and ``setup_requires`` (incompatible with modern workflows/standards)."
|
| 17 |
+
],
|
| 18 |
+
|
| 19 |
+
"type": "object",
|
| 20 |
+
"additionalProperties": false,
|
| 21 |
+
"properties": {
|
| 22 |
+
"platforms": {
|
| 23 |
+
"type": "array",
|
| 24 |
+
"items": {"type": "string"}
|
| 25 |
+
},
|
| 26 |
+
"provides": {
|
| 27 |
+
"$$description": [
|
| 28 |
+
"Package and virtual package names contained within this package",
|
| 29 |
+
"**(not supported by pip)**"
|
| 30 |
+
],
|
| 31 |
+
"type": "array",
|
| 32 |
+
"items": {"type": "string", "format": "pep508-identifier"}
|
| 33 |
+
},
|
| 34 |
+
"obsoletes": {
|
| 35 |
+
"$$description": [
|
| 36 |
+
"Packages which this package renders obsolete",
|
| 37 |
+
"**(not supported by pip)**"
|
| 38 |
+
],
|
| 39 |
+
"type": "array",
|
| 40 |
+
"items": {"type": "string", "format": "pep508-identifier"}
|
| 41 |
+
},
|
| 42 |
+
"zip-safe": {
|
| 43 |
+
"$$description": [
|
| 44 |
+
"Whether the project can be safely installed and run from a zip file.",
|
| 45 |
+
"**OBSOLETE**: only relevant for ``pkg_resources``, ``easy_install`` and",
|
| 46 |
+
"``setup.py install`` in the context of ``eggs`` (**DEPRECATED**)."
|
| 47 |
+
],
|
| 48 |
+
"type": "boolean"
|
| 49 |
+
},
|
| 50 |
+
"script-files": {
|
| 51 |
+
"$$description": [
|
| 52 |
+
"Legacy way of defining scripts (entry-points are preferred).",
|
| 53 |
+
"Equivalent to the ``script`` keyword in ``setup.py``",
|
| 54 |
+
"(it was renamed to avoid confusion with entry-point based ``project.scripts``",
|
| 55 |
+
"defined in :pep:`621`).",
|
| 56 |
+
"**DISCOURAGED**: generic script wrappers are tricky and may not work properly.",
|
| 57 |
+
"Whenever possible, please use ``project.scripts`` instead."
|
| 58 |
+
],
|
| 59 |
+
"type": "array",
|
| 60 |
+
"items": {"type": "string"},
|
| 61 |
+
"$comment": "TODO: is this field deprecated/should be removed?"
|
| 62 |
+
},
|
| 63 |
+
"eager-resources": {
|
| 64 |
+
"$$description": [
|
| 65 |
+
"Resources that should be extracted together, if any of them is needed,",
|
| 66 |
+
"or if any C extensions included in the project are imported.",
|
| 67 |
+
"**OBSOLETE**: only relevant for ``pkg_resources``, ``easy_install`` and",
|
| 68 |
+
"``setup.py install`` in the context of ``eggs`` (**DEPRECATED**)."
|
| 69 |
+
],
|
| 70 |
+
"type": "array",
|
| 71 |
+
"items": {"type": "string"}
|
| 72 |
+
},
|
| 73 |
+
"packages": {
|
| 74 |
+
"$$description": [
|
| 75 |
+
"Packages that should be included in the distribution.",
|
| 76 |
+
"It can be given either as a list of package identifiers",
|
| 77 |
+
"or as a ``dict``-like structure with a single key ``find``",
|
| 78 |
+
"which corresponds to a dynamic call to",
|
| 79 |
+
"``setuptools.config.expand.find_packages`` function.",
|
| 80 |
+
"The ``find`` key is associated with a nested ``dict``-like structure that can",
|
| 81 |
+
"contain ``where``, ``include``, ``exclude`` and ``namespaces`` keys,",
|
| 82 |
+
"mimicking the keyword arguments of the associated function."
|
| 83 |
+
],
|
| 84 |
+
"oneOf": [
|
| 85 |
+
{
|
| 86 |
+
"title": "Array of Python package identifiers",
|
| 87 |
+
"type": "array",
|
| 88 |
+
"items": {"$ref": "#/definitions/package-name"}
|
| 89 |
+
},
|
| 90 |
+
{"$ref": "#/definitions/find-directive"}
|
| 91 |
+
]
|
| 92 |
+
},
|
| 93 |
+
"package-dir": {
|
| 94 |
+
"$$description": [
|
| 95 |
+
":class:`dict`-like structure mapping from package names to directories where their",
|
| 96 |
+
"code can be found.",
|
| 97 |
+
"The empty string (as key) means that all packages are contained inside",
|
| 98 |
+
"the given directory will be included in the distribution."
|
| 99 |
+
],
|
| 100 |
+
"type": "object",
|
| 101 |
+
"additionalProperties": false,
|
| 102 |
+
"propertyNames": {
|
| 103 |
+
"anyOf": [{"const": ""}, {"$ref": "#/definitions/package-name"}]
|
| 104 |
+
},
|
| 105 |
+
"patternProperties": {
|
| 106 |
+
"^.*$": {"type": "string" }
|
| 107 |
+
}
|
| 108 |
+
},
|
| 109 |
+
"package-data": {
|
| 110 |
+
"$$description": [
|
| 111 |
+
"Mapping from package names to lists of glob patterns.",
|
| 112 |
+
"Usually this option is not needed when using ``include-package-data = true``",
|
| 113 |
+
"For more information on how to include data files, check ``setuptools`` `docs",
|
| 114 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 115 |
+
],
|
| 116 |
+
"type": "object",
|
| 117 |
+
"additionalProperties": false,
|
| 118 |
+
"propertyNames": {
|
| 119 |
+
"anyOf": [{"$ref": "#/definitions/package-name"}, {"const": "*"}]
|
| 120 |
+
},
|
| 121 |
+
"patternProperties": {
|
| 122 |
+
"^.*$": {"type": "array", "items": {"type": "string"}}
|
| 123 |
+
}
|
| 124 |
+
},
|
| 125 |
+
"include-package-data": {
|
| 126 |
+
"$$description": [
|
| 127 |
+
"Automatically include any data files inside the package directories",
|
| 128 |
+
"that are specified by ``MANIFEST.in``",
|
| 129 |
+
"For more information on how to include data files, check ``setuptools`` `docs",
|
| 130 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 131 |
+
],
|
| 132 |
+
"type": "boolean"
|
| 133 |
+
},
|
| 134 |
+
"exclude-package-data": {
|
| 135 |
+
"$$description": [
|
| 136 |
+
"Mapping from package names to lists of glob patterns that should be excluded",
|
| 137 |
+
"For more information on how to include data files, check ``setuptools`` `docs",
|
| 138 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 139 |
+
],
|
| 140 |
+
"type": "object",
|
| 141 |
+
"additionalProperties": false,
|
| 142 |
+
"propertyNames": {
|
| 143 |
+
"anyOf": [{"$ref": "#/definitions/package-name"}, {"const": "*"}]
|
| 144 |
+
},
|
| 145 |
+
"patternProperties": {
|
| 146 |
+
"^.*$": {"type": "array", "items": {"type": "string"}}
|
| 147 |
+
}
|
| 148 |
+
},
|
| 149 |
+
"namespace-packages": {
|
| 150 |
+
"type": "array",
|
| 151 |
+
"items": {"type": "string", "format": "python-module-name-relaxed"},
|
| 152 |
+
"$comment": "https://setuptools.pypa.io/en/latest/userguide/package_discovery.html",
|
| 153 |
+
"description": "**DEPRECATED**: use implicit namespaces instead (:pep:`420`)."
|
| 154 |
+
},
|
| 155 |
+
"py-modules": {
|
| 156 |
+
"description": "Modules that setuptools will manipulate",
|
| 157 |
+
"type": "array",
|
| 158 |
+
"items": {"type": "string", "format": "python-module-name-relaxed"},
|
| 159 |
+
"$comment": "TODO: clarify the relationship with ``packages``"
|
| 160 |
+
},
|
| 161 |
+
"ext-modules": {
|
| 162 |
+
"description": "Extension modules to be compiled by setuptools",
|
| 163 |
+
"type": "array",
|
| 164 |
+
"items": {"$ref": "#/definitions/ext-module"}
|
| 165 |
+
},
|
| 166 |
+
"data-files": {
|
| 167 |
+
"$$description": [
|
| 168 |
+
"``dict``-like structure where each key represents a directory and",
|
| 169 |
+
"the value is a list of glob patterns that should be installed in them.",
|
| 170 |
+
"**DISCOURAGED**: please notice this might not work as expected with wheels.",
|
| 171 |
+
"Whenever possible, consider using data files inside the package directories",
|
| 172 |
+
"(or create a new namespace package that only contains data files).",
|
| 173 |
+
"See `data files support",
|
| 174 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 175 |
+
],
|
| 176 |
+
"type": "object",
|
| 177 |
+
"patternProperties": {
|
| 178 |
+
"^.*$": {"type": "array", "items": {"type": "string"}}
|
| 179 |
+
}
|
| 180 |
+
},
|
| 181 |
+
"cmdclass": {
|
| 182 |
+
"$$description": [
|
| 183 |
+
"Mapping of distutils-style command names to ``setuptools.Command`` subclasses",
|
| 184 |
+
"which in turn should be represented by strings with a qualified class name",
|
| 185 |
+
"(i.e., \"dotted\" form with module), e.g.::\n\n",
|
| 186 |
+
" cmdclass = {mycmd = \"pkg.subpkg.module.CommandClass\"}\n\n",
|
| 187 |
+
"The command class should be a directly defined at the top-level of the",
|
| 188 |
+
"containing module (no class nesting)."
|
| 189 |
+
],
|
| 190 |
+
"type": "object",
|
| 191 |
+
"patternProperties": {
|
| 192 |
+
"^.*$": {"type": "string", "format": "python-qualified-identifier"}
|
| 193 |
+
}
|
| 194 |
+
},
|
| 195 |
+
"license-files": {
|
| 196 |
+
"type": "array",
|
| 197 |
+
"items": {"type": "string"},
|
| 198 |
+
"$$description": [
|
| 199 |
+
"**PROVISIONAL**: list of glob patterns for all license files being distributed.",
|
| 200 |
+
"(likely to become standard with :pep:`639`).",
|
| 201 |
+
"By default: ``['LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*']``"
|
| 202 |
+
],
|
| 203 |
+
"$comment": "TODO: revise if PEP 639 is accepted. Probably ``project.license-files``?"
|
| 204 |
+
},
|
| 205 |
+
"dynamic": {
|
| 206 |
+
"type": "object",
|
| 207 |
+
"description": "Instructions for loading :pep:`621`-related metadata dynamically",
|
| 208 |
+
"additionalProperties": false,
|
| 209 |
+
"properties": {
|
| 210 |
+
"version": {
|
| 211 |
+
"$$description": [
|
| 212 |
+
"A version dynamically loaded via either the ``attr:`` or ``file:``",
|
| 213 |
+
"directives. Please make sure the given file or attribute respects :pep:`440`.",
|
| 214 |
+
"Also ensure to set ``project.dynamic`` accordingly."
|
| 215 |
+
],
|
| 216 |
+
"oneOf": [
|
| 217 |
+
{"$ref": "#/definitions/attr-directive"},
|
| 218 |
+
{"$ref": "#/definitions/file-directive"}
|
| 219 |
+
]
|
| 220 |
+
},
|
| 221 |
+
"classifiers": {"$ref": "#/definitions/file-directive"},
|
| 222 |
+
"description": {"$ref": "#/definitions/file-directive"},
|
| 223 |
+
"entry-points": {"$ref": "#/definitions/file-directive"},
|
| 224 |
+
"dependencies": {"$ref": "#/definitions/file-directive-for-dependencies"},
|
| 225 |
+
"optional-dependencies": {
|
| 226 |
+
"type": "object",
|
| 227 |
+
"propertyNames": {"type": "string", "format": "pep508-identifier"},
|
| 228 |
+
"additionalProperties": false,
|
| 229 |
+
"patternProperties": {
|
| 230 |
+
".+": {"$ref": "#/definitions/file-directive-for-dependencies"}
|
| 231 |
+
}
|
| 232 |
+
},
|
| 233 |
+
"readme": {
|
| 234 |
+
"type": "object",
|
| 235 |
+
"anyOf": [
|
| 236 |
+
{"$ref": "#/definitions/file-directive"},
|
| 237 |
+
{
|
| 238 |
+
"type": "object",
|
| 239 |
+
"properties": {
|
| 240 |
+
"content-type": {"type": "string"},
|
| 241 |
+
"file": { "$ref": "#/definitions/file-directive/properties/file" }
|
| 242 |
+
},
|
| 243 |
+
"additionalProperties": false}
|
| 244 |
+
],
|
| 245 |
+
"required": ["file"]
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
},
|
| 250 |
+
|
| 251 |
+
"definitions": {
|
| 252 |
+
"package-name": {
|
| 253 |
+
"$id": "#/definitions/package-name",
|
| 254 |
+
"title": "Valid package name",
|
| 255 |
+
"description": "Valid package name (importable or :pep:`561`).",
|
| 256 |
+
"type": "string",
|
| 257 |
+
"anyOf": [
|
| 258 |
+
{"type": "string", "format": "python-module-name-relaxed"},
|
| 259 |
+
{"type": "string", "format": "pep561-stub-name"}
|
| 260 |
+
]
|
| 261 |
+
},
|
| 262 |
+
"ext-module": {
|
| 263 |
+
"$id": "#/definitions/ext-module",
|
| 264 |
+
"title": "Extension module",
|
| 265 |
+
"description": "Parameters to construct a :class:`setuptools.Extension` object",
|
| 266 |
+
"type": "object",
|
| 267 |
+
"required": ["name", "sources"],
|
| 268 |
+
"additionalProperties": false,
|
| 269 |
+
"properties": {
|
| 270 |
+
"name": {
|
| 271 |
+
"type": "string",
|
| 272 |
+
"format": "python-module-name-relaxed"
|
| 273 |
+
},
|
| 274 |
+
"sources": {
|
| 275 |
+
"type": "array",
|
| 276 |
+
"items": {"type": "string"}
|
| 277 |
+
},
|
| 278 |
+
"include-dirs":{
|
| 279 |
+
"type": "array",
|
| 280 |
+
"items": {"type": "string"}
|
| 281 |
+
},
|
| 282 |
+
"define-macros": {
|
| 283 |
+
"type": "array",
|
| 284 |
+
"items": {
|
| 285 |
+
"type": "array",
|
| 286 |
+
"items": [
|
| 287 |
+
{"description": "macro name", "type": "string"},
|
| 288 |
+
{"description": "macro value", "oneOf": [{"type": "string"}, {"type": "null"}]}
|
| 289 |
+
],
|
| 290 |
+
"additionalItems": false
|
| 291 |
+
}
|
| 292 |
+
},
|
| 293 |
+
"undef-macros": {
|
| 294 |
+
"type": "array",
|
| 295 |
+
"items": {"type": "string"}
|
| 296 |
+
},
|
| 297 |
+
"library-dirs": {
|
| 298 |
+
"type": "array",
|
| 299 |
+
"items": {"type": "string"}
|
| 300 |
+
},
|
| 301 |
+
"libraries": {
|
| 302 |
+
"type": "array",
|
| 303 |
+
"items": {"type": "string"}
|
| 304 |
+
},
|
| 305 |
+
"runtime-library-dirs": {
|
| 306 |
+
"type": "array",
|
| 307 |
+
"items": {"type": "string"}
|
| 308 |
+
},
|
| 309 |
+
"extra-objects": {
|
| 310 |
+
"type": "array",
|
| 311 |
+
"items": {"type": "string"}
|
| 312 |
+
},
|
| 313 |
+
"extra-compile-args": {
|
| 314 |
+
"type": "array",
|
| 315 |
+
"items": {"type": "string"}
|
| 316 |
+
},
|
| 317 |
+
"extra-link-args": {
|
| 318 |
+
"type": "array",
|
| 319 |
+
"items": {"type": "string"}
|
| 320 |
+
},
|
| 321 |
+
"export-symbols": {
|
| 322 |
+
"type": "array",
|
| 323 |
+
"items": {"type": "string"}
|
| 324 |
+
},
|
| 325 |
+
"swig-opts": {
|
| 326 |
+
"type": "array",
|
| 327 |
+
"items": {"type": "string"}
|
| 328 |
+
},
|
| 329 |
+
"depends": {
|
| 330 |
+
"type": "array",
|
| 331 |
+
"items": {"type": "string"}
|
| 332 |
+
},
|
| 333 |
+
"language": {"type": "string"},
|
| 334 |
+
"optional": {"type": "boolean"},
|
| 335 |
+
"py-limited-api": {"type": "boolean"}
|
| 336 |
+
}
|
| 337 |
+
},
|
| 338 |
+
"file-directive": {
|
| 339 |
+
"$id": "#/definitions/file-directive",
|
| 340 |
+
"title": "'file:' directive",
|
| 341 |
+
"description":
|
| 342 |
+
"Value is read from a file (or list of files and then concatenated)",
|
| 343 |
+
"type": "object",
|
| 344 |
+
"additionalProperties": false,
|
| 345 |
+
"properties": {
|
| 346 |
+
"file": {
|
| 347 |
+
"oneOf": [
|
| 348 |
+
{"type": "string"},
|
| 349 |
+
{"type": "array", "items": {"type": "string"}}
|
| 350 |
+
]
|
| 351 |
+
}
|
| 352 |
+
},
|
| 353 |
+
"required": ["file"]
|
| 354 |
+
},
|
| 355 |
+
"file-directive-for-dependencies": {
|
| 356 |
+
"title": "'file:' directive for dependencies",
|
| 357 |
+
"allOf": [
|
| 358 |
+
{
|
| 359 |
+
"$$description": [
|
| 360 |
+
"**BETA**: subset of the ``requirements.txt`` format",
|
| 361 |
+
"without ``pip`` flags and options",
|
| 362 |
+
"(one :pep:`508`-compliant string per line,",
|
| 363 |
+
"lines that are blank or start with ``#`` are excluded).",
|
| 364 |
+
"See `dynamic metadata",
|
| 365 |
+
"<https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata>`_."
|
| 366 |
+
]
|
| 367 |
+
},
|
| 368 |
+
{"$ref": "#/definitions/file-directive"}
|
| 369 |
+
]
|
| 370 |
+
},
|
| 371 |
+
"attr-directive": {
|
| 372 |
+
"title": "'attr:' directive",
|
| 373 |
+
"$id": "#/definitions/attr-directive",
|
| 374 |
+
"$$description": [
|
| 375 |
+
"Value is read from a module attribute. Supports callables and iterables;",
|
| 376 |
+
"unsupported types are cast via ``str()``"
|
| 377 |
+
],
|
| 378 |
+
"type": "object",
|
| 379 |
+
"additionalProperties": false,
|
| 380 |
+
"properties": {
|
| 381 |
+
"attr": {"type": "string", "format": "python-qualified-identifier"}
|
| 382 |
+
},
|
| 383 |
+
"required": ["attr"]
|
| 384 |
+
},
|
| 385 |
+
"find-directive": {
|
| 386 |
+
"$id": "#/definitions/find-directive",
|
| 387 |
+
"title": "'find:' directive",
|
| 388 |
+
"type": "object",
|
| 389 |
+
"additionalProperties": false,
|
| 390 |
+
"properties": {
|
| 391 |
+
"find": {
|
| 392 |
+
"type": "object",
|
| 393 |
+
"$$description": [
|
| 394 |
+
"Dynamic `package discovery",
|
| 395 |
+
"<https://setuptools.pypa.io/en/latest/userguide/package_discovery.html>`_."
|
| 396 |
+
],
|
| 397 |
+
"additionalProperties": false,
|
| 398 |
+
"properties": {
|
| 399 |
+
"where": {
|
| 400 |
+
"description":
|
| 401 |
+
"Directories to be searched for packages (Unix-style relative path)",
|
| 402 |
+
"type": "array",
|
| 403 |
+
"items": {"type": "string"}
|
| 404 |
+
},
|
| 405 |
+
"exclude": {
|
| 406 |
+
"type": "array",
|
| 407 |
+
"$$description": [
|
| 408 |
+
"Exclude packages that match the values listed in this field.",
|
| 409 |
+
"Can container shell-style wildcards (e.g. ``'pkg.*'``)"
|
| 410 |
+
],
|
| 411 |
+
"items": {"type": "string"}
|
| 412 |
+
},
|
| 413 |
+
"include": {
|
| 414 |
+
"type": "array",
|
| 415 |
+
"$$description": [
|
| 416 |
+
"Restrict the found packages to just the ones listed in this field.",
|
| 417 |
+
"Can container shell-style wildcards (e.g. ``'pkg.*'``)"
|
| 418 |
+
],
|
| 419 |
+
"items": {"type": "string"}
|
| 420 |
+
},
|
| 421 |
+
"namespaces": {
|
| 422 |
+
"type": "boolean",
|
| 423 |
+
"$$description": [
|
| 424 |
+
"When ``True``, directories without a ``__init__.py`` file will also",
|
| 425 |
+
"be scanned for :pep:`420`-style implicit namespaces"
|
| 426 |
+
]
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
}
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import locale
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
__all__ = ['fail_on_ascii']
|
| 7 |
+
|
| 8 |
+
if sys.version_info >= (3, 11):
|
| 9 |
+
locale_encoding = locale.getencoding()
|
| 10 |
+
else:
|
| 11 |
+
locale_encoding = locale.getpreferredencoding(False)
|
| 12 |
+
is_ascii = locale_encoding == 'ANSI_X3.4-1968'
|
| 13 |
+
fail_on_ascii = pytest.mark.xfail(is_ascii, reason="Test fails in this locale")
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/compat/__init__.py
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/compat/py39.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from jaraco.test.cpython import from_test_support, try_import
|
| 2 |
+
|
| 3 |
+
os_helper = try_import('os_helper') or from_test_support('can_symlink')
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/__init__.py
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/downloads/__init__.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
import time
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from urllib.error import HTTPError
|
| 7 |
+
from urllib.request import urlopen
|
| 8 |
+
|
| 9 |
+
__all__ = ["DOWNLOAD_DIR", "retrieve_file", "output_file", "urls_from_file"]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
NAME_REMOVE = ("http://", "https://", "github.com/", "/raw/")
|
| 13 |
+
DOWNLOAD_DIR = Path(__file__).parent
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# ----------------------------------------------------------------------
|
| 17 |
+
# Please update ./preload.py accordingly when modifying this file
|
| 18 |
+
# ----------------------------------------------------------------------
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def output_file(url: str, download_dir: Path = DOWNLOAD_DIR) -> Path:
|
| 22 |
+
file_name = url.strip()
|
| 23 |
+
for part in NAME_REMOVE:
|
| 24 |
+
file_name = file_name.replace(part, '').strip().strip('/:').strip()
|
| 25 |
+
return Path(download_dir, re.sub(r"[^\-_\.\w\d]+", "_", file_name))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def retrieve_file(url: str, download_dir: Path = DOWNLOAD_DIR, wait: float = 5) -> Path:
|
| 29 |
+
path = output_file(url, download_dir)
|
| 30 |
+
if path.exists():
|
| 31 |
+
print(f"Skipping {url} (already exists: {path})")
|
| 32 |
+
else:
|
| 33 |
+
download_dir.mkdir(exist_ok=True, parents=True)
|
| 34 |
+
print(f"Downloading {url} to {path}")
|
| 35 |
+
try:
|
| 36 |
+
download(url, path)
|
| 37 |
+
except HTTPError:
|
| 38 |
+
time.sleep(wait) # wait a few seconds and try again.
|
| 39 |
+
download(url, path)
|
| 40 |
+
return path
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def urls_from_file(list_file: Path) -> list[str]:
|
| 44 |
+
"""``list_file`` should be a text file where each line corresponds to a URL to
|
| 45 |
+
download.
|
| 46 |
+
"""
|
| 47 |
+
print(f"file: {list_file}")
|
| 48 |
+
content = list_file.read_text(encoding="utf-8")
|
| 49 |
+
return [url for url in content.splitlines() if not url.startswith("#")]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def download(url: str, dest: Path):
|
| 53 |
+
with urlopen(url) as f:
|
| 54 |
+
data = f.read()
|
| 55 |
+
|
| 56 |
+
with open(dest, "wb") as f:
|
| 57 |
+
f.write(data)
|
| 58 |
+
|
| 59 |
+
assert Path(dest).exists()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/downloads/preload.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""This file can be used to preload files needed for testing.
|
| 2 |
+
|
| 3 |
+
For example you can use::
|
| 4 |
+
|
| 5 |
+
cd setuptools/tests/config
|
| 6 |
+
python -m downloads.preload setupcfg_examples.txt
|
| 7 |
+
|
| 8 |
+
to make sure the `setup.cfg` examples are downloaded before starting the tests.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import sys
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
from . import retrieve_file, urls_from_file
|
| 15 |
+
|
| 16 |
+
if __name__ == "__main__":
|
| 17 |
+
urls = urls_from_file(Path(sys.argv[1]))
|
| 18 |
+
list(map(retrieve_file, urls))
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/setupcfg_examples.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ====================================================================
|
| 2 |
+
# Some popular packages that use setup.cfg (and others not so popular)
|
| 3 |
+
# Reference: https://hugovk.github.io/top-pypi-packages/
|
| 4 |
+
# ====================================================================
|
| 5 |
+
https://github.com/pypa/setuptools/raw/52c990172fec37766b3566679724aa8bf70ae06d/setup.cfg
|
| 6 |
+
https://github.com/pypa/wheel/raw/0acd203cd896afec7f715aa2ff5980a403459a3b/setup.cfg
|
| 7 |
+
https://github.com/python/importlib_metadata/raw/2f05392ca980952a6960d82b2f2d2ea10aa53239/setup.cfg
|
| 8 |
+
https://github.com/jaraco/skeleton/raw/d9008b5c510cd6969127a6a2ab6f832edddef296/setup.cfg
|
| 9 |
+
https://github.com/jaraco/zipp/raw/700d3a96390e970b6b962823bfea78b4f7e1c537/setup.cfg
|
| 10 |
+
https://github.com/pallets/jinja/raw/7d72eb7fefb7dce065193967f31f805180508448/setup.cfg
|
| 11 |
+
https://github.com/tkem/cachetools/raw/2fd87a94b8d3861d80e9e4236cd480bfdd21c90d/setup.cfg
|
| 12 |
+
https://github.com/aio-libs/aiohttp/raw/5e0e6b7080f2408d5f1dd544c0e1cf88378b7b10/setup.cfg
|
| 13 |
+
https://github.com/pallets/flask/raw/9486b6cf57bd6a8a261f67091aca8ca78eeec1e3/setup.cfg
|
| 14 |
+
https://github.com/pallets/click/raw/6411f425fae545f42795665af4162006b36c5e4a/setup.cfg
|
| 15 |
+
https://github.com/sqlalchemy/sqlalchemy/raw/533f5718904b620be8d63f2474229945d6f8ba5d/setup.cfg
|
| 16 |
+
https://github.com/pytest-dev/pluggy/raw/461ef63291d13589c4e21aa182cd1529257e9a0a/setup.cfg
|
| 17 |
+
https://github.com/pytest-dev/pytest/raw/c7be96dae487edbd2f55b561b31b68afac1dabe6/setup.cfg
|
| 18 |
+
https://github.com/platformdirs/platformdirs/raw/7b7852128dd6f07511b618d6edea35046bd0c6ff/setup.cfg
|
| 19 |
+
https://github.com/pandas-dev/pandas/raw/bc17343f934a33dc231c8c74be95d8365537c376/setup.cfg
|
| 20 |
+
https://github.com/django/django/raw/4e249d11a6e56ca8feb4b055b681cec457ef3a3d/setup.cfg
|
| 21 |
+
https://github.com/pyscaffold/pyscaffold/raw/de7aa5dc059fbd04307419c667cc4961bc9df4b8/setup.cfg
|
| 22 |
+
https://github.com/pypa/virtualenv/raw/f92eda6e3da26a4d28c2663ffb85c4960bdb990c/setup.cfg
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_apply_pyprojecttoml.py
ADDED
|
@@ -0,0 +1,794 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Make sure that applying the configuration from pyproject.toml is equivalent to
|
| 2 |
+
applying a similar configuration from setup.cfg
|
| 3 |
+
|
| 4 |
+
To run these tests offline, please have a look on ``./downloads/preload.py``
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import io
|
| 10 |
+
import re
|
| 11 |
+
import tarfile
|
| 12 |
+
from inspect import cleandoc
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from unittest.mock import Mock
|
| 15 |
+
|
| 16 |
+
import pytest
|
| 17 |
+
from ini2toml.api import LiteTranslator
|
| 18 |
+
from packaging.metadata import Metadata
|
| 19 |
+
|
| 20 |
+
import setuptools # noqa: F401 # ensure monkey patch to metadata
|
| 21 |
+
from setuptools._static import is_static
|
| 22 |
+
from setuptools.command.egg_info import write_requirements
|
| 23 |
+
from setuptools.config import expand, pyprojecttoml, setupcfg
|
| 24 |
+
from setuptools.config._apply_pyprojecttoml import _MissingDynamic, _some_attrgetter
|
| 25 |
+
from setuptools.dist import Distribution
|
| 26 |
+
from setuptools.errors import InvalidConfigError, RemovedConfigError
|
| 27 |
+
from setuptools.warnings import InformationOnly, SetuptoolsDeprecationWarning
|
| 28 |
+
|
| 29 |
+
from .downloads import retrieve_file, urls_from_file
|
| 30 |
+
|
| 31 |
+
HERE = Path(__file__).parent
|
| 32 |
+
EXAMPLES_FILE = "setupcfg_examples.txt"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def makedist(path, **attrs):
|
| 36 |
+
return Distribution({"src_root": path, **attrs})
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _mock_expand_patterns(patterns, *_, **__):
|
| 40 |
+
"""
|
| 41 |
+
Allow comparing the given patterns for 2 dist objects.
|
| 42 |
+
We need to strip special chars to avoid errors when validating.
|
| 43 |
+
"""
|
| 44 |
+
return [
|
| 45 |
+
re.sub("[^a-z0-9]+", "", p, flags=re.IGNORECASE) or "empty" for p in patterns
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
@pytest.mark.parametrize("url", urls_from_file(HERE / EXAMPLES_FILE))
|
| 50 |
+
@pytest.mark.filterwarnings("ignore")
|
| 51 |
+
@pytest.mark.uses_network
|
| 52 |
+
def test_apply_pyproject_equivalent_to_setupcfg(url, monkeypatch, tmp_path):
|
| 53 |
+
monkeypatch.setattr(expand, "read_attr", Mock(return_value="0.0.1"))
|
| 54 |
+
monkeypatch.setattr(
|
| 55 |
+
Distribution, "_expand_patterns", Mock(side_effect=_mock_expand_patterns)
|
| 56 |
+
)
|
| 57 |
+
setupcfg_example = retrieve_file(url)
|
| 58 |
+
pyproject_example = Path(tmp_path, "pyproject.toml")
|
| 59 |
+
setupcfg_text = setupcfg_example.read_text(encoding="utf-8")
|
| 60 |
+
toml_config = LiteTranslator().translate(setupcfg_text, "setup.cfg")
|
| 61 |
+
pyproject_example.write_text(toml_config, encoding="utf-8")
|
| 62 |
+
|
| 63 |
+
dist_toml = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject_example)
|
| 64 |
+
dist_cfg = setupcfg.apply_configuration(makedist(tmp_path), setupcfg_example)
|
| 65 |
+
|
| 66 |
+
pkg_info_toml = core_metadata(dist_toml)
|
| 67 |
+
pkg_info_cfg = core_metadata(dist_cfg)
|
| 68 |
+
assert pkg_info_toml == pkg_info_cfg
|
| 69 |
+
|
| 70 |
+
if any(getattr(d, "license_files", None) for d in (dist_toml, dist_cfg)):
|
| 71 |
+
assert set(dist_toml.license_files) == set(dist_cfg.license_files)
|
| 72 |
+
|
| 73 |
+
if any(getattr(d, "entry_points", None) for d in (dist_toml, dist_cfg)):
|
| 74 |
+
print(dist_cfg.entry_points)
|
| 75 |
+
ep_toml = {
|
| 76 |
+
(k, *sorted(i.replace(" ", "") for i in v))
|
| 77 |
+
for k, v in dist_toml.entry_points.items()
|
| 78 |
+
}
|
| 79 |
+
ep_cfg = {
|
| 80 |
+
(k, *sorted(i.replace(" ", "") for i in v))
|
| 81 |
+
for k, v in dist_cfg.entry_points.items()
|
| 82 |
+
}
|
| 83 |
+
assert ep_toml == ep_cfg
|
| 84 |
+
|
| 85 |
+
if any(getattr(d, "package_data", None) for d in (dist_toml, dist_cfg)):
|
| 86 |
+
pkg_data_toml = {(k, *sorted(v)) for k, v in dist_toml.package_data.items()}
|
| 87 |
+
pkg_data_cfg = {(k, *sorted(v)) for k, v in dist_cfg.package_data.items()}
|
| 88 |
+
assert pkg_data_toml == pkg_data_cfg
|
| 89 |
+
|
| 90 |
+
if any(getattr(d, "data_files", None) for d in (dist_toml, dist_cfg)):
|
| 91 |
+
data_files_toml = {(k, *sorted(v)) for k, v in dist_toml.data_files}
|
| 92 |
+
data_files_cfg = {(k, *sorted(v)) for k, v in dist_cfg.data_files}
|
| 93 |
+
assert data_files_toml == data_files_cfg
|
| 94 |
+
|
| 95 |
+
assert set(dist_toml.install_requires) == set(dist_cfg.install_requires)
|
| 96 |
+
if any(getattr(d, "extras_require", None) for d in (dist_toml, dist_cfg)):
|
| 97 |
+
extra_req_toml = {(k, *sorted(v)) for k, v in dist_toml.extras_require.items()}
|
| 98 |
+
extra_req_cfg = {(k, *sorted(v)) for k, v in dist_cfg.extras_require.items()}
|
| 99 |
+
assert extra_req_toml == extra_req_cfg
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
PEP621_EXAMPLE = """\
|
| 103 |
+
[project]
|
| 104 |
+
name = "spam"
|
| 105 |
+
version = "2020.0.0"
|
| 106 |
+
description = "Lovely Spam! Wonderful Spam!"
|
| 107 |
+
readme = "README.rst"
|
| 108 |
+
requires-python = ">=3.8"
|
| 109 |
+
license-files = ["LICENSE.txt"] # Updated to be PEP 639 compliant
|
| 110 |
+
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
|
| 111 |
+
authors = [
|
| 112 |
+
{email = "hi@pradyunsg.me"},
|
| 113 |
+
{name = "Tzu-Ping Chung"}
|
| 114 |
+
]
|
| 115 |
+
maintainers = [
|
| 116 |
+
{name = "Brett Cannon", email = "brett@python.org"},
|
| 117 |
+
{name = "John X. Ãørçeč", email = "john@utf8.org"},
|
| 118 |
+
{name = "Γαμα קּ 東", email = "gama@utf8.org"},
|
| 119 |
+
]
|
| 120 |
+
classifiers = [
|
| 121 |
+
"Development Status :: 4 - Beta",
|
| 122 |
+
"Programming Language :: Python"
|
| 123 |
+
]
|
| 124 |
+
|
| 125 |
+
dependencies = [
|
| 126 |
+
"httpx",
|
| 127 |
+
"gidgethub[httpx]>4.0.0",
|
| 128 |
+
"django>2.1; os_name != 'nt'",
|
| 129 |
+
"django>2.0; os_name == 'nt'"
|
| 130 |
+
]
|
| 131 |
+
|
| 132 |
+
[project.optional-dependencies]
|
| 133 |
+
test = [
|
| 134 |
+
"pytest < 5.0.0",
|
| 135 |
+
"pytest-cov[all]"
|
| 136 |
+
]
|
| 137 |
+
|
| 138 |
+
[project.urls]
|
| 139 |
+
homepage = "http://example.com"
|
| 140 |
+
documentation = "http://readthedocs.org"
|
| 141 |
+
repository = "http://github.com"
|
| 142 |
+
changelog = "http://github.com/me/spam/blob/master/CHANGELOG.md"
|
| 143 |
+
|
| 144 |
+
[project.scripts]
|
| 145 |
+
spam-cli = "spam:main_cli"
|
| 146 |
+
|
| 147 |
+
[project.gui-scripts]
|
| 148 |
+
spam-gui = "spam:main_gui"
|
| 149 |
+
|
| 150 |
+
[project.entry-points."spam.magical"]
|
| 151 |
+
tomatoes = "spam:main_tomatoes"
|
| 152 |
+
"""
|
| 153 |
+
|
| 154 |
+
PEP621_INTERNATIONAL_EMAIL_EXAMPLE = """\
|
| 155 |
+
[project]
|
| 156 |
+
name = "spam"
|
| 157 |
+
version = "2020.0.0"
|
| 158 |
+
authors = [
|
| 159 |
+
{email = "hi@pradyunsg.me"},
|
| 160 |
+
{name = "Tzu-Ping Chung"}
|
| 161 |
+
]
|
| 162 |
+
maintainers = [
|
| 163 |
+
{name = "अंकित अहलावत", email = "ankit@example.com"},
|
| 164 |
+
]
|
| 165 |
+
"""
|
| 166 |
+
|
| 167 |
+
PEP621_EXAMPLE_SCRIPT = """
|
| 168 |
+
def main_cli(): pass
|
| 169 |
+
def main_gui(): pass
|
| 170 |
+
def main_tomatoes(): pass
|
| 171 |
+
"""
|
| 172 |
+
|
| 173 |
+
PEP639_LICENSE_TEXT = """\
|
| 174 |
+
[project]
|
| 175 |
+
name = "spam"
|
| 176 |
+
version = "2020.0.0"
|
| 177 |
+
authors = [
|
| 178 |
+
{email = "hi@pradyunsg.me"},
|
| 179 |
+
{name = "Tzu-Ping Chung"}
|
| 180 |
+
]
|
| 181 |
+
license = {text = "MIT"}
|
| 182 |
+
"""
|
| 183 |
+
|
| 184 |
+
PEP639_LICENSE_EXPRESSION = """\
|
| 185 |
+
[project]
|
| 186 |
+
name = "spam"
|
| 187 |
+
version = "2020.0.0"
|
| 188 |
+
authors = [
|
| 189 |
+
{email = "hi@pradyunsg.me"},
|
| 190 |
+
{name = "Tzu-Ping Chung"}
|
| 191 |
+
]
|
| 192 |
+
license = "mit or apache-2.0" # should be normalized in metadata
|
| 193 |
+
classifiers = [
|
| 194 |
+
"Development Status :: 5 - Production/Stable",
|
| 195 |
+
"Programming Language :: Python",
|
| 196 |
+
]
|
| 197 |
+
"""
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def _pep621_example_project(
|
| 201 |
+
tmp_path,
|
| 202 |
+
readme="README.rst",
|
| 203 |
+
pyproject_text=PEP621_EXAMPLE,
|
| 204 |
+
):
|
| 205 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 206 |
+
text = pyproject_text
|
| 207 |
+
replacements = {'readme = "README.rst"': f'readme = "{readme}"'}
|
| 208 |
+
for orig, subst in replacements.items():
|
| 209 |
+
text = text.replace(orig, subst)
|
| 210 |
+
pyproject.write_text(text, encoding="utf-8")
|
| 211 |
+
|
| 212 |
+
(tmp_path / readme).write_text("hello world", encoding="utf-8")
|
| 213 |
+
(tmp_path / "LICENSE.txt").write_text("--- LICENSE stub ---", encoding="utf-8")
|
| 214 |
+
(tmp_path / "spam.py").write_text(PEP621_EXAMPLE_SCRIPT, encoding="utf-8")
|
| 215 |
+
return pyproject
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def test_pep621_example(tmp_path):
|
| 219 |
+
"""Make sure the example in PEP 621 works"""
|
| 220 |
+
pyproject = _pep621_example_project(tmp_path)
|
| 221 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 222 |
+
assert set(dist.metadata.license_files) == {"LICENSE.txt"}
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
@pytest.mark.parametrize(
|
| 226 |
+
("readme", "ctype"),
|
| 227 |
+
[
|
| 228 |
+
("Readme.txt", "text/plain"),
|
| 229 |
+
("readme.md", "text/markdown"),
|
| 230 |
+
("text.rst", "text/x-rst"),
|
| 231 |
+
],
|
| 232 |
+
)
|
| 233 |
+
def test_readme_content_type(tmp_path, readme, ctype):
|
| 234 |
+
pyproject = _pep621_example_project(tmp_path, readme)
|
| 235 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 236 |
+
assert dist.metadata.long_description_content_type == ctype
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def test_undefined_content_type(tmp_path):
|
| 240 |
+
pyproject = _pep621_example_project(tmp_path, "README.tex")
|
| 241 |
+
with pytest.raises(ValueError, match="Undefined content type for README.tex"):
|
| 242 |
+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def test_no_explicit_content_type_for_missing_extension(tmp_path):
|
| 246 |
+
pyproject = _pep621_example_project(tmp_path, "README")
|
| 247 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 248 |
+
assert dist.metadata.long_description_content_type is None
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
@pytest.mark.parametrize(
|
| 252 |
+
("pyproject_text", "expected_maintainers_meta_value"),
|
| 253 |
+
(
|
| 254 |
+
pytest.param(
|
| 255 |
+
PEP621_EXAMPLE,
|
| 256 |
+
(
|
| 257 |
+
'Brett Cannon <brett@python.org>, "John X. Ãørçeč" <john@utf8.org>, '
|
| 258 |
+
'Γαμα קּ 東 <gama@utf8.org>'
|
| 259 |
+
),
|
| 260 |
+
id='non-international-emails',
|
| 261 |
+
),
|
| 262 |
+
pytest.param(
|
| 263 |
+
PEP621_INTERNATIONAL_EMAIL_EXAMPLE,
|
| 264 |
+
'Ankit Ahlawat <अंकित@उदाहरण.भारत>',
|
| 265 |
+
marks=pytest.mark.xfail(
|
| 266 |
+
reason="CPython's `email.headerregistry.Address` only supports "
|
| 267 |
+
'RFC 5322, as of Oct 20, 2025 and latest Python 3.13.0',
|
| 268 |
+
strict=True,
|
| 269 |
+
),
|
| 270 |
+
id='international-email',
|
| 271 |
+
),
|
| 272 |
+
),
|
| 273 |
+
)
|
| 274 |
+
def test_utf8_maintainer_in_metadata( # issue-3663
|
| 275 |
+
expected_maintainers_meta_value,
|
| 276 |
+
pyproject_text,
|
| 277 |
+
tmp_path,
|
| 278 |
+
):
|
| 279 |
+
pyproject = _pep621_example_project(
|
| 280 |
+
tmp_path,
|
| 281 |
+
"README",
|
| 282 |
+
pyproject_text=pyproject_text,
|
| 283 |
+
)
|
| 284 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 285 |
+
assert dist.metadata.maintainer_email == expected_maintainers_meta_value
|
| 286 |
+
pkg_file = tmp_path / "PKG-FILE"
|
| 287 |
+
with open(pkg_file, "w", encoding="utf-8") as fh:
|
| 288 |
+
dist.metadata.write_pkg_file(fh)
|
| 289 |
+
content = pkg_file.read_text(encoding="utf-8")
|
| 290 |
+
assert f"Maintainer-email: {expected_maintainers_meta_value}" in content
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
@pytest.mark.parametrize(
|
| 294 |
+
(
|
| 295 |
+
'pyproject_text',
|
| 296 |
+
'license',
|
| 297 |
+
'license_expression',
|
| 298 |
+
'content_str',
|
| 299 |
+
'not_content_str',
|
| 300 |
+
),
|
| 301 |
+
(
|
| 302 |
+
pytest.param(
|
| 303 |
+
PEP639_LICENSE_TEXT,
|
| 304 |
+
'MIT',
|
| 305 |
+
None,
|
| 306 |
+
'License: MIT',
|
| 307 |
+
'License-Expression: ',
|
| 308 |
+
id='license-text',
|
| 309 |
+
marks=[
|
| 310 |
+
pytest.mark.filterwarnings(
|
| 311 |
+
"ignore:.project.license. as a TOML table is deprecated",
|
| 312 |
+
)
|
| 313 |
+
],
|
| 314 |
+
),
|
| 315 |
+
pytest.param(
|
| 316 |
+
PEP639_LICENSE_EXPRESSION,
|
| 317 |
+
None,
|
| 318 |
+
'MIT OR Apache-2.0',
|
| 319 |
+
'License-Expression: MIT OR Apache-2.0',
|
| 320 |
+
'License: ',
|
| 321 |
+
id='license-expression',
|
| 322 |
+
),
|
| 323 |
+
),
|
| 324 |
+
)
|
| 325 |
+
def test_license_in_metadata(
|
| 326 |
+
license,
|
| 327 |
+
license_expression,
|
| 328 |
+
content_str,
|
| 329 |
+
not_content_str,
|
| 330 |
+
pyproject_text,
|
| 331 |
+
tmp_path,
|
| 332 |
+
):
|
| 333 |
+
pyproject = _pep621_example_project(
|
| 334 |
+
tmp_path,
|
| 335 |
+
"README",
|
| 336 |
+
pyproject_text=pyproject_text,
|
| 337 |
+
)
|
| 338 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 339 |
+
assert dist.metadata.license == license
|
| 340 |
+
assert dist.metadata.license_expression == license_expression
|
| 341 |
+
pkg_file = tmp_path / "PKG-FILE"
|
| 342 |
+
with open(pkg_file, "w", encoding="utf-8") as fh:
|
| 343 |
+
dist.metadata.write_pkg_file(fh)
|
| 344 |
+
content = pkg_file.read_text(encoding="utf-8")
|
| 345 |
+
assert "Metadata-Version: 2.4" in content
|
| 346 |
+
assert content_str in content
|
| 347 |
+
assert not_content_str not in content
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
def test_license_classifier_with_license_expression(tmp_path):
|
| 351 |
+
text = PEP639_LICENSE_EXPRESSION.rsplit("\n", 2)[0]
|
| 352 |
+
pyproject = _pep621_example_project(
|
| 353 |
+
tmp_path,
|
| 354 |
+
"README",
|
| 355 |
+
f"{text}\n \"License :: OSI Approved :: MIT License\"\n]",
|
| 356 |
+
)
|
| 357 |
+
msg = "License classifiers have been superseded by license expressions"
|
| 358 |
+
with pytest.raises(InvalidConfigError, match=msg) as exc:
|
| 359 |
+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 360 |
+
|
| 361 |
+
assert "License :: OSI Approved :: MIT License" in str(exc.value)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def test_license_classifier_without_license_expression(tmp_path):
|
| 365 |
+
text = """\
|
| 366 |
+
[project]
|
| 367 |
+
name = "spam"
|
| 368 |
+
version = "2020.0.0"
|
| 369 |
+
license = {text = "mit or apache-2.0"}
|
| 370 |
+
classifiers = ["License :: OSI Approved :: MIT License"]
|
| 371 |
+
"""
|
| 372 |
+
pyproject = _pep621_example_project(tmp_path, "README", text)
|
| 373 |
+
|
| 374 |
+
msg1 = "License classifiers are deprecated(?:.|\n)*MIT License"
|
| 375 |
+
msg2 = ".project.license. as a TOML table is deprecated"
|
| 376 |
+
with (
|
| 377 |
+
pytest.warns(SetuptoolsDeprecationWarning, match=msg1),
|
| 378 |
+
pytest.warns(SetuptoolsDeprecationWarning, match=msg2),
|
| 379 |
+
):
|
| 380 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 381 |
+
|
| 382 |
+
# Check license classifier is still included
|
| 383 |
+
assert dist.metadata.get_classifiers() == ["License :: OSI Approved :: MIT License"]
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
class TestLicenseFiles:
|
| 387 |
+
def base_pyproject(
|
| 388 |
+
self,
|
| 389 |
+
tmp_path,
|
| 390 |
+
additional_text="",
|
| 391 |
+
license_toml='license = {file = "LICENSE.txt"}\n',
|
| 392 |
+
):
|
| 393 |
+
text = PEP639_LICENSE_EXPRESSION
|
| 394 |
+
|
| 395 |
+
# Sanity-check
|
| 396 |
+
assert 'license = "mit or apache-2.0"' in text
|
| 397 |
+
assert 'license-files' not in text
|
| 398 |
+
assert "[tool.setuptools]" not in text
|
| 399 |
+
|
| 400 |
+
text = re.sub(
|
| 401 |
+
r"(license = .*)\n",
|
| 402 |
+
license_toml,
|
| 403 |
+
text,
|
| 404 |
+
count=1,
|
| 405 |
+
)
|
| 406 |
+
assert license_toml in text # sanity check
|
| 407 |
+
text = f"{text}\n{additional_text}\n"
|
| 408 |
+
pyproject = _pep621_example_project(tmp_path, "README", pyproject_text=text)
|
| 409 |
+
return pyproject
|
| 410 |
+
|
| 411 |
+
def base_pyproject_license_pep639(self, tmp_path, additional_text=""):
|
| 412 |
+
return self.base_pyproject(
|
| 413 |
+
tmp_path,
|
| 414 |
+
additional_text=additional_text,
|
| 415 |
+
license_toml='license = "licenseref-Proprietary"'
|
| 416 |
+
'\nlicense-files = ["_FILE*"]\n',
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
+
def test_both_license_and_license_files_defined(self, tmp_path):
|
| 420 |
+
setuptools_config = '[tool.setuptools]\nlicense-files = ["_FILE*"]'
|
| 421 |
+
pyproject = self.base_pyproject(tmp_path, setuptools_config)
|
| 422 |
+
|
| 423 |
+
(tmp_path / "_FILE.txt").touch()
|
| 424 |
+
(tmp_path / "_FILE.rst").touch()
|
| 425 |
+
|
| 426 |
+
# Would normally match the `license_files` patterns, but we want to exclude it
|
| 427 |
+
# by being explicit. On the other hand, contents should be added to `license`
|
| 428 |
+
license = tmp_path / "LICENSE.txt"
|
| 429 |
+
license.write_text("LicenseRef-Proprietary\n", encoding="utf-8")
|
| 430 |
+
|
| 431 |
+
msg1 = "'tool.setuptools.license-files' is deprecated in favor of 'project.license-files'"
|
| 432 |
+
msg2 = ".project.license. as a TOML table is deprecated"
|
| 433 |
+
with (
|
| 434 |
+
pytest.warns(SetuptoolsDeprecationWarning, match=msg1),
|
| 435 |
+
pytest.warns(SetuptoolsDeprecationWarning, match=msg2),
|
| 436 |
+
):
|
| 437 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 438 |
+
assert set(dist.metadata.license_files) == {"_FILE.rst", "_FILE.txt"}
|
| 439 |
+
assert dist.metadata.license == "LicenseRef-Proprietary\n"
|
| 440 |
+
|
| 441 |
+
def test_both_license_and_license_files_defined_pep639(self, tmp_path):
|
| 442 |
+
# Set license and license-files
|
| 443 |
+
pyproject = self.base_pyproject_license_pep639(tmp_path)
|
| 444 |
+
|
| 445 |
+
(tmp_path / "_FILE.txt").touch()
|
| 446 |
+
(tmp_path / "_FILE.rst").touch()
|
| 447 |
+
|
| 448 |
+
msg = "Normalizing.*LicenseRef"
|
| 449 |
+
with pytest.warns(InformationOnly, match=msg):
|
| 450 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 451 |
+
|
| 452 |
+
assert set(dist.metadata.license_files) == {"_FILE.rst", "_FILE.txt"}
|
| 453 |
+
assert dist.metadata.license is None
|
| 454 |
+
assert dist.metadata.license_expression == "LicenseRef-Proprietary"
|
| 455 |
+
|
| 456 |
+
def test_license_files_defined_twice(self, tmp_path):
|
| 457 |
+
# Set project.license-files and tools.setuptools.license-files
|
| 458 |
+
setuptools_config = '[tool.setuptools]\nlicense-files = ["_FILE*"]'
|
| 459 |
+
pyproject = self.base_pyproject_license_pep639(tmp_path, setuptools_config)
|
| 460 |
+
|
| 461 |
+
msg = "'project.license-files' is defined already. Remove 'tool.setuptools.license-files'"
|
| 462 |
+
with pytest.raises(InvalidConfigError, match=msg):
|
| 463 |
+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 464 |
+
|
| 465 |
+
def test_default_patterns(self, tmp_path):
|
| 466 |
+
setuptools_config = '[tool.setuptools]\nzip-safe = false'
|
| 467 |
+
# ^ used just to trigger section validation
|
| 468 |
+
pyproject = self.base_pyproject(tmp_path, setuptools_config, license_toml="")
|
| 469 |
+
|
| 470 |
+
license_files = "LICENCE-a.html COPYING-abc.txt AUTHORS-xyz NOTICE,def".split()
|
| 471 |
+
|
| 472 |
+
for fname in license_files:
|
| 473 |
+
(tmp_path / fname).write_text(f"{fname}\n", encoding="utf-8")
|
| 474 |
+
|
| 475 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 476 |
+
|
| 477 |
+
assert (tmp_path / "LICENSE.txt").exists() # from base example
|
| 478 |
+
assert set(dist.metadata.license_files) == {*license_files, "LICENSE.txt"}
|
| 479 |
+
|
| 480 |
+
def test_missing_patterns(self, tmp_path):
|
| 481 |
+
pyproject = self.base_pyproject_license_pep639(tmp_path)
|
| 482 |
+
assert list(tmp_path.glob("_FILE*")) == [] # sanity check
|
| 483 |
+
|
| 484 |
+
msg1 = "Cannot find any files for the given pattern.*"
|
| 485 |
+
msg2 = "Normalizing 'licenseref-Proprietary' to 'LicenseRef-Proprietary'"
|
| 486 |
+
with (
|
| 487 |
+
pytest.warns(SetuptoolsDeprecationWarning, match=msg1),
|
| 488 |
+
pytest.warns(InformationOnly, match=msg2),
|
| 489 |
+
):
|
| 490 |
+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 491 |
+
|
| 492 |
+
def test_deprecated_file_expands_to_text(self, tmp_path):
|
| 493 |
+
"""Make sure the old example with ``license = {text = ...}`` works"""
|
| 494 |
+
|
| 495 |
+
assert 'license-files = ["LICENSE.txt"]' in PEP621_EXAMPLE # sanity check
|
| 496 |
+
text = PEP621_EXAMPLE.replace(
|
| 497 |
+
'license-files = ["LICENSE.txt"]',
|
| 498 |
+
'license = {file = "LICENSE.txt"}',
|
| 499 |
+
)
|
| 500 |
+
pyproject = _pep621_example_project(tmp_path, pyproject_text=text)
|
| 501 |
+
|
| 502 |
+
msg = ".project.license. as a TOML table is deprecated"
|
| 503 |
+
with pytest.warns(SetuptoolsDeprecationWarning, match=msg):
|
| 504 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 505 |
+
|
| 506 |
+
assert dist.metadata.license == "--- LICENSE stub ---"
|
| 507 |
+
assert set(dist.metadata.license_files) == {"LICENSE.txt"} # auto-filled
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class TestPyModules:
|
| 511 |
+
# https://github.com/pypa/setuptools/issues/4316
|
| 512 |
+
|
| 513 |
+
def dist(self, name):
|
| 514 |
+
toml_config = f"""
|
| 515 |
+
[project]
|
| 516 |
+
name = "test"
|
| 517 |
+
version = "42.0"
|
| 518 |
+
[tool.setuptools]
|
| 519 |
+
py-modules = [{name!r}]
|
| 520 |
+
"""
|
| 521 |
+
pyproject = Path("pyproject.toml")
|
| 522 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 523 |
+
return pyprojecttoml.apply_configuration(Distribution({}), pyproject)
|
| 524 |
+
|
| 525 |
+
@pytest.mark.parametrize("module", ["pip-run", "abc-d.λ-xyz-e"])
|
| 526 |
+
def test_valid_module_name(self, tmp_path, monkeypatch, module):
|
| 527 |
+
monkeypatch.chdir(tmp_path)
|
| 528 |
+
assert module in self.dist(module).py_modules
|
| 529 |
+
|
| 530 |
+
@pytest.mark.parametrize("module", ["pip run", "-pip-run", "pip-run-stubs"])
|
| 531 |
+
def test_invalid_module_name(self, tmp_path, monkeypatch, module):
|
| 532 |
+
monkeypatch.chdir(tmp_path)
|
| 533 |
+
with pytest.raises(ValueError, match="py-modules"):
|
| 534 |
+
self.dist(module).py_modules
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
class TestExtModules:
|
| 538 |
+
def make_dist(self, toml_config):
|
| 539 |
+
pyproject = Path("pyproject.toml")
|
| 540 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 541 |
+
with pytest.warns(pyprojecttoml._ExperimentalConfiguration):
|
| 542 |
+
return pyprojecttoml.apply_configuration(Distribution({}), pyproject)
|
| 543 |
+
|
| 544 |
+
def test_pyproject_sets_attribute(self, tmp_path, monkeypatch):
|
| 545 |
+
monkeypatch.chdir(tmp_path)
|
| 546 |
+
toml_config = """
|
| 547 |
+
[project]
|
| 548 |
+
name = "test"
|
| 549 |
+
version = "42.0"
|
| 550 |
+
[tool.setuptools]
|
| 551 |
+
ext-modules = [
|
| 552 |
+
{name = "my.ext", sources = ["hello.c", "world.c"]}
|
| 553 |
+
]
|
| 554 |
+
"""
|
| 555 |
+
dist = self.make_dist(toml_config)
|
| 556 |
+
assert len(dist.ext_modules) == 1
|
| 557 |
+
assert dist.ext_modules[0].name == "my.ext"
|
| 558 |
+
assert set(dist.ext_modules[0].sources) == {"hello.c", "world.c"}
|
| 559 |
+
|
| 560 |
+
def test_pyproject_define_macros_as_tuples(self, tmp_path, monkeypatch):
|
| 561 |
+
# https://github.com/pypa/setuptools/issues/4810
|
| 562 |
+
monkeypatch.chdir(tmp_path)
|
| 563 |
+
toml_config = """
|
| 564 |
+
[project]
|
| 565 |
+
name = "test"
|
| 566 |
+
version = "42.0"
|
| 567 |
+
[[tool.setuptools.ext-modules]]
|
| 568 |
+
name = "my.ext"
|
| 569 |
+
sources = ["hello.c", "world.c"]
|
| 570 |
+
define-macros = [["FIRST_SINGLE"], ["SECOND_TWO", "1"]]
|
| 571 |
+
"""
|
| 572 |
+
dist = self.make_dist(toml_config)
|
| 573 |
+
assert isinstance(dist.ext_modules[0].define_macros[0], tuple)
|
| 574 |
+
assert dist.ext_modules[0].define_macros[0] == ("FIRST_SINGLE",)
|
| 575 |
+
assert dist.ext_modules[0].define_macros[1] == ("SECOND_TWO", "1")
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
class TestDeprecatedFields:
|
| 579 |
+
def test_namespace_packages(self, tmp_path):
|
| 580 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 581 |
+
config = """
|
| 582 |
+
[project]
|
| 583 |
+
name = "myproj"
|
| 584 |
+
version = "42"
|
| 585 |
+
[tool.setuptools]
|
| 586 |
+
namespace-packages = ["myproj.pkg"]
|
| 587 |
+
"""
|
| 588 |
+
pyproject.write_text(cleandoc(config), encoding="utf-8")
|
| 589 |
+
with pytest.raises(RemovedConfigError, match="namespace-packages"):
|
| 590 |
+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
class TestPresetField:
|
| 594 |
+
def pyproject(self, tmp_path, dynamic, extra_content=""):
|
| 595 |
+
content = f"[project]\nname = 'proj'\ndynamic = {dynamic!r}\n"
|
| 596 |
+
if "version" not in dynamic:
|
| 597 |
+
content += "version = '42'\n"
|
| 598 |
+
file = tmp_path / "pyproject.toml"
|
| 599 |
+
file.write_text(content + extra_content, encoding="utf-8")
|
| 600 |
+
return file
|
| 601 |
+
|
| 602 |
+
@pytest.mark.parametrize(
|
| 603 |
+
("attr", "field", "value"),
|
| 604 |
+
[
|
| 605 |
+
("license_expression", "license", "MIT"),
|
| 606 |
+
pytest.param(
|
| 607 |
+
*("license", "license", "Not SPDX"),
|
| 608 |
+
marks=[pytest.mark.filterwarnings("ignore:.*license. overwritten")],
|
| 609 |
+
),
|
| 610 |
+
("classifiers", "classifiers", ["Private :: Classifier"]),
|
| 611 |
+
("entry_points", "scripts", {"console_scripts": ["foobar=foobar:main"]}),
|
| 612 |
+
("entry_points", "gui-scripts", {"gui_scripts": ["bazquux=bazquux:main"]}),
|
| 613 |
+
pytest.param(
|
| 614 |
+
*("install_requires", "dependencies", ["six"]),
|
| 615 |
+
marks=[
|
| 616 |
+
pytest.mark.filterwarnings("ignore:.*install_requires. overwritten")
|
| 617 |
+
],
|
| 618 |
+
),
|
| 619 |
+
],
|
| 620 |
+
)
|
| 621 |
+
def test_not_listed_in_dynamic(self, tmp_path, attr, field, value):
|
| 622 |
+
"""Setuptools cannot set a field if not listed in ``dynamic``"""
|
| 623 |
+
pyproject = self.pyproject(tmp_path, [])
|
| 624 |
+
dist = makedist(tmp_path, **{attr: value})
|
| 625 |
+
msg = re.compile(f"defined outside of `pyproject.toml`:.*{field}", re.DOTALL)
|
| 626 |
+
with pytest.warns(_MissingDynamic, match=msg):
|
| 627 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 628 |
+
|
| 629 |
+
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
|
| 630 |
+
assert not dist_value
|
| 631 |
+
|
| 632 |
+
@pytest.mark.parametrize(
|
| 633 |
+
("attr", "field", "value"),
|
| 634 |
+
[
|
| 635 |
+
("license_expression", "license", "MIT"),
|
| 636 |
+
("install_requires", "dependencies", []),
|
| 637 |
+
("extras_require", "optional-dependencies", {}),
|
| 638 |
+
("install_requires", "dependencies", ["six"]),
|
| 639 |
+
("classifiers", "classifiers", ["Private :: Classifier"]),
|
| 640 |
+
],
|
| 641 |
+
)
|
| 642 |
+
def test_listed_in_dynamic(self, tmp_path, attr, field, value):
|
| 643 |
+
pyproject = self.pyproject(tmp_path, [field])
|
| 644 |
+
dist = makedist(tmp_path, **{attr: value})
|
| 645 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 646 |
+
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
|
| 647 |
+
assert dist_value == value
|
| 648 |
+
|
| 649 |
+
def test_license_files_exempt_from_dynamic(self, monkeypatch, tmp_path):
|
| 650 |
+
"""
|
| 651 |
+
license-file is currently not considered in the context of dynamic.
|
| 652 |
+
As per 2025-02-19, https://packaging.python.org/en/latest/specifications/pyproject-toml/#license-files
|
| 653 |
+
allows setuptools to fill-in `license-files` the way it sees fit:
|
| 654 |
+
|
| 655 |
+
> If the license-files key is not defined, tools can decide how to handle license files.
|
| 656 |
+
> For example they can choose not to include any files or use their own
|
| 657 |
+
> logic to discover the appropriate files in the distribution.
|
| 658 |
+
|
| 659 |
+
Using license_files from setup.py to fill-in the value is in accordance
|
| 660 |
+
with this rule.
|
| 661 |
+
"""
|
| 662 |
+
monkeypatch.chdir(tmp_path)
|
| 663 |
+
pyproject = self.pyproject(tmp_path, [])
|
| 664 |
+
dist = makedist(tmp_path, license_files=["LIC*"])
|
| 665 |
+
(tmp_path / "LIC1").write_text("42", encoding="utf-8")
|
| 666 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 667 |
+
assert dist.metadata.license_files == ["LIC1"]
|
| 668 |
+
|
| 669 |
+
def test_warning_overwritten_dependencies(self, tmp_path):
|
| 670 |
+
src = "[project]\nname='pkg'\nversion='0.1'\ndependencies=['click']\n"
|
| 671 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 672 |
+
pyproject.write_text(src, encoding="utf-8")
|
| 673 |
+
dist = makedist(tmp_path, install_requires=["wheel"])
|
| 674 |
+
with pytest.warns(match="`install_requires` overwritten"):
|
| 675 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 676 |
+
assert "wheel" not in dist.install_requires
|
| 677 |
+
|
| 678 |
+
def test_optional_dependencies_dont_remove_env_markers(self, tmp_path):
|
| 679 |
+
"""
|
| 680 |
+
Internally setuptools converts dependencies with markers to "extras".
|
| 681 |
+
If ``install_requires`` is given by ``setup.py``, we have to ensure that
|
| 682 |
+
applying ``optional-dependencies`` does not overwrite the mandatory
|
| 683 |
+
dependencies with markers (see #3204).
|
| 684 |
+
"""
|
| 685 |
+
# If setuptools replace its internal mechanism that uses `requires.txt`
|
| 686 |
+
# this test has to be rewritten to adapt accordingly
|
| 687 |
+
extra = "\n[project.optional-dependencies]\nfoo = ['bar>1']\n"
|
| 688 |
+
pyproject = self.pyproject(tmp_path, ["dependencies"], extra)
|
| 689 |
+
install_req = ['importlib-resources (>=3.0.0) ; python_version < "3.7"']
|
| 690 |
+
dist = makedist(tmp_path, install_requires=install_req)
|
| 691 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 692 |
+
assert "foo" in dist.extras_require
|
| 693 |
+
egg_info = dist.get_command_obj("egg_info")
|
| 694 |
+
write_requirements(egg_info, tmp_path, tmp_path / "requires.txt")
|
| 695 |
+
reqs = (tmp_path / "requires.txt").read_text(encoding="utf-8")
|
| 696 |
+
assert "importlib-resources" in reqs
|
| 697 |
+
assert "bar" in reqs
|
| 698 |
+
assert ':python_version < "3.7"' in reqs
|
| 699 |
+
|
| 700 |
+
@pytest.mark.parametrize(
|
| 701 |
+
("field", "group"),
|
| 702 |
+
[("scripts", "console_scripts"), ("gui-scripts", "gui_scripts")],
|
| 703 |
+
)
|
| 704 |
+
@pytest.mark.filterwarnings("error")
|
| 705 |
+
def test_scripts_dont_require_dynamic_entry_points(self, tmp_path, field, group):
|
| 706 |
+
# Issue 3862
|
| 707 |
+
pyproject = self.pyproject(tmp_path, [field])
|
| 708 |
+
dist = makedist(tmp_path, entry_points={group: ["foobar=foobar:main"]})
|
| 709 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 710 |
+
assert group in dist.entry_points
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
class TestMeta:
|
| 714 |
+
def test_example_file_in_sdist(self, setuptools_sdist):
|
| 715 |
+
"""Meta test to ensure tests can run from sdist"""
|
| 716 |
+
with tarfile.open(setuptools_sdist) as tar:
|
| 717 |
+
assert any(name.endswith(EXAMPLES_FILE) for name in tar.getnames())
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
class TestInteropCommandLineParsing:
|
| 721 |
+
def test_version(self, tmp_path, monkeypatch, capsys):
|
| 722 |
+
# See pypa/setuptools#4047
|
| 723 |
+
# This test can be removed once the CLI interface of setup.py is removed
|
| 724 |
+
monkeypatch.chdir(tmp_path)
|
| 725 |
+
toml_config = """
|
| 726 |
+
[project]
|
| 727 |
+
name = "test"
|
| 728 |
+
version = "42.0"
|
| 729 |
+
"""
|
| 730 |
+
pyproject = Path(tmp_path, "pyproject.toml")
|
| 731 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 732 |
+
opts = {"script_args": ["--version"]}
|
| 733 |
+
dist = pyprojecttoml.apply_configuration(Distribution(opts), pyproject)
|
| 734 |
+
dist.parse_command_line() # <-- there should be no exception here.
|
| 735 |
+
captured = capsys.readouterr()
|
| 736 |
+
assert "42.0" in captured.out
|
| 737 |
+
|
| 738 |
+
|
| 739 |
+
class TestStaticConfig:
|
| 740 |
+
def test_mark_static_fields(self, tmp_path, monkeypatch):
|
| 741 |
+
monkeypatch.chdir(tmp_path)
|
| 742 |
+
toml_config = """
|
| 743 |
+
[project]
|
| 744 |
+
name = "test"
|
| 745 |
+
version = "42.0"
|
| 746 |
+
dependencies = ["hello"]
|
| 747 |
+
keywords = ["world"]
|
| 748 |
+
classifiers = ["private :: hello world"]
|
| 749 |
+
[tool.setuptools]
|
| 750 |
+
obsoletes = ["abcd"]
|
| 751 |
+
provides = ["abcd"]
|
| 752 |
+
platforms = ["abcd"]
|
| 753 |
+
"""
|
| 754 |
+
pyproject = Path(tmp_path, "pyproject.toml")
|
| 755 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 756 |
+
dist = pyprojecttoml.apply_configuration(Distribution({}), pyproject)
|
| 757 |
+
assert is_static(dist.install_requires)
|
| 758 |
+
assert is_static(dist.metadata.keywords)
|
| 759 |
+
assert is_static(dist.metadata.classifiers)
|
| 760 |
+
assert is_static(dist.metadata.obsoletes)
|
| 761 |
+
assert is_static(dist.metadata.provides)
|
| 762 |
+
assert is_static(dist.metadata.platforms)
|
| 763 |
+
|
| 764 |
+
|
| 765 |
+
# --- Auxiliary Functions ---
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
def core_metadata(dist) -> str:
|
| 769 |
+
with io.StringIO() as buffer:
|
| 770 |
+
dist.metadata.write_pkg_file(buffer)
|
| 771 |
+
pkg_file_txt = buffer.getvalue()
|
| 772 |
+
|
| 773 |
+
# Make sure core metadata is valid
|
| 774 |
+
Metadata.from_email(pkg_file_txt, validate=True) # can raise exceptions
|
| 775 |
+
|
| 776 |
+
skip_prefixes: tuple[str, ...] = ()
|
| 777 |
+
skip_lines = set()
|
| 778 |
+
# ---- DIFF NORMALISATION ----
|
| 779 |
+
# PEP 621 is very particular about author/maintainer metadata conversion, so skip
|
| 780 |
+
skip_prefixes += ("Author:", "Author-email:", "Maintainer:", "Maintainer-email:")
|
| 781 |
+
# May be redundant with Home-page
|
| 782 |
+
skip_prefixes += ("Project-URL: Homepage,", "Home-page:")
|
| 783 |
+
# May be missing in original (relying on default) but backfilled in the TOML
|
| 784 |
+
skip_prefixes += ("Description-Content-Type:",)
|
| 785 |
+
# Remove empty lines
|
| 786 |
+
skip_lines.add("")
|
| 787 |
+
|
| 788 |
+
result = []
|
| 789 |
+
for line in pkg_file_txt.splitlines():
|
| 790 |
+
if line.startswith(skip_prefixes) or line in skip_lines:
|
| 791 |
+
continue
|
| 792 |
+
result.append(line + "\n")
|
| 793 |
+
|
| 794 |
+
return "".join(result)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_expand.py
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from setuptools._static import is_static
|
| 8 |
+
from setuptools.config import expand
|
| 9 |
+
from setuptools.discovery import find_package_path
|
| 10 |
+
|
| 11 |
+
from distutils.errors import DistutilsOptionError
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def write_files(files, root_dir):
|
| 15 |
+
for file, content in files.items():
|
| 16 |
+
path = root_dir / file
|
| 17 |
+
path.parent.mkdir(exist_ok=True, parents=True)
|
| 18 |
+
path.write_text(content, encoding="utf-8")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_glob_relative(tmp_path, monkeypatch):
|
| 22 |
+
files = {
|
| 23 |
+
"dir1/dir2/dir3/file1.txt",
|
| 24 |
+
"dir1/dir2/file2.txt",
|
| 25 |
+
"dir1/file3.txt",
|
| 26 |
+
"a.ini",
|
| 27 |
+
"b.ini",
|
| 28 |
+
"dir1/c.ini",
|
| 29 |
+
"dir1/dir2/a.ini",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
write_files({k: "" for k in files}, tmp_path)
|
| 33 |
+
patterns = ["**/*.txt", "[ab].*", "**/[ac].ini"]
|
| 34 |
+
monkeypatch.chdir(tmp_path)
|
| 35 |
+
assert set(expand.glob_relative(patterns)) == files
|
| 36 |
+
# Make sure the same APIs work outside cwd
|
| 37 |
+
assert set(expand.glob_relative(patterns, tmp_path)) == files
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def test_read_files(tmp_path, monkeypatch):
|
| 41 |
+
dir_ = tmp_path / "dir_"
|
| 42 |
+
(tmp_path / "_dir").mkdir(exist_ok=True)
|
| 43 |
+
(tmp_path / "a.txt").touch()
|
| 44 |
+
files = {"a.txt": "a", "dir1/b.txt": "b", "dir1/dir2/c.txt": "c"}
|
| 45 |
+
write_files(files, dir_)
|
| 46 |
+
|
| 47 |
+
secrets = Path(str(dir_) + "secrets")
|
| 48 |
+
secrets.mkdir(exist_ok=True)
|
| 49 |
+
write_files({"secrets.txt": "secret keys"}, secrets)
|
| 50 |
+
|
| 51 |
+
with monkeypatch.context() as m:
|
| 52 |
+
m.chdir(dir_)
|
| 53 |
+
assert expand.read_files(list(files)) == "a\nb\nc"
|
| 54 |
+
|
| 55 |
+
cannot_access_msg = r"Cannot access '.*\.\..a\.txt'"
|
| 56 |
+
with pytest.raises(DistutilsOptionError, match=cannot_access_msg):
|
| 57 |
+
expand.read_files(["../a.txt"])
|
| 58 |
+
|
| 59 |
+
cannot_access_secrets_msg = r"Cannot access '.*secrets\.txt'"
|
| 60 |
+
with pytest.raises(DistutilsOptionError, match=cannot_access_secrets_msg):
|
| 61 |
+
expand.read_files(["../dir_secrets/secrets.txt"])
|
| 62 |
+
|
| 63 |
+
# Make sure the same APIs work outside cwd
|
| 64 |
+
assert expand.read_files(list(files), dir_) == "a\nb\nc"
|
| 65 |
+
with pytest.raises(DistutilsOptionError, match=cannot_access_msg):
|
| 66 |
+
expand.read_files(["../a.txt"], dir_)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class TestReadAttr:
|
| 70 |
+
@pytest.mark.parametrize(
|
| 71 |
+
"example",
|
| 72 |
+
[
|
| 73 |
+
# No cookie means UTF-8:
|
| 74 |
+
b"__version__ = '\xc3\xa9'\nraise SystemExit(1)\n",
|
| 75 |
+
# If a cookie is present, honor it:
|
| 76 |
+
b"# -*- coding: utf-8 -*-\n__version__ = '\xc3\xa9'\nraise SystemExit(1)\n",
|
| 77 |
+
b"# -*- coding: latin1 -*-\n__version__ = '\xe9'\nraise SystemExit(1)\n",
|
| 78 |
+
],
|
| 79 |
+
)
|
| 80 |
+
def test_read_attr_encoding_cookie(self, example, tmp_path):
|
| 81 |
+
(tmp_path / "mod.py").write_bytes(example)
|
| 82 |
+
assert expand.read_attr('mod.__version__', root_dir=tmp_path) == 'é'
|
| 83 |
+
|
| 84 |
+
def test_read_attr(self, tmp_path, monkeypatch):
|
| 85 |
+
files = {
|
| 86 |
+
"pkg/__init__.py": "",
|
| 87 |
+
"pkg/sub/__init__.py": "VERSION = '0.1.1'",
|
| 88 |
+
"pkg/sub/mod.py": (
|
| 89 |
+
"VALUES = {'a': 0, 'b': {42}, 'c': (0, 1, 1)}\nraise SystemExit(1)"
|
| 90 |
+
),
|
| 91 |
+
}
|
| 92 |
+
write_files(files, tmp_path)
|
| 93 |
+
|
| 94 |
+
with monkeypatch.context() as m:
|
| 95 |
+
m.chdir(tmp_path)
|
| 96 |
+
# Make sure it can read the attr statically without evaluating the module
|
| 97 |
+
version = expand.read_attr('pkg.sub.VERSION')
|
| 98 |
+
values = expand.read_attr('lib.mod.VALUES', {'lib': 'pkg/sub'})
|
| 99 |
+
|
| 100 |
+
assert version == '0.1.1'
|
| 101 |
+
assert is_static(values)
|
| 102 |
+
|
| 103 |
+
assert values['a'] == 0
|
| 104 |
+
assert values['b'] == {42}
|
| 105 |
+
assert is_static(values)
|
| 106 |
+
|
| 107 |
+
# Make sure the same APIs work outside cwd
|
| 108 |
+
assert expand.read_attr('pkg.sub.VERSION', root_dir=tmp_path) == '0.1.1'
|
| 109 |
+
values = expand.read_attr('lib.mod.VALUES', {'lib': 'pkg/sub'}, tmp_path)
|
| 110 |
+
assert values['c'] == (0, 1, 1)
|
| 111 |
+
|
| 112 |
+
@pytest.mark.parametrize(
|
| 113 |
+
"example",
|
| 114 |
+
[
|
| 115 |
+
"VERSION: str\nVERSION = '0.1.1'\nraise SystemExit(1)\n",
|
| 116 |
+
"VERSION: str = '0.1.1'\nraise SystemExit(1)\n",
|
| 117 |
+
],
|
| 118 |
+
)
|
| 119 |
+
def test_read_annotated_attr(self, tmp_path, example):
|
| 120 |
+
files = {
|
| 121 |
+
"pkg/__init__.py": "",
|
| 122 |
+
"pkg/sub/__init__.py": example,
|
| 123 |
+
}
|
| 124 |
+
write_files(files, tmp_path)
|
| 125 |
+
# Make sure this attribute can be read statically
|
| 126 |
+
version = expand.read_attr('pkg.sub.VERSION', root_dir=tmp_path)
|
| 127 |
+
assert version == '0.1.1'
|
| 128 |
+
assert is_static(version)
|
| 129 |
+
|
| 130 |
+
@pytest.mark.parametrize(
|
| 131 |
+
"example",
|
| 132 |
+
[
|
| 133 |
+
"VERSION = (lambda: '0.1.1')()\n",
|
| 134 |
+
"def fn(): return '0.1.1'\nVERSION = fn()\n",
|
| 135 |
+
"VERSION: str = (lambda: '0.1.1')()\n",
|
| 136 |
+
],
|
| 137 |
+
)
|
| 138 |
+
def test_read_dynamic_attr(self, tmp_path, monkeypatch, example):
|
| 139 |
+
files = {
|
| 140 |
+
"pkg/__init__.py": "",
|
| 141 |
+
"pkg/sub/__init__.py": example,
|
| 142 |
+
}
|
| 143 |
+
write_files(files, tmp_path)
|
| 144 |
+
monkeypatch.chdir(tmp_path)
|
| 145 |
+
version = expand.read_attr('pkg.sub.VERSION')
|
| 146 |
+
assert version == '0.1.1'
|
| 147 |
+
assert not is_static(version)
|
| 148 |
+
|
| 149 |
+
def test_import_order(self, tmp_path):
|
| 150 |
+
"""
|
| 151 |
+
Sometimes the import machinery will import the parent package of a nested
|
| 152 |
+
module, which triggers side-effects and might create problems (see issue #3176)
|
| 153 |
+
|
| 154 |
+
``read_attr`` should bypass these limitations by resolving modules statically
|
| 155 |
+
(via ast.literal_eval).
|
| 156 |
+
"""
|
| 157 |
+
files = {
|
| 158 |
+
"src/pkg/__init__.py": "from .main import func\nfrom .about import version",
|
| 159 |
+
"src/pkg/main.py": "import super_complicated_dep\ndef func(): return 42",
|
| 160 |
+
"src/pkg/about.py": "version = '42'",
|
| 161 |
+
}
|
| 162 |
+
write_files(files, tmp_path)
|
| 163 |
+
attr_desc = "pkg.about.version"
|
| 164 |
+
package_dir = {"": "src"}
|
| 165 |
+
# `import super_complicated_dep` should not run, otherwise the build fails
|
| 166 |
+
assert expand.read_attr(attr_desc, package_dir, tmp_path) == "42"
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
@pytest.mark.parametrize(
|
| 170 |
+
("package_dir", "file", "module", "return_value"),
|
| 171 |
+
[
|
| 172 |
+
({"": "src"}, "src/pkg/main.py", "pkg.main", 42),
|
| 173 |
+
({"pkg": "lib"}, "lib/main.py", "pkg.main", 13),
|
| 174 |
+
({}, "single_module.py", "single_module", 70),
|
| 175 |
+
({}, "flat_layout/pkg.py", "flat_layout.pkg", 836),
|
| 176 |
+
],
|
| 177 |
+
)
|
| 178 |
+
def test_resolve_class(monkeypatch, tmp_path, package_dir, file, module, return_value):
|
| 179 |
+
monkeypatch.setattr(sys, "modules", {}) # reproducibility
|
| 180 |
+
files = {file: f"class Custom:\n def testing(self): return {return_value}"}
|
| 181 |
+
write_files(files, tmp_path)
|
| 182 |
+
cls = expand.resolve_class(f"{module}.Custom", package_dir, tmp_path)
|
| 183 |
+
assert cls().testing() == return_value
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
@pytest.mark.parametrize(
|
| 187 |
+
("args", "pkgs"),
|
| 188 |
+
[
|
| 189 |
+
({"where": ["."], "namespaces": False}, {"pkg", "other"}),
|
| 190 |
+
({"where": [".", "dir1"], "namespaces": False}, {"pkg", "other", "dir2"}),
|
| 191 |
+
({"namespaces": True}, {"pkg", "other", "dir1", "dir1.dir2"}),
|
| 192 |
+
({}, {"pkg", "other", "dir1", "dir1.dir2"}), # default value for `namespaces`
|
| 193 |
+
],
|
| 194 |
+
)
|
| 195 |
+
def test_find_packages(tmp_path, args, pkgs):
|
| 196 |
+
files = {
|
| 197 |
+
"pkg/__init__.py",
|
| 198 |
+
"other/__init__.py",
|
| 199 |
+
"dir1/dir2/__init__.py",
|
| 200 |
+
}
|
| 201 |
+
write_files({k: "" for k in files}, tmp_path)
|
| 202 |
+
|
| 203 |
+
package_dir = {}
|
| 204 |
+
kwargs = {"root_dir": tmp_path, "fill_package_dir": package_dir, **args}
|
| 205 |
+
where = kwargs.get("where", ["."])
|
| 206 |
+
assert set(expand.find_packages(**kwargs)) == pkgs
|
| 207 |
+
for pkg in pkgs:
|
| 208 |
+
pkg_path = find_package_path(pkg, package_dir, tmp_path)
|
| 209 |
+
assert os.path.exists(pkg_path)
|
| 210 |
+
|
| 211 |
+
# Make sure the same APIs work outside cwd
|
| 212 |
+
where = [
|
| 213 |
+
str((tmp_path / p).resolve()).replace(os.sep, "/") # ensure posix-style paths
|
| 214 |
+
for p in args.pop("where", ["."])
|
| 215 |
+
]
|
| 216 |
+
|
| 217 |
+
assert set(expand.find_packages(where=where, **args)) == pkgs
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
@pytest.mark.parametrize(
|
| 221 |
+
("files", "where", "expected_package_dir"),
|
| 222 |
+
[
|
| 223 |
+
(["pkg1/__init__.py", "pkg1/other.py"], ["."], {}),
|
| 224 |
+
(["pkg1/__init__.py", "pkg2/__init__.py"], ["."], {}),
|
| 225 |
+
(["src/pkg1/__init__.py", "src/pkg1/other.py"], ["src"], {"": "src"}),
|
| 226 |
+
(["src/pkg1/__init__.py", "src/pkg2/__init__.py"], ["src"], {"": "src"}),
|
| 227 |
+
(
|
| 228 |
+
["src1/pkg1/__init__.py", "src2/pkg2/__init__.py"],
|
| 229 |
+
["src1", "src2"],
|
| 230 |
+
{"pkg1": "src1/pkg1", "pkg2": "src2/pkg2"},
|
| 231 |
+
),
|
| 232 |
+
(
|
| 233 |
+
["src/pkg1/__init__.py", "pkg2/__init__.py"],
|
| 234 |
+
["src", "."],
|
| 235 |
+
{"pkg1": "src/pkg1"},
|
| 236 |
+
),
|
| 237 |
+
],
|
| 238 |
+
)
|
| 239 |
+
def test_fill_package_dir(tmp_path, files, where, expected_package_dir):
|
| 240 |
+
write_files({k: "" for k in files}, tmp_path)
|
| 241 |
+
pkg_dir = {}
|
| 242 |
+
kwargs = {"root_dir": tmp_path, "fill_package_dir": pkg_dir, "namespaces": False}
|
| 243 |
+
pkgs = expand.find_packages(where=where, **kwargs)
|
| 244 |
+
assert set(pkg_dir.items()) == set(expected_package_dir.items())
|
| 245 |
+
for pkg in pkgs:
|
| 246 |
+
pkg_path = find_package_path(pkg, pkg_dir, tmp_path)
|
| 247 |
+
assert os.path.exists(pkg_path)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_pyprojecttoml.py
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
from configparser import ConfigParser
|
| 3 |
+
from inspect import cleandoc
|
| 4 |
+
|
| 5 |
+
import jaraco.path
|
| 6 |
+
import pytest
|
| 7 |
+
import tomli_w
|
| 8 |
+
from path import Path
|
| 9 |
+
|
| 10 |
+
import setuptools # noqa: F401 # force distutils.core to be patched
|
| 11 |
+
from setuptools.config.pyprojecttoml import (
|
| 12 |
+
_ToolsTypoInMetadata,
|
| 13 |
+
apply_configuration,
|
| 14 |
+
expand_configuration,
|
| 15 |
+
read_configuration,
|
| 16 |
+
validate,
|
| 17 |
+
)
|
| 18 |
+
from setuptools.dist import Distribution
|
| 19 |
+
from setuptools.errors import OptionError
|
| 20 |
+
|
| 21 |
+
import distutils.core
|
| 22 |
+
|
| 23 |
+
EXAMPLE = """
|
| 24 |
+
[project]
|
| 25 |
+
name = "myproj"
|
| 26 |
+
keywords = ["some", "key", "words"]
|
| 27 |
+
dynamic = ["version", "readme"]
|
| 28 |
+
requires-python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
| 29 |
+
dependencies = [
|
| 30 |
+
'importlib-metadata>=0.12;python_version<"3.8"',
|
| 31 |
+
'importlib-resources>=1.0;python_version<"3.7"',
|
| 32 |
+
'pathlib2>=2.3.3,<3;python_version < "3.4" and sys.platform != "win32"',
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
[project.optional-dependencies]
|
| 36 |
+
docs = [
|
| 37 |
+
"sphinx>=3",
|
| 38 |
+
"sphinx-argparse>=0.2.5",
|
| 39 |
+
"sphinx-rtd-theme>=0.4.3",
|
| 40 |
+
]
|
| 41 |
+
testing = [
|
| 42 |
+
"pytest>=1",
|
| 43 |
+
"coverage>=3,<5",
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
[project.scripts]
|
| 47 |
+
exec = "pkg.__main__:exec"
|
| 48 |
+
|
| 49 |
+
[build-system]
|
| 50 |
+
requires = ["setuptools", "wheel"]
|
| 51 |
+
build-backend = "setuptools.build_meta"
|
| 52 |
+
|
| 53 |
+
[tool.setuptools]
|
| 54 |
+
package-dir = {"" = "src"}
|
| 55 |
+
zip-safe = true
|
| 56 |
+
platforms = ["any"]
|
| 57 |
+
|
| 58 |
+
[tool.setuptools.packages.find]
|
| 59 |
+
where = ["src"]
|
| 60 |
+
|
| 61 |
+
[tool.setuptools.cmdclass]
|
| 62 |
+
sdist = "pkg.mod.CustomSdist"
|
| 63 |
+
|
| 64 |
+
[tool.setuptools.dynamic.version]
|
| 65 |
+
attr = "pkg.__version__.VERSION"
|
| 66 |
+
|
| 67 |
+
[tool.setuptools.dynamic.readme]
|
| 68 |
+
file = ["README.md"]
|
| 69 |
+
content-type = "text/markdown"
|
| 70 |
+
|
| 71 |
+
[tool.setuptools.package-data]
|
| 72 |
+
"*" = ["*.txt"]
|
| 73 |
+
|
| 74 |
+
[tool.setuptools.data-files]
|
| 75 |
+
"data" = ["_files/*.txt"]
|
| 76 |
+
|
| 77 |
+
[tool.distutils.sdist]
|
| 78 |
+
formats = "gztar"
|
| 79 |
+
|
| 80 |
+
[tool.distutils.bdist_wheel]
|
| 81 |
+
universal = true
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def create_example(path, pkg_root):
|
| 86 |
+
files = {
|
| 87 |
+
"pyproject.toml": EXAMPLE,
|
| 88 |
+
"README.md": "hello world",
|
| 89 |
+
"_files": {
|
| 90 |
+
"file.txt": "",
|
| 91 |
+
},
|
| 92 |
+
}
|
| 93 |
+
packages = {
|
| 94 |
+
"pkg": {
|
| 95 |
+
"__init__.py": "",
|
| 96 |
+
"mod.py": "class CustomSdist: pass",
|
| 97 |
+
"__version__.py": "VERSION = (3, 10)",
|
| 98 |
+
"__main__.py": "def exec(): print('hello')",
|
| 99 |
+
},
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
assert pkg_root # Meta-test: cannot be empty string.
|
| 103 |
+
|
| 104 |
+
if pkg_root == ".":
|
| 105 |
+
files = {**files, **packages}
|
| 106 |
+
# skip other files: flat-layout will raise error for multi-package dist
|
| 107 |
+
else:
|
| 108 |
+
# Use this opportunity to ensure namespaces are discovered
|
| 109 |
+
files[pkg_root] = {**packages, "other": {"nested": {"__init__.py": ""}}}
|
| 110 |
+
|
| 111 |
+
jaraco.path.build(files, prefix=path)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def verify_example(config, path, pkg_root):
|
| 115 |
+
pyproject = path / "pyproject.toml"
|
| 116 |
+
pyproject.write_text(tomli_w.dumps(config), encoding="utf-8")
|
| 117 |
+
expanded = expand_configuration(config, path)
|
| 118 |
+
expanded_project = expanded["project"]
|
| 119 |
+
assert read_configuration(pyproject, expand=True) == expanded
|
| 120 |
+
assert expanded_project["version"] == "3.10"
|
| 121 |
+
assert expanded_project["readme"]["text"] == "hello world"
|
| 122 |
+
assert "packages" in expanded["tool"]["setuptools"]
|
| 123 |
+
if pkg_root == ".":
|
| 124 |
+
# Auto-discovery will raise error for multi-package dist
|
| 125 |
+
assert set(expanded["tool"]["setuptools"]["packages"]) == {"pkg"}
|
| 126 |
+
else:
|
| 127 |
+
assert set(expanded["tool"]["setuptools"]["packages"]) == {
|
| 128 |
+
"pkg",
|
| 129 |
+
"other",
|
| 130 |
+
"other.nested",
|
| 131 |
+
}
|
| 132 |
+
assert expanded["tool"]["setuptools"]["include-package-data"] is True
|
| 133 |
+
assert "" in expanded["tool"]["setuptools"]["package-data"]
|
| 134 |
+
assert "*" not in expanded["tool"]["setuptools"]["package-data"]
|
| 135 |
+
assert expanded["tool"]["setuptools"]["data-files"] == [
|
| 136 |
+
("data", ["_files/file.txt"])
|
| 137 |
+
]
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def test_read_configuration(tmp_path):
|
| 141 |
+
create_example(tmp_path, "src")
|
| 142 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 143 |
+
|
| 144 |
+
config = read_configuration(pyproject, expand=False)
|
| 145 |
+
assert config["project"].get("version") is None
|
| 146 |
+
assert config["project"].get("readme") is None
|
| 147 |
+
|
| 148 |
+
verify_example(config, tmp_path, "src")
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
@pytest.mark.parametrize(
|
| 152 |
+
("pkg_root", "opts"),
|
| 153 |
+
[
|
| 154 |
+
(".", {}),
|
| 155 |
+
("src", {}),
|
| 156 |
+
("lib", {"packages": {"find": {"where": ["lib"]}}}),
|
| 157 |
+
],
|
| 158 |
+
)
|
| 159 |
+
def test_discovered_package_dir_with_attr_directive_in_config(tmp_path, pkg_root, opts):
|
| 160 |
+
create_example(tmp_path, pkg_root)
|
| 161 |
+
|
| 162 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 163 |
+
|
| 164 |
+
config = read_configuration(pyproject, expand=False)
|
| 165 |
+
assert config["project"].get("version") is None
|
| 166 |
+
assert config["project"].get("readme") is None
|
| 167 |
+
config["tool"]["setuptools"].pop("packages", None)
|
| 168 |
+
config["tool"]["setuptools"].pop("package-dir", None)
|
| 169 |
+
|
| 170 |
+
config["tool"]["setuptools"].update(opts)
|
| 171 |
+
verify_example(config, tmp_path, pkg_root)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
ENTRY_POINTS = {
|
| 175 |
+
"console_scripts": {"a": "mod.a:func"},
|
| 176 |
+
"gui_scripts": {"b": "mod.b:func"},
|
| 177 |
+
"other": {"c": "mod.c:func [extra]"},
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class TestEntryPoints:
|
| 182 |
+
def write_entry_points(self, tmp_path):
|
| 183 |
+
entry_points = ConfigParser()
|
| 184 |
+
entry_points.read_dict(ENTRY_POINTS)
|
| 185 |
+
with open(tmp_path / "entry-points.txt", "w", encoding="utf-8") as f:
|
| 186 |
+
entry_points.write(f)
|
| 187 |
+
|
| 188 |
+
def pyproject(self, dynamic=None):
|
| 189 |
+
project = {"dynamic": dynamic or ["scripts", "gui-scripts", "entry-points"]}
|
| 190 |
+
tool = {"dynamic": {"entry-points": {"file": "entry-points.txt"}}}
|
| 191 |
+
return {"project": project, "tool": {"setuptools": tool}}
|
| 192 |
+
|
| 193 |
+
def test_all_listed_in_dynamic(self, tmp_path):
|
| 194 |
+
self.write_entry_points(tmp_path)
|
| 195 |
+
expanded = expand_configuration(self.pyproject(), tmp_path)
|
| 196 |
+
expanded_project = expanded["project"]
|
| 197 |
+
assert len(expanded_project["scripts"]) == 1
|
| 198 |
+
assert expanded_project["scripts"]["a"] == "mod.a:func"
|
| 199 |
+
assert len(expanded_project["gui-scripts"]) == 1
|
| 200 |
+
assert expanded_project["gui-scripts"]["b"] == "mod.b:func"
|
| 201 |
+
assert len(expanded_project["entry-points"]) == 1
|
| 202 |
+
assert expanded_project["entry-points"]["other"]["c"] == "mod.c:func [extra]"
|
| 203 |
+
|
| 204 |
+
@pytest.mark.parametrize("missing_dynamic", ("scripts", "gui-scripts"))
|
| 205 |
+
def test_scripts_not_listed_in_dynamic(self, tmp_path, missing_dynamic):
|
| 206 |
+
self.write_entry_points(tmp_path)
|
| 207 |
+
dynamic = {"scripts", "gui-scripts", "entry-points"} - {missing_dynamic}
|
| 208 |
+
|
| 209 |
+
msg = f"defined outside of `pyproject.toml`:.*{missing_dynamic}"
|
| 210 |
+
with pytest.raises(OptionError, match=re.compile(msg, re.DOTALL)):
|
| 211 |
+
expand_configuration(self.pyproject(dynamic), tmp_path)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class TestClassifiers:
|
| 215 |
+
def test_dynamic(self, tmp_path):
|
| 216 |
+
# Let's create a project example that has dynamic classifiers
|
| 217 |
+
# coming from a txt file.
|
| 218 |
+
create_example(tmp_path, "src")
|
| 219 |
+
classifiers = cleandoc(
|
| 220 |
+
"""
|
| 221 |
+
Framework :: Flask
|
| 222 |
+
Programming Language :: Haskell
|
| 223 |
+
"""
|
| 224 |
+
)
|
| 225 |
+
(tmp_path / "classifiers.txt").write_text(classifiers, encoding="utf-8")
|
| 226 |
+
|
| 227 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 228 |
+
config = read_configuration(pyproject, expand=False)
|
| 229 |
+
dynamic = config["project"]["dynamic"]
|
| 230 |
+
config["project"]["dynamic"] = list({*dynamic, "classifiers"})
|
| 231 |
+
dynamic_config = config["tool"]["setuptools"]["dynamic"]
|
| 232 |
+
dynamic_config["classifiers"] = {"file": "classifiers.txt"}
|
| 233 |
+
|
| 234 |
+
# When the configuration is expanded,
|
| 235 |
+
# each line of the file should be an different classifier.
|
| 236 |
+
validate(config, pyproject)
|
| 237 |
+
expanded = expand_configuration(config, tmp_path)
|
| 238 |
+
|
| 239 |
+
assert set(expanded["project"]["classifiers"]) == {
|
| 240 |
+
"Framework :: Flask",
|
| 241 |
+
"Programming Language :: Haskell",
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
def test_dynamic_without_config(self, tmp_path):
|
| 245 |
+
config = """
|
| 246 |
+
[project]
|
| 247 |
+
name = "myproj"
|
| 248 |
+
version = '42'
|
| 249 |
+
dynamic = ["classifiers"]
|
| 250 |
+
"""
|
| 251 |
+
|
| 252 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 253 |
+
pyproject.write_text(cleandoc(config), encoding="utf-8")
|
| 254 |
+
with pytest.raises(OptionError, match="No configuration .* .classifiers."):
|
| 255 |
+
read_configuration(pyproject)
|
| 256 |
+
|
| 257 |
+
def test_dynamic_readme_from_setup_script_args(self, tmp_path):
|
| 258 |
+
config = """
|
| 259 |
+
[project]
|
| 260 |
+
name = "myproj"
|
| 261 |
+
version = '42'
|
| 262 |
+
dynamic = ["readme"]
|
| 263 |
+
"""
|
| 264 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 265 |
+
pyproject.write_text(cleandoc(config), encoding="utf-8")
|
| 266 |
+
dist = Distribution(attrs={"long_description": "42"})
|
| 267 |
+
# No error should occur because of missing `readme`
|
| 268 |
+
dist = apply_configuration(dist, pyproject)
|
| 269 |
+
assert dist.metadata.long_description == "42"
|
| 270 |
+
|
| 271 |
+
def test_dynamic_without_file(self, tmp_path):
|
| 272 |
+
config = """
|
| 273 |
+
[project]
|
| 274 |
+
name = "myproj"
|
| 275 |
+
version = '42'
|
| 276 |
+
dynamic = ["classifiers"]
|
| 277 |
+
|
| 278 |
+
[tool.setuptools.dynamic]
|
| 279 |
+
classifiers = {file = ["classifiers.txt"]}
|
| 280 |
+
"""
|
| 281 |
+
|
| 282 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 283 |
+
pyproject.write_text(cleandoc(config), encoding="utf-8")
|
| 284 |
+
with pytest.warns(UserWarning, match="File .*classifiers.txt. cannot be found"):
|
| 285 |
+
expanded = read_configuration(pyproject)
|
| 286 |
+
assert "classifiers" not in expanded["project"]
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
class TestImportNames:
|
| 290 |
+
EXAMPLES = [
|
| 291 |
+
'import-names = ["hello", "world"]',
|
| 292 |
+
'import-namespaces = ["hello", "world"]',
|
| 293 |
+
'dynamic = ["import-names"]',
|
| 294 |
+
'dynamic = ["import-namespaces"]',
|
| 295 |
+
]
|
| 296 |
+
|
| 297 |
+
@pytest.mark.parametrize("example", EXAMPLES)
|
| 298 |
+
def test_not_implemented(self, monkeypatch, tmp_path, example):
|
| 299 |
+
monkeypatch.chdir(tmp_path)
|
| 300 |
+
pyproject = Path("pyproject.toml")
|
| 301 |
+
toml_config = f"""
|
| 302 |
+
[project]
|
| 303 |
+
name = 'proj'
|
| 304 |
+
version = '42'
|
| 305 |
+
{example}
|
| 306 |
+
"""
|
| 307 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 308 |
+
with pytest.raises(NotImplementedError, match='import-names'):
|
| 309 |
+
apply_configuration(Distribution({}), pyproject)
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
@pytest.mark.parametrize(
|
| 313 |
+
"example",
|
| 314 |
+
(
|
| 315 |
+
"""
|
| 316 |
+
[project]
|
| 317 |
+
name = "myproj"
|
| 318 |
+
version = "1.2"
|
| 319 |
+
|
| 320 |
+
[my-tool.that-disrespect.pep518]
|
| 321 |
+
value = 42
|
| 322 |
+
""",
|
| 323 |
+
),
|
| 324 |
+
)
|
| 325 |
+
def test_ignore_unrelated_config(tmp_path, example):
|
| 326 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 327 |
+
pyproject.write_text(cleandoc(example), encoding="utf-8")
|
| 328 |
+
|
| 329 |
+
# Make sure no error is raised due to 3rd party configs in pyproject.toml
|
| 330 |
+
assert read_configuration(pyproject) is not None
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
@pytest.mark.parametrize(
|
| 334 |
+
("example", "error_msg"),
|
| 335 |
+
[
|
| 336 |
+
(
|
| 337 |
+
"""
|
| 338 |
+
[project]
|
| 339 |
+
name = "myproj"
|
| 340 |
+
version = "1.2"
|
| 341 |
+
requires = ['pywin32; platform_system=="Windows"' ]
|
| 342 |
+
""",
|
| 343 |
+
"configuration error: .project. must not contain ..requires.. properties",
|
| 344 |
+
),
|
| 345 |
+
],
|
| 346 |
+
)
|
| 347 |
+
def test_invalid_example(tmp_path, example, error_msg):
|
| 348 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 349 |
+
pyproject.write_text(cleandoc(example), encoding="utf-8")
|
| 350 |
+
|
| 351 |
+
pattern = re.compile(
|
| 352 |
+
f"invalid pyproject.toml.*{error_msg}.*", re.MULTILINE | re.DOTALL
|
| 353 |
+
)
|
| 354 |
+
with pytest.raises(ValueError, match=pattern):
|
| 355 |
+
read_configuration(pyproject)
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
@pytest.mark.parametrize("config", ("", "[tool.something]\nvalue = 42"))
|
| 359 |
+
def test_empty(tmp_path, config):
|
| 360 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 361 |
+
pyproject.write_text(config, encoding="utf-8")
|
| 362 |
+
|
| 363 |
+
# Make sure no error is raised
|
| 364 |
+
assert read_configuration(pyproject) == {}
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
@pytest.mark.parametrize("config", ("[project]\nname = 'myproj'\nversion='42'\n",))
|
| 368 |
+
def test_include_package_data_by_default(tmp_path, config):
|
| 369 |
+
"""Builds with ``pyproject.toml`` should consider ``include-package-data=True`` as
|
| 370 |
+
default.
|
| 371 |
+
"""
|
| 372 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 373 |
+
pyproject.write_text(config, encoding="utf-8")
|
| 374 |
+
|
| 375 |
+
config = read_configuration(pyproject)
|
| 376 |
+
assert config["tool"]["setuptools"]["include-package-data"] is True
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def test_include_package_data_in_setuppy(tmp_path):
|
| 380 |
+
"""Builds with ``pyproject.toml`` should consider ``include_package_data`` set in
|
| 381 |
+
``setup.py``.
|
| 382 |
+
|
| 383 |
+
See https://github.com/pypa/setuptools/issues/3197#issuecomment-1079023889
|
| 384 |
+
"""
|
| 385 |
+
files = {
|
| 386 |
+
"pyproject.toml": "[project]\nname = 'myproj'\nversion='42'\n",
|
| 387 |
+
"setup.py": "__import__('setuptools').setup(include_package_data=False)",
|
| 388 |
+
}
|
| 389 |
+
jaraco.path.build(files, prefix=tmp_path)
|
| 390 |
+
|
| 391 |
+
with Path(tmp_path):
|
| 392 |
+
dist = distutils.core.run_setup("setup.py", {}, stop_after="config")
|
| 393 |
+
|
| 394 |
+
assert dist.get_name() == "myproj"
|
| 395 |
+
assert dist.get_version() == "42"
|
| 396 |
+
assert dist.include_package_data is False
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def test_warn_tools_typo(tmp_path):
|
| 400 |
+
"""Test that the common ``tools.setuptools`` typo in ``pyproject.toml`` issues a warning
|
| 401 |
+
|
| 402 |
+
See https://github.com/pypa/setuptools/issues/4150
|
| 403 |
+
"""
|
| 404 |
+
config = """
|
| 405 |
+
[build-system]
|
| 406 |
+
requires = ["setuptools"]
|
| 407 |
+
build-backend = "setuptools.build_meta"
|
| 408 |
+
|
| 409 |
+
[project]
|
| 410 |
+
name = "myproj"
|
| 411 |
+
version = '42'
|
| 412 |
+
|
| 413 |
+
[tools.setuptools]
|
| 414 |
+
packages = ["package"]
|
| 415 |
+
"""
|
| 416 |
+
|
| 417 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 418 |
+
pyproject.write_text(cleandoc(config), encoding="utf-8")
|
| 419 |
+
|
| 420 |
+
with pytest.warns(_ToolsTypoInMetadata):
|
| 421 |
+
read_configuration(pyproject)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_pyprojecttoml_dynamic_deps.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from inspect import cleandoc
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
from jaraco import path
|
| 5 |
+
|
| 6 |
+
from setuptools.config.pyprojecttoml import apply_configuration
|
| 7 |
+
from setuptools.dist import Distribution
|
| 8 |
+
from setuptools.warnings import SetuptoolsWarning
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_dynamic_dependencies(tmp_path):
|
| 12 |
+
files = {
|
| 13 |
+
"requirements.txt": "six\n # comment\n",
|
| 14 |
+
"pyproject.toml": cleandoc(
|
| 15 |
+
"""
|
| 16 |
+
[project]
|
| 17 |
+
name = "myproj"
|
| 18 |
+
version = "1.0"
|
| 19 |
+
dynamic = ["dependencies"]
|
| 20 |
+
|
| 21 |
+
[build-system]
|
| 22 |
+
requires = ["setuptools", "wheel"]
|
| 23 |
+
build-backend = "setuptools.build_meta"
|
| 24 |
+
|
| 25 |
+
[tool.setuptools.dynamic.dependencies]
|
| 26 |
+
file = ["requirements.txt"]
|
| 27 |
+
"""
|
| 28 |
+
),
|
| 29 |
+
}
|
| 30 |
+
path.build(files, prefix=tmp_path)
|
| 31 |
+
dist = Distribution()
|
| 32 |
+
dist = apply_configuration(dist, tmp_path / "pyproject.toml")
|
| 33 |
+
assert dist.install_requires == ["six"]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_dynamic_optional_dependencies(tmp_path):
|
| 37 |
+
files = {
|
| 38 |
+
"requirements-docs.txt": "sphinx\n # comment\n",
|
| 39 |
+
"pyproject.toml": cleandoc(
|
| 40 |
+
"""
|
| 41 |
+
[project]
|
| 42 |
+
name = "myproj"
|
| 43 |
+
version = "1.0"
|
| 44 |
+
dynamic = ["optional-dependencies"]
|
| 45 |
+
|
| 46 |
+
[tool.setuptools.dynamic.optional-dependencies.docs]
|
| 47 |
+
file = ["requirements-docs.txt"]
|
| 48 |
+
|
| 49 |
+
[build-system]
|
| 50 |
+
requires = ["setuptools", "wheel"]
|
| 51 |
+
build-backend = "setuptools.build_meta"
|
| 52 |
+
"""
|
| 53 |
+
),
|
| 54 |
+
}
|
| 55 |
+
path.build(files, prefix=tmp_path)
|
| 56 |
+
dist = Distribution()
|
| 57 |
+
dist = apply_configuration(dist, tmp_path / "pyproject.toml")
|
| 58 |
+
assert dist.extras_require == {"docs": ["sphinx"]}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def test_mixed_dynamic_optional_dependencies(tmp_path):
|
| 62 |
+
"""
|
| 63 |
+
Test that if PEP 621 was loosened to allow mixing of dynamic and static
|
| 64 |
+
configurations in the case of fields containing sub-fields (groups),
|
| 65 |
+
things would work out.
|
| 66 |
+
"""
|
| 67 |
+
files = {
|
| 68 |
+
"requirements-images.txt": "pillow~=42.0\n # comment\n",
|
| 69 |
+
"pyproject.toml": cleandoc(
|
| 70 |
+
"""
|
| 71 |
+
[project]
|
| 72 |
+
name = "myproj"
|
| 73 |
+
version = "1.0"
|
| 74 |
+
dynamic = ["optional-dependencies"]
|
| 75 |
+
|
| 76 |
+
[project.optional-dependencies]
|
| 77 |
+
docs = ["sphinx"]
|
| 78 |
+
|
| 79 |
+
[tool.setuptools.dynamic.optional-dependencies.images]
|
| 80 |
+
file = ["requirements-images.txt"]
|
| 81 |
+
"""
|
| 82 |
+
),
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
path.build(files, prefix=tmp_path)
|
| 86 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 87 |
+
with pytest.raises(ValueError, match="project.optional-dependencies"):
|
| 88 |
+
apply_configuration(Distribution(), pyproject)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def test_mixed_extras_require_optional_dependencies(tmp_path):
|
| 92 |
+
files = {
|
| 93 |
+
"pyproject.toml": cleandoc(
|
| 94 |
+
"""
|
| 95 |
+
[project]
|
| 96 |
+
name = "myproj"
|
| 97 |
+
version = "1.0"
|
| 98 |
+
optional-dependencies.docs = ["sphinx"]
|
| 99 |
+
"""
|
| 100 |
+
),
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
path.build(files, prefix=tmp_path)
|
| 104 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 105 |
+
|
| 106 |
+
dist = Distribution({"extras_require": {"hello": ["world"]}})
|
| 107 |
+
|
| 108 |
+
with pytest.warns(SetuptoolsWarning, match=".extras_require. overwritten"):
|
| 109 |
+
dist = apply_configuration(dist, pyproject)
|
| 110 |
+
|
| 111 |
+
assert dist.extras_require == {"docs": ["sphinx"]}
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/tests/config/test_setupcfg.py
ADDED
|
@@ -0,0 +1,987 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import configparser
|
| 2 |
+
import contextlib
|
| 3 |
+
import inspect
|
| 4 |
+
import re
|
| 5 |
+
import sys
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from unittest.mock import Mock, patch
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
from packaging.requirements import InvalidRequirement
|
| 11 |
+
|
| 12 |
+
from setuptools.config.setupcfg import ConfigHandler, Target, read_configuration
|
| 13 |
+
from setuptools.dist import Distribution, _Distribution
|
| 14 |
+
from setuptools.warnings import SetuptoolsDeprecationWarning
|
| 15 |
+
|
| 16 |
+
from ..textwrap import DALS
|
| 17 |
+
|
| 18 |
+
from distutils.errors import DistutilsFileError, DistutilsOptionError
|
| 19 |
+
|
| 20 |
+
IS_PYPY = '__pypy__' in sys.builtin_module_names
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class ErrConfigHandler(ConfigHandler[Target]):
|
| 24 |
+
"""Erroneous handler. Fails to implement required methods."""
|
| 25 |
+
|
| 26 |
+
section_prefix = "**err**"
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def make_package_dir(name, base_dir, ns=False):
|
| 30 |
+
dir_package = base_dir
|
| 31 |
+
for dir_name in name.split('/'):
|
| 32 |
+
dir_package = dir_package.mkdir(dir_name)
|
| 33 |
+
init_file = None
|
| 34 |
+
if not ns:
|
| 35 |
+
init_file = dir_package.join('__init__.py')
|
| 36 |
+
init_file.write('')
|
| 37 |
+
return dir_package, init_file
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def fake_env(
|
| 41 |
+
tmpdir, setup_cfg, setup_py=None, encoding='ascii', package_path='fake_package'
|
| 42 |
+
):
|
| 43 |
+
if setup_py is None:
|
| 44 |
+
setup_py = 'from setuptools import setup\nsetup()\n'
|
| 45 |
+
|
| 46 |
+
tmpdir.join('setup.py').write(setup_py)
|
| 47 |
+
config = tmpdir.join('setup.cfg')
|
| 48 |
+
config.write(setup_cfg.encode(encoding), mode='wb')
|
| 49 |
+
|
| 50 |
+
package_dir, init_file = make_package_dir(package_path, tmpdir)
|
| 51 |
+
|
| 52 |
+
init_file.write(
|
| 53 |
+
'VERSION = (1, 2, 3)\n'
|
| 54 |
+
'\n'
|
| 55 |
+
'VERSION_MAJOR = 1'
|
| 56 |
+
'\n'
|
| 57 |
+
'def get_version():\n'
|
| 58 |
+
' return [3, 4, 5, "dev"]\n'
|
| 59 |
+
'\n'
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
return package_dir, config
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
@contextlib.contextmanager
|
| 66 |
+
def get_dist(tmpdir, kwargs_initial=None, parse=True):
|
| 67 |
+
kwargs_initial = kwargs_initial or {}
|
| 68 |
+
|
| 69 |
+
with tmpdir.as_cwd():
|
| 70 |
+
dist = Distribution(kwargs_initial)
|
| 71 |
+
dist.script_name = 'setup.py'
|
| 72 |
+
parse and dist.parse_config_files()
|
| 73 |
+
|
| 74 |
+
yield dist
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def test_parsers_implemented():
|
| 78 |
+
with pytest.raises(NotImplementedError):
|
| 79 |
+
handler = ErrConfigHandler(None, {}, False, Mock())
|
| 80 |
+
handler.parsers
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class TestConfigurationReader:
|
| 84 |
+
def test_basic(self, tmpdir):
|
| 85 |
+
_, config = fake_env(
|
| 86 |
+
tmpdir,
|
| 87 |
+
'[metadata]\n'
|
| 88 |
+
'version = 10.1.1\n'
|
| 89 |
+
'keywords = one, two\n'
|
| 90 |
+
'\n'
|
| 91 |
+
'[options]\n'
|
| 92 |
+
'scripts = bin/a.py, bin/b.py\n',
|
| 93 |
+
)
|
| 94 |
+
config_dict = read_configuration(str(config))
|
| 95 |
+
assert config_dict['metadata']['version'] == '10.1.1'
|
| 96 |
+
assert config_dict['metadata']['keywords'] == ['one', 'two']
|
| 97 |
+
assert config_dict['options']['scripts'] == ['bin/a.py', 'bin/b.py']
|
| 98 |
+
|
| 99 |
+
def test_no_config(self, tmpdir):
|
| 100 |
+
with pytest.raises(DistutilsFileError):
|
| 101 |
+
read_configuration(str(tmpdir.join('setup.cfg')))
|
| 102 |
+
|
| 103 |
+
def test_ignore_errors(self, tmpdir):
|
| 104 |
+
_, config = fake_env(
|
| 105 |
+
tmpdir,
|
| 106 |
+
'[metadata]\nversion = attr: none.VERSION\nkeywords = one, two\n',
|
| 107 |
+
)
|
| 108 |
+
with pytest.raises(ImportError):
|
| 109 |
+
read_configuration(str(config))
|
| 110 |
+
|
| 111 |
+
config_dict = read_configuration(str(config), ignore_option_errors=True)
|
| 112 |
+
|
| 113 |
+
assert config_dict['metadata']['keywords'] == ['one', 'two']
|
| 114 |
+
assert 'version' not in config_dict['metadata']
|
| 115 |
+
|
| 116 |
+
config.remove()
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class TestMetadata:
|
| 120 |
+
def test_basic(self, tmpdir):
|
| 121 |
+
fake_env(
|
| 122 |
+
tmpdir,
|
| 123 |
+
'[metadata]\n'
|
| 124 |
+
'version = 10.1.1\n'
|
| 125 |
+
'description = Some description\n'
|
| 126 |
+
'long_description_content_type = text/something\n'
|
| 127 |
+
'long_description = file: README\n'
|
| 128 |
+
'name = fake_name\n'
|
| 129 |
+
'keywords = one, two\n'
|
| 130 |
+
'provides = package, package.sub\n'
|
| 131 |
+
'license = otherlic\n'
|
| 132 |
+
'download_url = http://test.test.com/test/\n'
|
| 133 |
+
'maintainer_email = test@test.com\n',
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
tmpdir.join('README').write('readme contents\nline2')
|
| 137 |
+
|
| 138 |
+
meta_initial = {
|
| 139 |
+
# This will be used so `otherlic` won't replace it.
|
| 140 |
+
'license': 'BSD 3-Clause License',
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
with get_dist(tmpdir, meta_initial) as dist:
|
| 144 |
+
metadata = dist.metadata
|
| 145 |
+
|
| 146 |
+
assert metadata.version == '10.1.1'
|
| 147 |
+
assert metadata.description == 'Some description'
|
| 148 |
+
assert metadata.long_description_content_type == 'text/something'
|
| 149 |
+
assert metadata.long_description == 'readme contents\nline2'
|
| 150 |
+
assert metadata.provides == ['package', 'package.sub']
|
| 151 |
+
assert metadata.license == 'BSD 3-Clause License'
|
| 152 |
+
assert metadata.name == 'fake_name'
|
| 153 |
+
assert metadata.keywords == ['one', 'two']
|
| 154 |
+
assert metadata.download_url == 'http://test.test.com/test/'
|
| 155 |
+
assert metadata.maintainer_email == 'test@test.com'
|
| 156 |
+
|
| 157 |
+
def test_license_cfg(self, tmpdir):
|
| 158 |
+
fake_env(
|
| 159 |
+
tmpdir,
|
| 160 |
+
DALS(
|
| 161 |
+
"""
|
| 162 |
+
[metadata]
|
| 163 |
+
name=foo
|
| 164 |
+
version=0.0.1
|
| 165 |
+
license=Apache 2.0
|
| 166 |
+
"""
|
| 167 |
+
),
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
with get_dist(tmpdir) as dist:
|
| 171 |
+
metadata = dist.metadata
|
| 172 |
+
|
| 173 |
+
assert metadata.name == "foo"
|
| 174 |
+
assert metadata.version == "0.0.1"
|
| 175 |
+
assert metadata.license == "Apache 2.0"
|
| 176 |
+
|
| 177 |
+
def test_file_mixed(self, tmpdir):
|
| 178 |
+
fake_env(
|
| 179 |
+
tmpdir,
|
| 180 |
+
'[metadata]\nlong_description = file: README.rst, CHANGES.rst\n\n',
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
tmpdir.join('README.rst').write('readme contents\nline2')
|
| 184 |
+
tmpdir.join('CHANGES.rst').write('changelog contents\nand stuff')
|
| 185 |
+
|
| 186 |
+
with get_dist(tmpdir) as dist:
|
| 187 |
+
assert dist.metadata.long_description == (
|
| 188 |
+
'readme contents\nline2\nchangelog contents\nand stuff'
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
def test_file_sandboxed(self, tmpdir):
|
| 192 |
+
tmpdir.ensure("README")
|
| 193 |
+
project = tmpdir.join('depth1', 'depth2')
|
| 194 |
+
project.ensure(dir=True)
|
| 195 |
+
fake_env(project, '[metadata]\nlong_description = file: ../../README\n')
|
| 196 |
+
|
| 197 |
+
with get_dist(project, parse=False) as dist:
|
| 198 |
+
with pytest.raises(DistutilsOptionError):
|
| 199 |
+
dist.parse_config_files() # file: out of sandbox
|
| 200 |
+
|
| 201 |
+
def test_aliases(self, tmpdir):
|
| 202 |
+
fake_env(
|
| 203 |
+
tmpdir,
|
| 204 |
+
'[metadata]\n'
|
| 205 |
+
'author_email = test@test.com\n'
|
| 206 |
+
'home_page = http://test.test.com/test/\n'
|
| 207 |
+
'summary = Short summary\n'
|
| 208 |
+
'platform = a, b\n'
|
| 209 |
+
'classifier =\n'
|
| 210 |
+
' Framework :: Django\n'
|
| 211 |
+
' Programming Language :: Python :: 3.5\n',
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
with get_dist(tmpdir) as dist:
|
| 215 |
+
metadata = dist.metadata
|
| 216 |
+
assert metadata.author_email == 'test@test.com'
|
| 217 |
+
assert metadata.url == 'http://test.test.com/test/'
|
| 218 |
+
assert metadata.description == 'Short summary'
|
| 219 |
+
assert metadata.platforms == ['a', 'b']
|
| 220 |
+
assert metadata.classifiers == [
|
| 221 |
+
'Framework :: Django',
|
| 222 |
+
'Programming Language :: Python :: 3.5',
|
| 223 |
+
]
|
| 224 |
+
|
| 225 |
+
def test_multiline(self, tmpdir):
|
| 226 |
+
fake_env(
|
| 227 |
+
tmpdir,
|
| 228 |
+
'[metadata]\n'
|
| 229 |
+
'name = fake_name\n'
|
| 230 |
+
'keywords =\n'
|
| 231 |
+
' one\n'
|
| 232 |
+
' two\n'
|
| 233 |
+
'classifiers =\n'
|
| 234 |
+
' Framework :: Django\n'
|
| 235 |
+
' Programming Language :: Python :: 3.5\n',
|
| 236 |
+
)
|
| 237 |
+
with get_dist(tmpdir) as dist:
|
| 238 |
+
metadata = dist.metadata
|
| 239 |
+
assert metadata.keywords == ['one', 'two']
|
| 240 |
+
assert metadata.classifiers == [
|
| 241 |
+
'Framework :: Django',
|
| 242 |
+
'Programming Language :: Python :: 3.5',
|
| 243 |
+
]
|
| 244 |
+
|
| 245 |
+
def test_dict(self, tmpdir):
|
| 246 |
+
fake_env(
|
| 247 |
+
tmpdir,
|
| 248 |
+
'[metadata]\n'
|
| 249 |
+
'project_urls =\n'
|
| 250 |
+
' Link One = https://example.com/one/\n'
|
| 251 |
+
' Link Two = https://example.com/two/\n',
|
| 252 |
+
)
|
| 253 |
+
with get_dist(tmpdir) as dist:
|
| 254 |
+
metadata = dist.metadata
|
| 255 |
+
assert metadata.project_urls == {
|
| 256 |
+
'Link One': 'https://example.com/one/',
|
| 257 |
+
'Link Two': 'https://example.com/two/',
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
def test_version(self, tmpdir):
|
| 261 |
+
package_dir, config = fake_env(
|
| 262 |
+
tmpdir, '[metadata]\nversion = attr: fake_package.VERSION\n'
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
sub_a = package_dir.mkdir('subpkg_a')
|
| 266 |
+
sub_a.join('__init__.py').write('')
|
| 267 |
+
sub_a.join('mod.py').write('VERSION = (2016, 11, 26)')
|
| 268 |
+
|
| 269 |
+
sub_b = package_dir.mkdir('subpkg_b')
|
| 270 |
+
sub_b.join('__init__.py').write('')
|
| 271 |
+
sub_b.join('mod.py').write(
|
| 272 |
+
'import third_party_module\nVERSION = (2016, 11, 26)'
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
with get_dist(tmpdir) as dist:
|
| 276 |
+
assert dist.metadata.version == '1.2.3'
|
| 277 |
+
|
| 278 |
+
config.write('[metadata]\nversion = attr: fake_package.get_version\n')
|
| 279 |
+
with get_dist(tmpdir) as dist:
|
| 280 |
+
assert dist.metadata.version == '3.4.5.dev'
|
| 281 |
+
|
| 282 |
+
config.write('[metadata]\nversion = attr: fake_package.VERSION_MAJOR\n')
|
| 283 |
+
with get_dist(tmpdir) as dist:
|
| 284 |
+
assert dist.metadata.version == '1'
|
| 285 |
+
|
| 286 |
+
config.write('[metadata]\nversion = attr: fake_package.subpkg_a.mod.VERSION\n')
|
| 287 |
+
with get_dist(tmpdir) as dist:
|
| 288 |
+
assert dist.metadata.version == '2016.11.26'
|
| 289 |
+
|
| 290 |
+
config.write('[metadata]\nversion = attr: fake_package.subpkg_b.mod.VERSION\n')
|
| 291 |
+
with get_dist(tmpdir) as dist:
|
| 292 |
+
assert dist.metadata.version == '2016.11.26'
|
| 293 |
+
|
| 294 |
+
def test_version_file(self, tmpdir):
|
| 295 |
+
fake_env(tmpdir, '[metadata]\nversion = file: fake_package/version.txt\n')
|
| 296 |
+
tmpdir.join('fake_package', 'version.txt').write('1.2.3\n')
|
| 297 |
+
|
| 298 |
+
with get_dist(tmpdir) as dist:
|
| 299 |
+
assert dist.metadata.version == '1.2.3'
|
| 300 |
+
|
| 301 |
+
tmpdir.join('fake_package', 'version.txt').write('1.2.3\n4.5.6\n')
|
| 302 |
+
with pytest.raises(DistutilsOptionError):
|
| 303 |
+
with get_dist(tmpdir) as dist:
|
| 304 |
+
dist.metadata.version
|
| 305 |
+
|
| 306 |
+
def test_version_with_package_dir_simple(self, tmpdir):
|
| 307 |
+
fake_env(
|
| 308 |
+
tmpdir,
|
| 309 |
+
'[metadata]\n'
|
| 310 |
+
'version = attr: fake_package_simple.VERSION\n'
|
| 311 |
+
'[options]\n'
|
| 312 |
+
'package_dir =\n'
|
| 313 |
+
' = src\n',
|
| 314 |
+
package_path='src/fake_package_simple',
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
with get_dist(tmpdir) as dist:
|
| 318 |
+
assert dist.metadata.version == '1.2.3'
|
| 319 |
+
|
| 320 |
+
def test_version_with_package_dir_rename(self, tmpdir):
|
| 321 |
+
fake_env(
|
| 322 |
+
tmpdir,
|
| 323 |
+
'[metadata]\n'
|
| 324 |
+
'version = attr: fake_package_rename.VERSION\n'
|
| 325 |
+
'[options]\n'
|
| 326 |
+
'package_dir =\n'
|
| 327 |
+
' fake_package_rename = fake_dir\n',
|
| 328 |
+
package_path='fake_dir',
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
with get_dist(tmpdir) as dist:
|
| 332 |
+
assert dist.metadata.version == '1.2.3'
|
| 333 |
+
|
| 334 |
+
def test_version_with_package_dir_complex(self, tmpdir):
|
| 335 |
+
fake_env(
|
| 336 |
+
tmpdir,
|
| 337 |
+
'[metadata]\n'
|
| 338 |
+
'version = attr: fake_package_complex.VERSION\n'
|
| 339 |
+
'[options]\n'
|
| 340 |
+
'package_dir =\n'
|
| 341 |
+
' fake_package_complex = src/fake_dir\n',
|
| 342 |
+
package_path='src/fake_dir',
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
with get_dist(tmpdir) as dist:
|
| 346 |
+
assert dist.metadata.version == '1.2.3'
|
| 347 |
+
|
| 348 |
+
def test_unknown_meta_item(self, tmpdir):
|
| 349 |
+
fake_env(tmpdir, '[metadata]\nname = fake_name\nunknown = some\n')
|
| 350 |
+
with get_dist(tmpdir, parse=False) as dist:
|
| 351 |
+
dist.parse_config_files() # Skip unknown.
|
| 352 |
+
|
| 353 |
+
def test_usupported_section(self, tmpdir):
|
| 354 |
+
fake_env(tmpdir, '[metadata.some]\nkey = val\n')
|
| 355 |
+
with get_dist(tmpdir, parse=False) as dist:
|
| 356 |
+
with pytest.raises(DistutilsOptionError):
|
| 357 |
+
dist.parse_config_files()
|
| 358 |
+
|
| 359 |
+
def test_classifiers(self, tmpdir):
|
| 360 |
+
expected = set([
|
| 361 |
+
'Framework :: Django',
|
| 362 |
+
'Programming Language :: Python :: 3',
|
| 363 |
+
'Programming Language :: Python :: 3.5',
|
| 364 |
+
])
|
| 365 |
+
|
| 366 |
+
# From file.
|
| 367 |
+
_, config = fake_env(tmpdir, '[metadata]\nclassifiers = file: classifiers\n')
|
| 368 |
+
|
| 369 |
+
tmpdir.join('classifiers').write(
|
| 370 |
+
'Framework :: Django\n'
|
| 371 |
+
'Programming Language :: Python :: 3\n'
|
| 372 |
+
'Programming Language :: Python :: 3.5\n'
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
with get_dist(tmpdir) as dist:
|
| 376 |
+
assert set(dist.metadata.classifiers) == expected
|
| 377 |
+
|
| 378 |
+
# From list notation
|
| 379 |
+
config.write(
|
| 380 |
+
'[metadata]\n'
|
| 381 |
+
'classifiers =\n'
|
| 382 |
+
' Framework :: Django\n'
|
| 383 |
+
' Programming Language :: Python :: 3\n'
|
| 384 |
+
' Programming Language :: Python :: 3.5\n'
|
| 385 |
+
)
|
| 386 |
+
with get_dist(tmpdir) as dist:
|
| 387 |
+
assert set(dist.metadata.classifiers) == expected
|
| 388 |
+
|
| 389 |
+
def test_interpolation(self, tmpdir):
|
| 390 |
+
fake_env(tmpdir, '[metadata]\ndescription = %(message)s\n')
|
| 391 |
+
with pytest.raises(configparser.InterpolationMissingOptionError):
|
| 392 |
+
with get_dist(tmpdir):
|
| 393 |
+
pass
|
| 394 |
+
|
| 395 |
+
def test_non_ascii_1(self, tmpdir):
|
| 396 |
+
fake_env(tmpdir, '[metadata]\ndescription = éàïôñ\n', encoding='utf-8')
|
| 397 |
+
with get_dist(tmpdir):
|
| 398 |
+
pass
|
| 399 |
+
|
| 400 |
+
def test_non_ascii_3(self, tmpdir):
|
| 401 |
+
fake_env(tmpdir, '\n# -*- coding: invalid\n')
|
| 402 |
+
with get_dist(tmpdir):
|
| 403 |
+
pass
|
| 404 |
+
|
| 405 |
+
def test_non_ascii_4(self, tmpdir):
|
| 406 |
+
fake_env(
|
| 407 |
+
tmpdir,
|
| 408 |
+
'# -*- coding: utf-8\n[metadata]\ndescription = éàïôñ\n',
|
| 409 |
+
encoding='utf-8',
|
| 410 |
+
)
|
| 411 |
+
with get_dist(tmpdir) as dist:
|
| 412 |
+
assert dist.metadata.description == 'éàïôñ'
|
| 413 |
+
|
| 414 |
+
def test_not_utf8(self, tmpdir):
|
| 415 |
+
"""
|
| 416 |
+
Config files encoded not in UTF-8 will fail
|
| 417 |
+
"""
|
| 418 |
+
fake_env(
|
| 419 |
+
tmpdir,
|
| 420 |
+
'# vim: set fileencoding=iso-8859-15 :\n[metadata]\ndescription = éàïôñ\n',
|
| 421 |
+
encoding='iso-8859-15',
|
| 422 |
+
)
|
| 423 |
+
with pytest.raises(UnicodeDecodeError):
|
| 424 |
+
with get_dist(tmpdir):
|
| 425 |
+
pass
|
| 426 |
+
|
| 427 |
+
@pytest.mark.parametrize(
|
| 428 |
+
("error_msg", "config", "invalid"),
|
| 429 |
+
[
|
| 430 |
+
(
|
| 431 |
+
"Invalid dash-separated key 'author-email' in 'metadata' (setup.cfg)",
|
| 432 |
+
DALS(
|
| 433 |
+
"""
|
| 434 |
+
[metadata]
|
| 435 |
+
author-email = test@test.com
|
| 436 |
+
maintainer_email = foo@foo.com
|
| 437 |
+
"""
|
| 438 |
+
),
|
| 439 |
+
{"author-email": "test@test.com"},
|
| 440 |
+
),
|
| 441 |
+
(
|
| 442 |
+
"Invalid uppercase key 'Name' in 'metadata' (setup.cfg)",
|
| 443 |
+
DALS(
|
| 444 |
+
"""
|
| 445 |
+
[metadata]
|
| 446 |
+
Name = foo
|
| 447 |
+
description = Some description
|
| 448 |
+
"""
|
| 449 |
+
),
|
| 450 |
+
{"Name": "foo"},
|
| 451 |
+
),
|
| 452 |
+
],
|
| 453 |
+
)
|
| 454 |
+
def test_invalid_options_previously_deprecated(
|
| 455 |
+
self, tmpdir, error_msg, config, invalid
|
| 456 |
+
):
|
| 457 |
+
# This test and related methods can be removed when no longer needed.
|
| 458 |
+
# Deprecation postponed due to push-back from the community in
|
| 459 |
+
# https://github.com/pypa/setuptools/issues/4910
|
| 460 |
+
fake_env(tmpdir, config)
|
| 461 |
+
with pytest.warns(SetuptoolsDeprecationWarning, match=re.escape(error_msg)):
|
| 462 |
+
dist = get_dist(tmpdir).__enter__()
|
| 463 |
+
|
| 464 |
+
tmpdir.join('setup.cfg').remove()
|
| 465 |
+
|
| 466 |
+
for field, value in invalid.items():
|
| 467 |
+
attr = field.replace("-", "_").lower()
|
| 468 |
+
assert getattr(dist.metadata, attr) == value
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
class TestOptions:
|
| 472 |
+
def test_basic(self, tmpdir):
|
| 473 |
+
fake_env(
|
| 474 |
+
tmpdir,
|
| 475 |
+
'[options]\n'
|
| 476 |
+
'zip_safe = True\n'
|
| 477 |
+
'include_package_data = yes\n'
|
| 478 |
+
'package_dir = b=c, =src\n'
|
| 479 |
+
'packages = pack_a, pack_b.subpack\n'
|
| 480 |
+
'namespace_packages = pack1, pack2\n'
|
| 481 |
+
'scripts = bin/one.py, bin/two.py\n'
|
| 482 |
+
'eager_resources = bin/one.py, bin/two.py\n'
|
| 483 |
+
'install_requires = docutils>=0.3; pack ==1.1, ==1.3; hey\n'
|
| 484 |
+
'setup_requires = docutils>=0.3; spack ==1.1, ==1.3; there\n'
|
| 485 |
+
'dependency_links = http://some.com/here/1, '
|
| 486 |
+
'http://some.com/there/2\n'
|
| 487 |
+
'python_requires = >=1.0, !=2.8\n'
|
| 488 |
+
'py_modules = module1, module2\n',
|
| 489 |
+
)
|
| 490 |
+
deprec = pytest.warns(SetuptoolsDeprecationWarning, match="namespace_packages")
|
| 491 |
+
with deprec, get_dist(tmpdir) as dist:
|
| 492 |
+
assert dist.zip_safe
|
| 493 |
+
assert dist.include_package_data
|
| 494 |
+
assert dist.package_dir == {'': 'src', 'b': 'c'}
|
| 495 |
+
assert dist.packages == ['pack_a', 'pack_b.subpack']
|
| 496 |
+
assert dist.namespace_packages == ['pack1', 'pack2']
|
| 497 |
+
assert dist.scripts == ['bin/one.py', 'bin/two.py']
|
| 498 |
+
assert dist.dependency_links == ([
|
| 499 |
+
'http://some.com/here/1',
|
| 500 |
+
'http://some.com/there/2',
|
| 501 |
+
])
|
| 502 |
+
assert dist.install_requires == ([
|
| 503 |
+
'docutils>=0.3',
|
| 504 |
+
'pack==1.1,==1.3',
|
| 505 |
+
'hey',
|
| 506 |
+
])
|
| 507 |
+
assert dist.setup_requires == ([
|
| 508 |
+
'docutils>=0.3',
|
| 509 |
+
'spack ==1.1, ==1.3',
|
| 510 |
+
'there',
|
| 511 |
+
])
|
| 512 |
+
assert dist.python_requires == '>=1.0, !=2.8'
|
| 513 |
+
assert dist.py_modules == ['module1', 'module2']
|
| 514 |
+
|
| 515 |
+
def test_multiline(self, tmpdir):
|
| 516 |
+
fake_env(
|
| 517 |
+
tmpdir,
|
| 518 |
+
'[options]\n'
|
| 519 |
+
'package_dir = \n'
|
| 520 |
+
' b=c\n'
|
| 521 |
+
' =src\n'
|
| 522 |
+
'packages = \n'
|
| 523 |
+
' pack_a\n'
|
| 524 |
+
' pack_b.subpack\n'
|
| 525 |
+
'namespace_packages = \n'
|
| 526 |
+
' pack1\n'
|
| 527 |
+
' pack2\n'
|
| 528 |
+
'scripts = \n'
|
| 529 |
+
' bin/one.py\n'
|
| 530 |
+
' bin/two.py\n'
|
| 531 |
+
'eager_resources = \n'
|
| 532 |
+
' bin/one.py\n'
|
| 533 |
+
' bin/two.py\n'
|
| 534 |
+
'install_requires = \n'
|
| 535 |
+
' docutils>=0.3\n'
|
| 536 |
+
' pack ==1.1, ==1.3\n'
|
| 537 |
+
' hey\n'
|
| 538 |
+
'setup_requires = \n'
|
| 539 |
+
' docutils>=0.3\n'
|
| 540 |
+
' spack ==1.1, ==1.3\n'
|
| 541 |
+
' there\n'
|
| 542 |
+
'dependency_links = \n'
|
| 543 |
+
' http://some.com/here/1\n'
|
| 544 |
+
' http://some.com/there/2\n',
|
| 545 |
+
)
|
| 546 |
+
deprec = pytest.warns(SetuptoolsDeprecationWarning, match="namespace_packages")
|
| 547 |
+
with deprec, get_dist(tmpdir) as dist:
|
| 548 |
+
assert dist.package_dir == {'': 'src', 'b': 'c'}
|
| 549 |
+
assert dist.packages == ['pack_a', 'pack_b.subpack']
|
| 550 |
+
assert dist.namespace_packages == ['pack1', 'pack2']
|
| 551 |
+
assert dist.scripts == ['bin/one.py', 'bin/two.py']
|
| 552 |
+
assert dist.dependency_links == ([
|
| 553 |
+
'http://some.com/here/1',
|
| 554 |
+
'http://some.com/there/2',
|
| 555 |
+
])
|
| 556 |
+
assert dist.install_requires == ([
|
| 557 |
+
'docutils>=0.3',
|
| 558 |
+
'pack==1.1,==1.3',
|
| 559 |
+
'hey',
|
| 560 |
+
])
|
| 561 |
+
assert dist.setup_requires == ([
|
| 562 |
+
'docutils>=0.3',
|
| 563 |
+
'spack ==1.1, ==1.3',
|
| 564 |
+
'there',
|
| 565 |
+
])
|
| 566 |
+
|
| 567 |
+
def test_package_dir_fail(self, tmpdir):
|
| 568 |
+
fake_env(tmpdir, '[options]\npackage_dir = a b\n')
|
| 569 |
+
with get_dist(tmpdir, parse=False) as dist:
|
| 570 |
+
with pytest.raises(DistutilsOptionError):
|
| 571 |
+
dist.parse_config_files()
|
| 572 |
+
|
| 573 |
+
def test_package_data(self, tmpdir):
|
| 574 |
+
fake_env(
|
| 575 |
+
tmpdir,
|
| 576 |
+
'[options.package_data]\n'
|
| 577 |
+
'* = *.txt, *.rst\n'
|
| 578 |
+
'hello = *.msg\n'
|
| 579 |
+
'\n'
|
| 580 |
+
'[options.exclude_package_data]\n'
|
| 581 |
+
'* = fake1.txt, fake2.txt\n'
|
| 582 |
+
'hello = *.dat\n',
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
with get_dist(tmpdir) as dist:
|
| 586 |
+
assert dist.package_data == {
|
| 587 |
+
'': ['*.txt', '*.rst'],
|
| 588 |
+
'hello': ['*.msg'],
|
| 589 |
+
}
|
| 590 |
+
assert dist.exclude_package_data == {
|
| 591 |
+
'': ['fake1.txt', 'fake2.txt'],
|
| 592 |
+
'hello': ['*.dat'],
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
def test_packages(self, tmpdir):
|
| 596 |
+
fake_env(tmpdir, '[options]\npackages = find:\n')
|
| 597 |
+
|
| 598 |
+
with get_dist(tmpdir) as dist:
|
| 599 |
+
assert dist.packages == ['fake_package']
|
| 600 |
+
|
| 601 |
+
def test_find_directive(self, tmpdir):
|
| 602 |
+
dir_package, config = fake_env(tmpdir, '[options]\npackages = find:\n')
|
| 603 |
+
|
| 604 |
+
make_package_dir('sub_one', dir_package)
|
| 605 |
+
make_package_dir('sub_two', dir_package)
|
| 606 |
+
|
| 607 |
+
with get_dist(tmpdir) as dist:
|
| 608 |
+
assert set(dist.packages) == set([
|
| 609 |
+
'fake_package',
|
| 610 |
+
'fake_package.sub_two',
|
| 611 |
+
'fake_package.sub_one',
|
| 612 |
+
])
|
| 613 |
+
|
| 614 |
+
config.write(
|
| 615 |
+
'[options]\n'
|
| 616 |
+
'packages = find:\n'
|
| 617 |
+
'\n'
|
| 618 |
+
'[options.packages.find]\n'
|
| 619 |
+
'where = .\n'
|
| 620 |
+
'include =\n'
|
| 621 |
+
' fake_package.sub_one\n'
|
| 622 |
+
' two\n'
|
| 623 |
+
)
|
| 624 |
+
with get_dist(tmpdir) as dist:
|
| 625 |
+
assert dist.packages == ['fake_package.sub_one']
|
| 626 |
+
|
| 627 |
+
config.write(
|
| 628 |
+
'[options]\n'
|
| 629 |
+
'packages = find:\n'
|
| 630 |
+
'\n'
|
| 631 |
+
'[options.packages.find]\n'
|
| 632 |
+
'exclude =\n'
|
| 633 |
+
' fake_package.sub_one\n'
|
| 634 |
+
)
|
| 635 |
+
with get_dist(tmpdir) as dist:
|
| 636 |
+
assert set(dist.packages) == set(['fake_package', 'fake_package.sub_two'])
|
| 637 |
+
|
| 638 |
+
def test_find_namespace_directive(self, tmpdir):
|
| 639 |
+
dir_package, config = fake_env(
|
| 640 |
+
tmpdir, '[options]\npackages = find_namespace:\n'
|
| 641 |
+
)
|
| 642 |
+
|
| 643 |
+
make_package_dir('sub_one', dir_package)
|
| 644 |
+
make_package_dir('sub_two', dir_package, ns=True)
|
| 645 |
+
|
| 646 |
+
with get_dist(tmpdir) as dist:
|
| 647 |
+
assert set(dist.packages) == {
|
| 648 |
+
'fake_package',
|
| 649 |
+
'fake_package.sub_two',
|
| 650 |
+
'fake_package.sub_one',
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
config.write(
|
| 654 |
+
'[options]\n'
|
| 655 |
+
'packages = find_namespace:\n'
|
| 656 |
+
'\n'
|
| 657 |
+
'[options.packages.find]\n'
|
| 658 |
+
'where = .\n'
|
| 659 |
+
'include =\n'
|
| 660 |
+
' fake_package.sub_one\n'
|
| 661 |
+
' two\n'
|
| 662 |
+
)
|
| 663 |
+
with get_dist(tmpdir) as dist:
|
| 664 |
+
assert dist.packages == ['fake_package.sub_one']
|
| 665 |
+
|
| 666 |
+
config.write(
|
| 667 |
+
'[options]\n'
|
| 668 |
+
'packages = find_namespace:\n'
|
| 669 |
+
'\n'
|
| 670 |
+
'[options.packages.find]\n'
|
| 671 |
+
'exclude =\n'
|
| 672 |
+
' fake_package.sub_one\n'
|
| 673 |
+
)
|
| 674 |
+
with get_dist(tmpdir) as dist:
|
| 675 |
+
assert set(dist.packages) == {'fake_package', 'fake_package.sub_two'}
|
| 676 |
+
|
| 677 |
+
def test_extras_require(self, tmpdir):
|
| 678 |
+
fake_env(
|
| 679 |
+
tmpdir,
|
| 680 |
+
'[options.extras_require]\n'
|
| 681 |
+
'pdf = ReportLab>=1.2; RXP\n'
|
| 682 |
+
'rest = \n'
|
| 683 |
+
' docutils>=0.3\n'
|
| 684 |
+
' pack ==1.1, ==1.3\n',
|
| 685 |
+
)
|
| 686 |
+
|
| 687 |
+
with get_dist(tmpdir) as dist:
|
| 688 |
+
assert dist.extras_require == {
|
| 689 |
+
'pdf': ['ReportLab>=1.2', 'RXP'],
|
| 690 |
+
'rest': ['docutils>=0.3', 'pack==1.1,==1.3'],
|
| 691 |
+
}
|
| 692 |
+
assert set(dist.metadata.provides_extras) == {'pdf', 'rest'}
|
| 693 |
+
|
| 694 |
+
@pytest.mark.parametrize(
|
| 695 |
+
"config",
|
| 696 |
+
[
|
| 697 |
+
"[options.extras_require]\nfoo = bar;python_version<'3'",
|
| 698 |
+
"[options.extras_require]\nfoo = bar;os_name=='linux'",
|
| 699 |
+
"[options.extras_require]\nfoo = bar;python_version<'3'\n",
|
| 700 |
+
"[options.extras_require]\nfoo = bar;os_name=='linux'\n",
|
| 701 |
+
"[options]\ninstall_requires = bar;python_version<'3'",
|
| 702 |
+
"[options]\ninstall_requires = bar;os_name=='linux'",
|
| 703 |
+
"[options]\ninstall_requires = bar;python_version<'3'\n",
|
| 704 |
+
"[options]\ninstall_requires = bar;os_name=='linux'\n",
|
| 705 |
+
],
|
| 706 |
+
)
|
| 707 |
+
@pytest.mark.xfail(IS_PYPY, reason="Exceptions missing on PyPy")
|
| 708 |
+
# TODO: investigate PyPy problem
|
| 709 |
+
def test_raises_accidental_env_marker_misconfig(self, config, tmpdir):
|
| 710 |
+
fake_env(tmpdir, config)
|
| 711 |
+
match = (
|
| 712 |
+
r"One of the parsed requirements in `(install_requires|extras_require.+)` "
|
| 713 |
+
"looks like a valid environment marker.*"
|
| 714 |
+
)
|
| 715 |
+
with pytest.raises(InvalidRequirement, match=match):
|
| 716 |
+
with get_dist(tmpdir) as _:
|
| 717 |
+
pass
|
| 718 |
+
|
| 719 |
+
@pytest.mark.parametrize(
|
| 720 |
+
"config",
|
| 721 |
+
[
|
| 722 |
+
"[options.extras_require]\nfoo = bar;python_version<3",
|
| 723 |
+
"[options.extras_require]\nfoo = bar;python_version<3\n",
|
| 724 |
+
"[options]\ninstall_requires = bar;python_version<3",
|
| 725 |
+
"[options]\ninstall_requires = bar;python_version<3\n",
|
| 726 |
+
],
|
| 727 |
+
)
|
| 728 |
+
@pytest.mark.xfail(IS_PYPY, reason="Warnings missing on PyPy (minor issue)")
|
| 729 |
+
# TODO: investigate PyPy problem
|
| 730 |
+
def test_warn_accidental_env_marker_misconfig(self, config, tmpdir):
|
| 731 |
+
fake_env(tmpdir, config)
|
| 732 |
+
match = (
|
| 733 |
+
r"One of the parsed requirements in `(install_requires|extras_require.+)` "
|
| 734 |
+
"looks like a valid environment marker.*"
|
| 735 |
+
)
|
| 736 |
+
with pytest.warns(SetuptoolsDeprecationWarning, match=match):
|
| 737 |
+
with get_dist(tmpdir) as _:
|
| 738 |
+
pass
|
| 739 |
+
|
| 740 |
+
@pytest.mark.parametrize(
|
| 741 |
+
"config",
|
| 742 |
+
[
|
| 743 |
+
"[options.extras_require]\nfoo =\n bar;python_version<'3'",
|
| 744 |
+
"[options.extras_require]\nfoo = bar;baz\nboo = xxx;yyy",
|
| 745 |
+
"[options.extras_require]\nfoo =\n bar;python_version<'3'\n",
|
| 746 |
+
"[options.extras_require]\nfoo = bar;baz\nboo = xxx;yyy\n",
|
| 747 |
+
"[options.extras_require]\nfoo =\n bar\n python_version<3\n",
|
| 748 |
+
"[options]\ninstall_requires =\n bar;python_version<'3'",
|
| 749 |
+
"[options]\ninstall_requires = bar;baz\nboo = xxx;yyy",
|
| 750 |
+
"[options]\ninstall_requires =\n bar;python_version<'3'\n",
|
| 751 |
+
"[options]\ninstall_requires = bar;baz\nboo = xxx;yyy\n",
|
| 752 |
+
"[options]\ninstall_requires =\n bar\n python_version<3\n",
|
| 753 |
+
],
|
| 754 |
+
)
|
| 755 |
+
@pytest.mark.filterwarnings("error::setuptools.SetuptoolsDeprecationWarning")
|
| 756 |
+
def test_nowarn_accidental_env_marker_misconfig(self, config, tmpdir, recwarn):
|
| 757 |
+
fake_env(tmpdir, config)
|
| 758 |
+
num_warnings = len(recwarn)
|
| 759 |
+
with get_dist(tmpdir) as _:
|
| 760 |
+
pass
|
| 761 |
+
# The examples are valid, no warnings shown
|
| 762 |
+
assert len(recwarn) == num_warnings
|
| 763 |
+
|
| 764 |
+
def test_dash_preserved_extras_require(self, tmpdir):
|
| 765 |
+
fake_env(tmpdir, '[options.extras_require]\nfoo-a = foo\nfoo_b = test\n')
|
| 766 |
+
|
| 767 |
+
with get_dist(tmpdir) as dist:
|
| 768 |
+
assert dist.extras_require == {'foo-a': ['foo'], 'foo_b': ['test']}
|
| 769 |
+
|
| 770 |
+
def test_entry_points(self, tmpdir):
|
| 771 |
+
_, config = fake_env(
|
| 772 |
+
tmpdir,
|
| 773 |
+
'[options.entry_points]\n'
|
| 774 |
+
'group1 = point1 = pack.module:func, '
|
| 775 |
+
'.point2 = pack.module2:func_rest [rest]\n'
|
| 776 |
+
'group2 = point3 = pack.module:func2\n',
|
| 777 |
+
)
|
| 778 |
+
|
| 779 |
+
with get_dist(tmpdir) as dist:
|
| 780 |
+
assert dist.entry_points == {
|
| 781 |
+
'group1': [
|
| 782 |
+
'point1 = pack.module:func',
|
| 783 |
+
'.point2 = pack.module2:func_rest [rest]',
|
| 784 |
+
],
|
| 785 |
+
'group2': ['point3 = pack.module:func2'],
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
expected = (
|
| 789 |
+
'[blogtool.parsers]\n'
|
| 790 |
+
'.rst = some.nested.module:SomeClass.some_classmethod[reST]\n'
|
| 791 |
+
)
|
| 792 |
+
|
| 793 |
+
tmpdir.join('entry_points').write(expected)
|
| 794 |
+
|
| 795 |
+
# From file.
|
| 796 |
+
config.write('[options]\nentry_points = file: entry_points\n')
|
| 797 |
+
|
| 798 |
+
with get_dist(tmpdir) as dist:
|
| 799 |
+
assert dist.entry_points == expected
|
| 800 |
+
|
| 801 |
+
def test_case_sensitive_entry_points(self, tmpdir):
|
| 802 |
+
fake_env(
|
| 803 |
+
tmpdir,
|
| 804 |
+
'[options.entry_points]\n'
|
| 805 |
+
'GROUP1 = point1 = pack.module:func, '
|
| 806 |
+
'.point2 = pack.module2:func_rest [rest]\n'
|
| 807 |
+
'group2 = point3 = pack.module:func2\n',
|
| 808 |
+
)
|
| 809 |
+
|
| 810 |
+
with get_dist(tmpdir) as dist:
|
| 811 |
+
assert dist.entry_points == {
|
| 812 |
+
'GROUP1': [
|
| 813 |
+
'point1 = pack.module:func',
|
| 814 |
+
'.point2 = pack.module2:func_rest [rest]',
|
| 815 |
+
],
|
| 816 |
+
'group2': ['point3 = pack.module:func2'],
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
def test_data_files(self, tmpdir):
|
| 820 |
+
fake_env(
|
| 821 |
+
tmpdir,
|
| 822 |
+
'[options.data_files]\n'
|
| 823 |
+
'cfg =\n'
|
| 824 |
+
' a/b.conf\n'
|
| 825 |
+
' c/d.conf\n'
|
| 826 |
+
'data = e/f.dat, g/h.dat\n',
|
| 827 |
+
)
|
| 828 |
+
|
| 829 |
+
with get_dist(tmpdir) as dist:
|
| 830 |
+
expected = [
|
| 831 |
+
('cfg', ['a/b.conf', 'c/d.conf']),
|
| 832 |
+
('data', ['e/f.dat', 'g/h.dat']),
|
| 833 |
+
]
|
| 834 |
+
assert sorted(dist.data_files) == sorted(expected)
|
| 835 |
+
|
| 836 |
+
def test_data_files_globby(self, tmpdir):
|
| 837 |
+
fake_env(
|
| 838 |
+
tmpdir,
|
| 839 |
+
'[options.data_files]\n'
|
| 840 |
+
'cfg =\n'
|
| 841 |
+
' a/b.conf\n'
|
| 842 |
+
' c/d.conf\n'
|
| 843 |
+
'data = *.dat\n'
|
| 844 |
+
'icons = \n'
|
| 845 |
+
' *.ico\n'
|
| 846 |
+
'audio = \n'
|
| 847 |
+
' *.wav\n'
|
| 848 |
+
' sounds.db\n',
|
| 849 |
+
)
|
| 850 |
+
|
| 851 |
+
# Create dummy files for glob()'s sake:
|
| 852 |
+
tmpdir.join('a.dat').write('')
|
| 853 |
+
tmpdir.join('b.dat').write('')
|
| 854 |
+
tmpdir.join('c.dat').write('')
|
| 855 |
+
tmpdir.join('a.ico').write('')
|
| 856 |
+
tmpdir.join('b.ico').write('')
|
| 857 |
+
tmpdir.join('c.ico').write('')
|
| 858 |
+
tmpdir.join('beep.wav').write('')
|
| 859 |
+
tmpdir.join('boop.wav').write('')
|
| 860 |
+
tmpdir.join('sounds.db').write('')
|
| 861 |
+
|
| 862 |
+
with get_dist(tmpdir) as dist:
|
| 863 |
+
expected = [
|
| 864 |
+
('cfg', ['a/b.conf', 'c/d.conf']),
|
| 865 |
+
('data', ['a.dat', 'b.dat', 'c.dat']),
|
| 866 |
+
('icons', ['a.ico', 'b.ico', 'c.ico']),
|
| 867 |
+
('audio', ['beep.wav', 'boop.wav', 'sounds.db']),
|
| 868 |
+
]
|
| 869 |
+
assert sorted(dist.data_files) == sorted(expected)
|
| 870 |
+
|
| 871 |
+
def test_python_requires_simple(self, tmpdir):
|
| 872 |
+
fake_env(
|
| 873 |
+
tmpdir,
|
| 874 |
+
DALS(
|
| 875 |
+
"""
|
| 876 |
+
[options]
|
| 877 |
+
python_requires=>=2.7
|
| 878 |
+
"""
|
| 879 |
+
),
|
| 880 |
+
)
|
| 881 |
+
with get_dist(tmpdir) as dist:
|
| 882 |
+
dist.parse_config_files()
|
| 883 |
+
|
| 884 |
+
def test_python_requires_compound(self, tmpdir):
|
| 885 |
+
fake_env(
|
| 886 |
+
tmpdir,
|
| 887 |
+
DALS(
|
| 888 |
+
"""
|
| 889 |
+
[options]
|
| 890 |
+
python_requires=>=2.7,!=3.0.*
|
| 891 |
+
"""
|
| 892 |
+
),
|
| 893 |
+
)
|
| 894 |
+
with get_dist(tmpdir) as dist:
|
| 895 |
+
dist.parse_config_files()
|
| 896 |
+
|
| 897 |
+
def test_python_requires_invalid(self, tmpdir):
|
| 898 |
+
fake_env(
|
| 899 |
+
tmpdir,
|
| 900 |
+
DALS(
|
| 901 |
+
"""
|
| 902 |
+
[options]
|
| 903 |
+
python_requires=invalid
|
| 904 |
+
"""
|
| 905 |
+
),
|
| 906 |
+
)
|
| 907 |
+
with pytest.raises(Exception):
|
| 908 |
+
with get_dist(tmpdir) as dist:
|
| 909 |
+
dist.parse_config_files()
|
| 910 |
+
|
| 911 |
+
def test_cmdclass(self, tmpdir):
|
| 912 |
+
module_path = Path(tmpdir, "src/custom_build.py") # auto discovery for src
|
| 913 |
+
module_path.parent.mkdir(parents=True, exist_ok=True)
|
| 914 |
+
module_path.write_text(
|
| 915 |
+
"from distutils.core import Command\nclass CustomCmd(Command): pass\n",
|
| 916 |
+
encoding="utf-8",
|
| 917 |
+
)
|
| 918 |
+
|
| 919 |
+
setup_cfg = """
|
| 920 |
+
[options]
|
| 921 |
+
cmdclass =
|
| 922 |
+
customcmd = custom_build.CustomCmd
|
| 923 |
+
"""
|
| 924 |
+
fake_env(tmpdir, inspect.cleandoc(setup_cfg))
|
| 925 |
+
|
| 926 |
+
with get_dist(tmpdir) as dist:
|
| 927 |
+
cmdclass = dist.cmdclass['customcmd']
|
| 928 |
+
assert cmdclass.__name__ == "CustomCmd"
|
| 929 |
+
assert cmdclass.__module__ == "custom_build"
|
| 930 |
+
assert module_path.samefile(inspect.getfile(cmdclass))
|
| 931 |
+
|
| 932 |
+
def test_requirements_file(self, tmpdir):
|
| 933 |
+
fake_env(
|
| 934 |
+
tmpdir,
|
| 935 |
+
DALS(
|
| 936 |
+
"""
|
| 937 |
+
[options]
|
| 938 |
+
install_requires = file:requirements.txt
|
| 939 |
+
[options.extras_require]
|
| 940 |
+
colors = file:requirements-extra.txt
|
| 941 |
+
"""
|
| 942 |
+
),
|
| 943 |
+
)
|
| 944 |
+
|
| 945 |
+
tmpdir.join('requirements.txt').write('\ndocutils>=0.3\n\n')
|
| 946 |
+
tmpdir.join('requirements-extra.txt').write('colorama')
|
| 947 |
+
|
| 948 |
+
with get_dist(tmpdir) as dist:
|
| 949 |
+
assert dist.install_requires == ['docutils>=0.3']
|
| 950 |
+
assert dist.extras_require == {'colors': ['colorama']}
|
| 951 |
+
|
| 952 |
+
|
| 953 |
+
saved_dist_init = _Distribution.__init__
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
class TestExternalSetters:
|
| 957 |
+
# During creation of the setuptools Distribution() object, we call
|
| 958 |
+
# the init of the parent distutils Distribution object via
|
| 959 |
+
# _Distribution.__init__ ().
|
| 960 |
+
#
|
| 961 |
+
# It's possible distutils calls out to various keyword
|
| 962 |
+
# implementations (i.e. distutils.setup_keywords entry points)
|
| 963 |
+
# that may set a range of variables.
|
| 964 |
+
#
|
| 965 |
+
# This wraps distutil's Distribution.__init__ and simulates
|
| 966 |
+
# pbr or something else setting these values.
|
| 967 |
+
def _fake_distribution_init(self, dist, attrs):
|
| 968 |
+
saved_dist_init(dist, attrs)
|
| 969 |
+
# see self._DISTUTILS_UNSUPPORTED_METADATA
|
| 970 |
+
dist.metadata.long_description_content_type = 'text/something'
|
| 971 |
+
# Test overwrite setup() args
|
| 972 |
+
dist.metadata.project_urls = {
|
| 973 |
+
'Link One': 'https://example.com/one/',
|
| 974 |
+
'Link Two': 'https://example.com/two/',
|
| 975 |
+
}
|
| 976 |
+
|
| 977 |
+
@patch.object(_Distribution, '__init__', autospec=True)
|
| 978 |
+
def test_external_setters(self, mock_parent_init, tmpdir):
|
| 979 |
+
mock_parent_init.side_effect = self._fake_distribution_init
|
| 980 |
+
|
| 981 |
+
dist = Distribution(attrs={'project_urls': {'will_be': 'ignored'}})
|
| 982 |
+
|
| 983 |
+
assert dist.metadata.long_description_content_type == 'text/something'
|
| 984 |
+
assert dist.metadata.project_urls == {
|
| 985 |
+
'Link One': 'https://example.com/one/',
|
| 986 |
+
'Link Two': 'https://example.com/two/',
|
| 987 |
+
}
|