Skip to content

Commit dbc2b1e

Browse files
committed
README
1 parent df21c1f commit dbc2b1e

File tree

1 file changed

+77
-16
lines changed

1 file changed

+77
-16
lines changed

README.md

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,79 @@ python setup.py install
122122

123123
### CLI
124124

125-
For regular usage CLI tool is a best option. After you install this package you could use it as `json2models`
126-
or `python -m json_to_models`.
125+
For regular usage CLI tool is the best option. After you install this package you could use it as `json2models <arguments>`
126+
or `python -m json_to_models <arguments>`. I.e.:
127+
```
128+
json2models -m Car car_*.json -f attrs > car.py
129+
```
127130

128131
Arguments:
129-
130-
| Key | Format | Description | Example | Note |
131-
| --- | --- | --- | --- | --- |
132-
| `-h, -help` | - | show help message and exit | | |
133-
| `-m, --model` | `-m <Model name> [<JSON files> ...]` | Model name and its JSON data as path or unix-like path pattern. `*`, `**` or `?` patterns symbols are supported. | `-m Car audi.json reno.json` or `-m Car audi.json -m Car reno.json` (results will be the same) | |
134-
| `-l, --list` | `-l <Model name> <JSON key> <JSON file>` | Like `-m` but given json file should contain list of model data (dataset). If this file contains dict with nested list than you can pass `<JSON key>` to lookup. Deep lookups are supported by dot-separated path. If no lookup needed pass '-' as <JSON key> | `-l Car - cars.json -l Person fetch_results.items.persons result.json` | Models names under `-l` arguments should be unique |
135-
| `-f, --framework` | `-f {base,attrs,dataclasses,custom}` | Model framework for which python code is generated. 'base' (default) mean no framework so code will be generated without any decorators and additional meta-data. | `-f attrs` | Default: `-f base` |
136-
| `-s , --structure` | `-s {nested, flat}` | Models composition style. | `-s flat` | Default: `-s nested` |
137-
| `--datetime` | - | Enable datetime/date/time strings parsing. Warn.: This can lead to 6-7 times slowdown on large datasets. Be sure that you really need this option. | | Default: disabled |
138-
| `--merge`| `--merge MERGE_POLICY [MERGE_POLICY ...]` | Merge policy settings. Possible values are: `percent[_<percent>]` - two models had a certain percentage of matched field names. Custom value could be i.e. `percent_95`. `number[_<number>]` - two models had a certain number of matched field names. `exact` - two models should have exact same field names to merge. | `--merge percent_95 number_20` - merge if 95% of fields match or 20 fields match | Default: `--merge percent_70 number_10` |
139-
| `--dict-keys-regex, --dkr` | `--dkr RegEx [RegEx ...]` | List of regular expressions (Python syntax). If all keys of some dict are match one of them then this dict will be marked as dict field but not nested model. | `--dkr node_\d+ \d+_\d+_\d+` | `^` and `$` (string borders) tokens will be added automatically but you have escape to other special characters manually. | Optional |
140-
| `--dict-keys-fields, --dkf` | `--dkf FIELD_NAME [FIELD_NAME ...]` | List of model fields names that will be marked as dict fields | `--dkf "dict_data" "mapping"` | Optional |
141-
| `--code-generator` | `--code-generator CODE_GENERATOR` | Absolute import path to GenericModelCodeGenerator subclass. | `-f mypackage.mymodule.DjangoModelsGenerator` | Is ignored without `-f custom` but is required with it |
142-
| `--code-generator-kwargs` | `--code-generator-kwargs [NAME=VALUE [NAME=VALUE ...]]` | List of GenericModelCodeGenerator subclass arguments (for `__init__` method, see docs of specific subclass). Each argument should be in following format: `argument_name=value` or `"argument_name=value with space"`. Boolean values should be passed in JS style: `true` or `false` | `--code-generator-kwargs kwarg1=true kwarg2=10 "kwarg3=It is string with spaces"` | Optional |
132+
* `-h`, `--help`
133+
* Show help message and exit
134+
135+
* `-m`, `--model`
136+
* **Format**: `-m <Model name> [<JSON files> ...]`
137+
* **Description**: Model name and its JSON data as path or unix-like path pattern. `*`, `**` or `?` patterns symbols are supported.
138+
* **Example**: `-m Car audi.json reno.json` or `-m Car audi.json -m Car reno.json` (results will be the same)
139+
140+
* `-l`, `--list`
141+
* **Format**: `-l <Model name> <JSON key> <JSON file>`
142+
* **Description**: Like `-m` but given json file should contain list of model data (dataset).
143+
If this file contains dict with nested list than you can pass `<JSON key>` to lookup.
144+
Deep lookups are supported by dot-separated path. If no lookup needed pass `-` as `<JSON key>`.
145+
* **Example**: `-l Car - cars.json -l Person fetch_results.items.persons result.json`
146+
* **Note**: Models names under this arguments should be unique.
147+
148+
* `-f`, `--framework`
149+
* **Format**: `-f {base,attrs,dataclasses,custom}`
150+
* **Description**: Model framework for which python code is generated.
151+
`base` (default) mean no framework so code will be generated without any decorators and additional meta-data.
152+
* **Example**: `-f attrs`
153+
* **Default**: `-f base`
154+
155+
* `--datetime`
156+
* **Description**: Enable datetime/date/time strings parsing.
157+
* **Default**: disabled
158+
* **Warning**: This can lead to 6-7 times slowdown on large datasets. Be sure that you really need this option.
159+
160+
* `--merge`
161+
* **Format**: `--merge MERGE_POLICY [MERGE_POLICY ...]`
162+
* **Description**: Merge policy settings. Possible values are:
163+
* `percent[_<percent>]` - two models had a certain percentage of matched field names.
164+
Custom value could be i.e. `percent_95`.
165+
* `number[_<number>]` - two models had a certain number of matched field names.
166+
* `exact` - two models should have exact same field names to merge.
167+
* **Example**: `--merge percent_95 number_20` - merge if 95% of fields are matched or 20 of fields are matched
168+
* **Default**: `--merge percent_70 number_10`
169+
170+
* `--dict-keys-regex`, `--dkr`
171+
* **Format**: `--dkr RegEx [RegEx ...]`
172+
* **Description**: List of regular expressions (Python syntax).
173+
If all keys of some dict are match one of them then this dict will be marked as dict field but not nested model.
174+
* **Example**: `--dkr node_\d+ \d+_\d+_\d+`
175+
* **Note**: `^` and `$` (string borders) tokens will be added automatically but you have escape to other special characters manually.
176+
* **Optional**
177+
178+
* `--dict-keys-fields`, `--dkf`
179+
* **Format**: `--dkf FIELD_NAME [FIELD_NAME ...]`
180+
* **Description**: List of model fields names that will be marked as dict fields
181+
* **Example**: `--dkf "dict_data" "mapping"`
182+
* **Optional**
183+
184+
* `--code-generator`
185+
* **Format**: `--code-generator CODE_GENERATOR`
186+
* **Description**: Absolute import path to GenericModelCodeGenerator subclass.
187+
* **Example**: `-f mypackage.mymodule.DjangoModelsGenerator`
188+
* **Note**: Is ignored without `-f custom` but is required with it.
189+
190+
* `--code-generator-kwargs`
191+
* **Format**: `--code-generator-kwargs [NAME=VALUE [NAME=VALUE ...]]`
192+
* **Description**: List of GenericModelCodeGenerator subclass arguments (for `__init__` method,
193+
see docs of specific subclass).
194+
Each argument should be in following format: `argument_name=value` or `"argument_name=value with space"`.
195+
Boolean values should be passed in JS style: `true` or `false`
196+
* **Example**: `--code-generator-kwargs kwarg1=true kwarg2=10 "kwarg3=It is string with spaces"`
197+
* **Optional**
143198

144199
One of model arguments (`-m` or `-l`) is required.
145200

@@ -175,6 +230,12 @@ Downloaded data will be saved at `testing_tools/real_apis/<name of example>/<dat
175230
* [Jinja2](https://github.com/pallets/jinja) - Code templates
176231
* [ordered-set](https://github.com/LuminosoInsight/ordered-set) is used in models merging algorithm
177232

233+
Test tools:
234+
* [pytest](https://github.com/pytest-dev/pytest) - Test framework
235+
* [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) - Parallel execution of test suites
236+
* [pytest-sugar](https://github.com/Frozenball/pytest-sugar) - Test results pretty printing
237+
* [requests](https://github.com/kennethreitz/requests) - Test data download
238+
178239
## Contributing
179240

180241
Feel free to open pull requests with new features or bug fixes. Just follow few rules:

0 commit comments

Comments
 (0)