Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kororo committed Apr 12, 2020
2 parents a28e324 + 4c97a61 commit 441014c
Show file tree
Hide file tree
Showing 21 changed files with 1,013 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.tox
dist
__pycache__
*.egg-info
.coverage
17 changes: 17 additions & 0 deletions .travis.yml
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
124 changes: 124 additions & 0 deletions README.md
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"
```

4 changes: 0 additions & 4 deletions README.rst

This file was deleted.

5 changes: 5 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch": ["rand"],
"exec": "python -c \"import rand\"",
"ext": "py"
}
21 changes: 21 additions & 0 deletions package.json
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"
}
Loading

0 comments on commit 441014c

Please sign in to comment.