Skip to content

Commit

Permalink
- fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
maycuatroi committed Jun 8, 2023
1 parent c724b1b commit e424734
Show file tree
Hide file tree
Showing 39 changed files with 203 additions and 161 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install project
run: make install
- name: Run linter
run: make lint
# - name: Run linter
# run: make lint

tests_linux:
needs: linter
Expand Down
2 changes: 1 addition & 1 deletion evoflow/__info__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
__maintainer__ = "Nguyen Anh binh"
__email__ = "sometimesocrazy@gmail.com"
__status__ = "developing"
__website__ = "https://github.com/maycuatroi/evo-flow/"
__website__ = "https://github.com/maycuatroi/evo-flow/"
22 changes: 14 additions & 8 deletions evoflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import os

os.environ['GIT_PYTHON_REFRESH'] = 'quiet'
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
import sys

from evoflow import params
Expand All @@ -13,7 +13,9 @@
from evoflow.entities.core.step import Step
from evoflow.__info__ import __website__

logger.debug(f'Start evoflow v {evoflow_version.__version__}. You can visit {__website__} for more information')
logger.debug(
f"Start evoflow v {evoflow_version.__version__}. You can visit {__website__} for more information"
)

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
Expand All @@ -23,8 +25,9 @@
def init_setting():
try:
import setting

for key in setting.__dict__:
if str(key).startswith('__'):
if str(key).startswith("__"):
continue
value = setting.__dict__[key]
os.environ[key] = str(value)
Expand All @@ -38,14 +41,16 @@ def versioning(version_module):
repo = git.Repo(search_parent_directories=True)
sha = repo.head.object.hexsha
if version_module.__sha__ != sha:
commits = list(repo.iter_commits('HEAD'))
commits = list(repo.iter_commits("HEAD"))
total_commit = len(commits)
version_parts = version_module.__version__.split('.')
version_parts = version_module.__version__.split(".")
version_parts[3] = str(total_commit)
version_path = inspect.getfile(version_module)
version_lines = [f"__version__ = '{'.'.join(version_parts)}'\n",
f"__sha__ = '{sha}'"]
open(version_path, 'w').writelines(version_lines)
version_lines = [
f"__version__ = '{'.'.join(version_parts)}'\n",
f"__sha__ = '{sha}'",
]
open(version_path, "w").writelines(version_lines)
except:
logger.error("Can't versioning")

Expand All @@ -57,6 +62,7 @@ def framework_versioning():
def bot_versioning():
try:
import version

versioning(version)
except:
logger.error("Can't versioning For Bot")
Expand Down
4 changes: 2 additions & 2 deletions evoflow/controller/common_step_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_all_common_steps_name():
return [step.name for step in get_all_common_steps()]


if __name__ == '__main__':
if __name__ == "__main__":
data = get_all_common_steps()
for key, value in data.items():
print(f'{key} - {str(value)}')
print(f"{key} - {str(value)}")
2 changes: 1 addition & 1 deletion evoflow/controller/data_manipulate/PdfFileOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def read(self, file_path, **args):

@staticmethod
def supported_file_types():
return ['pdf']
return ["pdf"]
2 changes: 1 addition & 1 deletion evoflow/controller/data_manipulate/PptxFileOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def read(self, file_path, **args):

@staticmethod
def supported_file_types():
return ['ppt', 'pptx']
return ["ppt", "pptx"]
3 changes: 1 addition & 2 deletions evoflow/controller/data_manipulate/excel_file_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class ExcelFileOperator(FileOperator):

