diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-04-11 19:54:06 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-04-11 19:54:06 +0000 |
| commit | d83e244ff8ee9e4ca42a0c05870e1fb7751a26cb (patch) | |
| tree | 78a42124686034586e3c46093539ac32777e1a36 | |
| parent | 231ff583e4f6acde807d1ecce548bc5ac1088acb (diff) | |
automatic import of python-simple-parsing
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-simple-parsing.spec | 487 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 489 insertions, 0 deletions
@@ -0,0 +1 @@ +/simple_parsing-0.1.1.tar.gz diff --git a/python-simple-parsing.spec b/python-simple-parsing.spec new file mode 100644 index 0000000..3d64030 --- /dev/null +++ b/python-simple-parsing.spec @@ -0,0 +1,487 @@ +%global _empty_manifest_terminate_build 0 +Name: python-simple-parsing +Version: 0.1.1 +Release: 1 +Summary: A small utility for simplifying and cleaning up argument parsing scripts. +License: MIT License +URL: https://github.com/lebrice/SimpleParsing +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/1b/4e/a018566236c97fcb8a85d4c8f86cc5a76342fd20472aa9b592a2890207bf/simple_parsing-0.1.1.tar.gz +BuildArch: noarch + +Requires: python3-docstring-parser +Requires: python3-typing-extensions +Requires: python3-pytest-regressions +Requires: python3-pytest +Requires: python3-pytest-xdist +Requires: python3-pyyaml +Requires: python3-pytest +Requires: python3-pytest-xdist +Requires: python3-pytest-regressions +Requires: python3-pyyaml + +%description + [](https://badge.fury.io/py/simple-parsing) + + +# Simple, Elegant, Typed Argument Parsing <!-- omit in toc --> + +`simple-parsing` allows you to transform your ugly `argparse` scripts into beautifully structured, strongly typed little works of art. This isn't a fancy, complicated new command-line tool either, ***this simply adds new features to plain-old argparse!*** +Using [dataclasses](https://docs.python.org/3.7/library/dataclasses.html), `simple-parsing` makes it easier to share and reuse command-line arguments - ***no more copy pasting!*** + +Supports inheritance, **nesting**, easy serialization to json/yaml, automatic help strings from comments, and much more! + +```python +# examples/demo.py +from dataclasses import dataclass +from simple_parsing import ArgumentParser + +parser = ArgumentParser() +parser.add_argument("--foo", type=int, default=123, help="foo help") + +@dataclass +class Options: + """ Help string for this group of command-line arguments """ + log_dir: str # Help string for a required str argument + learning_rate: float = 1e-4 # Help string for a float argument + +parser.add_arguments(Options, dest="options") + +args = parser.parse_args() +print("foo:", args.foo) +print("options:", args.options) +``` +```console +$ python examples/demo.py --log_dir logs --foo 123 +foo: 123 +options: Options(log_dir='logs', learning_rate=0.0001) +``` +```console +$ python examples/demo.py --help +usage: demo.py [-h] [--foo int] --log_dir str [--learning_rate float] + +optional arguments: + -h, --help show this help message and exit + --foo int foo help (default: 123) + +Options ['options']: + Help string for this group of command-line arguments + + --log_dir str Help string for a required str argument (default: + None) + --learning_rate float + Help string for a float argument (default: 0.0001) +``` + +### (*new*) Simplified API: + +For a simple use-case, where you only want to parse a single dataclass, you can use the `simple_parsing.parse` or `simple_parsing.parse_known_args` functions: + +```python +options: Options = simple_parsing.parse(Options) +# or: +options, leftover_args = simple_parsing.parse_known_args(Options) +``` + + +## installation + +`pip install simple-parsing` + +## [Examples](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md) + +## [API Documentation](https://github.com/lebrice/SimpleParsing/tree/master/docs/README.md) (Under construction) + +## Features +- ### [Automatic "--help" strings](https://github.com/lebrice/SimpleParsing/tree/master/examples/docstrings/README.md) + + As developers, we want to make it easy for people coming into our projects to understand how to run them. However, a user-friendly `--help` message is often hard to write and to maintain, especially as the number of arguments increases. + + With `simple-parsing`, your arguments and their descriptions are defined in the same place, making your code easier to read, write, and maintain. + +- ### Modular, Reusable, Cleanly Grouped Arguments + + *(no more copy-pasting)* + + When you need to add a new group of command-line arguments similar to an existing one, instead of copy-pasting a block of `argparse` code and renaming variables, you can reuse your argument class, and let the `ArgumentParser` take care of adding relevant prefixes to the arguments for you: + + ```python + parser.add_arguments(Options, dest="train") + parser.add_arguments(Options, dest="valid") + args = parser.parse_args() + train_options: Options = args.train + valid_options: Options = args.valid + print(train_options) + print(valid_options) + ``` + ```console + $ python examples/demo.py \ + --train.log_dir "training" \ + --valid.log_dir "validation" + Options(log_dir='training', learning_rate=0.0001) + Options(log_dir='validation', learning_rate=0.0001) + ``` + + These prefixes can also be set explicitly, or not be used at all. For more info, take a look at the [Prefixing Guide](https://github.com/lebrice/SimpleParsing/tree/master/examples/prefixing/README.md) + +- ### [Argument subgroups](https://github.com/lebrice/SimpleParsing/tree/master/examples/subgroups/README.md) + + It's easy to choose between different argument groups of arguments, with the `subgroups` + function! + +- ### [Setting defaults from Configuration files](https://github.com/lebrice/SimpleParsing/tree/master/examples/config_files/README.md) + + Default values for command-line arguments can easily be read from many different formats, including json/yaml! + +- ### [**Easy serialization**](https://github.com/lebrice/SimpleParsing/tree/master/examples/serialization/README.md): + + Easily save/load configs to `json` or `yaml`!. + +- ### [**Inheritance**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance/README.md) + + You can easily customize an existing argument class by extending it and adding your own attributes, which helps promote code reuse across projects. For more info, take a look at the [inheritance example](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance_example.py) + +- ### [**Nesting**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/nesting/README.md): + + Dataclasses can be nested within dataclasses, as deep as you need! + +- ### [Easier parsing of lists and tuples](https://github.com/lebrice/SimpleParsing/tree/master/examples/container_types/README.md) : + This is sometimes tricky to do with regular `argparse`, but `simple-parsing` makes it a lot easier by using the python's builtin type annotations to automatically convert the values to the right type for you. + As an added feature, by using these type annotations, `simple-parsing` allows you to parse nested lists or tuples, as can be seen in [this example](https://github.com/lebrice/SimpleParsing/tree/master/examples/merging/README.md) + +- ### [Enums support](https://github.com/lebrice/SimpleParsing/tree/master/examples/enums/README.md) + +- (More to come!) + + +## Examples: +Additional examples for all the features mentioned above can be found in the [examples folder](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md) + + +%package -n python3-simple-parsing +Summary: A small utility for simplifying and cleaning up argument parsing scripts. +Provides: python-simple-parsing +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-simple-parsing + [](https://badge.fury.io/py/simple-parsing) + + +# Simple, Elegant, Typed Argument Parsing <!-- omit in toc --> + +`simple-parsing` allows you to transform your ugly `argparse` scripts into beautifully structured, strongly typed little works of art. This isn't a fancy, complicated new command-line tool either, ***this simply adds new features to plain-old argparse!*** +Using [dataclasses](https://docs.python.org/3.7/library/dataclasses.html), `simple-parsing` makes it easier to share and reuse command-line arguments - ***no more copy pasting!*** + +Supports inheritance, **nesting**, easy serialization to json/yaml, automatic help strings from comments, and much more! + +```python +# examples/demo.py +from dataclasses import dataclass +from simple_parsing import ArgumentParser + +parser = ArgumentParser() +parser.add_argument("--foo", type=int, default=123, help="foo help") + +@dataclass +class Options: + """ Help string for this group of command-line arguments """ + log_dir: str # Help string for a required str argument + learning_rate: float = 1e-4 # Help string for a float argument + +parser.add_arguments(Options, dest="options") + +args = parser.parse_args() +print("foo:", args.foo) +print("options:", args.options) +``` +```console +$ python examples/demo.py --log_dir logs --foo 123 +foo: 123 +options: Options(log_dir='logs', learning_rate=0.0001) +``` +```console +$ python examples/demo.py --help +usage: demo.py [-h] [--foo int] --log_dir str [--learning_rate float] + +optional arguments: + -h, --help show this help message and exit + --foo int foo help (default: 123) + +Options ['options']: + Help string for this group of command-line arguments + + --log_dir str Help string for a required str argument (default: + None) + --learning_rate float + Help string for a float argument (default: 0.0001) +``` + +### (*new*) Simplified API: + +For a simple use-case, where you only want to parse a single dataclass, you can use the `simple_parsing.parse` or `simple_parsing.parse_known_args` functions: + +```python +options: Options = simple_parsing.parse(Options) +# or: +options, leftover_args = simple_parsing.parse_known_args(Options) +``` + + +## installation + +`pip install simple-parsing` + +## [Examples](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md) + +## [API Documentation](https://github.com/lebrice/SimpleParsing/tree/master/docs/README.md) (Under construction) + +## Features +- ### [Automatic "--help" strings](https://github.com/lebrice/SimpleParsing/tree/master/examples/docstrings/README.md) + + As developers, we want to make it easy for people coming into our projects to understand how to run them. However, a user-friendly `--help` message is often hard to write and to maintain, especially as the number of arguments increases. + + With `simple-parsing`, your arguments and their descriptions are defined in the same place, making your code easier to read, write, and maintain. + +- ### Modular, Reusable, Cleanly Grouped Arguments + + *(no more copy-pasting)* + + When you need to add a new group of command-line arguments similar to an existing one, instead of copy-pasting a block of `argparse` code and renaming variables, you can reuse your argument class, and let the `ArgumentParser` take care of adding relevant prefixes to the arguments for you: + + ```python + parser.add_arguments(Options, dest="train") + parser.add_arguments(Options, dest="valid") + args = parser.parse_args() + train_options: Options = args.train + valid_options: Options = args.valid + print(train_options) + print(valid_options) + ``` + ```console + $ python examples/demo.py \ + --train.log_dir "training" \ + --valid.log_dir "validation" + Options(log_dir='training', learning_rate=0.0001) + Options(log_dir='validation', learning_rate=0.0001) + ``` + + These prefixes can also be set explicitly, or not be used at all. For more info, take a look at the [Prefixing Guide](https://github.com/lebrice/SimpleParsing/tree/master/examples/prefixing/README.md) + +- ### [Argument subgroups](https://github.com/lebrice/SimpleParsing/tree/master/examples/subgroups/README.md) + + It's easy to choose between different argument groups of arguments, with the `subgroups` + function! + +- ### [Setting defaults from Configuration files](https://github.com/lebrice/SimpleParsing/tree/master/examples/config_files/README.md) + + Default values for command-line arguments can easily be read from many different formats, including json/yaml! + +- ### [**Easy serialization**](https://github.com/lebrice/SimpleParsing/tree/master/examples/serialization/README.md): + + Easily save/load configs to `json` or `yaml`!. + +- ### [**Inheritance**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance/README.md) + + You can easily customize an existing argument class by extending it and adding your own attributes, which helps promote code reuse across projects. For more info, take a look at the [inheritance example](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance_example.py) + +- ### [**Nesting**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/nesting/README.md): + + Dataclasses can be nested within dataclasses, as deep as you need! + +- ### [Easier parsing of lists and tuples](https://github.com/lebrice/SimpleParsing/tree/master/examples/container_types/README.md) : + This is sometimes tricky to do with regular `argparse`, but `simple-parsing` makes it a lot easier by using the python's builtin type annotations to automatically convert the values to the right type for you. + As an added feature, by using these type annotations, `simple-parsing` allows you to parse nested lists or tuples, as can be seen in [this example](https://github.com/lebrice/SimpleParsing/tree/master/examples/merging/README.md) + +- ### [Enums support](https://github.com/lebrice/SimpleParsing/tree/master/examples/enums/README.md) + +- (More to come!) + + +## Examples: +Additional examples for all the features mentioned above can be found in the [examples folder](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md) + + +%package help +Summary: Development documents and examples for simple-parsing +Provides: python3-simple-parsing-doc +%description help + [](https://badge.fury.io/py/simple-parsing) + + +# Simple, Elegant, Typed Argument Parsing <!-- omit in toc --> + +`simple-parsing` allows you to transform your ugly `argparse` scripts into beautifully structured, strongly typed little works of art. This isn't a fancy, complicated new command-line tool either, ***this simply adds new features to plain-old argparse!*** +Using [dataclasses](https://docs.python.org/3.7/library/dataclasses.html), `simple-parsing` makes it easier to share and reuse command-line arguments - ***no more copy pasting!*** + +Supports inheritance, **nesting**, easy serialization to json/yaml, automatic help strings from comments, and much more! + +```python +# examples/demo.py +from dataclasses import dataclass +from simple_parsing import ArgumentParser + +parser = ArgumentParser() +parser.add_argument("--foo", type=int, default=123, help="foo help") + +@dataclass +class Options: + """ Help string for this group of command-line arguments """ + log_dir: str # Help string for a required str argument + learning_rate: float = 1e-4 # Help string for a float argument + +parser.add_arguments(Options, dest="options") + +args = parser.parse_args() +print("foo:", args.foo) +print("options:", args.options) +``` +```console +$ python examples/demo.py --log_dir logs --foo 123 +foo: 123 +options: Options(log_dir='logs', learning_rate=0.0001) +``` +```console +$ python examples/demo.py --help +usage: demo.py [-h] [--foo int] --log_dir str [--learning_rate float] + +optional arguments: + -h, --help show this help message and exit + --foo int foo help (default: 123) + +Options ['options']: + Help string for this group of command-line arguments + + --log_dir str Help string for a required str argument (default: + None) + --learning_rate float + Help string for a float argument (default: 0.0001) +``` + +### (*new*) Simplified API: + +For a simple use-case, where you only want to parse a single dataclass, you can use the `simple_parsing.parse` or `simple_parsing.parse_known_args` functions: + +```python +options: Options = simple_parsing.parse(Options) +# or: +options, leftover_args = simple_parsing.parse_known_args(Options) +``` + + +## installation + +`pip install simple-parsing` + +## [Examples](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md) + +## [API Documentation](https://github.com/lebrice/SimpleParsing/tree/master/docs/README.md) (Under construction) + +## Features +- ### [Automatic "--help" strings](https://github.com/lebrice/SimpleParsing/tree/master/examples/docstrings/README.md) + + As developers, we want to make it easy for people coming into our projects to understand how to run them. However, a user-friendly `--help` message is often hard to write and to maintain, especially as the number of arguments increases. + + With `simple-parsing`, your arguments and their descriptions are defined in the same place, making your code easier to read, write, and maintain. + +- ### Modular, Reusable, Cleanly Grouped Arguments + + *(no more copy-pasting)* + + When you need to add a new group of command-line arguments similar to an existing one, instead of copy-pasting a block of `argparse` code and renaming variables, you can reuse your argument class, and let the `ArgumentParser` take care of adding relevant prefixes to the arguments for you: + + ```python + parser.add_arguments(Options, dest="train") + parser.add_arguments(Options, dest="valid") + args = parser.parse_args() + train_options: Options = args.train + valid_options: Options = args.valid + print(train_options) + print(valid_options) + ``` + ```console + $ python examples/demo.py \ + --train.log_dir "training" \ + --valid.log_dir "validation" + Options(log_dir='training', learning_rate=0.0001) + Options(log_dir='validation', learning_rate=0.0001) + ``` + + These prefixes can also be set explicitly, or not be used at all. For more info, take a look at the [Prefixing Guide](https://github.com/lebrice/SimpleParsing/tree/master/examples/prefixing/README.md) + +- ### [Argument subgroups](https://github.com/lebrice/SimpleParsing/tree/master/examples/subgroups/README.md) + + It's easy to choose between different argument groups of arguments, with the `subgroups` + function! + +- ### [Setting defaults from Configuration files](https://github.com/lebrice/SimpleParsing/tree/master/examples/config_files/README.md) + + Default values for command-line arguments can easily be read from many different formats, including json/yaml! + +- ### [**Easy serialization**](https://github.com/lebrice/SimpleParsing/tree/master/examples/serialization/README.md): + + Easily save/load configs to `json` or `yaml`!. + +- ### [**Inheritance**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance/README.md) + + You can easily customize an existing argument class by extending it and adding your own attributes, which helps promote code reuse across projects. For more info, take a look at the [inheritance example](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance_example.py) + +- ### [**Nesting**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/nesting/README.md): + + Dataclasses can be nested within dataclasses, as deep as you need! + +- ### [Easier parsing of lists and tuples](https://github.com/lebrice/SimpleParsing/tree/master/examples/container_types/README.md) : + This is sometimes tricky to do with regular `argparse`, but `simple-parsing` makes it a lot easier by using the python's builtin type annotations to automatically convert the values to the right type for you. + As an added feature, by using these type annotations, `simple-parsing` allows you to parse nested lists or tuples, as can be seen in [this example](https://github.com/lebrice/SimpleParsing/tree/master/examples/merging/README.md) + +- ### [Enums support](https://github.com/lebrice/SimpleParsing/tree/master/examples/enums/README.md) + +- (More to come!) + + +## Examples: +Additional examples for all the features mentioned above can be found in the [examples folder](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md) + + +%prep +%autosetup -n simple-parsing-0.1.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-simple-parsing -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.1-1 +- Package Spec generated @@ -0,0 +1 @@ +8b7a17c64f9e2852818a30091cd0df75 simple_parsing-0.1.1.tar.gz |
