summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-05-17 04:57:13 +0000
committerCoprDistGit <infra@openeuler.org>2023-05-17 04:57:13 +0000
commit86876e5a71f18ee547aedb8bf6a37328828acbbe (patch)
tree9e474c162aa23a8cc18b4e035ba7f715acb4d0f2
parente9b43e3f939ded0998340193ba6382182fe4d63d (diff)
automatic import of python-avro-to-python-types
-rw-r--r--.gitignore1
-rw-r--r--python-avro-to-python-types.spec445
-rw-r--r--sources1
3 files changed, 447 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..8f18925 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/avro-to-python-types-0.12.1.tar.gz
diff --git a/python-avro-to-python-types.spec b/python-avro-to-python-types.spec
new file mode 100644
index 0000000..c8ff642
--- /dev/null
+++ b/python-avro-to-python-types.spec
@@ -0,0 +1,445 @@
+%global _empty_manifest_terminate_build 0
+Name: python-avro-to-python-types
+Version: 0.12.1
+Release: 1
+Summary: A library for converting avro schemas to python types.
+License: MIT
+URL: https://github.com/waveaccounting/avro-to-python-types
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/3f/2a/21e735b43d072d60c53ae7b4b8eafb24b20e72cb26d1577aa8e80d4f381b/avro-to-python-types-0.12.1.tar.gz
+BuildArch: noarch
+
+Requires: python3-fastavro
+
+%description
+# avro-to-python-types
+
+A library for converting avro schemas to python types.
+
+Currently, it supports converting `record`s to `TypedDict`. If you would like to see more features added, please open up an issue.
+
+## Why would I want this?
+
+This library is targeted to people writing code generation for python apps that are using [avro](https://avro.apache.org/docs/current/spec.html).
+
+## Usage
+
+This library does [one thing](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well), it converts Avro schemas to python types.
+
+To get up and running quickly, you can use this to simply load schemas and print out the python
+code that is generated.
+
+```python
+import glob
+from avro_to_python_types import typed_dict_from_schema_file
+
+schema_files = glob.glob("schemas/*.avsc")
+
+for schema_file in schema_files:
+ types = typed_dict_from_schema_file(schema_file)
+ print(types)
+
+```
+
+For a real world example of syncing a directory of schemas into a directory of matching python typed dictionaries
+check out the example app [here](/examples/sync_types)
+
+To try it out, simply clone this repo and run:
+
+`poetry env use 3.9`
+- This must be done as this library only supports Python 3.9 and above for type generation. You can still use this library in apps that use a lower Python version, as long as Python 3.9 is the active version when the types are generated (either locally or in your CI system).
+
+`poetry install`
+
+`poetry run sync-example`
+
+For some more advanced examples, like referencing other schema files by their full name take a look at the tests [here](/tests)
+
+### Referencing schemas
+
+This library supports referencing schemas in different files by their fullname.
+
+In order for this behaviour to work, all schemas must be in the same directory and use the following naming convention: `namespace.name.avsc`. Note that is the same as `fullname.avsc`
+
+For more on this checkout the docs for fastavro [here](https://fastavro.readthedocs.io/en/latest/schema.html#fastavro._schema_py.load_schema).
+
+An example of this can be found in the tests.
+
+### Example output
+
+The following example shows the type generated for a given schema.
+
+```json
+{
+ "namespace": "example",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ { "name": "name", "type": "string" },
+ { "name": "favorite_number", "type": ["null", "int"] },
+ { "name": "favorite_color", "type": ["null", "string"] },
+ {
+ "name": "address",
+ "type": {
+ "type": "record",
+ "name": "AddressUSRecord",
+ "fields": [
+ { "name": "streetaddress", "type": "string" },
+ { "name": "city", "type": "string" }
+ ]
+ }
+ },
+ {
+ "name": "other_thing",
+ "type": {
+ "type": "record",
+ "name": "OtherThing",
+ "fields": [
+ { "name": "thing1", "type": "string" },
+ { "name": "thing2", "type": ["null", "int"] }
+ ]
+ }
+ }
+ ]
+}
+```
+
+```python
+from typing import TypedDict, Optional
+
+# total=False allows us to skip passing optional fields into the constructor
+class ExampleAddressUSRecord(TypedDict, total=False):
+ streetaddress: str
+ city: str
+
+
+class ExampleOtherThing(TypedDict, total=False):
+ thing1: str
+ thing2: Optional[int]
+
+
+class ExampleUser(TypedDict, total=False):
+ name: str
+ favorite_number: Optional[int]
+ favorite_color: Optional[str]
+ address: AddressUSRecord
+ other_thing: OtherThing
+
+```
+
+## Testing
+
+To run unit tests, run `poetry run pytest`.
+
+You can also run tests in docker via `make test`
+
+## Requirements
+
+Python 3.9 or greater.
+
+
+%package -n python3-avro-to-python-types
+Summary: A library for converting avro schemas to python types.
+Provides: python-avro-to-python-types
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-avro-to-python-types
+# avro-to-python-types
+
+A library for converting avro schemas to python types.
+
+Currently, it supports converting `record`s to `TypedDict`. If you would like to see more features added, please open up an issue.
+
+## Why would I want this?
+
+This library is targeted to people writing code generation for python apps that are using [avro](https://avro.apache.org/docs/current/spec.html).
+
+## Usage
+
+This library does [one thing](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well), it converts Avro schemas to python types.
+
+To get up and running quickly, you can use this to simply load schemas and print out the python
+code that is generated.
+
+```python
+import glob
+from avro_to_python_types import typed_dict_from_schema_file
+
+schema_files = glob.glob("schemas/*.avsc")
+
+for schema_file in schema_files:
+ types = typed_dict_from_schema_file(schema_file)
+ print(types)
+
+```
+
+For a real world example of syncing a directory of schemas into a directory of matching python typed dictionaries
+check out the example app [here](/examples/sync_types)
+
+To try it out, simply clone this repo and run:
+
+`poetry env use 3.9`
+- This must be done as this library only supports Python 3.9 and above for type generation. You can still use this library in apps that use a lower Python version, as long as Python 3.9 is the active version when the types are generated (either locally or in your CI system).
+
+`poetry install`
+
+`poetry run sync-example`
+
+For some more advanced examples, like referencing other schema files by their full name take a look at the tests [here](/tests)
+
+### Referencing schemas
+
+This library supports referencing schemas in different files by their fullname.
+
+In order for this behaviour to work, all schemas must be in the same directory and use the following naming convention: `namespace.name.avsc`. Note that is the same as `fullname.avsc`
+
+For more on this checkout the docs for fastavro [here](https://fastavro.readthedocs.io/en/latest/schema.html#fastavro._schema_py.load_schema).
+
+An example of this can be found in the tests.
+
+### Example output
+
+The following example shows the type generated for a given schema.
+
+```json
+{
+ "namespace": "example",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ { "name": "name", "type": "string" },
+ { "name": "favorite_number", "type": ["null", "int"] },
+ { "name": "favorite_color", "type": ["null", "string"] },
+ {
+ "name": "address",
+ "type": {
+ "type": "record",
+ "name": "AddressUSRecord",
+ "fields": [
+ { "name": "streetaddress", "type": "string" },
+ { "name": "city", "type": "string" }
+ ]
+ }
+ },
+ {
+ "name": "other_thing",
+ "type": {
+ "type": "record",
+ "name": "OtherThing",
+ "fields": [
+ { "name": "thing1", "type": "string" },
+ { "name": "thing2", "type": ["null", "int"] }
+ ]
+ }
+ }
+ ]
+}
+```
+
+```python
+from typing import TypedDict, Optional
+
+# total=False allows us to skip passing optional fields into the constructor
+class ExampleAddressUSRecord(TypedDict, total=False):
+ streetaddress: str
+ city: str
+
+
+class ExampleOtherThing(TypedDict, total=False):
+ thing1: str
+ thing2: Optional[int]
+
+
+class ExampleUser(TypedDict, total=False):
+ name: str
+ favorite_number: Optional[int]
+ favorite_color: Optional[str]
+ address: AddressUSRecord
+ other_thing: OtherThing
+
+```
+
+## Testing
+
+To run unit tests, run `poetry run pytest`.
+
+You can also run tests in docker via `make test`
+
+## Requirements
+
+Python 3.9 or greater.
+
+
+%package help
+Summary: Development documents and examples for avro-to-python-types
+Provides: python3-avro-to-python-types-doc
+%description help
+# avro-to-python-types
+
+A library for converting avro schemas to python types.
+
+Currently, it supports converting `record`s to `TypedDict`. If you would like to see more features added, please open up an issue.
+
+## Why would I want this?
+
+This library is targeted to people writing code generation for python apps that are using [avro](https://avro.apache.org/docs/current/spec.html).
+
+## Usage
+
+This library does [one thing](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well), it converts Avro schemas to python types.
+
+To get up and running quickly, you can use this to simply load schemas and print out the python
+code that is generated.
+
+```python
+import glob
+from avro_to_python_types import typed_dict_from_schema_file
+
+schema_files = glob.glob("schemas/*.avsc")
+
+for schema_file in schema_files:
+ types = typed_dict_from_schema_file(schema_file)
+ print(types)
+
+```
+
+For a real world example of syncing a directory of schemas into a directory of matching python typed dictionaries
+check out the example app [here](/examples/sync_types)
+
+To try it out, simply clone this repo and run:
+
+`poetry env use 3.9`
+- This must be done as this library only supports Python 3.9 and above for type generation. You can still use this library in apps that use a lower Python version, as long as Python 3.9 is the active version when the types are generated (either locally or in your CI system).
+
+`poetry install`
+
+`poetry run sync-example`
+
+For some more advanced examples, like referencing other schema files by their full name take a look at the tests [here](/tests)
+
+### Referencing schemas
+
+This library supports referencing schemas in different files by their fullname.
+
+In order for this behaviour to work, all schemas must be in the same directory and use the following naming convention: `namespace.name.avsc`. Note that is the same as `fullname.avsc`
+
+For more on this checkout the docs for fastavro [here](https://fastavro.readthedocs.io/en/latest/schema.html#fastavro._schema_py.load_schema).
+
+An example of this can be found in the tests.
+
+### Example output
+
+The following example shows the type generated for a given schema.
+
+```json
+{
+ "namespace": "example",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ { "name": "name", "type": "string" },
+ { "name": "favorite_number", "type": ["null", "int"] },
+ { "name": "favorite_color", "type": ["null", "string"] },
+ {
+ "name": "address",
+ "type": {
+ "type": "record",
+ "name": "AddressUSRecord",
+ "fields": [
+ { "name": "streetaddress", "type": "string" },
+ { "name": "city", "type": "string" }
+ ]
+ }
+ },
+ {
+ "name": "other_thing",
+ "type": {
+ "type": "record",
+ "name": "OtherThing",
+ "fields": [
+ { "name": "thing1", "type": "string" },
+ { "name": "thing2", "type": ["null", "int"] }
+ ]
+ }
+ }
+ ]
+}
+```
+
+```python
+from typing import TypedDict, Optional
+
+# total=False allows us to skip passing optional fields into the constructor
+class ExampleAddressUSRecord(TypedDict, total=False):
+ streetaddress: str
+ city: str
+
+
+class ExampleOtherThing(TypedDict, total=False):
+ thing1: str
+ thing2: Optional[int]
+
+
+class ExampleUser(TypedDict, total=False):
+ name: str
+ favorite_number: Optional[int]
+ favorite_color: Optional[str]
+ address: AddressUSRecord
+ other_thing: OtherThing
+
+```
+
+## Testing
+
+To run unit tests, run `poetry run pytest`.
+
+You can also run tests in docker via `make test`
+
+## Requirements
+
+Python 3.9 or greater.
+
+
+%prep
+%autosetup -n avro-to-python-types-0.12.1
+
+%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-avro-to-python-types -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Wed May 17 2023 Python_Bot <Python_Bot@openeuler.org> - 0.12.1-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..2168b82
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+8f0475a6b68bf0d705b0f6095ea9bc5e avro-to-python-types-0.12.1.tar.gz