summaryrefslogtreecommitdiffstats
path: root/third_party/python/pep487
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/python/pep487
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/pep487')
-rw-r--r--third_party/python/pep487/PKG-INFO87
-rw-r--r--third_party/python/pep487/README.rst68
-rw-r--r--third_party/python/pep487/lib/pep487/__init__.py81
-rw-r--r--third_party/python/pep487/lib/pep487/version.py27
-rw-r--r--third_party/python/pep487/setup.cfg12
-rw-r--r--third_party/python/pep487/setup.py121
6 files changed, 396 insertions, 0 deletions
diff --git a/third_party/python/pep487/PKG-INFO b/third_party/python/pep487/PKG-INFO
new file mode 100644
index 0000000000..c44d702629
--- /dev/null
+++ b/third_party/python/pep487/PKG-INFO
@@ -0,0 +1,87 @@
+Metadata-Version: 2.1
+Name: pep487
+Version: 1.0.1
+Summary: PEP487 - Simpler customisation of class creation
+Home-page: https://github.com/zaehlwerk/pep487
+Author: Gregor Giesen
+Author-email: giesen@zaehlwerk.net
+License: GPLv3
+Description: ===============================================
+ PEP487: Simpler customisation of class creation
+ ===============================================
+
+ This is a backport of PEP487's simpler customisation of class
+ creation by Martin Teichmann <https://www.python.org/dev/peps/pep-0487/>
+ for Python versions before 3.6.
+
+ PEP487 is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+
+ Subclass init
+ =============
+
+ >>> from pep487 import PEP487Object
+ >>> class FooBase(PEP487Object):
+ ... foos = set()
+ ...
+ ... def __init_subclass__(cls, **kwargs):
+ ... cls.foos.add(cls.__name__)
+
+ Using `PEP487Object` as base class all subclasses of FooBase
+ will add their name to the common class variable 'foos'.
+
+ >>> class Foo1(FooBase):
+ ... pass
+ >>> class Foo2(FooBase):
+ ... pass
+
+ Hence:
+
+ >>> FooBase.foos
+ {'Foo1', 'Foo2'}
+
+
+
+ Property names and owner
+ ========================
+
+ If a class object has a method `__set_name__` upon declaration
+ of an PEP487Object class, it will be called:
+
+ >>> class NamedProperty:
+ ... def __set_name__(self, owner, name):
+ ... self.context = owner
+ ... self.name = name
+
+ >>> class Bar(PEP487Object):
+ ... foo = NamedProperty()
+ ... bar = NamedProperty()
+
+ Consequently:
+
+ >>> Bar.foo.name is 'foo' and Bar.foo.context is Bar
+ True
+ >>> Bar.bar.name is 'bar' and Bar.bar.context is Bar
+ True
+
+
+ Abstract base classes
+ =====================
+
+ Since `PEP487Object` has a custom metaclass, it is incompatible
+ to `abc.ABC`. Therefore `pep487` contains patched versions of `ABC`
+ and `ABCMeta`.
+
+Keywords: pep487
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Provides-Extra: test
diff --git a/third_party/python/pep487/README.rst b/third_party/python/pep487/README.rst
new file mode 100644
index 0000000000..4190c77f79
--- /dev/null
+++ b/third_party/python/pep487/README.rst
@@ -0,0 +1,68 @@
+===============================================
+PEP487: Simpler customisation of class creation
+===============================================
+
+This is a backport of PEP487's simpler customisation of class
+creation by Martin Teichmann <https://www.python.org/dev/peps/pep-0487/>
+for Python versions before 3.6.
+
+PEP487 is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License,
+or (at your option) any later version.
+
+
+Subclass init
+=============
+
+>>> from pep487 import PEP487Object
+>>> class FooBase(PEP487Object):
+... foos = set()
+...
+... def __init_subclass__(cls, **kwargs):
+... cls.foos.add(cls.__name__)
+
+Using `PEP487Object` as base class all subclasses of FooBase
+will add their name to the common class variable 'foos'.
+
+>>> class Foo1(FooBase):
+... pass
+>>> class Foo2(FooBase):
+... pass
+
+Hence:
+
+>>> FooBase.foos
+{'Foo1', 'Foo2'}
+
+
+
+Property names and owner
+========================
+
+If a class object has a method `__set_name__` upon declaration
+of an PEP487Object class, it will be called:
+
+>>> class NamedProperty:
+... def __set_name__(self, owner, name):
+... self.context = owner
+... self.name = name
+
+>>> class Bar(PEP487Object):
+... foo = NamedProperty()
+... bar = NamedProperty()
+
+Consequently:
+
+>>> Bar.foo.name is 'foo' and Bar.foo.context is Bar
+True
+>>> Bar.bar.name is 'bar' and Bar.bar.context is Bar
+True
+
+
+Abstract base classes
+=====================
+
+Since `PEP487Object` has a custom metaclass, it is incompatible
+to `abc.ABC`. Therefore `pep487` contains patched versions of `ABC`
+and `ABCMeta`.
diff --git a/third_party/python/pep487/lib/pep487/__init__.py b/third_party/python/pep487/lib/pep487/__init__.py
new file mode 100644
index 0000000000..1bfcec0036
--- /dev/null
+++ b/third_party/python/pep487/lib/pep487/__init__.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2017 by Gregor Giesen
+#
+# This is a backport of PEP487's simpler customisation of class
+# creation by Martin Teichmann <https://www.python.org/dev/peps/pep-0487/>
+# for Python versions before 3.6.
+#
+# PEP487 is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published
+# by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# PEP487 is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with PEP487. If not, see <http://www.gnu.org/licenses/>.
+#
+"""pep487.py: Simpler customisation of class creation"""
+
+import abc
+import sys
+import types
+
+__all__ = ('PEP487Meta', 'PEP487Object', 'ABCMeta', 'ABC')
+
+HAS_PY36 = sys.version_info >= (3, 6)
+HAS_PEP487 = HAS_PY36
+
+if HAS_PEP487:
+ PEP487Meta = type # pragma: no cover
+ ABCMeta = abc.ABCMeta # pragma: no cover
+ ABC = abc.ABC # pragma: no cover
+ PEP487Base = object # pragma: no cover
+ PEP487Object = object # pragma: no cover
+else:
+ class PEP487Meta(type):
+ def __new__(mcls, name, bases, ns, **kwargs):
+ init = ns.get('__init_subclass__')
+ if isinstance(init, types.FunctionType):
+ ns['__init_subclass__'] = classmethod(init)
+ cls = super().__new__(mcls, name, bases, ns)
+ for key, value in cls.__dict__.items():
+ func = getattr(value, '__set_name__', None)
+ if func is not None:
+ func(cls, key)
+ super(cls, cls).__init_subclass__(**kwargs)
+ return cls
+
+ def __init__(cls, name, bases, ns, **kwargs):
+ super().__init__(name, bases, ns)
+
+ class ABCMeta(abc.ABCMeta):
+ def __new__(mcls, name, bases, ns, **kwargs):
+ init = ns.get('__init_subclass__')
+ if isinstance(init, types.FunctionType):
+ ns['__init_subclass__'] = classmethod(init)
+ cls = super().__new__(mcls, name, bases, ns)
+ for key, value in cls.__dict__.items():
+ func = getattr(value, '__set_name__', None)
+ if func is not None:
+ func(cls, key)
+ super(cls, cls).__init_subclass__(**kwargs)
+ return cls
+
+ def __init__(cls, name, bases, ns, **kwargs):
+ super().__init__(name, bases, ns)
+
+ class PEP487Base:
+ @classmethod
+ def __init_subclass__(cls, **kwargs):
+ pass
+
+ class PEP487Object(PEP487Base, metaclass=PEP487Meta):
+ pass
+
+ class ABC(PEP487Base, metaclass=ABCMeta):
+ pass
diff --git a/third_party/python/pep487/lib/pep487/version.py b/third_party/python/pep487/lib/pep487/version.py
new file mode 100644
index 0000000000..02a2605ea5
--- /dev/null
+++ b/third_party/python/pep487/lib/pep487/version.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2017 by Gregor Giesen
+#
+# This file is part of PEP487.
+#
+# PEP487 is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published
+# by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# PEP487 is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with PEP487. If not, see <http://www.gnu.org/licenses/>.
+#
+"""pep487/version.py: version info"""
+
+__author__ = "Gregor Giesen"
+__copyright__ = "Copyright 2017, Gregor Giesen"
+__credits__ = ["Martin Teichmann", "Gregor Giesen"]
+__license__ = "GPLv3"
+__version__ = "1.0.1"
+__maintainer__ = "Gregor Giesen"
diff --git a/third_party/python/pep487/setup.cfg b/third_party/python/pep487/setup.cfg
new file mode 100644
index 0000000000..f80f35b7f5
--- /dev/null
+++ b/third_party/python/pep487/setup.cfg
@@ -0,0 +1,12 @@
+[bdist_wheel]
+universal = 1
+
+[aliases]
+test = pytest
+
+[tool:pytest]
+
+[egg_info]
+tag_build =
+tag_date = 0
+
diff --git a/third_party/python/pep487/setup.py b/third_party/python/pep487/setup.py
new file mode 100644
index 0000000000..a3d833202b
--- /dev/null
+++ b/third_party/python/pep487/setup.py
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2017 by Gregor Giesen
+#
+# This file is part of PEP487.
+#
+# PEP487 is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published
+# by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# PEP487 is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with PEP487. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# Always prefer setuptools over distutils
+from setuptools import setup, find_packages
+# To use a consistent encoding
+from codecs import open
+import re
+import os.path
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+version_file = os.path.join(here, 'lib', 'pep487', 'version.py')
+with open(version_file, 'rt') as fp:
+ re_version = re.compile(
+ r"""^__version__[ ]*=[ ]*["']{1,3}(.+)["']{1,3}$""")
+ for line in fp:
+ r = re_version.match(line)
+ if r is not None:
+ version = r.group(1)
+ break
+ else:
+ raise RuntimeError("Cannot find version string in %s" % version_file)
+
+# Get the long description from the README file
+with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
+ long_description = f.read()
+
+setup(
+ name='pep487',
+
+ # Versions should comply with PEP440. For a discussion on single-sourcing
+ # the version across setup.py and the project code, see
+ # https://packaging.python.org/en/latest/single_source_version.html
+ version=version,
+
+ description='PEP487 - Simpler customisation of class creation',
+ long_description=long_description,
+
+ # The project's main homepage.
+ url='https://github.com/zaehlwerk/pep487',
+
+ # Author details
+ author='Gregor Giesen',
+ author_email='giesen@zaehlwerk.net',
+
+ # Choose your license
+ license="GPLv3",
+
+ # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 3.4',
+ 'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: 3.6',
+ ],
+
+ # What does your project relate to?
+ keywords='pep487',
+
+ # You can just specify the packages manually here if your project is
+ # simple. Or you can use find_packages().
+ package_dir={'': 'lib'},
+ packages=find_packages('lib', exclude=['tests']),
+
+ # List run-time dependencies here. These will be installed by pip when
+ # your project is installed. For an analysis of "install_requires" vs pip's
+ # requirements files see:
+ # https://packaging.python.org/en/latest/requirements.html
+ install_requires=[],
+
+ # List additional groups of dependencies here (e.g. development
+ # dependencies). You can install these using the following syntax,
+ # for example:
+ # $ pip install -e .[dev,test]
+ extras_require={
+ 'test': ['pytest',
+ 'pytest-cov',
+ 'pytest-flakes',
+ 'pytest-mock',
+ 'pytest-pep8',
+ 'pytest-runner'],
+ },
+
+ # If there are data files included in your packages that need to be
+ # installed, specify them here. If using Python 2.6 or less, then these
+ # have to be included in MANIFEST.in as well.
+ package_data={},
+
+ setup_requires=['pytest-runner'],
+ tests_require=['pytest',
+ 'pytest-cov',
+ 'pytest-flakes',
+ 'pytest-pep8',
+ 'pytest-mock'],
+
+ # To provide executable scripts, use entry points in preference to the
+ # "scripts" keyword. Entry points provide cross-platform support and allow
+ # pip to create the appropriate form of executable for the target platform.
+ entry_points={},
+)