def read(self, file_path, **args) -> File:
"""
read file excel
Expand All @@ -33,4 +32,4 @@ def save(self, file: File, file_path) -> bool:

@staticmethod
def supported_file_types():
return ['xlsx', 'csv', 'xls']
return ["xlsx", "csv", "xls"]
2 changes: 1 addition & 1 deletion evoflow/controller/data_manipulate/file_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_file_type(file_path):
"""
Trả về file type của file_path
"""
file_type = file_path.split('.')[-1].lower()
file_type = file_path.split(".")[-1].lower()
return file_type


Expand Down
4 changes: 2 additions & 2 deletions evoflow/controller/data_manipulate/image_file_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def imread(path, flags: int = -1):


def imwrite(path, mat):
image_type = path.split('.')[-1]
image_type = path.split(".")[-1]
is_success, im_buf_arr = cv2.imencode(".{}".format(image_type), mat)
im_buf_arr.tofile(path)
return is_success
Expand All @@ -49,4 +49,4 @@ def read(self, file_path, **args):

@staticmethod
def supported_file_types():
return ['jpg', 'png', 'tiff', 'tif']
return ["jpg", "png", "tiff", "tif"]
20 changes: 11 additions & 9 deletions evoflow/controller/log_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@

import coloredlogs

pathlib.Path('logs').mkdir(parents=True, exist_ok=True)
pathlib.Path("logs").mkdir(parents=True, exist_ok=True)
logger = logging.getLogger()
current_time_string = time.strftime('%Y%m%d-%H%M%S')
FILE_NAME = 'logs/evoflow.log'
fh = logging.FileHandler(filename=FILE_NAME, mode='a', encoding='utf-8')
current_time_string = time.strftime("%Y%m%d-%H%M%S")
FILE_NAME = "logs/evoflow.log"
fh = logging.FileHandler(filename=FILE_NAME, mode="a", encoding="utf-8")
fh.setLevel(logging.ERROR)
formatter = coloredlogs.ColoredFormatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = coloredlogs.ColoredFormatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
fh.setFormatter(formatter)
logger.addHandler(fh)
coloredlogs.install(level=logging.INFO, logger=logger)


def pretty_dict(dict_object, indent=0):
pretty_string = '\n'
pretty_string = "\n"
for key, value in dict_object.items():
pretty_string += '\t' * indent + str(key) + ' : '
pretty_string += '\t' * (indent + 1) + str(value) + '\n'
pretty_string += "\t" * indent + str(key) + " : "
pretty_string += "\t" * (indent + 1) + str(value) + "\n"
return pretty_string


Expand All @@ -35,7 +37,7 @@ def get_os_information():
uname: %s
version: %s
""" % (
sys.version.split('\n'),
sys.version.split("\n"),
str(platform.win32_edition()),
platform.system(),
platform.machine(),
Expand Down
2 changes: 1 addition & 1 deletion evoflow/controller/visualize_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from PIL import ImageFont


def draw_boxes(image, bounds, color='yellow', width=2):
def draw_boxes(image, bounds, color="yellow", width=2):
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("data/HachiMaruPop-Regular.ttf", 32)
for bound in bounds:
Expand Down
20 changes: 11 additions & 9 deletions evoflow/entities/common/step/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
def get_all_common_steps():
current_dir = os.path.split(__file__)[0]
cwd = os.path.split(os.getcwd())[0]
file_paths = glob.glob(f'{current_dir}/*.py')
file_paths = glob.glob(f"{current_dir}/*.py")
data = {}
for file_path in file_paths:
file_path = os.path.normpath(file_path)
file_path = file_path.replace(cwd, '')
if file_path.startswith('__init__'):
file_path = file_path.replace(cwd, "")
if file_path.startswith("__init__"):
continue

import_string = file_path.replace(os.sep, '.')[:-3][1:]
imported_module = __import__(import_string, fromlist=import_string.split('.')[-1])
import_string = file_path.replace(os.sep, ".")[:-3][1:]
imported_module = __import__(
import_string, fromlist=import_string.split(".")[-1]
)

for class_name, import_class in inspect.getmembers(imported_module):
if class_name == import_string.split('.')[-1]:
if class_name == import_string.split(".")[-1]:
data[class_name] = import_class()
break
return data
Expand All @@ -29,6 +31,6 @@ def get_all_common_steps():
@evoflow.Step()
def show_menu(menu_dict: dict = {}):
for key, value in menu_dict.items():
print(f'{key}. {value}')
select_option = os.environ.get('SELECT_OPTION') or input('Enter your option: ')
return {'select_option': int(select_option)}
print(f"{key}. {value}")
select_option = os.environ.get("SELECT_OPTION") or input("Enter your option: ")
return {"select_option": int(select_option)}
20 changes: 11 additions & 9 deletions evoflow/entities/common/step/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def open_browser(url: str = None, proxy: Proxy = None) -> dict:
"""
browser = webdriver.Firefox(proxy=proxy)
browser.get(url)
return {'browser': browser}
return {"browser": browser}


@evoflow.Step()
Expand All @@ -29,11 +29,13 @@ def setup_proxy(proxy_url: str = None):
"""
proxy = None
if proxy_url:
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': proxy_url,
'ftpProxy': proxy_url,
'sslProxy': proxy_url,
'noProxy': '' # set this value as desired
})
return {'proxy': proxy}
proxy = Proxy(
{
"proxyType": ProxyType.MANUAL,
"httpProxy": proxy_url,
"ftpProxy": proxy_url,
"sslProxy": proxy_url,
"noProxy": "", # set this value as desired
}
)
return {"proxy": proxy}
16 changes: 12 additions & 4 deletions evoflow/entities/common/step/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ def download_urls(urls: list = None, download_dir: str = "Downloads") -> object:
try:
res = requests.get(url)
filename = "zasdvadf"
with TqdmDownload(unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=filename) as t:
download_path, result = urlretrieve(url, f"{download_dir}/miniconda.exe")
with TqdmDownload(
unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=filename
) as t:
download_path, result = urlretrieve(
url, f"{download_dir}/miniconda.exe"
)
download_paths.append(download_path)

