diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-04-11 05:27:16 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-04-11 05:27:16 +0000 |
| commit | 24a621d9855dbf13c2d7ef2f58cab5e022a4c3b1 (patch) | |
| tree | d85d8db20299aa132de9b02139f0a1ded7f0fc45 /python-astpretty.spec | |
| parent | 18dd1ade3c2818c46d07c46de5b3e95d82297b3f (diff) | |
automatic import of python-astpretty
Diffstat (limited to 'python-astpretty.spec')
| -rw-r--r-- | python-astpretty.spec | 432 |
1 files changed, 432 insertions, 0 deletions
diff --git a/python-astpretty.spec b/python-astpretty.spec new file mode 100644 index 0000000..4f77b21 --- /dev/null +++ b/python-astpretty.spec @@ -0,0 +1,432 @@ +%global _empty_manifest_terminate_build 0 +Name: python-astpretty +Version: 3.0.0 +Release: 1 +Summary: Pretty print the output of python stdlib `ast.parse`. +License: MIT +URL: https://github.com/asottile/astpretty +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/2d/b6/ffec7edce2a8315ef1acd4ae2e334ba428db2b2e8d7577a9aaf1e434034d/astpretty-3.0.0.tar.gz +BuildArch: noarch + + +%description +Pretty print the output of python stdlib `ast.parse`. +astpretty is intended to be a replacement for `ast.dump`. +## Installation +`pip install astpretty` +## Usage +`astpretty` provides two api functions: +### `astpretty.pprint(node, indent=FOUR_SPACE_INDENT, show_offsets=True)` +Print a representation of the ast node. +```python +>>> astpretty.pprint(ast.parse('if x == y: y += 4').body[0]) +If( + lineno=1, + col_offset=0, + test=Compare( + lineno=1, + col_offset=3, + left=Name(lineno=1, col_offset=3, id='x', ctx=Load()), + ops=[Eq()], + comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())], + ), + body=[ + AugAssign( + lineno=1, + col_offset=11, + target=Name(lineno=1, col_offset=11, id='y', ctx=Store()), + op=Add(), + value=Num(lineno=1, col_offset=16, n=4), + ), + ], + orelse=[], +) +``` +`indent` allows control over the indentation string: +```python +>>> astpretty.pprint(ast.parse('if x == y: y += 4').body[0], indent=' ') +If( + lineno=1, + col_offset=0, + test=Compare( + lineno=1, + col_offset=3, + left=Name(lineno=1, col_offset=3, id='x', ctx=Load()), + ops=[Eq()], + comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())], + ), + body=[ + AugAssign( + lineno=1, + col_offset=11, + target=Name(lineno=1, col_offset=11, id='y', ctx=Store()), + op=Add(), + value=Num(lineno=1, col_offset=16, n=4), + ), + ], + orelse=[], +) +``` +`show_offsets` controls whether the output includes line / column information: +```python +>>> astpretty.pprint(ast.parse('x += 5').body[0], show_offsets=False) +AugAssign( + target=Name(id='x', ctx=Store()), + op=Add(), + value=Num(n=5), +) +``` +### `astpretty.pformat(node, indent=FOUR_SPACE_INDENT, show_offsets=True)` +Return a string representation of the ast node. +Arguments are identical to `astpretty.pprint`. +```python +>>> astpretty.pformat(ast.parse('if x == y: y += 4').body[0]) +"If(\n lineno=1,\n col_offset=0,\n test=Compare(\n lineno=1,\n col_offset=3,\n left=Name(lineno=1, col_offset=3, id='x', ctx=Load()),\n ops=[Eq()],\n comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())],\n ),\n body=[\n AugAssign(\n lineno=1,\n col_offset=11,\n target=Name(lineno=1, col_offset=11, id='y', ctx=Store()),\n op=Add(),\n value=Num(lineno=1, col_offset=16, n=4),\n ),\n ],\n orelse=[],\n)" +``` +### Comparison with stdlib `ast.dump` +```python +>>> print(ast.dump(ast.parse('if x == y: y += 4').body[0])) +If(test=Compare(left=Name(id='x', ctx=Load()), ops=[Eq()], comparators=[Name(id='y', ctx=Load())]), body=[AugAssign(target=Name(id='y', ctx=Store()), op=Add(), value=Num(n=4))], orelse=[]) +``` +### `typed-ast` support +`astpretty` works with [typed-ast](https://github.com/python/typed_ast)! +For usage with `typed-ast` make sure you have `typed-ast` installed, a +convenient way to do this is with the `typed` extra to `astpretty`: +```bash +pip install astpretty[typed] +``` +The apis above work equally well with the return values from the `ast` modules +provided by `typed_ast`: +```pycon +>>> import astpretty +>>> from typed_ast import ast3 +>>> astpretty.pprint(ast3.parse('x = 4 # type: int')) +Module( + body=[ + Assign( + lineno=1, + col_offset=0, + targets=[Name(lineno=1, col_offset=0, id='x', ctx=Store())], + value=Num(lineno=1, col_offset=4, n=4), + type_comment='int', + ), + ], + type_ignores=[], +) +``` +With `typed-ast` installed, the commandline interface adds `--typed-27` and +`--typed-3` options for using the alternative ast parsers: +```console +$ astpretty --typed-3 t.py +Module( + body=[ + Assign( + lineno=1, + col_offset=0, + targets=[Name(lineno=1, col_offset=0, id='x', ctx=Store())], + value=Num(lineno=1, col_offset=4, n=4), + type_comment='int', + ), + ], + type_ignores=[], +) +``` + +%package -n python3-astpretty +Summary: Pretty print the output of python stdlib `ast.parse`. +Provides: python-astpretty +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-astpretty +Pretty print the output of python stdlib `ast.parse`. +astpretty is intended to be a replacement for `ast.dump`. +## Installation +`pip install astpretty` +## Usage +`astpretty` provides two api functions: +### `astpretty.pprint(node, indent=FOUR_SPACE_INDENT, show_offsets=True)` +Print a representation of the ast node. +```python +>>> astpretty.pprint(ast.parse('if x == y: y += 4').body[0]) +If( + lineno=1, + col_offset=0, + test=Compare( + lineno=1, + col_offset=3, + left=Name(lineno=1, col_offset=3, id='x', ctx=Load()), + ops=[Eq()], + comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())], + ), + body=[ + AugAssign( + lineno=1, + col_offset=11, + target=Name(lineno=1, col_offset=11, id='y', ctx=Store()), + op=Add(), + value=Num(lineno=1, col_offset=16, n=4), + ), + ], + orelse=[], +) +``` +`indent` allows control over the indentation string: +```python +>>> astpretty.pprint(ast.parse('if x == y: y += 4').body[0], indent=' ') +If( + lineno=1, + col_offset=0, + test=Compare( + lineno=1, + col_offset=3, + left=Name(lineno=1, col_offset=3, id='x', ctx=Load()), + ops=[Eq()], + comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())], + ), + body=[ + AugAssign( + lineno=1, + col_offset=11, + target=Name(lineno=1, col_offset=11, id='y', ctx=Store()), + op=Add(), + value=Num(lineno=1, col_offset=16, n=4), + ), + ], + orelse=[], +) +``` +`show_offsets` controls whether the output includes line / column information: +```python +>>> astpretty.pprint(ast.parse('x += 5').body[0], show_offsets=False) +AugAssign( + target=Name(id='x', ctx=Store()), + op=Add(), + value=Num(n=5), +) +``` +### `astpretty.pformat(node, indent=FOUR_SPACE_INDENT, show_offsets=True)` +Return a string representation of the ast node. +Arguments are identical to `astpretty.pprint`. +```python +>>> astpretty.pformat(ast.parse('if x == y: y += 4').body[0]) +"If(\n lineno=1,\n col_offset=0,\n test=Compare(\n lineno=1,\n col_offset=3,\n left=Name(lineno=1, col_offset=3, id='x', ctx=Load()),\n ops=[Eq()],\n comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())],\n ),\n body=[\n AugAssign(\n lineno=1,\n col_offset=11,\n target=Name(lineno=1, col_offset=11, id='y', ctx=Store()),\n op=Add(),\n value=Num(lineno=1, col_offset=16, n=4),\n ),\n ],\n orelse=[],\n)" +``` +### Comparison with stdlib `ast.dump` +```python +>>> print(ast.dump(ast.parse('if x == y: y += 4').body[0])) +If(test=Compare(left=Name(id='x', ctx=Load()), ops=[Eq()], comparators=[Name(id='y', ctx=Load())]), body=[AugAssign(target=Name(id='y', ctx=Store()), op=Add(), value=Num(n=4))], orelse=[]) +``` +### `typed-ast` support +`astpretty` works with [typed-ast](https://github.com/python/typed_ast)! +For usage with `typed-ast` make sure you have `typed-ast` installed, a +convenient way to do this is with the `typed` extra to `astpretty`: +```bash +pip install astpretty[typed] +``` +The apis above work equally well with the return values from the `ast` modules +provided by `typed_ast`: +```pycon +>>> import astpretty +>>> from typed_ast import ast3 +>>> astpretty.pprint(ast3.parse('x = 4 # type: int')) +Module( + body=[ + Assign( + lineno=1, + col_offset=0, + targets=[Name(lineno=1, col_offset=0, id='x', ctx=Store())], + value=Num(lineno=1, col_offset=4, n=4), + type_comment='int', + ), + ], + type_ignores=[], +) +``` +With `typed-ast` installed, the commandline interface adds `--typed-27` and +`--typed-3` options for using the alternative ast parsers: +```console +$ astpretty --typed-3 t.py +Module( + body=[ + Assign( + lineno=1, + col_offset=0, + targets=[Name(lineno=1, col_offset=0, id='x', ctx=Store())], + value=Num(lineno=1, col_offset=4, n=4), + type_comment='int', + ), + ], + type_ignores=[], +) +``` + +%package help +Summary: Development documents and examples for astpretty +Provides: python3-astpretty-doc +%description help +Pretty print the output of python stdlib `ast.parse`. +astpretty is intended to be a replacement for `ast.dump`. +## Installation +`pip install astpretty` +## Usage +`astpretty` provides two api functions: +### `astpretty.pprint(node, indent=FOUR_SPACE_INDENT, show_offsets=True)` +Print a representation of the ast node. +```python +>>> astpretty.pprint(ast.parse('if x == y: y += 4').body[0]) +If( + lineno=1, + col_offset=0, + test=Compare( + lineno=1, + col_offset=3, + left=Name(lineno=1, col_offset=3, id='x', ctx=Load()), + ops=[Eq()], + comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())], + ), + body=[ + AugAssign( + lineno=1, + col_offset=11, + target=Name(lineno=1, col_offset=11, id='y', ctx=Store()), + op=Add(), + value=Num(lineno=1, col_offset=16, n=4), + ), + ], + orelse=[], +) +``` +`indent` allows control over the indentation string: +```python +>>> astpretty.pprint(ast.parse('if x == y: y += 4').body[0], indent=' ') +If( + lineno=1, + col_offset=0, + test=Compare( + lineno=1, + col_offset=3, + left=Name(lineno=1, col_offset=3, id='x', ctx=Load()), + ops=[Eq()], + comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())], + ), + body=[ + AugAssign( + lineno=1, + col_offset=11, + target=Name(lineno=1, col_offset=11, id='y', ctx=Store()), + op=Add(), + value=Num(lineno=1, col_offset=16, n=4), + ), + ], + orelse=[], +) +``` +`show_offsets` controls whether the output includes line / column information: +```python +>>> astpretty.pprint(ast.parse('x += 5').body[0], show_offsets=False) +AugAssign( + target=Name(id='x', ctx=Store()), + op=Add(), + value=Num(n=5), +) +``` +### `astpretty.pformat(node, indent=FOUR_SPACE_INDENT, show_offsets=True)` +Return a string representation of the ast node. +Arguments are identical to `astpretty.pprint`. +```python +>>> astpretty.pformat(ast.parse('if x == y: y += 4').body[0]) +"If(\n lineno=1,\n col_offset=0,\n test=Compare(\n lineno=1,\n col_offset=3,\n left=Name(lineno=1, col_offset=3, id='x', ctx=Load()),\n ops=[Eq()],\n comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())],\n ),\n body=[\n AugAssign(\n lineno=1,\n col_offset=11,\n target=Name(lineno=1, col_offset=11, id='y', ctx=Store()),\n op=Add(),\n value=Num(lineno=1, col_offset=16, n=4),\n ),\n ],\n orelse=[],\n)" +``` +### Comparison with stdlib `ast.dump` +```python +>>> print(ast.dump(ast.parse('if x == y: y += 4').body[0])) +If(test=Compare(left=Name(id='x', ctx=Load()), ops=[Eq()], comparators=[Name(id='y', ctx=Load())]), body=[AugAssign(target=Name(id='y', ctx=Store()), op=Add(), value=Num(n=4))], orelse=[]) +``` +### `typed-ast` support +`astpretty` works with [typed-ast](https://github.com/python/typed_ast)! +For usage with `typed-ast` make sure you have `typed-ast` installed, a +convenient way to do this is with the `typed` extra to `astpretty`: +```bash +pip install astpretty[typed] +``` +The apis above work equally well with the return values from the `ast` modules +provided by `typed_ast`: +```pycon +>>> import astpretty +>>> from typed_ast import ast3 +>>> astpretty.pprint(ast3.parse('x = 4 # type: int')) +Module( + body=[ + Assign( + lineno=1, + col_offset=0, + targets=[Name(lineno=1, col_offset=0, id='x', ctx=Store())], + value=Num(lineno=1, col_offset=4, n=4), + type_comment='int', + ), + ], + type_ignores=[], +) +``` +With `typed-ast` installed, the commandline interface adds `--typed-27` and +`--typed-3` options for using the alternative ast parsers: +```console +$ astpretty --typed-3 t.py +Module( + body=[ + Assign( + lineno=1, + col_offset=0, + targets=[Name(lineno=1, col_offset=0, id='x', ctx=Store())], + value=Num(lineno=1, col_offset=4, n=4), + type_comment='int', + ), + ], + type_ignores=[], +) +``` + +%prep +%autosetup -n astpretty-3.0.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-astpretty -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 3.0.0-1 +- Package Spec generated |
