mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 22:13:00 +00:00
Rename MemorySpecification to ByteSpecification
This commit is contained in:
@@ -24,7 +24,7 @@ from traitlets import (
|
|||||||
validate,
|
validate,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .traitlets import Command, MemorySpecification
|
from .traitlets import Command, ByteSpecification
|
||||||
from .utils import random_port
|
from .utils import random_port
|
||||||
|
|
||||||
class Spawner(LoggingConfigurable):
|
class Spawner(LoggingConfigurable):
|
||||||
@@ -183,7 +183,7 @@ class Spawner(LoggingConfigurable):
|
|||||||
"""
|
"""
|
||||||
).tag(config=True)
|
).tag(config=True)
|
||||||
|
|
||||||
mem_limit = MemorySpecification(
|
mem_limit = ByteSpecification(
|
||||||
None,
|
None,
|
||||||
help="""
|
help="""
|
||||||
Maximum number of bytes a single-user notebook server is allowed to use.
|
Maximum number of bytes a single-user notebook server is allowed to use.
|
||||||
@@ -220,7 +220,7 @@ class Spawner(LoggingConfigurable):
|
|||||||
"""
|
"""
|
||||||
).tag(config=True)
|
).tag(config=True)
|
||||||
|
|
||||||
mem_guarantee = MemorySpecification(
|
mem_guarantee = ByteSpecification(
|
||||||
None,
|
None,
|
||||||
help="""
|
help="""
|
||||||
Minimum number of bytes a single-user notebook server is guaranteed to have available.
|
Minimum number of bytes a single-user notebook server is guaranteed to have available.
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from traitlets import HasTraits, TraitError
|
from traitlets import HasTraits, TraitError
|
||||||
|
|
||||||
from jupyterhub.traitlets import URLPrefix, Command, MemorySpecification
|
from jupyterhub.traitlets import URLPrefix, Command, ByteSpecification
|
||||||
|
|
||||||
|
|
||||||
def test_url_prefix():
|
def test_url_prefix():
|
||||||
@@ -29,7 +29,7 @@ def test_command():
|
|||||||
|
|
||||||
def test_memoryspec():
|
def test_memoryspec():
|
||||||
class C(HasTraits):
|
class C(HasTraits):
|
||||||
mem = MemorySpecification()
|
mem = ByteSpecification()
|
||||||
|
|
||||||
c = C()
|
c = C()
|
||||||
|
|
||||||
|
@@ -32,9 +32,9 @@ class Command(List):
|
|||||||
return super().validate(obj, value)
|
return super().validate(obj, value)
|
||||||
|
|
||||||
|
|
||||||
class MemorySpecification(Integer):
|
class ByteSpecification(Integer):
|
||||||
"""
|
"""
|
||||||
Allow easily specifying memory in units of 1024 with suffixes
|
Allow easily specifying bytes in units of 1024 with suffixes
|
||||||
|
|
||||||
Suffixes allowed are:
|
Suffixes allowed are:
|
||||||
- K -> Kilobyte
|
- K -> Kilobyte
|
||||||
@@ -65,7 +65,7 @@ class MemorySpecification(Integer):
|
|||||||
return value
|
return value
|
||||||
num = value[:-1]
|
num = value[:-1]
|
||||||
suffix = value[-1]
|
suffix = value[-1]
|
||||||
if not num.isdigit() and suffix not in MemorySpecification.UNIT_SUFFIXES:
|
if not num.isdigit() and suffix not in ByteSpecification.UNIT_SUFFIXES:
|
||||||
raise TraitError('{val} is not a valid memory specification. Must be an int or a string with suffix K, M, G, T'.format(val=value))
|
raise TraitError('{val} is not a valid memory specification. Must be an int or a string with suffix K, M, G, T'.format(val=value))
|
||||||
else:
|
else:
|
||||||
return int(num) * MemorySpecification.UNIT_SUFFIXES[suffix]
|
return int(num) * ByteSpecification.UNIT_SUFFIXES[suffix]
|
||||||
|
Reference in New Issue
Block a user