diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-pydifact.spec | 438 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 440 insertions, 0 deletions
@@ -0,0 +1 @@ +/pydifact-0.1.6.tar.gz diff --git a/python-pydifact.spec b/python-pydifact.spec new file mode 100644 index 0000000..3be2ae9 --- /dev/null +++ b/python-pydifact.spec @@ -0,0 +1,438 @@ +%global _empty_manifest_terminate_build 0 +Name: python-pydifact +Version: 0.1.6 +Release: 1 +Summary: A Python EDI file parser. +License: MIT +URL: https://github.com/nerdocs/pydifact +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/32/3e/283218a3c61fb41a1500111080de9bf31f299f8af1f18d4a39a65e787cde/pydifact-0.1.6.tar.gz +BuildArch: noarch + + +%description +# pydifact + +A Python library to parse and serialize UN/EDIFACT interchanges. + +## Preamble + +This is a port of [metroplex-systems/edifact](https://github.com/metroplex-systems/edifact) to Python. Thanks here at the start to [Craig Duncan](https://github.com/duncan3dc) for this cool piece of software. Porting was like a breeze due to the high code quality there. All credits for the initial code here go to him, I just did the translation to Python(3), some "pythonifications" of the code and little improvements. + +### Why another EDIFACT library? + +Because I did not find a decent UN/EDIFACT library for Python, so I decided to port one of the available good PHP libraries to Python. Here is the result. + +ATM this is a Work In Progress, the API is not stable yet. +Feel free to help. + +## Install + +As usual, use a virtualenv, and install via pip or pipenv: + +```bash +pip install pydifact +``` + +However, it is not stable yet, so the pypi version, including documentation and code examples, could differ from the latest git code. If in doubt, use the git version: +```bash +git clone https://github.com/nerdocs/pydifact.git +cd pydifact +pip install -e . +``` + + +## Usage + +To read a full Interchange from a file or string, take the `Interchange` class and +iter over the messages and segments: + +```python +from pydifact.segmentcollection import Interchange +interchange = Interchange.from_file("./tests/data/order.edi") +interchange = Interchange.from_str( + "UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'UNT+2+42z42'UNZ+2+42'" +) +for message in interchange.get_messages(): + for segment in message.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) +``` + +You may also want to iterate directly on segments : + +```python +from pydifact.segmentcollection import Interchange +interchange = Interchange.from_file("./tests/data/order.edi") +interchange = Interchange.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'") + +for segment in interchange.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) +``` + +Or you can create an EDI interchange on the fly: + +```python +from pydifact.segmentcollection import Interchange +from pydifact.segments import Segment +interchange = Interchange() +interchange.add_segment(Segment('QTY', ['12', '3'])) +print(interchange.serialize()) +``` + +You may also want to parse a « raw » segment bunch which is not an interchange : + +``` +from pydifact.segmentcollection import RawSegmentCollection +collection = RawSegmentCollection.from_str("UNH+1+ORDERS:D:96A:UN:EAN008'") + +for segment in collection.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) + +``` + + +## Limitations + +- No support of optional functional groups (`UNG`→`UNE`), + +## Alternatives + +In python ecosystem: + +- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained. +- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine. +- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping. + + +## Development + +To develop pydifact, install the dev requirements with `pipenv install --dev`. This installs all the python packages needed for development and testing. + +Format all python files using [black](https://black.readthedocs.io). + +Happy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs. Nevertheless, don't forget adding tests for every aspect you add in code. + +### Testing + +pydifact uses [pytest](http://pytest.org) for testing. +Just exec `pytest` within the project folder to execute the unit tests. + +There is one test to check the performance of parsing huge files, named `test_huge_message` - you can skip that test by calling + +```bash +pytest --ignore tests/test_huge_message.py +``` +This is recommended for fast testing. + + +## License + +This library is licensed under the +*MIT* license, see the +[LICENSE file](LICENSE). + + +%package -n python3-pydifact +Summary: A Python EDI file parser. +Provides: python-pydifact +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-pydifact +# pydifact + +A Python library to parse and serialize UN/EDIFACT interchanges. + +## Preamble + +This is a port of [metroplex-systems/edifact](https://github.com/metroplex-systems/edifact) to Python. Thanks here at the start to [Craig Duncan](https://github.com/duncan3dc) for this cool piece of software. Porting was like a breeze due to the high code quality there. All credits for the initial code here go to him, I just did the translation to Python(3), some "pythonifications" of the code and little improvements. + +### Why another EDIFACT library? + +Because I did not find a decent UN/EDIFACT library for Python, so I decided to port one of the available good PHP libraries to Python. Here is the result. + +ATM this is a Work In Progress, the API is not stable yet. +Feel free to help. + +## Install + +As usual, use a virtualenv, and install via pip or pipenv: + +```bash +pip install pydifact +``` + +However, it is not stable yet, so the pypi version, including documentation and code examples, could differ from the latest git code. If in doubt, use the git version: +```bash +git clone https://github.com/nerdocs/pydifact.git +cd pydifact +pip install -e . +``` + + +## Usage + +To read a full Interchange from a file or string, take the `Interchange` class and +iter over the messages and segments: + +```python +from pydifact.segmentcollection import Interchange +interchange = Interchange.from_file("./tests/data/order.edi") +interchange = Interchange.from_str( + "UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'UNT+2+42z42'UNZ+2+42'" +) +for message in interchange.get_messages(): + for segment in message.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) +``` + +You may also want to iterate directly on segments : + +```python +from pydifact.segmentcollection import Interchange +interchange = Interchange.from_file("./tests/data/order.edi") +interchange = Interchange.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'") + +for segment in interchange.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) +``` + +Or you can create an EDI interchange on the fly: + +```python +from pydifact.segmentcollection import Interchange +from pydifact.segments import Segment +interchange = Interchange() +interchange.add_segment(Segment('QTY', ['12', '3'])) +print(interchange.serialize()) +``` + +You may also want to parse a « raw » segment bunch which is not an interchange : + +``` +from pydifact.segmentcollection import RawSegmentCollection +collection = RawSegmentCollection.from_str("UNH+1+ORDERS:D:96A:UN:EAN008'") + +for segment in collection.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) + +``` + + +## Limitations + +- No support of optional functional groups (`UNG`→`UNE`), + +## Alternatives + +In python ecosystem: + +- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained. +- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine. +- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping. + + +## Development + +To develop pydifact, install the dev requirements with `pipenv install --dev`. This installs all the python packages needed for development and testing. + +Format all python files using [black](https://black.readthedocs.io). + +Happy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs. Nevertheless, don't forget adding tests for every aspect you add in code. + +### Testing + +pydifact uses [pytest](http://pytest.org) for testing. +Just exec `pytest` within the project folder to execute the unit tests. + +There is one test to check the performance of parsing huge files, named `test_huge_message` - you can skip that test by calling + +```bash +pytest --ignore tests/test_huge_message.py +``` +This is recommended for fast testing. + + +## License + +This library is licensed under the +*MIT* license, see the +[LICENSE file](LICENSE). + + +%package help +Summary: Development documents and examples for pydifact +Provides: python3-pydifact-doc +%description help +# pydifact + +A Python library to parse and serialize UN/EDIFACT interchanges. + +## Preamble + +This is a port of [metroplex-systems/edifact](https://github.com/metroplex-systems/edifact) to Python. Thanks here at the start to [Craig Duncan](https://github.com/duncan3dc) for this cool piece of software. Porting was like a breeze due to the high code quality there. All credits for the initial code here go to him, I just did the translation to Python(3), some "pythonifications" of the code and little improvements. + +### Why another EDIFACT library? + +Because I did not find a decent UN/EDIFACT library for Python, so I decided to port one of the available good PHP libraries to Python. Here is the result. + +ATM this is a Work In Progress, the API is not stable yet. +Feel free to help. + +## Install + +As usual, use a virtualenv, and install via pip or pipenv: + +```bash +pip install pydifact +``` + +However, it is not stable yet, so the pypi version, including documentation and code examples, could differ from the latest git code. If in doubt, use the git version: +```bash +git clone https://github.com/nerdocs/pydifact.git +cd pydifact +pip install -e . +``` + + +## Usage + +To read a full Interchange from a file or string, take the `Interchange` class and +iter over the messages and segments: + +```python +from pydifact.segmentcollection import Interchange +interchange = Interchange.from_file("./tests/data/order.edi") +interchange = Interchange.from_str( + "UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'UNT+2+42z42'UNZ+2+42'" +) +for message in interchange.get_messages(): + for segment in message.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) +``` + +You may also want to iterate directly on segments : + +```python +from pydifact.segmentcollection import Interchange +interchange = Interchange.from_file("./tests/data/order.edi") +interchange = Interchange.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'") + +for segment in interchange.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) +``` + +Or you can create an EDI interchange on the fly: + +```python +from pydifact.segmentcollection import Interchange +from pydifact.segments import Segment +interchange = Interchange() +interchange.add_segment(Segment('QTY', ['12', '3'])) +print(interchange.serialize()) +``` + +You may also want to parse a « raw » segment bunch which is not an interchange : + +``` +from pydifact.segmentcollection import RawSegmentCollection +collection = RawSegmentCollection.from_str("UNH+1+ORDERS:D:96A:UN:EAN008'") + +for segment in collection.segments: + print('Segment tag: {}, content: {}'.format( + segment.tag, segment.elements)) + +``` + + +## Limitations + +- No support of optional functional groups (`UNG`→`UNE`), + +## Alternatives + +In python ecosystem: + +- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained. +- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine. +- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping. + + +## Development + +To develop pydifact, install the dev requirements with `pipenv install --dev`. This installs all the python packages needed for development and testing. + +Format all python files using [black](https://black.readthedocs.io). + +Happy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs. Nevertheless, don't forget adding tests for every aspect you add in code. + +### Testing + +pydifact uses [pytest](http://pytest.org) for testing. +Just exec `pytest` within the project folder to execute the unit tests. + +There is one test to check the performance of parsing huge files, named `test_huge_message` - you can skip that test by calling + +```bash +pytest --ignore tests/test_huge_message.py +``` +This is recommended for fast testing. + + +## License + +This library is licensed under the +*MIT* license, see the +[LICENSE file](LICENSE). + + +%prep +%autosetup -n pydifact-0.1.6 + +%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-pydifact -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.6-1 +- Package Spec generated @@ -0,0 +1 @@ +73bc9fbcf016d2ba0c8746e3cfb0c87e pydifact-0.1.6.tar.gz |
