Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_stream_blend(self):
proc = gramex.cache.Subprocess(
self.args1, stream_stdout='list_out', stream_stderr='list_out', buffer_size='line')
[wait(future) for future in proc.wait_for_exit()]
eq_(set(proc.list_out), {self.msg(s) for s in ('OUT:0', 'OUT:1', 'ERR:0', 'ERR:1')})
proc = gramex.cache.Subprocess(
self.args1, stream_stdout='queue_out', stream_stderr='queue_out', buffer_size='line')
[wait(future) for future in proc.wait_for_exit()]
items = set()
for index in range(proc.queue_out.qsize()):
items.add(proc.queue_out.get_nowait())
eq_(items, {self.msg(s) for s in ('OUT:0', 'OUT:1', 'ERR:0', 'ERR:1')})
def test_stream_blend(self):
proc = gramex.cache.Subprocess(
self.args1, stream_stdout='list_out', stream_stderr='list_out', buffer_size='line')
[wait(future) for future in proc.wait_for_exit()]
eq_(set(proc.list_out), {self.msg(s) for s in ('OUT:0', 'OUT:1', 'ERR:0', 'ERR:1')})
proc = gramex.cache.Subprocess(
self.args1, stream_stdout='queue_out', stream_stderr='queue_out', buffer_size='line')
[wait(future) for future in proc.wait_for_exit()]
items = set()
for index in range(proc.queue_out.qsize()):
items.add(proc.queue_out.get_nowait())
eq_(items, {self.msg(s) for s in ('OUT:0', 'OUT:1', 'ERR:0', 'ERR:1')})
def test_stream_none(self):
proc = gramex.cache.Subprocess(self.args)
stdout, stderr = [wait(future) for future in proc.wait_for_exit()]
eq_(stdout, self.msg('OUT:0'))
eq_(stderr, self.msg('ERR:0'))
proc = gramex.cache.Subprocess(self.args1)
stdout, stderr = [wait(future) for future in proc.wait_for_exit()]
eq_(stdout, self.msg('OUT:0') + self.msg('OUT:1'))
eq_(stderr, self.msg('ERR:0') + self.msg('ERR:1'))
def test_stream_list(self):
proc = gramex.cache.Subprocess(
self.args, stream_stdout='list_out', stream_stderr='list_err', buffer_size='line')
[wait(future) for future in proc.wait_for_exit()]
eq_(proc.list_out, [self.msg('OUT:0')])
eq_(proc.list_err, [self.msg('ERR:0')])
proc = gramex.cache.Subprocess(
self.args1, stream_stdout='list_out', stream_stderr='list_err', buffer_size='line')
wait_till(lambda: len(proc.list_out) > 0)
wait_till(lambda: len(proc.list_err) > 0)
eq_(proc.list_out, [self.msg('OUT:0')])
eq_(proc.list_err, [self.msg('ERR:0')])
wait_till(lambda: len(proc.list_out) > 1)
wait_till(lambda: len(proc.list_err) > 1)
eq_(proc.list_out, [self.msg('OUT:0'), self.msg('OUT:1')])
eq_(proc.list_err, [self.msg('ERR:0'), self.msg('ERR:1')])
[wait(future) for future in proc.wait_for_exit()]
def test_stream_none(self):
proc = gramex.cache.Subprocess(self.args)
stdout, stderr = [wait(future) for future in proc.wait_for_exit()]
eq_(stdout, self.msg('OUT:0'))
eq_(stderr, self.msg('ERR:0'))
proc = gramex.cache.Subprocess(self.args1)
stdout, stderr = [wait(future) for future in proc.wait_for_exit()]
eq_(stdout, self.msg('OUT:0') + self.msg('OUT:1'))
eq_(stderr, self.msg('ERR:0') + self.msg('ERR:1'))
def test_stream_queue(self):
proc = gramex.cache.Subprocess(
self.args, stream_stdout='queue_out', stream_stderr='queue_err')
[wait(future) for future in proc.wait_for_exit()]
eq_(proc.queue_out.get(), self.msg('OUT:0'))
eq_(proc.queue_err.get(), self.msg('ERR:0'))
proc = gramex.cache.Subprocess(
self.args1, stream_stdout='queue_out', stream_stderr='queue_err', buffer_size='line')
eq_(proc.queue_out.get(), self.msg('OUT:0'))
eq_(proc.queue_err.get(), self.msg('ERR:0'))
eq_(proc.queue_out.get(), self.msg('OUT:1'))
eq_(proc.queue_err.get(), self.msg('ERR:1'))
[wait(future) for future in proc.wait_for_exit()]
eq_(proc.queue_out.qsize(), 0)
eq_(proc.queue_err.qsize(), 0)
error['gramex', 'open-files'] = 'psutil not installed'
try:
import conda
value['conda', 'version'] = conda.__version__,
except ImportError:
app_log.warning('conda required for conda stats')
error['conda', 'version'] = 'conda not installed'
from shutilwhich import which
value['node', 'path'] = which('node')
value['git', 'path'] = which('git')
from gramex.cache import Subprocess
apps = {
('node', 'version'): Subprocess('node --version', shell=True),
('npm', 'version'): Subprocess('npm --version', shell=True),
('yarn', 'version'): Subprocess('yarn --version', shell=True),
('git', 'version'): Subprocess('git --version', shell=True),
}
for key, proc in apps.items():
stdout, stderr = yield proc.wait_for_exit()
value[key] = stdout.strip()
if not value[key]:
error[key] = stderr.strip()
value['python', 'version'] = '{0}.{1}.{2}'.format(*sys.version_info[:3])
value['python', 'path'] = sys.executable
value['gramex', 'version'] = gramex.__version__
value['gramex', 'path'] = os.path.dirname(gramex.__file__)
import pandas as pd
df = pd.DataFrame({'value': value, 'error': error}).reset_index()
error['gramex', 'memory-usage'] = 'psutil not installed'
error['gramex', 'open-files'] = 'psutil not installed'
try:
import conda
value['conda', 'version'] = conda.__version__,
except ImportError:
app_log.warning('conda required for conda stats')
error['conda', 'version'] = 'conda not installed'
from shutilwhich import which
value['node', 'path'] = which('node')
value['git', 'path'] = which('git')
from gramex.cache import Subprocess
apps = {
('node', 'version'): Subprocess('node --version', shell=True),
('npm', 'version'): Subprocess('npm --version', shell=True),
('yarn', 'version'): Subprocess('yarn --version', shell=True),
('git', 'version'): Subprocess('git --version', shell=True),
}
for key, proc in apps.items():
stdout, stderr = yield proc.wait_for_exit()
value[key] = stdout.strip()
if not value[key]:
error[key] = stderr.strip()
value['python', 'version'] = '{0}.{1}.{2}'.format(*sys.version_info[:3])
value['python', 'path'] = sys.executable
value['gramex', 'version'] = gramex.__version__
value['gramex', 'path'] = os.path.dirname(gramex.__file__)
import pandas as pd
try:
import conda
value['conda', 'version'] = conda.__version__,
except ImportError:
app_log.warning('conda required for conda stats')
error['conda', 'version'] = 'conda not installed'
from shutilwhich import which
value['node', 'path'] = which('node')
value['git', 'path'] = which('git')
from gramex.cache import Subprocess
apps = {
('node', 'version'): Subprocess('node --version', shell=True),
('npm', 'version'): Subprocess('npm --version', shell=True),
('yarn', 'version'): Subprocess('yarn --version', shell=True),
('git', 'version'): Subprocess('git --version', shell=True),
}
for key, proc in apps.items():
stdout, stderr = yield proc.wait_for_exit()
value[key] = stdout.strip()
if not value[key]:
error[key] = stderr.strip()
value['python', 'version'] = '{0}.{1}.{2}'.format(*sys.version_info[:3])
value['python', 'path'] = sys.executable
value['gramex', 'version'] = gramex.__version__
value['gramex', 'path'] = os.path.dirname(gramex.__file__)
import pandas as pd
df = pd.DataFrame({'value': value, 'error': error}).reset_index()
df.columns = ['section', 'key'] + df.columns[2:].tolist()
base = os.path.splitext(os.path.basename(template))[0] + '.' + cache_key
cache_path = join(cache_dir, base + '.css')
if not os.path.exists(cache_path) or os.stat(template).st_mtime > os.stat(cache_path).st_mtime:
# Create a SCSS file based on the args
scss_path = join(cache_dir, base + '.scss')
with io.open(scss_path, 'wb') as handle:
result = gramex.cache.open(template, 'template').generate(
variables=args,
uicomponents_path=uicomponents_path.replace('\\', '/'),
bootstrap_path=bootstrap_path.replace('\\', '/'),
google_fonts=google_fonts,
)
handle.write(result)
# Run sass to generate the output
options = ['--output-style', 'compressed']
proc = gramex.cache.Subprocess(
['node', sass_path, scss_path, cache_path] + options)
out, err = yield proc.wait_for_exit()
if proc.proc.returncode:
app_log.error('node-sass error: %s', err)
raise RuntimeError('Compilation failure')
handler.set_header('Content-Type', 'text/css')
raise Return(gramex.cache.open(cache_path, 'bin', mode='rb'))