dataflow-conda-plugin 0.1.3__tar.gz → 0.1.4__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.

Potentially problematic release.


This version of dataflow-conda-plugin might be problematic. Click here for more details.

@@ -1,3 +1,3 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataflow-conda-plugin
3
- Version: 0.1.3
3
+ Version: 0.1.4
@@ -1,3 +1,3 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataflow-conda-plugin
3
- Version: 0.1.3
3
+ Version: 0.1.4
@@ -0,0 +1,161 @@
1
+ import subprocess, sys, pkg_resources, os, requests
2
+ from conda import plugins
3
+ from conda.base.context import context
4
+ from dataflow.utils.logger import CustomLogger
5
+ from dataflow.configuration import ConfigurationManager
6
+
7
+ logger = CustomLogger().get_logger(__name__)
8
+ dataflow_config = ConfigurationManager('/dataflow/app/auth_config/dataflow_auth.cfg')
9
+
10
+ env_api = dataflow_config.get_config_value('auth', 'env_api')
11
+
12
+ def is_local_environment(target_prefix):
13
+ """Check if the environment is a local user environment."""
14
+ return (
15
+ os.environ.get('HOSTNAME') is not None and
16
+ target_prefix and
17
+ target_prefix.startswith('/home/jovyan')
18
+ )
19
+
20
+ def save_environment(env_name: str, status: str):
21
+ """Save environment information via API."""
22
+ try:
23
+ response = requests.post(
24
+ env_api,
25
+ params={
26
+ "env_name": env_name,
27
+ "status": status
28
+ },
29
+ timeout=30
30
+ )
31
+
32
+ if response.status_code in [200, 201]:
33
+ logger.info(f"Environment '{env_name}' saved successfully")
34
+ else:
35
+ logger.error(f"Error saving environment: {response.status_code} - {response.text}")
36
+ print("Error saving environment! Please try again after deleting the environment")
37
+
38
+ except requests.exceptions.RequestException as e:
39
+ logger.error(f"Network error saving environment: {str(e)}")
40
+ print("Error saving environment! Please check your connection and try again")
41
+ except Exception as e:
42
+ logger.error(f"Unexpected error saving environment: {str(e)}")
43
+ print("Error saving environment! Please try again after deleting the environment")
44
+
45
+ def install_deps(command: str):
46
+ """Install dataflow dependencies."""
47
+ target_prefix = context.target_prefix
48
+ args = context._argparse_args
49
+ env_name = os.path.basename(target_prefix) if target_prefix else None
50
+
51
+ should_save_to_db = is_local_environment(target_prefix) and env_name
52
+
53
+ try:
54
+ if (args.get('clone') is not None):
55
+ if should_save_to_db:
56
+ save_environment(env_name, "Success")
57
+ return
58
+
59
+ if env_name and should_save_to_db:
60
+ save_environment(env_name, "Success")
61
+
62
+ install_dataflow_deps = pkg_resources.resource_filename('plugin', 'scripts/install_dataflow_deps.sh')
63
+ process = subprocess.Popen(
64
+ ["bash", install_dataflow_deps, target_prefix],
65
+ stdout=subprocess.PIPE,
66
+ stderr=subprocess.STDOUT,
67
+ text=True,
68
+ bufsize=1
69
+ )
70
+
71
+ for line in iter(process.stdout.readline, ''):
72
+ print(line, end='')
73
+ sys.stdout.flush()
74
+
75
+ return_code = process.wait()
76
+ if return_code != 0:
77
+ print(f"Error in creating environment!!")
78
+ if should_save_to_db and env_name:
79
+ save_environment(env_name, "Failed")
80
+ else:
81
+ if env_name and should_save_to_db:
82
+ save_environment(env_name, "Success")
83
+
84
+ except Exception as e:
85
+ print(f"An unexpected error occurred: {str(e)}\nPlease delete the environment and try again.")
86
+ logger.error(f"Error installing dependencies: {str(e)}")
87
+ if should_save_to_db and env_name:
88
+ save_environment(env_name, "Failed")
89
+
90
+ def remove_environment(env_name: str):
91
+ """Remove environment information via API."""
92
+ try:
93
+ response = requests.delete(
94
+ env_api,
95
+ params={"env_name": env_name},
96
+ timeout=30
97
+ )
98
+
99
+ if response.status_code == 200:
100
+ logger.info(f"Environment '{env_name}' removed successfully")
101
+ elif response.status_code == 404:
102
+ logger.warning(f"Environment '{env_name}' not found")
103
+ else:
104
+ logger.error(f"Error removing environment: {response.status_code} - {response.text}")
105
+ print("Error removing environment! Please delete from the dataflow environment page")
106
+
107
+ except requests.exceptions.RequestException as e:
108
+ logger.error(f"Network error removing environment: {str(e)}")
109
+ print("Error removing environment! Please delete from the dataflow environment page")
110
+ except Exception as e:
111
+ logger.error(f"Unexpected error removing environment: {str(e)}")
112
+ print("Error removing environment! Please delete from the dataflow environment page")
113
+
114
+ def mark_environment_for_refresh(env_name: str):
115
+ """Mark environment for refresh via API."""
116
+ try:
117
+ response = requests.put(
118
+ env_api,
119
+ params={"env_name": env_name},
120
+ json={"need_refresh": True},
121
+ timeout=30
122
+ )
123
+
124
+ if response.status_code == 200:
125
+ logger.info(f"Environment '{env_name}' marked for refresh")
126
+ else:
127
+ logger.error(f"Error marking environment for refresh: {response.status_code} - {response.text}")
128
+
129
+ except requests.exceptions.RequestException as e:
130
+ logger.error(f"Network error marking environment for refresh: {str(e)}")
131
+ except Exception as e:
132
+ logger.error(f"Unexpected error marking environment for refresh: {str(e)}")
133
+
134
+ def package_operations(command: str):
135
+ """Track conda install/remove/update commands for packages and update libraries in database."""
136
+ target_prefix = context.target_prefix
137
+ env_name = os.path.basename(target_prefix) if target_prefix else None
138
+
139
+ # to catch env removal
140
+ if not os.path.exists(target_prefix):
141
+ if is_local_environment(target_prefix) and env_name:
142
+ remove_environment(env_name)
143
+ return
144
+
145
+ should_update_db = is_local_environment(target_prefix) and env_name
146
+
147
+ if should_update_db:
148
+ mark_environment_for_refresh(env_name)
149
+
150
+ @plugins.hookimpl
151
+ def conda_post_commands():
152
+ yield plugins.CondaPostCommand(
153
+ name=f"install_deps_post_command",
154
+ action=install_deps,
155
+ run_for={"create", "env_create"},
156
+ )
157
+ yield plugins.CondaPostCommand(
158
+ name=f"package_operations_post_command",
159
+ action=package_operations,
160
+ run_for={"install", "remove", "update"},
161
+ )
@@ -4,12 +4,12 @@ conda_env_path=$1
4
4
 
