コード例 #1
0
 def save(self, path_, **kwargs):
     from cereja import FileIO, Path
     path_ = Path(path_)
     if path_.is_dir:
         path_ = path_.join(f'{self.name}.py')
     assert path_.suffix == '.py', "Only python source code."
     FileIO.create(path_, self._source_code).save(**kwargs)
コード例 #2
0
 def test_eval(self):
     with tempfile.TemporaryDirectory() as tempdir:
         eval_data = [1, 2, 3, 'hi', ['oi']]
         file = FileIO.create(Path(tempdir).join(self.file.name), eval_data)
         self.assertEqual(file.data, eval_data)
         file.save()
         file = FileIO.load(file.path)
         self.assertEqual(file.data, eval_data)
コード例 #3
0
ファイル: _utils.py プロジェクト: LucaswasTaken/cereja
def _add_license(base_dir, ext='.py'):
    from cereja.file import FileIO
    from cereja.config import BASE_DIR
    licence_file = FileIO.load(BASE_DIR)
    for file in FileIO.load_files(base_dir, ext=ext, recursive=True):
        if 'Copyright (c) 2019 The Cereja Project' in file.string:
            continue
        file.insert('"""\n' + licence_file.string + '\n"""')
        file.save(exist_ok=True)
コード例 #4
0
 def to_json(self, path_: str):
     try:
         preprocess_function = str(pickle.dumps(self._preprocess_function)
                                   ) if self._preprocess_function else None
     except Exception as err:
         raise Exception(f'Error on preprocess function save: {err}')
     use_unk = self._use_unk
     tokenizer_data = {
         '_metadata': {
             '_preprocess_function': preprocess_function,
             '_use_unk': use_unk
         },
         'data': self._index_to_item
     }
     FileIO.create(path_, tokenizer_data).save(exist_ok=True)
コード例 #5
0
 def test_sanity(self):
     console.log(f'Testing {self.name}')
     with tempfile.TemporaryDirectory() as tempdir:
         self.file.set_path(Path(tempdir).join(self.file.name))
         data_before_save = self.file.data
         self.file.save(exist_ok=True)
         file = FileIO.load(self.file.path, **self.load_kwargs)
         self.assertTrue(file.path.exists, msg="File don't exist.")
         self.assertEqual(file.data, data_before_save, msg='Data corrupted')
         file.delete()
         self.assertFalse(file.path.exists)
コード例 #6
0
ファイル: _utils.py プロジェクト: LucaswasTaken/cereja
 def save(self, path_, **kwargs):
     from cereja import FileIO, Path
     assert Path(path_).suffix == '.py', "Only python source code."
     FileIO.create(path_, self._source_code).save(**kwargs)
コード例 #7
0
 def load_from_json(cls, path_: str):
     data = FileIO.load(path_)
     return cls(data.data, load_mode=True)
コード例 #8
0
 def to_json(self, path_, probability=False, **kwargs):
     content = self.probability if probability else self
     FileIO.create(path_=path_, data=content).save(**kwargs)
コード例 #9
0
 def create(self):
     return FileIO.json('test.json', data=self.data, creation_mode=True)
コード例 #10
0
 def create(self):
     file = FileIO.txt('test.txt', data=self.data, creation_mode=True)
     return file
コード例 #11
0
 def create(self):
     file = FileIO.create('test', data=self.data)  # generic
     return file
コード例 #12
0
 def create(self):
     return FileIO.create('test.pkl', data=self.data)
コード例 #13
0
 def create(self):
     return FileIO.csv('test.csv',
                       data=self.data,
                       creation_mode=True,
                       cols=self.cols)
コード例 #14
0
ファイル: __main__.py プロジェクト: d4Rk35T/cereja
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.
"""

import argparse
import sys
from cereja import get_version_pep440_compliant, Path
from cereja.config import BASE_DIR
from cereja.file import FileIO

if __name__ == "__main__":
    sys.stdout.write("\U0001F352 Cereja Tools\n")
    sys.stdout.flush()
    parser = argparse.ArgumentParser(description='Cereja Tools.')
    parser.add_argument('--version',
                        action='version',
                        version=get_version_pep440_compliant())
    parser.add_argument('--startmodule', type=str)
    args = parser.parse_args()
    if args.startmodule:
        base_dir = Path(BASE_DIR)
        license_ = b''.join(FileIO.load(
            base_dir.parent.join('LICENSE')).data).decode()
        license_ = '"""\n' + license_ + '"""'
        new_module_path = base_dir.join(*args.startmodule.split('/'))
        if new_module_path.parent.exists and new_module_path.parent.is_dir:
            FileIO.create(new_module_path, license_).save()
        else:
            print(f"{new_module_path} is not valid.")