dataflow-core 2.0.5__py3-none-any.whl → 2.0.6__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 dataflow-core might be problematic. Click here for more details.

dataflow/dataflow.py CHANGED
@@ -2,21 +2,21 @@ import os, requests
2
2
  from .models.database import DatabaseManager
3
3
  from sqlalchemy.inspection import inspect
4
4
  from .utils.aws_secrets_manager import SecretsManagerClient
5
- import json
5
+ import json, asyncio, pkg_resources
6
6
  from authenticator.package.configuration import ConfigurationManager
7
7
 
8
8
 
9
9
  class Dataflow:
10
10
  def __init__(self):
11
- self.dataflow_config = ConfigurationManager('/dataflow/app/auth_config/dataflow_auth.cfg')
12
- self.auth_api = self.dataflow_config.get_config_value('auth', 'ui_auth_api')
13
11
  self.secrets_manager = SecretsManagerClient('us-east-1')
14
12
 
15
13
  def auth(self, session_id: str):
16
14
  """Retrieve user information from the auth API."""
17
15
  try:
16
+ dataflow_config = ConfigurationManager('/dataflow/app/auth_config/dataflow_auth.cfg')
17
+ auth_api = dataflow_config.get_config_value('auth', 'ui_auth_api')
18
18
  response = requests.get(
19
- self.auth_api,
19
+ auth_api,
20
20
  cookies={"dataflow_session": session_id, "jupyterhub-hub-login": ""}
21
21
  )
22
22
 
@@ -86,3 +86,42 @@ class Dataflow:
86
86
 
87
87
  except Exception as e:
88
88
  return None
89
+
90
+ async def create_env(self, env_name, py_version, py_requirements, status, env_version=None):
91
+ """
92
+ Creates a conda environment at the specified path and installs libraries in one command.
93
+ """
94
+ config = ConfigurationManager('/dataflow/app/config/dataflow.cfg')
95
+ status = status.lower()
96
+ if status == "published":
97
+ env_base_path = config.get_config_value('paths', 'published_env_path')
98
+ conda_env_path = os.path.join(env_base_path, env_name)
99
+ else:
100
+ env_base_path = config.get_config_value('paths', 'drafts_env_path')
101
+ conda_env_path = os.path.join(env_base_path, env_name, f"{env_name}_v{env_version}")
102
+ try:
103
+ if not os.path.exists(conda_env_path):
104
+ os.makedirs(conda_env_path, exist_ok=True)
105
+
106
+ py_requirements = ",".join(py_requirements)
107
+
108
+ script_path = pkg_resources.resource_filename('dataflow', 'scripts/create_environment.sh')
109
+
110
+ # Make the script executable
111
+ os.chmod(script_path, 0o755)
112
+
113
+ # Prepare command with arguments
114
+ command = ["bash", script_path, py_requirements, conda_env_path, py_version]
115
+
116
+ process = await asyncio.create_subprocess_exec(
117
+ *command,
118
+ stdout=asyncio.subprocess.PIPE,
119
+ stderr=asyncio.subprocess.PIPE
120
+ )
121
+
122
+ return process
123
+ except OSError as e:
124
+ print(f"OS error while creating {conda_env_path}: {e}")
125
+ except Exception as e:
126
+ print(f"Unexpected error while creating {conda_env_path}: {e}")
127
+ return {"error": str(e)}
@@ -0,0 +1,34 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ IFS=',' read -r -a libraries <<< $1
5
+ conda_env_path=$2
6
+ py_version=$3
7
+
8
+ # Use an isolated conda package cache to avoid concurrency issues
9
+ export CONDA_PKGS_DIRS=$(mktemp -d)
10
+ # to delete conda package cache after script finishes
11
+ trap 'rm -rf "$CONDA_PKGS_DIRS"' EXIT
12
+
13
+ # 1. Creating conda environment
14
+ conda create --prefix ${conda_env_path} --yes python=${py_version}
15
+ ${conda_env_path}/bin/pip install --root-user-action ignore ${libraries[@]}
16
+
17
+ # 3. Install Dataflow Airflow to a separate path in environment
18
+ ${conda_env_path}/bin/pip install \
19
+ --force-reinstall --root-user-action ignore \
20
+ --no-warn-conflicts dataflow-airflow==2.10.3 \
21
+ --target ${conda_env_path}/bin/airflow-libraries/ \
22
+ --constraint https://raw.githubusercontent.com//apache/airflow/constraints-2.10.3/constraints-${py_version}.txt || true
23
+
24
+ files=(
25
+ ${conda_env_path}/lib/python${py_version}/site-packages/dbt/config/profile.py
26
+ ${conda_env_path}/lib/python${py_version}/site-packages/dbt/task/debug.py
27
+ )
28
+ for file in ${files[@]}
29
+ do
30
+ awk '{gsub("from dbt.clients.yaml_helper import load_yaml_text", "from dbt.dataflow_config.secrets_manager import load_yaml_text"); print}' $file > temp
31
+ mv temp $file
32
+ done
33
+
34
+ echo "Environment Creation Successful"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dataflow-core
3
- Version: 2.0.5
3
+ Version: 2.0.6
4
4
  Summary: Dataflow core package
