-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,013 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.tox | ||
dist | ||
__pycache__ | ||
*.egg-info | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
os: linux | ||
language: python | ||
dist: xenial | ||
# env: | ||
python: | ||
- 3.6 | ||
- 3.7 | ||
- 3.8 | ||
# before_install: | ||
# - sudo apt-get install -y | ||
install: | ||
- pip install tox | ||
- pip install -r requirements.txt | ||
script: | ||
- tox | ||
after_success: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
rand | ||
==== | ||
|
||
[![Travis (.org)](https://img.shields.io/travis/kororo/rand)](https://pypi.python.org/project/rand/) | ||
[![Coveralls github](https://img.shields.io/coveralls/github/kororo/rand)](https://pypi.python.org/project/rand/) | ||
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/) | ||
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/rand.svg)](https://pypi.python.org/project/rand/) | ||
[![PyPI - Downloads](https://img.shields.io/pypi/dm/rand)](https://pypi.python.org/project/rand/) | ||
|
||
|
||
Random generated String from regex pattern. | ||
|
||
WARNING | ||
------- | ||
|
||
The library **rand** is still in working-in-progress. It is subject to high possibility of API changes. Would appreciate for feedbacks, suggestions or helps. | ||
|
||
Install | ||
------- | ||
|
||
Use pip or clone this repository and execute the setup.py file. | ||
|
||
```shell script | ||
$ pip install rand | ||
``` | ||
|
||
Usages | ||
------ | ||
|
||
```python | ||
# import module | ||
from rand import Rand | ||
|
||
# initialise object | ||
rand = Rand() | ||
|
||
# generate pattern literal | ||
rand.gen('koro') # ['koro'] | ||
rand.gen('28') # ['28'] | ||
rand.gen('a-z') # ['a-z'] | ||
|
||
# generate pattern any | ||
rand.gen('.') # any char in string.printable | ||
|
||
# generate pattern branch | ||
rand.gen('ko|ro') # either ['ko'] or ['ro'] | ||
rand.gen('ko|ro|ro') # either ['ko'] or ['ro'] | ||
|
||
# generate pattern in | ||
rand.gen('[kororo]') # either ['k'] or ['o'] or ['r'] | ||
rand.gen('k[o]r[o]r[o]') # ['kororo'] | ||
|
||
# generate pattern repeat | ||
rand.gen('r{2,8}') # char r in length between 2 to 8 times | ||
|
||
# generate pattern range | ||
rand.gen('[a-z]') # char between a to z | ||
|
||
# generate pattern subpattern | ||
rand.gen('(ro)') # ['ro'] | ||
|
||
# use built-in providers | ||
rand.gen('(:en_vocal:)') # char either a, i, u, e, o | ||
``` | ||
|
||
Providers | ||
--------- | ||
|
||
The library **rand** at core only provide random generator based on regex. Providers are built to allow extensions for rand. | ||
Below is sample code how to integrate existing class definition (TestProxy) to Rand. | ||
|
||
```python | ||
from rand import Rand | ||
from rand.providers.base import RandProxyBaseProvider | ||
|
||
# class definition | ||
class TestProxy: | ||
# simple function definition to return args values | ||
def target(self, arg1='def1', arg2='def2'): | ||
return '%s-%s' % (arg1, arg2) | ||
|
||
# init rand class | ||
rand = Rand() | ||
|
||
# create proxy provider helper and register to rand | ||
test_proxy = RandProxyBaseProvider(prefix='test', target=TestProxy()) | ||
rand.register_provider(test_proxy) | ||
|
||
# test | ||
print(rand.gen('(:test_target:)')) # ['def1-def2'] | ||
print(rand.gen('(:test_target:)', ['ok1'])) # ['ok1-def2'] | ||
print(rand.gen('(:test_target:)', ['ok1', 'ok2'])) # ['ok1-def2'] | ||
print(rand.gen('(:test_target:)', [['ok1', 'ok2']])) # ['ok1-ok2'] | ||
print(rand.gen('(:test_target:)', [['ok1', 'ok2'], 'ok3'])) # ['ok1-ok2'] | ||
print(rand.gen('(:test_target:)', [{'arg1': 'ok1'}])) # ['ok1-def2'] | ||
print(rand.gen('(:test_target:)', [{'arg1': 'ok1', 'arg2': 'ok2'}])) # ['ok1-ok2'] | ||
``` | ||
|
||
The library *rand* also has integration with existing projects such as Faker. Ensure you have faker library installed. | ||
|
||
```python | ||
from rand import Rand | ||
|
||
|
||
rand = Rand() | ||
rand.gen('(:faker_hexify:)') # abc | ||
``` | ||
|
||
Test | ||
---- | ||
|
||
Run test by installing packages and run tox | ||
|
||
```shell script | ||
$ pip install poetry tox | ||
$ tox | ||
``` | ||
|
||
For hot-reload development coding | ||
```shell script | ||
$ npm i -g nodemon | ||
$ nodemon -w rand --exec python -c "from rand import Rand" | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"watch": ["rand"], | ||
"exec": "python -c \"import rand\"", | ||
"ext": "py" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "rand", | ||
"version": "1.0.0", | ||
"description": "Generate String from regex pattern", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "nodemon -w rand --exec python -c \"from rand import Rand\"", | ||
"test": "tox", | ||
"deploy": "poetry export -f requirements.txt > requirements.txt && poetry update && poetry build && poetry deploy" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kororo/rand.git" | ||
}, | ||
"author": "kororo", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/kororo/rand/issues" | ||
}, | ||
"homepage": "https://github.com/kororo/rand#readme" | ||
} |
Oops, something went wrong.