ob-metaflow-extensions 1.1.49__py2.py3-none-any.whl → 1.1.50__py2.py3-none-any.whl

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.

Potentially problematic release.


This version of ob-metaflow-extensions might be problematic. Click here for more details.

@@ -0,0 +1,56 @@
1
+ import os
2
+ import fcntl
3
+ from os import path
4
+ import json
5
+ from metaflow.exception import MetaflowException
6
+ from typing import Union
7
+
8
+ CURRENT_PERIMETER_KEY = "OB_CURRENT_PERIMETER"
9
+ CURRENT_PERIMETER_URL = "OB_CURRENT_PERIMETER_MF_CONFIG_URL"
10
+
11
+
12
+ def get_perimeter_config_url_if_set_in_ob_config() -> Union[str, None]:
13
+ # If OBP_CONFIG_DIR is set, use that, otherwise use METAFLOW_HOME
14
+ # If neither are set, use ~/.metaflowconfig
15
+ obp_config_dir = path.expanduser(
16
+ os.environ.get(
17
+ "OBP_CONFIG_DIR", os.environ.get("METAFLOW_HOME", "~/.metaflowconfig")
18
+ )
19
+ )
20
+
21
+ profile = os.environ.get("METAFLOW_PROFILE")
22
+ file_path = (
23
+ os.path.join(obp_config_dir, "ob_config.json")
24
+ if not profile
25
+ else os.path.join(obp_config_dir, f"ob_config_{profile}.json")
26
+ )
27
+
28
+ if os.path.exists(file_path):
29
+ # Acquire a shared read lock on the file
30
+ # This is important! Any process that is using metaflow at the moment will hold this lock
31
+ # disallowing the outerbounds CLI from changing the perimeter mid process.
32
+ # Note that this is an advisory lock, the file can still be edited by any process should it choose to.
33
+ # The lock is released when the metaflow process finishes, whether gracefully or not.
34
+ fd = os.open(file_path, os.O_RDONLY)
35
+ fcntl.flock(fd, fcntl.LOCK_SH)
36
+
37
+ with open(file_path, "r") as f:
38
+ ob_config = json.loads(f.read())
39
+
40
+ if CURRENT_PERIMETER_KEY in ob_config and CURRENT_PERIMETER_URL in ob_config:
41
+ os.environ[CURRENT_PERIMETER_KEY] = ob_config[CURRENT_PERIMETER_KEY]
42
+ os.environ[CURRENT_PERIMETER_URL] = ob_config[CURRENT_PERIMETER_URL]
43
+ return ob_config[CURRENT_PERIMETER_URL]
44
+ else:
45
+ raise MetaflowException(
46
+ "{} does not contain the key {}".format(
47
+ file_path, CURRENT_PERIMETER_KEY
48
+ )
49
+ )
50
+ elif "OBP_CONFIG_DIR" in os.environ:
51
+ raise MetaflowException(
52
+ "Environment variable OBP_CONFIG_DIR is set to {} but this directory does not contain an ob_config.json file.".format(
53
+ os.environ["OBP_CONFIG_DIR"]
54
+ )
55
+ )
56
+ return None
@@ -7,6 +7,9 @@ from typing import Optional, Dict
7
7
  import requests
8
8
  from metaflow.exception import MetaflowException
9
9
  from requests.models import HTTPError
10
+ from metaflow_extensions.outerbounds.plugins.perimeters import (
11
+ get_perimeter_config_url_if_set_in_ob_config,
12
+ )
10
13
 
11
14
  OBP_REMOTE_CONFIG_KEY = "OBP_METAFLOW_CONFIG_URL"
12
15
  HOSTNAME_KEY = "OBP_API_SERVER"
@@ -87,11 +90,14 @@ def init_config() -> Dict[str, str]:
87
90
  if OBP_REMOTE_CONFIG_KEY not in remote_config:
88
91
  return remote_config
89
92
 
93
+ perimeter_config_url = get_perimeter_config_url_if_set_in_ob_config()
94
+ if perimeter_config_url:
95
+ remote_config[OBP_REMOTE_CONFIG_KEY] = perimeter_config_url
96
+
90
97
  metaflow_config = resolve_config_from_remote(
91
98
  remote_url=remote_config[OBP_REMOTE_CONFIG_KEY],
92
99
  auth_token=remote_config[AUTH_KEY],
93
100
  )