except:
Expand All @@ -79,7 +83,9 @@ def download_urls(urls: list = None, download_dir: str = None) -> object:
for i, url in tqdm(enumerate(urls), total=len(urls)):
try:
res = requests.get(url)
with TqdmDownload(unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=url) as t:
with TqdmDownload(
unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=url
) as t:
download_path, result = urlretrieve(url)
file_name = os.path.split(download_path)[1]
if download_dir:
Expand All @@ -88,7 +94,9 @@ def download_urls(urls: list = None, download_dir: str = None) -> object:
download_paths.append(download_path)

df.loc[i] = [url, download_path]
df.to_csv(f"{download_dir}/downloader_log.csv", encoding="utf-8", index=False)
df.to_csv(
f"{download_dir}/downloader_log.csv", encoding="utf-8", index=False
)
except Exception as e:
logger.error(f"{e}")

Expand Down
6 changes: 3 additions & 3 deletions evoflow/entities/core/base_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class BaseObject:
"""

def __init__(self, name=None, **kwargs):
self.name = f'{self.__class__.__name__} {name}'
self.name = f"{self.__class__.__name__} {name}"
self.id = uuid.uuid4().hex
for key, value in kwargs.items():
setattr(self, key, value)

def summary(self, **kwargs):
info = self.__info__(**kwargs)
info['name'] = self.name
info["name"] = self.name
json_string = json.dumps(info, ensure_ascii=False, indent=2)
return json_string

Expand All @@ -32,7 +32,7 @@ def __info__(self) -> dict:
@rtype: return object info to display or log
@param kwargs:
"""
return {'name': self.name}
return {"name": self.name}

def to_json(self):
data = self.__dict__
Expand Down
2 changes: 1 addition & 1 deletion evoflow/entities/core/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def to_dict(self):
if type(self.condition_function) != str:
args = inspect.getfullargspec(self.condition_function).args
z = inspect.getsource(self.condition_function)
return {'condition_function': {'args': args, 'source': z}}
return {"condition_function": {"args": args, "source": z}}
return self.__dict__
3 changes: 1 addition & 2 deletions evoflow/entities/core/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Session:
def __init__(self):
pass
Expand All @@ -7,4 +6,4 @@ def __enter__(self):
pass

def __exit__(self, exc_type, exc_value, traceback):
pass
pass
3 changes: 2 additions & 1 deletion evoflow/entities/core/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@ def set_all_params(self, params):
# support '>>' operator
def __rshift__(self, other):
from evoflow.entities.core.step_list import StepList

# connect to other step
if isinstance(other, Step) or isinstance(other, StepList):
return self.next(other)
elif isinstance(other, list):
return self.next(StepList(other))

def __lshift__(self, other):

from evoflow.entities.core.step_list import StepList

# connect to other step
if isinstance(other, Step) or isinstance(other, StepList):
return other.next(self)
Expand Down
4 changes: 3 additions & 1 deletion evoflow/entities/core/step_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def action(self, **kwargs):
with ThreadPoolExecutor(max_workers=10) as executor:
list(
tqdm(
executor.map(lambda step: step.action(**kwargs), self.steps), total=len(self.steps), desc=self.name
executor.map(lambda step: step.action(**kwargs), self.steps),
total=len(self.steps),
desc=self.name,
)
)
11 changes: 9 additions & 2 deletions evoflow/entities/core/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def validate(self, **kwargs):
if type(self.condition.condition_function) == str:
if self.condition.condition_function == "always":
return True
return self.build_condition_from_string(self.condition.condition_function, self.__from_step__.params)
return self.build_condition_from_string(
self.condition.condition_function, self.__from_step__.params
)
return bool(self.condition.condition_function(**kwargs))

def build_condition_from_string(self, condition_function_string, params):
Expand All @@ -36,6 +38,11 @@ def build_condition_from_string(self, condition_function_string, params):
return result

def to_dict(self):
data = {"id": self.id, "from": self.__from_step__.id, "to": self.to.id, "condition": self.condition}
data = {
"id": self.id,
"from": self.__from_step__.id,
"to": self.to.id,
"condition": self.condition,
}

return data
Loading

0 comments on commit e424734

Please sign in to comment.