-
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.
dev(hansbug): add new tests and features
- Loading branch information
Showing
24 changed files
with
433 additions
and
37 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
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
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 @@ | ||
import os | ||
import shutil | ||
from typing import Optional, Mapping, Any | ||
|
||
from .base import RenderJob | ||
from ..utils import get_archive_type | ||
|
||
|
||
class ArchiveUnpackJob(RenderJob): | ||
def __init__(self, srcpath: str, dstpath: str, extras: Optional[Mapping[str, Any]] = None): | ||
RenderJob.__init__(self, srcpath, dstpath) | ||
_ = extras | ||
|
||
def _run(self): | ||
archive_fmt = get_archive_type(self.srcpath) | ||
os.makedirs(self.dstpath, exist_ok=True) | ||
shutil.unpack_archive(self.srcpath, self.dstpath, archive_fmt) |
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
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
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
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,58 @@ | ||
import mimetypes | ||
import os | ||
from itertools import chain | ||
|
||
_TEXT_CHARS = bytearray({7, 8, 9, 10, 12, 13, 27} | set(range(0x20, 0x100)) - {0x7f}) | ||
|
||
|
||
def _is_binary_string(data: bytes) -> bool: | ||
return bool(data.translate(None, _TEXT_CHARS)) | ||
|
||
|
||
def _take_sample(filename, size=1024) -> bytes: | ||
with open(filename, 'rb') as f: | ||
return f.read(size) | ||
|
||
|
||
def is_binary_file(filename) -> bool: | ||
""" | ||
Overview: | ||
Check if the given file is binary file. | ||
:param filename: Filename. | ||
:return: Is binary file or not. | ||
""" | ||
return _is_binary_string(_take_sample(filename)) | ||
|
||
|
||
def _iter_extensions(): | ||
for n1, n2 in chain(*map( | ||
lambda x: x.items(), | ||
[mimetypes.types_map, mimetypes.common_types, mimetypes.encodings_map, mimetypes.suffix_map] | ||
)): | ||
if n1.startswith('.'): | ||
yield n1 | ||
if n2.startswith('.'): | ||
yield n2 | ||
|
||
|
||
def get_file_ext(filename) -> str: | ||
filename = os.path.normcase(filename) | ||
|
||
ext = '' | ||
for exist_ext in _iter_extensions(): | ||
if filename.endswith(exist_ext) and len(exist_ext) > len(ext): | ||
ext = exist_ext | ||
|
||
if not ext: | ||
_, ext = os.path.splitext(filename) | ||
|
||
return ext | ||
|
||
|
||
def splitext(filename): | ||
ext = get_file_ext(filename) | ||
if ext: | ||
return filename[:-len(ext)], ext | ||
else: | ||
return filename, '' |
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
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 igm4ai | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,3 @@ | ||
# template-test | ||
|
||
Just a test template for IGM's unittest. |
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,44 @@ | ||
from InquirerPy import inquirer | ||
|
||
from igm.conf import InquireRestart | ||
from igm.env import env | ||
|
||
_LAST_NAME = "" | ||
_LAST_AGE = 18 | ||
_LAST_GENDER = "Male" | ||
|
||
|
||
def inquire_func(): | ||
global _LAST_AGE, _LAST_NAME, _LAST_GENDER | ||
|
||
name = env.NAME or inquirer.text(message="What's your name:", default=_LAST_NAME).execute() | ||
age = int(env.AGE or inquirer.number( | ||
message="What's your age:", | ||
min_allowed=1, | ||
float_allowed=False, | ||
invalid_message='Age should not be less than 1.', | ||
default=_LAST_AGE, | ||
).execute()) | ||
gender = str(env.GENDER or inquirer.select( | ||
message="Your gender?", | ||
choices=["Male", "Female", "Others"], | ||
default=_LAST_GENDER, | ||
).execute()) | ||
|
||
if env.NON_CONFIRM: | ||
confirm = True | ||
else: | ||
confirm = inquirer.confirm(message=f"{name}, {age}, {gender}, confirm?").execute() | ||
|
||
if confirm: | ||
return { | ||
'name': name, | ||
'age': age, | ||
'gender': gender | ||
} | ||
else: | ||
# save this time's fillings | ||
_LAST_NAME = name | ||
_LAST_AGE = age | ||
_LAST_GENDER = gender | ||
raise InquireRestart('Not confirmed.') |
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,9 @@ | ||
from igm.conf import igm_setup | ||
from inquirer import inquire_func | ||
|
||
igm_setup( | ||
name='test', | ||
version='0.0.1', | ||
description='Just a test template for IGM.', | ||
inquire=inquire_func, | ||
) |
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 @@ | ||
inquirerpy>=0.3.3 |
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,14 @@ | ||
cpus = {{ sys.cpu.num }} | ||
mem_size = {{ sys.memory.total | str | potc }} | ||
os = {{ sys.os.type | str | potc }} | ||
python = {{ sys.python | str | potc }} | ||
{% if sys.cuda %} | ||
cuda_version = {{ sys.cuda.version | str | potc }} | ||
gpu_num = {{ sys.gpu.num | potc }} | ||
{% endif %} | ||
|
||
print('This is your first try!') | ||
print(f'UR running {python} on {os}, with a {cpus} core {mem_size} device.') | ||
{% if sys.cuda %} | ||
print(f'CUDA {cuda_version} is also detected, with {gpu_num} gpu(s).') | ||
{% endif %} |
Binary file not shown.
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,9 @@ | ||
# hello world for {{ user.name }} | ||
|
||
This is a hello world project of igm created by {{ user.name | potc }} (age: `{{ user.age }}`). | ||
|
||
You can start this project by the following command: | ||
|
||
```python | ||
python main.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,14 @@ | ||
cpus = {{ sys.cpu.num }} | ||
mem_size = {{ sys.memory.total | str | potc }} | ||
os = {{ sys.os.type | str | potc }} | ||
python = {{ sys.python | str | potc }} | ||
{% if sys.cuda %} | ||
cuda_version = {{ sys.cuda.version | str | potc }} | ||
gpu_num = {{ sys.gpu.num | potc }} | ||
{% endif %} | ||
|
||
print('This is your first try!') | ||
print(f'UR running {python} on {os}, with a {cpus} core {mem_size} device.') | ||
{% if sys.cuda %} | ||
print(f'CUDA {cuda_version} is also detected, with {gpu_num} gpu(s).') | ||
{% endif %} |
Binary file not shown.
Oops, something went wrong.