From b0da12368117c992381e55b980863c54e32348ad Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Fri, 16 Dec 2022 10:52:54 +0100 Subject: [PATCH 1/2] vendor: bump plette to 0.4.4 --- pipenv/vendor/plette/__init__.py | 2 +- pipenv/vendor/plette/__main__.py | 24 ++++++++++++++++++++++++ pipenv/vendor/plette/models/__init__.py | 8 +++++++- pipenv/vendor/plette/models/packages.py | 17 ++++++++++++++++- pipenv/vendor/plette/models/sections.py | 18 ++++++++++++++++++ pipenv/vendor/plette/pipfiles.py | 10 ++++++++-- pipenv/vendor/vendor.txt | 2 +- 7 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 pipenv/vendor/plette/__main__.py diff --git a/pipenv/vendor/plette/__init__.py b/pipenv/vendor/plette/__init__.py index 6e842ee465..7734698d76 100644 --- a/pipenv/vendor/plette/__init__.py +++ b/pipenv/vendor/plette/__init__.py @@ -3,7 +3,7 @@ "Lockfile", "Pipfile", ] -__version__ = '0.4.2' +__version__ = '0.4.4' from .lockfiles import Lockfile from .pipfiles import Pipfile diff --git a/pipenv/vendor/plette/__main__.py b/pipenv/vendor/plette/__main__.py new file mode 100644 index 0000000000..e5798bae29 --- /dev/null +++ b/pipenv/vendor/plette/__main__.py @@ -0,0 +1,24 @@ +""" +A simple entry point which can be use to test Pipfiles + +e.g. + +python -m plette -f examples/Pipfile.valid.list +python -m plette -f examples/Pipfile.valid.editable +# throws exception +python -m plette -f examples/Pipfile.invalid.list + +""" +from pipenv.vendor.plette import Pipfile + +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("-f", "--file", help="Input file") + +args = parser.parse_args() + +dest = args.file + +with open(dest) as f: + pipfile = Pipfile.load(f) diff --git a/pipenv/vendor/plette/models/__init__.py b/pipenv/vendor/plette/models/__init__.py index 42b8c49f49..20c2899330 100644 --- a/pipenv/vendor/plette/models/__init__.py +++ b/pipenv/vendor/plette/models/__init__.py @@ -16,5 +16,11 @@ from .sources import Source from .sections import ( - Meta, Requires, PackageCollection, ScriptCollection, SourceCollection, + Meta, + Requires, + PackageCollection, + Pipenv, + PipfileSection, + ScriptCollection, + SourceCollection, ) diff --git a/pipenv/vendor/plette/models/packages.py b/pipenv/vendor/plette/models/packages.py index 93b35c3adc..8b0ebe4f61 100644 --- a/pipenv/vendor/plette/models/packages.py +++ b/pipenv/vendor/plette/models/packages.py @@ -21,7 +21,9 @@ class Package(DataView): def validate(cls, data): # HACK: Make this validatable for Cerberus. See comments in validation # side for more information. - return super(Package, cls).validate({"__package__": data}) + super(Package, cls).validate({"__package__": data}) + if isinstance(data, dict): + PackageSpecfiers.validate({"__specifiers__": data}) def __getattr__(self, key): if isinstance(self._data, str): @@ -41,3 +43,16 @@ def __setattr__(self, key, value): self._data = value else: self._data[key] = value + +class PackageSpecfiers(DataView): + # TODO: one could add here more validation for path editable + # and more stuff which is currently allowed and undocumented + __SCHEMA__ = { + "__specifiers__": { + "type": "dict", + "schema":{ + "version": {"type": "string"}, + "extras": {"type": "list"}, + } + } + } diff --git a/pipenv/vendor/plette/models/sections.py b/pipenv/vendor/plette/models/sections.py index 2600bb1f85..acaaa4dd86 100644 --- a/pipenv/vendor/plette/models/sections.py +++ b/pipenv/vendor/plette/models/sections.py @@ -50,6 +50,16 @@ def python_full_version(self): "sources": SourceCollection, } +class PipfileSection(DataView): + + """ + Dummy pipfile validator that needs to be completed in a future PR + Hint: many pipfile features are undocumented in pipenv/project.py + """ + + @classmethod + def validate(cls, data): + pass class Meta(DataView): """Representation of the `_meta` section in a Pipfile.lock.""" @@ -119,3 +129,11 @@ def sources(self): @sources.setter def sources(self, value): self["sources"] = value + + +class Pipenv(DataView): + """Represent the [pipenv] section in Pipfile""" + + __SCHEMA__ = { + "allow_prereleases": {"type": "boolean", "required": False}, + } diff --git a/pipenv/vendor/plette/pipfiles.py b/pipenv/vendor/plette/pipfiles.py index 85260fba69..0113ebeeff 100644 --- a/pipenv/vendor/plette/pipfiles.py +++ b/pipenv/vendor/plette/pipfiles.py @@ -4,7 +4,7 @@ import pipenv.vendor.tomlkit as tomlkit from .models import ( - DataView, Hash, Requires, + DataView, Hash, Requires, PipfileSection, Pipenv, PackageCollection, ScriptCollection, SourceCollection, ) @@ -15,6 +15,8 @@ "dev-packages": PackageCollection, "requires": Requires, "scripts": ScriptCollection, + "pipfile": PipfileSection, + "pipenv": Pipenv } DEFAULT_SOURCE_TOML = """\ @@ -24,7 +26,6 @@ verify_ssl = true """ - class Pipfile(DataView): """Representation of a Pipfile. """ @@ -42,6 +43,11 @@ def validate(cls, data): continue klass.validate(data[key]) + package_categories = set(data.keys()) - set(PIPFILE_SECTIONS.keys()) + + for category in package_categories: + PackageCollection.validate(data[category]) + @classmethod def load(cls, f, encoding=None): content = f.read() diff --git a/pipenv/vendor/vendor.txt b/pipenv/vendor/vendor.txt index c3b58032f3..37494fadd7 100644 --- a/pipenv/vendor/vendor.txt +++ b/pipenv/vendor/vendor.txt @@ -7,7 +7,7 @@ dparse==0.6.2 markupsafe==2.0.1 pexpect==4.8.0 pipdeptree==2.3.1 -plette[validation]==0.4.2 +plette[validation]==0.4.4 ptyprocess==0.7.0 pyparsing==3.0.9 python-dotenv==0.19.0 From 5f6e55782318d691099e3409d4a350d2a3608580 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Fri, 16 Dec 2022 10:56:44 +0100 Subject: [PATCH 2/2] Add news snippet for vendoring plette --- news/5539.vendor.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/5539.vendor.rst diff --git a/news/5539.vendor.rst b/news/5539.vendor.rst new file mode 100644 index 0000000000..1ca7573db7 --- /dev/null +++ b/news/5539.vendor.rst @@ -0,0 +1 @@ +Bump plette version to 0.4.4