summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--python-pylibyaml.spec519
-rw-r--r--sources1
3 files changed, 521 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..bd71239 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/pylibyaml-0.1.0.tar.gz
diff --git a/python-pylibyaml.spec b/python-pylibyaml.spec
new file mode 100644
index 0000000..7e4a951
--- /dev/null
+++ b/python-pylibyaml.spec
@@ -0,0 +1,519 @@
+%global _empty_manifest_terminate_build 0
+Name: python-pylibyaml
+Version: 0.1.0
+Release: 1
+Summary: Speed up PyYAML by automatically enabling LibYAML bindings.
+License: MIT License
+URL: https://github.com/philsphicas/pylibyaml
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/c9/1a/3ae773a0d4cc0b787d1b7307786c666de0729df2c4159ec964e8ba45d06d/pylibyaml-0.1.0.tar.gz
+BuildArch: noarch
+
+
+%description
+# pylibyaml
+
+pylibyaml is a simple Python module that monkey patches PyYAML to
+automatically enable the fast LibYAML-based parser and emitter if they
+are installed.
+
+## Installation
+
+To install, run:
+
+ pip install pylibyaml
+
+There is no explicit requirement for PyYAML or LibYAML to be installed
+in advance, but this package will be useless without them. Please refer
+to the PyYAML installation documentation, especially the points about
+installing the LibYAML bindings.
+
+- https://pyyaml.org/wiki/PyYAMLDocumentation
+- https://pyyaml.org/wiki/LibYAML
+
+## Usage
+
+Run `import pylibyaml` **BEFORE** `import yaml`, and enjoy!
+
+```python
+import pylibyaml
+import yaml
+
+yaml.safe_load(stream)
+yaml.load(stream, Loader=yaml.SafeLoader)
+
+yaml.safe_dump(data)
+yaml.dump(data, Dumper=yaml.SafeDumper)
+```
+
+Most existing code should run without modification. Any references to
+`yaml.Loader` and `yaml.Dumper` (including `Safe`, `Unsafe`, and `Full`
+flavors) will automatically point to their `yaml.cyaml.CLoader` and
+`yaml.cyaml.CDumper` equivalents. The convenience methods (`safe_load`,
+`safe_dump`, etc.) will all use the C classes, as well as the methods
+for adding resolvers, constructors, or representers. Objects that
+inherit from `YAMLObject` should work as intended.
+
+## Details
+
+### Background
+
+PyYAML is the canonical YAML parser and emitter library for Python. It
+is not particularly fast.
+
+LibYAML is a C library for parsing and emitting YAML. It is very fast.
+
+By default, the setup.py script for PyYAML checks whether LibYAML is
+installed and if so, builds and installs LibYAML bindings.
+
+For the bindings to actually be used, they need to be explicitly
+selected. The PyYAML documentation suggests some variations of the
+following:
+
+> When LibYAML bindings are installed, you may use fast LibYAML-based
+parser and emitter as follows:
+
+ >>> yaml.load(stream, Loader=yaml.CLoader)
+ >>> yaml.dump(data, Dumper=yaml.CDumper)
+
+> In order to use LibYAML based parser and emitter, use the classes
+> CParser and CEmitter. For instance,
+
+ from yaml import load, dump
+ try:
+ from yaml import CLoader as Loader, CDumper as Dumper
+ except ImportError:
+ from yaml import Loader, Dumper
+ # ...
+ data = load(stream, Loader=Loader)
+ # ...
+ output = dump(data, Dumper=Dumper)
+
+This approach is repetitive, inconvenient, and ineffectual when dealing
+with third-party libraries that also use PyYAML.
+
+### Implementation
+
+The approach taken by `pylibyaml` is to rebind the global names of the
+Loaders and Dumpers in the `yaml` module to the LibYAML versions if they
+are available, before the various functions and classes are defined.
+
+For example, compare the following.
+
+Without pylibyaml:
+
+ >>> import yaml
+ >>> yaml.Loader
+ <class 'yaml.loader.Loader'>
+ >>> yaml.Dumper
+ <class 'yaml.dumper.Dumper'>
+ >>> help(yaml.dump)
+ Help on function dump in module yaml:
+
+ dump(data, stream=None, Dumper=<class 'yaml.dumper.Dumper'>, **kwds)
+ Serialize a Python object into a YAML stream.
+ If stream is None, return the produced string instead.
+
+Using pylibyaml (with LibYAML bindings available):
+
+ >>> import pylibyaml
+ >>> import yaml
+ >>> yaml.Loader
+ <class 'yaml.cyaml.CLoader'>
+ >>> yaml.Dumper
+ <class 'yaml.cyaml.CDumper'>
+ >>> help(yaml.dump)
+ Help on function dump in module yaml:
+
+ dump(data, stream=None, Dumper=<class 'yaml.cyaml.CDumper'>, **kwds)
+ Serialize a Python object into a YAML stream.
+ If stream is None, return the produced string instead.
+
+Note that the top-level names now point to the cyaml versions, and that
+the default function arguments have changed.
+
+The code samples above will still run without modification, but the second
+can be simplified - the logic of determining the best loader and dumper is
+not longer required.
+
+ import pylibyaml
+ from yaml import load, dump
+ from yaml import Loader, Dumper
+ # ...
+ data = load(stream, Loader=Loader)
+ # ...
+ output = dump(data, Dumper=Dumper)
+
+## Caveats
+
+### This is a rather ugly hack.
+
+In order need to rebind the names of the default loaders and dumpers
+prior to the function and class definitions in PyYAML's `__init__.py`,
+we use `inspect` to get the source, edit it, and reload it with
+`importlib`. This works for now (the current version of PyYAML is
+5.3.1), and as far back as 3.11, but it may not always.
+
+### LibYAML and PyYAML are not 100% interchangeable.
+
+From the [PyYAML docs](https://pyyaml.org/wiki/PyYAMLDocumentation):
+
+> Note that there are some subtle (but not really significant)
+> differences between pure Python and
+> [LibYAML](https://pyyaml.org/wiki/LibYAML) based parsers and emitters.
+
+%package -n python3-pylibyaml
+Summary: Speed up PyYAML by automatically enabling LibYAML bindings.
+Provides: python-pylibyaml
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-pylibyaml
+# pylibyaml
+
+pylibyaml is a simple Python module that monkey patches PyYAML to
+automatically enable the fast LibYAML-based parser and emitter if they
+are installed.
+
+## Installation
+
+To install, run:
+
+ pip install pylibyaml
+
+There is no explicit requirement for PyYAML or LibYAML to be installed
+in advance, but this package will be useless without them. Please refer
+to the PyYAML installation documentation, especially the points about
+installing the LibYAML bindings.
+
+- https://pyyaml.org/wiki/PyYAMLDocumentation
+- https://pyyaml.org/wiki/LibYAML
+
+## Usage
+
+Run `import pylibyaml` **BEFORE** `import yaml`, and enjoy!
+
+```python
+import pylibyaml
+import yaml
+
+yaml.safe_load(stream)
+yaml.load(stream, Loader=yaml.SafeLoader)
+
+yaml.safe_dump(data)
+yaml.dump(data, Dumper=yaml.SafeDumper)
+```
+
+Most existing code should run without modification. Any references to
+`yaml.Loader` and `yaml.Dumper` (including `Safe`, `Unsafe`, and `Full`
+flavors) will automatically point to their `yaml.cyaml.CLoader` and
+`yaml.cyaml.CDumper` equivalents. The convenience methods (`safe_load`,
+`safe_dump`, etc.) will all use the C classes, as well as the methods
+for adding resolvers, constructors, or representers. Objects that
+inherit from `YAMLObject` should work as intended.
+
+## Details
+
+### Background
+
+PyYAML is the canonical YAML parser and emitter library for Python. It
+is not particularly fast.
+
+LibYAML is a C library for parsing and emitting YAML. It is very fast.
+
+By default, the setup.py script for PyYAML checks whether LibYAML is
+installed and if so, builds and installs LibYAML bindings.
+
+For the bindings to actually be used, they need to be explicitly
+selected. The PyYAML documentation suggests some variations of the
+following:
+
+> When LibYAML bindings are installed, you may use fast LibYAML-based
+parser and emitter as follows:
+
+ >>> yaml.load(stream, Loader=yaml.CLoader)
+ >>> yaml.dump(data, Dumper=yaml.CDumper)
+
+> In order to use LibYAML based parser and emitter, use the classes
+> CParser and CEmitter. For instance,
+
+ from yaml import load, dump
+ try:
+ from yaml import CLoader as Loader, CDumper as Dumper
+ except ImportError:
+ from yaml import Loader, Dumper
+ # ...
+ data = load(stream, Loader=Loader)
+ # ...
+ output = dump(data, Dumper=Dumper)
+
+This approach is repetitive, inconvenient, and ineffectual when dealing
+with third-party libraries that also use PyYAML.
+
+### Implementation
+
+The approach taken by `pylibyaml` is to rebind the global names of the
+Loaders and Dumpers in the `yaml` module to the LibYAML versions if they
+are available, before the various functions and classes are defined.
+
+For example, compare the following.
+
+Without pylibyaml:
+
+ >>> import yaml
+ >>> yaml.Loader
+ <class 'yaml.loader.Loader'>
+ >>> yaml.Dumper
+ <class 'yaml.dumper.Dumper'>
+ >>> help(yaml.dump)
+ Help on function dump in module yaml:
+
+ dump(data, stream=None, Dumper=<class 'yaml.dumper.Dumper'>, **kwds)
+ Serialize a Python object into a YAML stream.
+ If stream is None, return the produced string instead.
+
+Using pylibyaml (with LibYAML bindings available):
+
+ >>> import pylibyaml
+ >>> import yaml
+ >>> yaml.Loader
+ <class 'yaml.cyaml.CLoader'>
+ >>> yaml.Dumper
+ <class 'yaml.cyaml.CDumper'>
+ >>> help(yaml.dump)
+ Help on function dump in module yaml:
+
+ dump(data, stream=None, Dumper=<class 'yaml.cyaml.CDumper'>, **kwds)
+ Serialize a Python object into a YAML stream.
+ If stream is None, return the produced string instead.
+
+Note that the top-level names now point to the cyaml versions, and that
+the default function arguments have changed.
+
+The code samples above will still run without modification, but the second
+can be simplified - the logic of determining the best loader and dumper is
+not longer required.
+
+ import pylibyaml
+ from yaml import load, dump
+ from yaml import Loader, Dumper
+ # ...
+ data = load(stream, Loader=Loader)
+ # ...
+ output = dump(data, Dumper=Dumper)
+
+## Caveats
+
+### This is a rather ugly hack.
+
+In order need to rebind the names of the default loaders and dumpers
+prior to the function and class definitions in PyYAML's `__init__.py`,
+we use `inspect` to get the source, edit it, and reload it with
+`importlib`. This works for now (the current version of PyYAML is
+5.3.1), and as far back as 3.11, but it may not always.
+
+### LibYAML and PyYAML are not 100% interchangeable.
+
+From the [PyYAML docs](https://pyyaml.org/wiki/PyYAMLDocumentation):
+
+> Note that there are some subtle (but not really significant)
+> differences between pure Python and
+> [LibYAML](https://pyyaml.org/wiki/LibYAML) based parsers and emitters.
+
+%package help
+Summary: Development documents and examples for pylibyaml
+Provides: python3-pylibyaml-doc
+%description help
+# pylibyaml
+
+pylibyaml is a simple Python module that monkey patches PyYAML to
+automatically enable the fast LibYAML-based parser and emitter if they
+are installed.
+
+## Installation
+
+To install, run:
+
+ pip install pylibyaml
+
+There is no explicit requirement for PyYAML or LibYAML to be installed
+in advance, but this package will be useless without them. Please refer
+to the PyYAML installation documentation, especially the points about
+installing the LibYAML bindings.
+
+- https://pyyaml.org/wiki/PyYAMLDocumentation
+- https://pyyaml.org/wiki/LibYAML
+
+## Usage
+
+Run `import pylibyaml` **BEFORE** `import yaml`, and enjoy!
+
+```python
+import pylibyaml
+import yaml
+
+yaml.safe_load(stream)
+yaml.load(stream, Loader=yaml.SafeLoader)
+
+yaml.safe_dump(data)
+yaml.dump(data, Dumper=yaml.SafeDumper)
+```
+
+Most existing code should run without modification. Any references to
+`yaml.Loader` and `yaml.Dumper` (including `Safe`, `Unsafe`, and `Full`
+flavors) will automatically point to their `yaml.cyaml.CLoader` and
+`yaml.cyaml.CDumper` equivalents. The convenience methods (`safe_load`,
+`safe_dump`, etc.) will all use the C classes, as well as the methods
+for adding resolvers, constructors, or representers. Objects that
+inherit from `YAMLObject` should work as intended.
+
+## Details
+
+### Background
+
+PyYAML is the canonical YAML parser and emitter library for Python. It
+is not particularly fast.
+
+LibYAML is a C library for parsing and emitting YAML. It is very fast.
+
+By default, the setup.py script for PyYAML checks whether LibYAML is
+installed and if so, builds and installs LibYAML bindings.
+
+For the bindings to actually be used, they need to be explicitly
+selected. The PyYAML documentation suggests some variations of the
+following:
+
+> When LibYAML bindings are installed, you may use fast LibYAML-based
+parser and emitter as follows:
+
+ >>> yaml.load(stream, Loader=yaml.CLoader)
+ >>> yaml.dump(data, Dumper=yaml.CDumper)
+
+> In order to use LibYAML based parser and emitter, use the classes
+> CParser and CEmitter. For instance,
+
+ from yaml import load, dump
+ try:
+ from yaml import CLoader as Loader, CDumper as Dumper
+ except ImportError:
+ from yaml import Loader, Dumper
+ # ...
+ data = load(stream, Loader=Loader)
+ # ...
+ output = dump(data, Dumper=Dumper)
+
+This approach is repetitive, inconvenient, and ineffectual when dealing
+with third-party libraries that also use PyYAML.
+
+### Implementation
+
+The approach taken by `pylibyaml` is to rebind the global names of the
+Loaders and Dumpers in the `yaml` module to the LibYAML versions if they
+are available, before the various functions and classes are defined.
+
+For example, compare the following.
+
+Without pylibyaml:
+
+ >>> import yaml
+ >>> yaml.Loader
+ <class 'yaml.loader.Loader'>
+ >>> yaml.Dumper
+ <class 'yaml.dumper.Dumper'>
+ >>> help(yaml.dump)
+ Help on function dump in module yaml:
+
+ dump(data, stream=None, Dumper=<class 'yaml.dumper.Dumper'>, **kwds)
+ Serialize a Python object into a YAML stream.
+ If stream is None, return the produced string instead.
+
+Using pylibyaml (with LibYAML bindings available):
+
+ >>> import pylibyaml
+ >>> import yaml
+ >>> yaml.Loader
+ <class 'yaml.cyaml.CLoader'>
+ >>> yaml.Dumper
+ <class 'yaml.cyaml.CDumper'>
+ >>> help(yaml.dump)
+ Help on function dump in module yaml:
+
+ dump(data, stream=None, Dumper=<class 'yaml.cyaml.CDumper'>, **kwds)
+ Serialize a Python object into a YAML stream.
+ If stream is None, return the produced string instead.
+
+Note that the top-level names now point to the cyaml versions, and that
+the default function arguments have changed.
+
+The code samples above will still run without modification, but the second
+can be simplified - the logic of determining the best loader and dumper is
+not longer required.
+
+ import pylibyaml
+ from yaml import load, dump
+ from yaml import Loader, Dumper
+ # ...
+ data = load(stream, Loader=Loader)
+ # ...
+ output = dump(data, Dumper=Dumper)
+
+## Caveats
+
+### This is a rather ugly hack.
+
+In order need to rebind the names of the default loaders and dumpers
+prior to the function and class definitions in PyYAML's `__init__.py`,
+we use `inspect` to get the source, edit it, and reload it with
+`importlib`. This works for now (the current version of PyYAML is
+5.3.1), and as far back as 3.11, but it may not always.
+
+### LibYAML and PyYAML are not 100% interchangeable.
+
+From the [PyYAML docs](https://pyyaml.org/wiki/PyYAMLDocumentation):
+
+> Note that there are some subtle (but not really significant)
+> differences between pure Python and
+> [LibYAML](https://pyyaml.org/wiki/LibYAML) based parsers and emitters.
+
+%prep
+%autosetup -n pylibyaml-0.1.0
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-pylibyaml -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.0-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..7f0ec93
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+825ea77151d7e91e3d5f2143712ece50 pylibyaml-0.1.0.tar.gz