def test_write_file(): _files.write_file('/tmp/my-file', '42') open.assert_called_with('/tmp/my-file', 'w') open().write.assert_called_with('42') _files.write_file('/tmp/my-file', '42', 'a') open.assert_called_with('/tmp/my-file', 'a') open().write.assert_called_with('42')
def test_write_file(): _files.write_file("/tmp/my-file", "42") open.assert_called_with("/tmp/my-file", "w") open().write.assert_called_with("42") _files.write_file("/tmp/my-file", "42", "a") open.assert_called_with("/tmp/my-file", "a") open().write.assert_called_with("42")
def _create_nginx_config(serving_env): template = _files.read_file(nginx_config_template_file) pattern = re.compile(r'%(\w+)%') template_values = { 'NGINX_HTTP_PORT': serving_env.http_port } config = pattern.sub(lambda x: template_values[x.group(1)], template) logger.info('nginx config: \n%s\n', config) _files.write_file(nginx_config_file, config)
def _create_nginx_config(serving_env): """Placeholder docstring""" template = _files.read_file(nginx_config_template_file) pattern = re.compile(r"%(\w+)%") template_values = { "NGINX_HTTP_PORT": serving_env.http_port, "NGINX_PROXY_READ_TIMEOUT": str(serving_env.model_server_timeout), } config = pattern.sub(lambda x: template_values[x.group(1)], template) logger.info("nginx config: \n%s\n", config) _files.write_file(nginx_config_file, config)
def prepare(path, name): # type: (str, str) -> None """Prepare a Python script (or module) to be imported as a module. If the script does not contain a setup.py file, it creates a minimal setup. Args: path (str): path to directory with the script or module. name (str): name of the script or module. """ setup_path = os.path.join(path, "setup.py") if not os.path.exists(setup_path): data = textwrap.dedent( """ from setuptools import setup setup(packages=[''], name="%s", version='1.0.0', include_package_data=True) """ % name ) logger.info("Module %s does not provide a setup.py. \nGenerating setup.py" % name) _files.write_file(setup_path, data) data = textwrap.dedent( """ [wheel] universal = 1 """ ) logger.info("Generating setup.cfg") _files.write_file(os.path.join(path, "setup.cfg"), data) data = textwrap.dedent( """ recursive-include . * recursive-exclude . __pycache__* recursive-exclude . *.pyc recursive-exclude . *.pyo """ ) logger.info("Generating MANIFEST.in") _files.write_file(os.path.join(path, "MANIFEST.in"), data)