scope 0.3.2__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scope-0.4.0/PKG-INFO +66 -0
- scope-0.4.0/requirements.txt +6 -0
- {scope-0.3.2 → scope-0.4.0}/scope/__init__.py +1 -1
- {scope-0.3.2 → scope-0.4.0}/scope/reader.py +1 -1
- {scope-0.3.2 → scope-0.4.0}/scope/writer.py +1 -1
- {scope-0.3.2 → scope-0.4.0}/setup.py +36 -2
- scope-0.4.0/viewer/__main__.py +24 -0
- scope-0.4.0/viewer/dist/favicon.png +0 -0
- scope-0.4.0/viewer/dist/index.html +14 -0
- scope-0.4.0/viewer/dist/logo.png +0 -0
- scope-0.4.0/viewer/filesystems.py +89 -0
- scope-0.4.0/viewer/server.py +178 -0
- scope-0.3.2/LICENSE +0 -19
- scope-0.3.2/MANIFEST.in +0 -1
- scope-0.3.2/PKG-INFO +0 -10
- scope-0.3.2/pyproject.toml +0 -5
- scope-0.3.2/requirements.txt +0 -3
- scope-0.3.2/scope.egg-info/PKG-INFO +0 -10
- scope-0.3.2/scope.egg-info/SOURCES.txt +0 -18
- scope-0.3.2/scope.egg-info/dependency_links.txt +0 -1
- scope-0.3.2/scope.egg-info/requires.txt +0 -3
- scope-0.3.2/scope.egg-info/top_level.txt +0 -1
- scope-0.3.2/setup.cfg +0 -4
- {scope-0.3.2 → scope-0.4.0}/scope/formats.py +0 -0
- {scope-0.3.2 → scope-0.4.0}/tests/test_float.py +0 -0
- {scope-0.3.2 → scope-0.4.0}/tests/test_image.py +0 -0
- {scope-0.3.2 → scope-0.4.0}/tests/test_video.py +0 -0
- /scope-0.3.2/README.md → /scope-0.4.0/viewer/__init__.py +0 -0
scope-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: scope
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Metrics logging and analysis
|
|
5
|
+
Home-page: http://github.com/danijar/scope
|
|
6
|
+
Classifier: Intended Audience :: Science/Research
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
|
|
12
|
+
# 🔬 Scope
|
|
13
|
+
|
|
14
|
+
Scalable metrics logging and analysis.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- 🚀 **Scalable:** Quickly log and view petabytes of metrics, thousands of keys, and large videos.
|
|
19
|
+
- 🎞️ **Formats:** Log and view scalars, text, images, and videos. Easy to extend with custom formats.
|
|
20
|
+
- 🧑🏻🔬 **Productivity:** Metrics viewer with focus on power users and full keyboard support.
|
|
21
|
+
- ☁️ **Cloud support:** Directly write to and read from Cloud storage via pathlib interface.
|
|
22
|
+
- 🍃 **Lightweight:** The writer and reader measure only ~400 lines of Python code.
|
|
23
|
+
- 🧱 **Reliability:** Unit tested and used across diverse research projects.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Installation
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pip install scope
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Writing
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import scope
|
|
37
|
+
|
|
38
|
+
writer = scope.Writer(logdir)
|
|
39
|
+
for step in range(3)
|
|
40
|
+
video = np.zeros((100, 640, 360, 3), np.uint8)
|
|
41
|
+
writer.add(step, {'foo': 42, 'bar': video, 'baz': 'Hello World'})
|
|
42
|
+
writer.flush()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Viewing
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
python -m scope.viewer --basedir ... --port 8000
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Reading
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import scope
|
|
55
|
+
|
|
56
|
+
reader = scope.Reader(logdir)
|
|
57
|
+
print(reader.keys()) # ('foo', 'bar', 'baz')
|
|
58
|
+
|
|
59
|
+
print(reader.length('foo')) # 3
|
|
60
|
+
steps, values = reader['foo']
|
|
61
|
+
print(steps) # np.array([0, 1, 2], np.int64)
|
|
62
|
+
print(values) # np.array([42, 42, 42], np.float64)
|
|
63
|
+
|
|
64
|
+
steps, filenames = reader['bar']
|
|
65
|
+
reader.load('bar', filenames[-1]) # np.zeros((100, 640, 360, 3), np.uint8)
|
|
66
|
+
```
|
|
@@ -18,7 +18,7 @@ class Reader:
|
|
|
18
18
|
formats = formats or FORMATS
|
|
19
19
|
if isinstance(logdir, str):
|
|
20
20
|
logdir = pathlib.Path(logdir)
|
|
21
|
-
self.logdir = logdir
|
|
21
|
+
self.logdir = logdir / 'scope'
|
|
22
22
|
self.fmts = {x.extension: x for x in formats}
|
|
23
23
|
self.cols = {}
|
|
24
24
|
for child in sorted(logdir.glob('*')):
|
|
@@ -33,7 +33,7 @@ class Writer:
|
|
|
33
33
|
formats = formats or FORMATS
|
|
34
34
|
if isinstance(logdir, str):
|
|
35
35
|
logdir = pathlib.Path(logdir)
|
|
36
|
-
self.logdir = logdir
|
|
36
|
+
self.logdir = logdir / 'scope'
|
|
37
37
|
self.logdir.mkdir(parents=True, exist_ok=True)
|
|
38
38
|
self.workers = workers
|
|
39
39
|
self.rng = np.random.default_rng(seed=None)
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import os
|
|
1
2
|
import pathlib
|
|
2
3
|
import re
|
|
4
|
+
import subprocess
|
|
5
|
+
|
|
3
6
|
import setuptools
|
|
7
|
+
from distutils.command.sdist import sdist as _sdist
|
|
8
|
+
from setuptools.command.develop import develop as _develop
|
|
4
9
|
|
|
5
10
|
|
|
6
11
|
def parse_requirements(filename):
|
|
@@ -16,6 +21,24 @@ def parse_version(filename):
|
|
|
16
21
|
return version
|
|
17
22
|
|
|
18
23
|
|
|
24
|
+
def build_viewer():
|
|
25
|
+
orig = os.getcwd()
|
|
26
|
+
try:
|
|
27
|
+
os.chdir(pathlib.Path(__file__).parent / 'viewer')
|
|
28
|
+
subprocess.check_call(['npm', 'install'])
|
|
29
|
+
subprocess.check_call(['npm', 'run', 'build'])
|
|
30
|
+
finally:
|
|
31
|
+
os.chdir(orig)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def patch(cmd):
|
|
35
|
+
class Patched(cmd):
|
|
36
|
+
def run(self):
|
|
37
|
+
build_viewer()
|
|
38
|
+
cmd.run(self)
|
|
39
|
+
return Patched
|
|
40
|
+
|
|
41
|
+
|
|
19
42
|
setuptools.setup(
|
|
20
43
|
name='scope',
|
|
21
44
|
version=parse_version('scope/__init__.py'),
|
|
@@ -23,9 +46,20 @@ setuptools.setup(
|
|
|
23
46
|
url='http://github.com/danijar/scope',
|
|
24
47
|
long_description=pathlib.Path('README.md').read_text(),
|
|
25
48
|
long_description_content_type='text/markdown',
|
|
26
|
-
packages=['scope'],
|
|
27
|
-
include_package_data=True,
|
|
28
49
|
install_requires=parse_requirements('requirements.txt'),
|
|
50
|
+
packages=['scope', 'scope.viewer'],
|
|
51
|
+
package_dir={
|
|
52
|
+
'scope': 'scope',
|
|
53
|
+
'scope.viewer': 'viewer',
|
|
54
|
+
},
|
|
55
|
+
package_data={
|
|
56
|
+
'scope.viewer': ['dist/*'],
|
|
57
|
+
},
|
|
58
|
+
include_package_data=True,
|
|
59
|
+
cmdclass={
|
|
60
|
+
'sdist': patch(_sdist),
|
|
61
|
+
'develop': patch(_develop),
|
|
62
|
+
},
|
|
29
63
|
classifiers=[
|
|
30
64
|
'Intended Audience :: Science/Research',
|
|
31
65
|
'License :: OSI Approved :: MIT License',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import elements
|
|
6
|
+
import uvicorn
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
args, sys.argv[1:] = elements.Flags(
|
|
10
|
+
port=int(os.environ.get('SCOPE_SERVER_PORT', 8000)),
|
|
11
|
+
workers=32,
|
|
12
|
+
debug=False,
|
|
13
|
+
).parse_known()
|
|
14
|
+
|
|
15
|
+
sys.argv.append(f'--debug={args.debug}')
|
|
16
|
+
sys.path.insert(0, str(pathlib.Path(__file__).parent))
|
|
17
|
+
|
|
18
|
+
uvicorn.run(
|
|
19
|
+
'server:app',
|
|
20
|
+
host='0.0.0.0',
|
|
21
|
+
port=args.port,
|
|
22
|
+
reload=args.debug,
|
|
23
|
+
workers=None if args.debug else args.workers,
|
|
24
|
+
)
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<link rel="icon" href="/favicon.png">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Scope</title>
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BZlTxr6y.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DlFPK5at.css">
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="app"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
Binary file
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import elements
|
|
2
|
+
import io
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Local:
|
|
8
|
+
|
|
9
|
+
def list(self, path):
|
|
10
|
+
return os.listdir(path)
|
|
11
|
+
|
|
12
|
+
def size(self, path):
|
|
13
|
+
return os.path.getsize(path)
|
|
14
|
+
|
|
15
|
+
def read(self, path):
|
|
16
|
+
with open(path, 'rb') as f:
|
|
17
|
+
return f.read()
|
|
18
|
+
|
|
19
|
+
def open(self, path, seek=0, limit=None):
|
|
20
|
+
f = open(path, 'rb')
|
|
21
|
+
f.seek(seek)
|
|
22
|
+
return f
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Elements:
|
|
26
|
+
|
|
27
|
+
def list(self, path):
|
|
28
|
+
paths = elements.Path(path).glob('*')
|
|
29
|
+
return [str(x) for x in paths]
|
|
30
|
+
|
|
31
|
+
def size(self, path):
|
|
32
|
+
return elements.Path(path).size
|
|
33
|
+
|
|
34
|
+
def read(self, path):
|
|
35
|
+
return elements.Path(path).read_bytes()
|
|
36
|
+
|
|
37
|
+
def open(self, path, seek=0, limit=None):
|
|
38
|
+
f = elements.Path(path).open('rb')
|
|
39
|
+
f.seek(seek)
|
|
40
|
+
return f
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Fileutil:
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
ls='fileutil ls {}',
|
|
48
|
+
cat='fileutil cat {}',
|
|
49
|
+
size="fileutil ls -l {} | tr -s ' ' | cut -d' ' -f5",
|
|
50
|
+
catrange='fileutil cat -input_startpos={} -input_endpos={} {}',
|
|
51
|
+
):
|
|
52
|
+
self._ls = ls
|
|
53
|
+
self._cat = cat
|
|
54
|
+
self._size = size
|
|
55
|
+
self._catrange = catrange
|
|
56
|
+
|
|
57
|
+
def list(self, path):
|
|
58
|
+
try:
|
|
59
|
+
output = self._sh(self._ls.format(path))
|
|
60
|
+
return [x.rstrip('/') for x in output.decode('utf-8').splitlines()]
|
|
61
|
+
except RuntimeError as e:
|
|
62
|
+
print(e)
|
|
63
|
+
return []
|
|
64
|
+
|
|
65
|
+
def size(self, path):
|
|
66
|
+
output = self._sh(self._size.format(path))
|
|
67
|
+
return int(output.decode('utf-8').strip('\n'))
|
|
68
|
+
|
|
69
|
+
def read(self, path):
|
|
70
|
+
return self._sh(self._cat.format(path))
|
|
71
|
+
|
|
72
|
+
def open(self, path, seek=0, limit=None):
|
|
73
|
+
limit = limit or self._size(path)
|
|
74
|
+
buffer = self._sh(self._catrange.format(seek, limit, path))
|
|
75
|
+
return io.BytesIO(buffer)
|
|
76
|
+
|
|
77
|
+
def _sh(self, cmd):
|
|
78
|
+
if '|' in cmd:
|
|
79
|
+
process = subprocess.Popen(
|
|
80
|
+
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
81
|
+
out, err = process.communicate()
|
|
82
|
+
if process.returncode:
|
|
83
|
+
raise RuntimeError((process.returncode, out, err))
|
|
84
|
+
return out
|
|
85
|
+
else:
|
|
86
|
+
try:
|
|
87
|
+
return subprocess.check_output(cmd.split(), shell=False)
|
|
88
|
+
except subprocess.CalledProcessError as e:
|
|
89
|
+
raise RuntimeError(f'Error in subprocess: {e}')
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import concurrent.futures
|
|
2
|
+
import functools
|
|
3
|
+
import os
|
|
4
|
+
import pathlib
|
|
5
|
+
import struct
|
|
6
|
+
|
|
7
|
+
import elements
|
|
8
|
+
import fastapi
|
|
9
|
+
import fastapi.responses
|
|
10
|
+
import fastapi.staticfiles
|
|
11
|
+
|
|
12
|
+
import filesystems
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
args = elements.Flags(
|
|
16
|
+
basedir=os.environ.get('SCOPE_ROOT', ''),
|
|
17
|
+
fs=os.environ.get('SCOPE_FS', 'elements'),
|
|
18
|
+
maxdepth=2,
|
|
19
|
+
debug=False,
|
|
20
|
+
).parse()
|
|
21
|
+
print(args)
|
|
22
|
+
assert args.basedir, args.basedir
|
|
23
|
+
basedir = args.basedir.rstrip('/')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
fs = dict(
|
|
27
|
+
elements=filesystems.Elements,
|
|
28
|
+
fileutil=filesystems.Fileutil,
|
|
29
|
+
local=filesystems.Local,
|
|
30
|
+
)[args.fs]()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
app = fastapi.FastAPI(debug=args.debug)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@app.get('/api/exps')
|
|
37
|
+
def get_exps():
|
|
38
|
+
print('GET /exps', flush=True)
|
|
39
|
+
folders = fs.list(basedir)
|
|
40
|
+
expids = [x.rsplit('/', 1)[-1] for x in folders]
|
|
41
|
+
return {'exps': expids}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@app.get('/api/exp/{expid}')
|
|
45
|
+
def get_exp(expid: str):
|
|
46
|
+
print(f'GET /exp/{expid}', flush=True)
|
|
47
|
+
folders = find_runs(basedir + '/' + expid)
|
|
48
|
+
folders = [x.removeprefix(str(basedir))[1:] for x in folders]
|
|
49
|
+
runids = [x.replace('/', ':') for x in folders]
|
|
50
|
+
return {'id': expid, 'runs': runids}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@app.get('/api/run/{runid}')
|
|
54
|
+
def get_run(runid: str):
|
|
55
|
+
print(f'GET /run/{runid}', flush=True)
|
|
56
|
+
folder = basedir + '/' + runid.replace(':', '/') + '/scope'
|
|
57
|
+
children = fs.list(folder)
|
|
58
|
+
children = [x.removeprefix(str(basedir))[1:] for x in children]
|
|
59
|
+
colids = [x.replace('/', ':') for x in children]
|
|
60
|
+
return {'id': runid, 'cols': colids}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@app.get('/api/col/{colid}')
|
|
64
|
+
def get_col(colid: str):
|
|
65
|
+
print(f'GET /col/{colid}', flush=True)
|
|
66
|
+
ext = colid.rsplit('.', 1)[-1]
|
|
67
|
+
path = basedir + '/' + colid.replace(':', '/')
|
|
68
|
+
runid = colid.rsplit(':', 2)[0] # Remove metric name and scope folder.
|
|
69
|
+
if ext == 'float':
|
|
70
|
+
buffer = fs.read(path)
|
|
71
|
+
steps, values = tuple(zip(*struct.iter_unpack('>qd', buffer)))
|
|
72
|
+
return {'id': colid, 'run': runid, 'steps': steps, 'values': values}
|
|
73
|
+
elif ext in ('txt', 'mp4', 'webm'):
|
|
74
|
+
buffer = fs.read(path + '/index')
|
|
75
|
+
steps, idents = tuple(zip(*struct.iter_unpack('q8s', buffer)))
|
|
76
|
+
filenames = [f'{s:020}-{x.hex()}.{ext}' for s, x in zip(steps, idents)]
|
|
77
|
+
values = [f'{colid}:{x}' for x in filenames]
|
|
78
|
+
return {'id': colid, 'run': runid, 'steps': steps, 'values': values}
|
|
79
|
+
else:
|
|
80
|
+
raise NotImplementedError((colid, ext))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@app.get('/api/file/{fileid}')
|
|
84
|
+
def get_file(request: fastapi.Request, fileid: str):
|
|
85
|
+
print(f'GET /file/{fileid}', flush=True)
|
|
86
|
+
ext = fileid.rsplit('.', 1)[-1]
|
|
87
|
+
path = basedir + '/' + fileid.replace(':', '/')
|
|
88
|
+
if ext == 'txt':
|
|
89
|
+
text = fs.read(path).decode('utf-8')
|
|
90
|
+
return {'id': fileid, 'text': text}
|
|
91
|
+
elif ext in ('mp4', 'webm'):
|
|
92
|
+
filesize = fs.size(path)
|
|
93
|
+
openfn = functools.partial(fs.open, path)
|
|
94
|
+
content_type = f'video/{ext}'
|
|
95
|
+
return RangeResponse(request, openfn, filesize, content_type)
|
|
96
|
+
else:
|
|
97
|
+
raise NotImplementedError((fileid, ext))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
dist = pathlib.Path(__file__).parent / 'dist'
|
|
101
|
+
app.mount('/', fastapi.staticfiles.StaticFiles(directory=dist, html=True))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def find_runs(folder, maxdepth=args.maxdepth, workers=64):
|
|
105
|
+
if not workers:
|
|
106
|
+
runs = []
|
|
107
|
+
queue = [(folder, 0)]
|
|
108
|
+
while queue:
|
|
109
|
+
node, depth = queue.pop(0)
|
|
110
|
+
children = fs.list(node)
|
|
111
|
+
if any(x.endswith('/scope') for x in children):
|
|
112
|
+
runs.append(node)
|
|
113
|
+
elif depth < maxdepth:
|
|
114
|
+
queue += [(x, depth + 1) for x in children]
|
|
115
|
+
return runs
|
|
116
|
+
runs = []
|
|
117
|
+
with concurrent.futures.ThreadPoolExecutor(workers) as pool:
|
|
118
|
+
future = pool.submit(fs.list, folder)
|
|
119
|
+
future.parent = folder
|
|
120
|
+
future.depth = 0
|
|
121
|
+
queue = [future]
|
|
122
|
+
while queue:
|
|
123
|
+
current = queue.pop(0)
|
|
124
|
+
children = current.result()
|
|
125
|
+
if any(x.endswith('/scope') for x in children):
|
|
126
|
+
runs.append(current.parent)
|
|
127
|
+
elif current.depth < maxdepth:
|
|
128
|
+
for child in children:
|
|
129
|
+
future = pool.submit(fs.list, child)
|
|
130
|
+
future.parent = child
|
|
131
|
+
future.depth = current.depth + 1
|
|
132
|
+
queue.append(future)
|
|
133
|
+
return runs
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def RangeResponse(request, openfn, filesize, content_type):
|
|
137
|
+
headers = {
|
|
138
|
+
'content-type': content_type,
|
|
139
|
+
'accept-ranges': 'bytes',
|
|
140
|
+
'content-length': str(filesize),
|
|
141
|
+
'access-control-expose-headers': (
|
|
142
|
+
'content-type, accept-ranges, content-length, '
|
|
143
|
+
'content-range, content-encoding'
|
|
144
|
+
),
|
|
145
|
+
}
|
|
146
|
+
range_header = request.headers.get('range')
|
|
147
|
+
if range_header:
|
|
148
|
+
try:
|
|
149
|
+
h = range_header.replace('bytes=', '').split('-')
|
|
150
|
+
start = int(h[0]) if h[0] != '' else 0
|
|
151
|
+
end = int(h[1]) if h[1] != '' else filesize - 1
|
|
152
|
+
except ValueError:
|
|
153
|
+
raise fastapi.HTTPException(
|
|
154
|
+
fastapi.status.HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE,
|
|
155
|
+
detail=f'Invalid request range (Range:{range_header!r})')
|
|
156
|
+
if start > end or start < 0 or end > filesize - 1:
|
|
157
|
+
raise fastapi.HTTPException(
|
|
158
|
+
fastapi.status.HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE,
|
|
159
|
+
detail=f'Invalid request range (Range:{range_header!r})')
|
|
160
|
+
size = end - start + 1
|
|
161
|
+
headers['content-length'] = str(size)
|
|
162
|
+
headers['content-range'] = f'bytes {start}-{end}/{filesize}'
|
|
163
|
+
status_code = fastapi.status.HTTP_206_PARTIAL_CONTENT
|
|
164
|
+
else:
|
|
165
|
+
start = 0
|
|
166
|
+
end = filesize - 1
|
|
167
|
+
status_code = fastapi.status.HTTP_200_OK
|
|
168
|
+
stop = end + 1
|
|
169
|
+
def iterfile(chunksize=int(2e5)):
|
|
170
|
+
with openfn(start, stop) as f:
|
|
171
|
+
total = stop - start
|
|
172
|
+
nbytes = 0
|
|
173
|
+
while nbytes < total:
|
|
174
|
+
chunk = f.read(min(chunksize, total - nbytes))
|
|
175
|
+
nbytes += len(chunk)
|
|
176
|
+
yield chunk
|
|
177
|
+
return fastapi.responses.StreamingResponse(
|
|
178
|
+
iterfile(), headers=headers, status_code=status_code)
|
scope-0.3.2/LICENSE
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2024 Danijar Hafner
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
-
SOFTWARE.
|
scope-0.3.2/MANIFEST.in
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
include requirements.txt
|
scope-0.3.2/PKG-INFO
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: scope
|
|
3
|
-
Version: 0.3.2
|
|
4
|
-
Summary: Metrics logging and analysis
|
|
5
|
-
Home-page: http://github.com/danijar/scope
|
|
6
|
-
Classifier: Intended Audience :: Science/Research
|
|
7
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
scope-0.3.2/pyproject.toml
DELETED
scope-0.3.2/requirements.txt
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: scope
|
|
3
|
-
Version: 0.3.2
|
|
4
|
-
Summary: Metrics logging and analysis
|
|
5
|
-
Home-page: http://github.com/danijar/scope
|
|
6
|
-
Classifier: Intended Audience :: Science/Research
|
|
7
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
MANIFEST.in
|
|
3
|
-
README.md
|
|
4
|
-
pyproject.toml
|
|
5
|
-
requirements.txt
|
|
6
|
-
setup.py
|
|
7
|
-
scope/__init__.py
|
|
8
|
-
scope/formats.py
|
|
9
|
-
scope/reader.py
|
|
10
|
-
scope/writer.py
|
|
11
|
-
scope.egg-info/PKG-INFO
|
|
12
|
-
scope.egg-info/SOURCES.txt
|
|
13
|
-
scope.egg-info/dependency_links.txt
|
|
14
|
-
scope.egg-info/requires.txt
|
|
15
|
-
scope.egg-info/top_level.txt
|
|
16
|
-
tests/test_float.py
|
|
17
|
-
tests/test_image.py
|
|
18
|
-
tests/test_video.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
scope
|
scope-0.3.2/setup.cfg
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|