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)
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)
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)
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)
def to_json(self, path_, probability=False, **kwargs): content = self.probability if probability else self FileIO.create(path_=path_, data=content).save(**kwargs)
def create(self): file = FileIO.create('test', data=self.data) # generic return file
def create(self): return FileIO.create('test.pkl', data=self.data)
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.")