94
- metaflow_config[AUTH_KEY] = remote_config[AUTH_KEY]
95
101
 
96
102
  # set cache
97
103
  os.environ[CONFIG_READ_ONCE_KEY] = json.dumps(metaflow_config)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ob-metaflow-extensions
3
- Version: 1.1.49
3
+ Version: 1.1.50
4
4
  Summary: Outerbounds Platform Extensions for Metaflow
5
5
  Author: Outerbounds, Inc.
6
6
  License: Commercial
@@ -1,8 +1,9 @@
1
1
  metaflow_extensions/outerbounds/__init__.py,sha256=TRGvIUMjkfneWtYUFSWoubu_Kf2ekAL4WLbV3IxOj9k,499
2
- metaflow_extensions/outerbounds/remote_config.py,sha256=S9mTxLyf4EbsM_mpoeEL8pjWG-TruXUKYYodk3-qFgg,3812
2
+ metaflow_extensions/outerbounds/remote_config.py,sha256=jHNHDbWAoKOgv3IH2I-Gzwfe2tr1gO3ds_VjsXBaCh8,4045
3
3
  metaflow_extensions/outerbounds/config/__init__.py,sha256=mYo95obHU1IE1wbPkeVz_pfTzNqlNabp1QBEMTGllbE,112
4
4
  metaflow_extensions/outerbounds/plugins/__init__.py,sha256=rK-EPg7107su6dY-yAx1IK3wAzyvQIIg6y4um_F_BXc,9343
5
5
  metaflow_extensions/outerbounds/plugins/auth_server.py,sha256=rUzhRfE0ov3pWTM9S4UdAhnz13JBb5amiQCs5d1xJQU,1418
6
+ metaflow_extensions/outerbounds/plugins/perimeters.py,sha256=z8tSAkWtiITB-JtSQS7fkhlBwvxSxeTgEwFjahAzv-U,2238
6
7
  metaflow_extensions/outerbounds/plugins/kubernetes/__init__.py,sha256=5zG8gShSj8m7rgF4xgWBZFuY3GDP5n1T0ktjRpGJLHA,69
7
8
  metaflow_extensions/outerbounds/plugins/kubernetes/kubernetes_client.py,sha256=k5HP9JJIcZhCDUKrR9u--B_wbwL3RTPCJWhgEWgh7k0,1806
8
9
  metaflow_extensions/outerbounds/profilers/__init__.py,sha256=wa_jhnCBr82TBxoS0e8b6_6sLyZX0fdHicuGJZNTqKw,29
@@ -12,7 +13,7 @@ metaflow_extensions/outerbounds/toplevel/global_aliases_for_metaflow_package.py,
12
13
  metaflow_extensions/outerbounds/toplevel/plugins/azure/__init__.py,sha256=WUuhz2YQfI4fz7nIcipwwWq781eaoHEk7n4GAn1npDg,63
13
14
  metaflow_extensions/outerbounds/toplevel/plugins/gcp/__init__.py,sha256=BbZiaH3uILlEZ6ntBLKeNyqn3If8nIXZFq_Apd7Dhco,70
14
15
  metaflow_extensions/outerbounds/toplevel/plugins/kubernetes/__init__.py,sha256=5zG8gShSj8m7rgF4xgWBZFuY3GDP5n1T0ktjRpGJLHA,69
15
- ob_metaflow_extensions-1.1.49.dist-info/METADATA,sha256=VvpQ3PzuRmpVjk7paQ2A2V-D_rXX2T3fLpGTfr3JkP4,565
16
- ob_metaflow_extensions-1.1.49.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
17
- ob_metaflow_extensions-1.1.49.dist-info/top_level.txt,sha256=NwG0ukwjygtanDETyp_BUdtYtqIA_lOjzFFh1TsnxvI,20
18
- ob_metaflow_extensions-1.1.49.dist-info/RECORD,,
16
+ ob_metaflow_extensions-1.1.50.dist-info/METADATA,sha256=duZTQ3sCjV6IFnVCq9DmkR56x9f5bpgo6USljOHfHKE,565
17
+ ob_metaflow_extensions-1.1.50.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
18
+ ob_metaflow_extensions-1.1.50.dist-info/top_level.txt,sha256=NwG0ukwjygtanDETyp_BUdtYtqIA_lOjzFFh1TsnxvI,20
19
+ ob_metaflow_extensions-1.1.50.dist-info/RECORD,,