5
5
  Home-page: UNKNOWN
6
6
  Author: Dataflow
@@ -10,15 +10,16 @@ authenticator/package/models/session.py,sha256=j6PhbrTMJxEkeDT4Vf5SqGtM_LI_vZy9O
10
10
  authenticator/package/models/user.py,sha256=IYogp_vt0yDBG5i936uNPjgTis77VYPzITn9XpQUIyw,788
11
11
  dataflow/__init__.py,sha256=WTRg8HMpMWSgxYJ9ZGVldx4k07fAbta3mBmZ1hG9mWE,30
12
12
  dataflow/configuration.py,sha256=7To6XwH1eESiYp39eqPcswXWwrdBUdPF6xN6WnazOF0,663
13
- dataflow/dataflow.py,sha256=8jLshxmxVtBTF6LYIGD9RJyB1mujo0tNr8vjHE04JNE,3418
13
+ dataflow/dataflow.py,sha256=viEKxu1bVFtenbPx8etCb7Gf-Hbwv0KvkE7occVbX8I,5136
14
14
  dataflow/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  dataflow/models/database.py,sha256=y09pqnglsBBtDZlyhvqDAlpUSFovwAzBAi6jOYl_XNk,896
16
16
  dataflow/models/session.py,sha256=C9crPh6ZDFuL27hZ_zhUXDZZ0ZiIDE8ZD19O_4WPw-I,488
17
17
  dataflow/models/user.py,sha256=IYogp_vt0yDBG5i936uNPjgTis77VYPzITn9XpQUIyw,788
18
+ dataflow/scripts/create_environment.sh,sha256=r4cKRTMf1G9pXx1fqMpzkvd-ROzUH0Qp16f9t84Nh5c,1300
18
19
  dataflow/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
20
  dataflow/utils/aws_secrets_manager.py,sha256=FqHm3YRynv580FpFsS0RfI1MSGY5aq-V7t4blpiYsS4,2588
20
- dataflow_core-2.0.5.dist-info/METADATA,sha256=L8jAsmbkSv0xT9rh2Ac2t3dHuI0kJMLhVDXcnUWYbyk,317
21
- dataflow_core-2.0.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
22
- dataflow_core-2.0.5.dist-info/entry_points.txt,sha256=lDLG2MMWlKfkqsVWFghF7sx-yEvM2xqMmHE7rMTysE4,118
23
- dataflow_core-2.0.5.dist-info/top_level.txt,sha256=SZsUOpSCK9ntUy-3Tusxzf5A2e8ebwD8vouPb1dPt_8,23
24
- dataflow_core-2.0.5.dist-info/RECORD,,
21
+ dataflow_core-2.0.6.dist-info/METADATA,sha256=BCXu55SZS71k7ZQ2ilfFn_nimogjDv0SDKtrDyje5iw,317
22
+ dataflow_core-2.0.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
23
+ dataflow_core-2.0.6.dist-info/entry_points.txt,sha256=lDLG2MMWlKfkqsVWFghF7sx-yEvM2xqMmHE7rMTysE4,118
24
+ dataflow_core-2.0.6.dist-info/top_level.txt,sha256=SZsUOpSCK9ntUy-3Tusxzf5A2e8ebwD8vouPb1dPt_8,23
25
+ dataflow_core-2.0.6.dist-info/RECORD,,