dataflow-conda-plugin 0.1.2__py3-none-any.whl → 0.1.3rc1__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-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.2
3
+ Version: 0.1.3rc1
@@ -0,0 +1,8 @@
1
+ plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ plugin/plugin.py,sha256=ubvJ7Zu_iMfOxVGHNgU_OtrXgx8zc7bCUsv1NJ_tda8,5516
3
+ plugin/scripts/install_dataflow_deps.sh,sha256=sbr4tbtjCE4nSKnn-Net4e73ZGGi1WWqkzQrU7_nZJI,1099
4
+ dataflow_conda_plugin-0.1.3rc1.dist-info/METADATA,sha256=VSNCzwWj974IkvGOUvfVs5Lrj-fAQmDvWsbCiCNyLMk,68
5
+ dataflow_conda_plugin-0.1.3rc1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ dataflow_conda_plugin-0.1.3rc1.dist-info/entry_points.txt,sha256=Vk2GKuQjr-5WV4NDKyPsnF37p3LUoAgPYOSMHxnpac8,46
7
+ dataflow_conda_plugin-0.1.3rc1.dist-info/top_level.txt,sha256=Io_dflkI6h0vZSGOzZxx4e76CDTSANVfu4v4tVY6zsA,7
8
+ dataflow_conda_plugin-0.1.3rc1.dist-info/RECORD,,
plugin/plugin.py CHANGED
@@ -1,14 +1,64 @@
1
1
  import subprocess, sys, pkg_resources, os
2
2
  from conda import plugins
3
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()
4
49
 
5
50
  def install_deps(command: str):
6
51
  """Install dataflow dependencies."""
7
52
  target_prefix = context.target_prefix
8
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
+
9
58
  try:
10
- # if cloning, skip the install
11
59
  if (args.get('clone') is not None):
60
+ if should_save_to_db:
61
+ save_environment_to_db(env_name, "Created")
12
62
  return
13
63
 
14
64
  install_dataflow_deps = pkg_resources.resource_filename('plugin', 'scripts/install_dataflow_deps.sh')
@@ -27,16 +77,77 @@ def install_deps(command: str):
27
77
  return_code = process.wait()
28
78
  if return_code != 0:
29
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)
30
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
+
31
106
  except Exception as e:
32
- print(f"An unexpected error occurred: {str(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()
33
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()
34
141
 
35
-
36
142
  @plugins.hookimpl
37
143
  def conda_post_commands():
38
144
  yield plugins.CondaPostCommand(
39
145
  name=f"install_deps_post_command",
40
146
  action=install_deps,
41
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"},
42
153
  )
@@ -1,8 +0,0 @@
1
- plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- plugin/plugin.py,sha256=ZFB2Uy3JCjufqY8sDlU09MciuEjQbXBDf8q4PmmVtO4,1268
3
- plugin/scripts/install_dataflow_deps.sh,sha256=sbr4tbtjCE4nSKnn-Net4e73ZGGi1WWqkzQrU7_nZJI,1099
4
- dataflow_conda_plugin-0.1.2.dist-info/METADATA,sha256=g3nDLWzU7goJ0CDx4Cn8nwGIJ35rLXTl7eWcsrWAi4o,65
5
- dataflow_conda_plugin-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- dataflow_conda_plugin-0.1.2.dist-info/entry_points.txt,sha256=Vk2GKuQjr-5WV4NDKyPsnF37p3LUoAgPYOSMHxnpac8,46
7
- dataflow_conda_plugin-0.1.2.dist-info/top_level.txt,sha256=Io_dflkI6h0vZSGOzZxx4e76CDTSANVfu4v4tVY6zsA,7
8
- dataflow_conda_plugin-0.1.2.dist-info/RECORD,,