Skip to content

Commit

Permalink
- First version evoflow
Browse files Browse the repository at this point in the history
  • Loading branch information
maycuatroi committed Jun 8, 2023
1 parent 3f81e7d commit a199ace
Show file tree
Hide file tree
Showing 85 changed files with 2,226 additions and 93 deletions.
8 changes: 4 additions & 4 deletions .github/rename_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ echo "Description: $description";
echo "Renaming project..."

original_author="maycuatroi"
original_name="evo_flow"
original_urlname="evo-flow"
original_description="Awesome evo_flow created by maycuatroi"
original_name="evoflow"
original_urlname="evoflow"
original_description="Awesome evoflow created by maycuatroi"
# for filename in $(find . -name "*.*")
for filename in $(git ls-files)
do
Expand All @@ -30,7 +30,7 @@ do
echo "Renamed $filename"
done

mv evo_flow $name
mv evoflow $name

# This command runs only once on GHA!
rm -rf .github/template.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ dmypy.json

# templates
.github/templates/*
/.idea/
4 changes: 2 additions & 2 deletions ABOUT_THIS_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Lets take a look at the structure of this template:
├── Makefile # A collection of utilities to manage the project
├── MANIFEST.in # A list of files to include in a package
├── mkdocs.yml # Configuration for documentation site
├── evo_flow # The main python package for the project
├── evoflow # The main python package for the project
│   ├── base.py # The base module for the project
│   ├── __init__.py # This tells Python that this is a package
│   ├── __main__.py # The entry point for the project
Expand Down Expand Up @@ -109,7 +109,7 @@ I had to do some tricks to read that version variable inside the setuptools
I decided to keep the version in a static file because it is easier to read from
wherever I want without the need to install the package.

e.g: `cat evo_flow/VERSION` will get the project version without harming
e.g: `cat evoflow/VERSION` will get the project version without harming
with module imports or anything else, it is useful for CI, logs and debugging.

### Why to include `tests`, `history` and `Containerfile` as part of the release?
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How to develop on this project

evo_flow welcomes contributions from the community.
evoflow welcomes contributions from the community.

**You need PYTHON3!**

Expand Down
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM python:3.7-alpine
COPY . /app
WORKDIR /app
RUN pip install .
CMD ["evo_flow"]
CMD ["evoflow"]
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include LICENSE
include HISTORY.md
include Containerfile
graft tests
graft evo_flow
graft evoflow
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ install: ## Install the project in dev mode.

.PHONY: fmt
fmt: ## Format code using black & isort.
$(ENV_PREFIX)isort evo_flow/
$(ENV_PREFIX)black -l 79 evo_flow/
$(ENV_PREFIX)isort evoflow/
$(ENV_PREFIX)black -l 79 evoflow/
$(ENV_PREFIX)black -l 79 tests/

.PHONY: lint
lint: ## Run pep8, black, mypy linters.
$(ENV_PREFIX)flake8 evo_flow/
$(ENV_PREFIX)black -l 79 --check evo_flow/
$(ENV_PREFIX)flake8 evoflow/
$(ENV_PREFIX)black -l 79 --check evoflow/
$(ENV_PREFIX)black -l 79 --check tests/
$(ENV_PREFIX)mypy --ignore-missing-imports evo_flow/
$(ENV_PREFIX)mypy --ignore-missing-imports evoflow/

.PHONY: test
test: lint ## Run tests and generate coverage report.
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=evo_flow -l --tb=short --maxfail=1 tests/
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=evoflow -l --tb=short --maxfail=1 tests/
$(ENV_PREFIX)coverage xml
$(ENV_PREFIX)coverage html

Expand Down Expand Up @@ -78,9 +78,9 @@ virtualenv: ## Create a virtual environment.
release: ## Create a new tag for release.
@echo "WARNING: This operation will create s version tag and push to github"
@read -p "Version? (provide the next x.y.z semver) : " TAG
@echo "$${TAG}" > evo_flow/VERSION
@echo "$${TAG}" > evoflow/VERSION
@$(ENV_PREFIX)gitchangelog > HISTORY.md
@git add evo_flow/VERSION HISTORY.md
@git add evoflow/VERSION HISTORY.md
@git commit -m "release: version $${TAG} 🚀"
@echo "creating git tag : $${TAG}"
@git tag $${TAG}
Expand All @@ -101,15 +101,15 @@ switch-to-poetry: ## Switch to poetry package manager.
@poetry init --no-interaction --name=a_flask_test --author=rochacbruno
@echo "" >> pyproject.toml
@echo "[tool.poetry.scripts]" >> pyproject.toml
@echo "evo_flow = 'evo_flow.__main__:main'" >> pyproject.toml
@echo "evoflow = 'evoflow.__main__:main'" >> pyproject.toml
@cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
@cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
@poetry install --no-interaction
@mkdir -p .github/backup
@mv requirements* .github/backup
@mv setup.py .github/backup
@echo "You have switched to https://python-poetry.org/ package manager."
@echo "Please run 'poetry shell' or 'poetry run evo_flow'"
@echo "Please run 'poetry shell' or 'poetry run evoflow'"

.PHONY: init
init: ## Initialize the project based on an application template.
Expand Down
65 changes: 6 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,28 @@

# Python Project Template

A low dependency and really simple to start project template for Python Projects.

See also
- [Flask-Project-Template](https://github.com/rochacbruno/flask-project-template/) for a full feature Flask project including database, API, admin interface, etc.
- [FastAPI-Project-Template](https://github.com/rochacbruno/fastapi-project-template/) The base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands.

### HOW TO USE THIS TEMPLATE

> **DO NOT FORK** this is meant to be used from **[Use this template](https://github.com/rochacbruno/python-project-template/generate)** feature.
1. Click on **[Use this template](https://github.com/rochacbruno/python-project-template/generate)**
3. Give a name to your project
(e.g. `my_awesome_project` recommendation is to use all lowercase and underscores separation for repo names.)
3. Wait until the first run of CI finishes
(Github Actions will process the template and commit to your new repo)
4. If you want [codecov](https://about.codecov.io/sign-up/) Reports and Automatic Release to [PyPI](https://pypi.org)
On the new repository `settings->secrets` add your `PYPI_API_TOKEN` and `CODECOV_TOKEN` (get the tokens on respective websites)
4. Read the file [CONTRIBUTING.md](CONTRIBUTING.md)
5. Then clone your new project and happy coding!

> **NOTE**: **WAIT** until first CI run on github actions before cloning your new project.
### What is included on this template?

- 🖼️ Templates for starting multiple application types:
* **Basic low dependency** Python program (default) [use this template](https://github.com/rochacbruno/python-project-template/generate)
* **Flask** with database, admin interface, restapi and authentication [use this template](https://github.com/rochacbruno/flask-project-template/generate).
**or Run `make init` after cloning to generate a new project based on a template.**
- 📦 A basic [setup.py](setup.py) file to provide installation, packaging and distribution for your project.
Template uses setuptools because it's the de-facto standard for Python packages, you can run `make switch-to-poetry` later if you want.
- 🤖 A [Makefile](Makefile) with the most useful commands to install, test, lint, format and release your project.
- 📃 Documentation structure using [mkdocs](http://www.mkdocs.org)
- 💬 Auto generation of change log using **gitchangelog** to keep a HISTORY.md file automatically based on your commit history on every release.
- 🐋 A simple [Containerfile](Containerfile) to build a container image for your project.
`Containerfile` is a more open standard for building container images than Dockerfile, you can use buildah or docker with this file.
- 🧪 Testing structure using [pytest](https://docs.pytest.org/en/latest/)
- ✅ Code linting using [flake8](https://flake8.pycqa.org/en/latest/)
- 📊 Code coverage reports using [codecov](https://about.codecov.io/sign-up/)
- 🛳️ Automatic release to [PyPI](https://pypi.org) using [twine](https://twine.readthedocs.io/en/latest/) and github actions.
- 🎯 Entry points to execute your program using `python -m <evo_flow>` or `$ evo_flow` with basic CLI argument parsing.
- 🔄 Continuous integration using [Github Actions](.github/workflows/) with jobs to lint, test and release your project on Linux, Mac and Windows environments.

> Curious about architectural decisions on this template? read [ABOUT_THIS_TEMPLATE.md](ABOUT_THIS_TEMPLATE.md)
> If you want to contribute to this template please open an [issue](https://github.com/rochacbruno/python-project-template/issues) or fork and send a PULL REQUEST.
[❤️ Sponsor this project](https://github.com/sponsors/rochacbruno/)

<!-- DELETE THE LINES ABOVE THIS AND WRITE YOUR PROJECT README BELOW -->

---
# evo_flow
# evoflow

[![codecov](https://codecov.io/gh/maycuatroi/evo-flow/branch/main/graph/badge.svg?token=evo-flow_token_here)](https://codecov.io/gh/maycuatroi/evo-flow)
[![CI](https://github.com/maycuatroi/evo-flow/actions/workflows/main.yml/badge.svg)](https://github.com/maycuatroi/evo-flow/actions/workflows/main.yml)

Awesome evo_flow created by maycuatroi
a lite weight RPA and Workflow engine

## Install it from PyPI

```bash
pip install evo_flow
pip install evoflow
```

## Usage

```py
from evo_flow import BaseClass
from evo_flow import base_function
from evoflow import BaseClass
from evoflow import base_function

BaseClass().base_method()
base_function()
```

```bash
$ python -m evo_flow
$ python -m evoflow
#or
$ evo_flow
```
Expand Down
1 change: 0 additions & 1 deletion evo_flow/VERSION

This file was deleted.

File renamed without changes.
18 changes: 18 additions & 0 deletions evoflow/Services/abstract_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import abc


class AbstractService:
def __init__(self):
pass

@abc.abstractmethod
def run(self, data, **args):
pass

@abc.abstractmethod
def start(self, **args):
pass

@abc.abstractmethod
def kill(self, **args):
pass
Empty file.
68 changes: 68 additions & 0 deletions evoflow/Services/ocr/easy_ocr_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright (c) 2021. Copyright belongs to evoflow team

import logging
import os.path
from typing import Iterator
from urllib.error import URLError

import numpy as np

from evoflow import logger
from evoflow.Services.ocr.result import OCRResult

try:
import easyocr
except ImportError:
logger.error("Can't import easyocr. Try to install with: pip install easyocr")

MODEL_PATH = "/ocr"


class EasyOCREngine:
"""
Engine OCR sử dụng thư viện easyocr
"""

def __init__(self, languages=None):
if languages is None:
languages = ["en"]
try:
model_storage_directory_evoflow = f'{os.getenv("userprofile")}/.evoflow/ocr'
model_storage_directory_data = "./data/.evoflow/ocr"
if os.path.isfile(model_storage_directory_evoflow):
model_storage_directory = model_storage_directory_evoflow
else:
model_storage_directory = model_storage_directory_data
self.reader = easyocr.Reader(
languages,
download_enabled=True,
model_storage_directory=model_storage_directory,
)
except URLError as url_error:
logger.error("Can't download model, internet blocked")
raise URLError(
reason="Can't download model, internet blocked"
) from url_error
logging.info("Initiated EasyOCREngine")

def ocr(self, image: np.array, detail=0) -> Iterator[OCRResult]:
"""
:param image: opencv image format
:param detail:
0 for simpler output.
1 for detail output.
"""
results = self.reader.readtext(np.array(image), detail=detail)

for i, result in enumerate(results):
bbox = result[0]
bbox = [list(map(int, z)) for z in bbox] # convert np.int32 to int
res = (bbox, result[1], result[2])
results[i] = OCRResult(*res)
return results

@staticmethod
def supported_languages() -> Iterator[str]:
all_lang_list = easyocr.easyocr.all_lang_list
return all_lang_list
56 changes: 56 additions & 0 deletions evoflow/Services/ocr/ocr_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typing import Iterator

import PIL
import numpy as np
from PIL import Image

from evoflow.controller.log_controller import logger
from evoflow.entities.data_manipulate.file_operator.file import File
from evoflow.entities.data_manipulate.file_operator.image_file import ImageFile
from evoflow.Services.abstract_service import AbstractService
from evoflow.Services.ocr.Result import OCRResult


def get_image(data: File):
pil_image = np.array(Image.open(data.file))
return pil_image


class OCRService(AbstractService):
def start(self, **args):
pass

def kill(self, **args):
pass

def run(self, data: File, **args):

image = get_image(data)
result = self.ocr(image, **args)
return result

def __init__(self, engine_name="easyocr", languages=None):
if languages is None:
languages = ["en", "ja"]
self.engine = None
if engine_name == "easyocr":
# pylint:disable=import-outside-toplevel
from evoflow.Services.OCR.EasyOCREngine import EasyOCREngine

self.engine = EasyOCREngine(languages=languages)
else:
logger.error("OCR engine name not valid")

super().__init__()

def ocr(self, image_file: ImageFile, **args) -> Iterator[OCRResult]:
"""
OCR text from image.
:param image_file: Image file format
"""
if isinstance(image_file, str):
image = PIL.Image.open(image_file)
else:
image = image_file.to_pil()
results = self.engine.ocr(image, **args)
return results
1 change: 1 addition & 0 deletions evoflow/Services/ocr/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
easyocr

0 comments on commit a199ace

Please sign in to comment.