5
5
  py_version=$(${conda_env_path}/bin/python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")
6
6
 
7
- ${conda_env_path}/bin/pip install dash==3.0.3 dash-renderer==1.9.1 plotly==6.0.1 typing==3.7.4.3 streamlit==1.45.1 ipython==9.2.0 ipykernel==6.29.5 ipython-sql==0.4.1 jupysql==0.10.14 psycopg2-binary==2.9.10 cryptography==44.0.3 dataflow-core dataflow-dbt
7
+ ${conda_env_path}/bin/pip install dash==3.0.3 dash-renderer==1.9.1 plotly==6.0.1 typing==3.7.4.3 streamlit==1.45.1 ipython==9.2.0 ipykernel==6.29.5 ipython-sql==0.4.1 jupysql==0.10.14 psycopg2-binary==2.9.10 cryptography==44.0.3 dataflow-core==2.1.11 dataflow-dbt==0.0.3
8
8
 
9
9
  # 3. Install Dataflow Airflow to a separate path in environment
10
10
  ${conda_env_path}/bin/pip install \
11
11
  --force-reinstall --root-user-action ignore \
12
- --no-warn-conflicts dataflow-airflow \
12
+ --no-warn-conflicts dataflow-airflow==2.10.7 \
13
13
  --target ${conda_env_path}/bin/airflow-libraries/
14
14
 
15
15
  files=(
@@ -14,7 +14,7 @@ class PostInstall(install):
14
14
 
15
15
  setup(
16
16
  name="dataflow-conda-plugin",
17
- version="0.1.3",
17
+ version="0.1.4",
18
18
  entry_points={"conda": ["dataflow-conda-plugin = plugin.plugin"]},
19
19
  packages=find_packages(include=["plugin"]),
20
20
  package_data={'plugin': ['scripts/*.sh']},
@@ -1,153 +0,0 @@
1
- import subprocess, sys, pkg_resources, os
2
- from conda import plugins
3
- from conda.base.context import context
4
- from dataflow.models import LocalEnvironment
5
- from dataflow.db import get_local_db
6
- from datetime import datetime, timezone
7
- from dataflow.utils.logger import CustomLogger
8
-
9
- logger = CustomLogger().get_logger(__name__)
10
-
11
- def is_local_environment(target_prefix):
12
- """Check if the environment is a local user environment."""
13
- return (
14
- os.environ.get('HOSTNAME') is not None and
15
- target_prefix and
16
- target_prefix.startswith('/home/jovyan')
17
- )
18
-
19
- def save_environment_to_db(env_name: str, status: str = "Created"):
20
- """Save environment information to LocalEnvironment table."""
21
- try:
22
- db_generator = get_local_db()
23
- db = next(db_generator)
24
-
25
- # Check if environment already exists
26
- existing_env = db.query(LocalEnvironment).filter_by(name=env_name).first()
27
- if existing_env:
28
- # Update status if environment exists
29
- existing_env.status = status
30
- existing_env.updated_at = datetime.now(timezone.utc)
31
- db.commit()
32
- return
33
-
34
- # Create new LocalEnvironment record
35
- local_env = LocalEnvironment(
36
- name=env_name,
37
- status=status,
38
- updated_at=datetime.now(timezone.utc)
39
- )
40
-
41
- db.add(local_env)
42
- db.commit()
43
-
44
- except Exception as e:
45
- print("Error saving environment! Please try again after deleting the environment")
46
- logger.error(f"Error saving environment to database: {str(e)}")
47
- finally:
48
- db_generator.close()
49
-
50
- def install_deps(command: str):
51
- """Install dataflow dependencies."""
52
- target_prefix = context.target_prefix
53
- args = context._argparse_args
54
- env_name = os.path.basename(target_prefix) if target_prefix else None
55
-
56
- should_save_to_db = is_local_environment(target_prefix) and env_name
57
-
58
- try:
59
- if (args.get('clone') is not None):
60
- if should_save_to_db:
61
- save_environment_to_db(env_name, "Created")
62
- return
63
-
64
- install_dataflow_deps = pkg_resources.resource_filename('plugin', 'scripts/install_dataflow_deps.sh')
65
- process = subprocess.Popen(
66
- ["bash", install_dataflow_deps, target_prefix],
67
- stdout=subprocess.PIPE,
68
- stderr=subprocess.STDOUT,
69
- text=True,
70
- bufsize=1
71
- )
72
-
73
- for line in iter(process.stdout.readline, ''):
74
- print(line, end='')
75
- sys.stdout.flush()
76
-
77
- return_code = process.wait()
78
- if return_code != 0:
79
- print(f"Error in creating environment!!")
80
- if should_save_to_db and env_name:
81
- save_environment_to_db(env_name, "Failed")
82
- else:
83
- if env_name and should_save_to_db:
84
- save_environment_to_db(env_name, "Created")
85
-
86
- except Exception as e:
87
- print(f"An unexpected error occurred: {str(e)}\nPlease delete the environment and try again.")
88
- logger.error(f"Error installing dependencies: {str(e)}")
89
- if should_save_to_db and env_name:
90
- save_environment_to_db(env_name, "Failed")
91
-
92
- def remove_environment_from_db(env_name: str):
93
- """Remove environment information from LocalEnvironment table."""
94
- try:
95
- db_generator = get_local_db()
96
- db = next(db_generator)
97
-
98
- # Find and delete the environment
99
- existing_env = db.query(LocalEnvironment).filter_by(name=env_name).first()
100
- if existing_env:
101
- db.delete(existing_env)
102
- db.commit()
103
- else:
104
- logger.warning(f"Environment '{env_name}' not found in database")
105
-
106
- except Exception as e:
107
- print(f"Error removing environment! Please delete from the dataflow enviornment page")
108
- logger.error(f"Error removing environment from database: {str(e)}")
109
- finally:
110
- db_generator.close()
111
-
112
- def package_operations(command: str):
113
- """Track conda install/remove/update commands for packages and update libraries in database."""
114
- target_prefix = context.target_prefix
115
- env_name = os.path.basename(target_prefix) if target_prefix else None
116
-
117
- # to catch env removal
118
- if not os.path.exists(target_prefix):
119
- if is_local_environment(target_prefix) and env_name:
120
- remove_environment_from_db(env_name)
121
- return
122
-
123
- should_update_db = is_local_environment(target_prefix) and env_name
124
-
125
- if should_update_db:
126
- try:
127
- db_generator = get_local_db()
128
- db = next(db_generator)
129
-
130
- # Find the environment and set need_refresh to True
131
- existing_env = db.query(LocalEnvironment).filter_by(name=env_name).first()
132
- if existing_env:
133
- existing_env.need_refresh = True
134
- existing_env.updated_at = datetime.now(timezone.utc)
135
- db.commit()
136
-
137
- except Exception as e:
138
- logger.error(f"Error updating need_refresh in database: {str(e)}")
139
- finally:
140
- db_generator.close()
141
-
142
- @plugins.hookimpl
143
- def conda_post_commands():
144
- yield plugins.CondaPostCommand(
145
- name=f"install_deps_post_command",
146
- action=install_deps,
147
- run_for={"create", "env_create"},
148
- )
149
- yield plugins.CondaPostCommand(
150
- name=f"package_operations_post_command",
151
- action=package_operations,
152
- run_for={"install", "remove", "update"},
153
- )