forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dependencies] Remove
kubernetes
requirement (ray-project#36333)
The kubernetes package is installed with ray["all"] but it's currently only used in two places: A helper function for converting units The GCS FT on K8s release test: ray/release/k8s_tests/run_gcs_ft_on_k8s.py Line 4 in 4070624 from kubernetes import client, config, watch This PR removes kubernetes from Ray's dependencies and removes it from the Ray docker image. This change is needed to reduce the overall package size of ray["all"]. For the helper function, we vendor it from the upstream. For the release test, kubernetes is installed separately: ray/release/k8s_tests/app_config.yaml Line 13 in 4070624 - kubernetes . I've also added it to release/requirements.txt to be safe. Related issue number Closes ray-project#36331 --------- Signed-off-by: Archit Kulkarni <[email protected]>
- Loading branch information
1 parent
6db5eb1
commit b935406
Showing
7 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Source: | ||
# https://github.com/kubernetes-client/python/blob/master/kubernetes/utils/quantity.py | ||
from decimal import Decimal, InvalidOperation | ||
|
||
|
||
def parse_quantity(quantity): | ||
""" | ||
Parse kubernetes canonical form quantity like 200Mi to a decimal number. | ||
Supported SI suffixes: | ||
base1024: Ki | Mi | Gi | Ti | Pi | Ei | ||
base1000: n | u | m | "" | k | M | G | T | P | E | ||
See | ||
https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go | ||
Input: | ||
quantity: string. kubernetes canonical form quantity | ||
Returns: | ||
Decimal | ||
Raises: | ||
ValueError on invalid or unknown input | ||
""" | ||
if isinstance(quantity, (int, float, Decimal)): | ||
return Decimal(quantity) | ||
|
||
exponents = { | ||
"n": -3, | ||
"u": -2, | ||
"m": -1, | ||
"K": 1, | ||
"k": 1, | ||
"M": 2, | ||
"G": 3, | ||
"T": 4, | ||
"P": 5, | ||
"E": 6, | ||
} | ||
|
||
quantity = str(quantity) | ||
number = quantity | ||
suffix = None | ||
if len(quantity) >= 2 and quantity[-1] == "i": | ||
if quantity[-2] in exponents: | ||
number = quantity[:-2] | ||
suffix = quantity[-2:] | ||
elif len(quantity) >= 1 and quantity[-1] in exponents: | ||
number = quantity[:-1] | ||
suffix = quantity[-1:] | ||
|
||
try: | ||
number = Decimal(number) | ||
except InvalidOperation: | ||
raise ValueError("Invalid number format: {}".format(number)) | ||
|
||
if suffix is None: | ||
return number | ||
|
||
if suffix.endswith("i"): | ||
base = 1024 | ||
elif len(suffix) == 1: | ||
base = 1000 | ||
else: | ||
raise ValueError("{} has unknown suffix".format(quantity)) | ||
|
||
# handle SI inconsistency | ||
if suffix == "ki": | ||
raise ValueError("{} has unknown suffix".format(quantity)) | ||
|
||
if suffix[0] not in exponents: | ||
raise ValueError("{} has unknown suffix".format(quantity)) | ||
|
||
exponent = Decimal(exponents[suffix[0]]) | ||
return number * (base**exponent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters