pybiolib 1.2.931__py3-none-any.whl → 1.2.942__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.
@@ -1,3 +1,4 @@
1
+ import hashlib
1
2
  import io
2
3
  import os
3
4
  import zipfile as zf
@@ -75,3 +76,47 @@ def get_iterable_zip_stream(files: List[str], chunk_size: int) -> Iterator[bytes
75
76
  if len(chunk) == 0:
76
77
  break
77
78
  yield chunk
79
+
80
+
81
+ def path_to_renamed_path(path_str: str, prefix_with_slash: bool = True) -> str:
82
+ """
83
+ Normalize file paths consistently:
84
+ - If path contains '..' (relative path going up), convert to absolute path
85
+ - If relative path not containing '..', keep as is, but prepend / if prefix_with_slash=True
86
+ - If absolute path that is subpath of current directory, convert to relative path
87
+ - If absolute path not subpath of current directory, hash the folder path and keep filename
88
+ """
89
+ path = Path(path_str)
90
+ current_dir = Path.cwd()
91
+
92
+ if '..' in path.parts:
93
+ resolved_path = path.resolve()
94
+ try:
95
+ relative_path = resolved_path.relative_to(current_dir)
96
+ result = str(relative_path)
97
+ except ValueError:
98
+ folder_path = str(resolved_path.parent)
99
+ filename = resolved_path.name
100
+ folder_hash = hashlib.md5(folder_path.encode()).hexdigest()[:6]
101
+ result = f'/{folder_hash}/{filename}'
102
+ elif path.is_absolute():
103
+ try:
104
+ resolved_path = path.resolve()
105
+ relative_path = resolved_path.relative_to(current_dir)
106
+ result = str(relative_path)
107
+ except ValueError:
108
+ folder_path = str(path.parent)
109
+ filename = path.name
110
+ folder_hash = hashlib.md5(folder_path.encode()).hexdigest()[:6]
111
+ result = f'/{folder_hash}/{filename}'
112
+ else:
113
+ result = path_str
114
+
115
+ if prefix_with_slash:
116
+ if not result.startswith('/'):
117
+ return '/' + result
118
+ return result
119
+ else:
120
+ if result.startswith('/'):
121
+ return result[1:]
122
+ return result
biolib/app/app.py CHANGED
@@ -20,6 +20,7 @@ from biolib.jobs.job import Result
20
20
  from biolib.typing_utils import Dict, Optional
21
21
  from biolib.utils.app_uri import parse_app_uri
22
22
  from biolib._runtime.runtime import Runtime
23
+ from biolib._internal.file_utils import path_to_renamed_path
23
24
 
24
25
 
25
26
  class BioLibApp:
@@ -168,16 +169,60 @@ Example: "app.cli('--help')"
168
169
  files = []
169
170
 
170
171
  files_dict = {}
172
+ if isinstance(files, list):
173
+ for file_path in files:
174
+ path = Path(file_path)
175
+ if path.is_dir():
176
+ for filename in path.rglob('*'):
177
+ if filename.is_dir():
178
+ continue
179
+ with open(filename, 'rb') as f:
180
+ relative_path = filename.relative_to(Path.cwd())
181
+ files_dict[path_to_renamed_path(str(relative_path))] = f.read()
182
+ else:
183
+ with open(path, 'rb') as f:
184
+ files_dict[path_to_renamed_path(str(path))] = f.read()
185
+ elif isinstance(files, dict):
186
+ files_dict = {}
187
+ for key, value in files.items():
188
+ if not key.startswith('/'):
189
+ key = '/' + key
190
+ files_dict[key] = value
191
+ else:
192
+ raise Exception('The given files input must be list or dict or None')
193
+
171
194
  for idx, arg in enumerate(args):
172
195
  if isinstance(arg, str):
173
196
  if os.path.isfile(arg) or os.path.isdir(arg):
174
- files.append(arg)
175
- args[idx] = Path(arg).name
197
+ if os.path.isfile(arg):
198
+ with open(arg, 'rb') as f:
199
+ files_dict[path_to_renamed_path(arg)] = f.read()
200
+ elif os.path.isdir(arg):
201
+ path = Path(arg)
202
+ for filename in path.rglob('*'):
203
+ if filename.is_dir():
204
+ continue
205
+ with open(filename, 'rb') as f:
206
+ files_dict[path_to_renamed_path(str(filename))] = f.read()
207
+ args[idx] = path_to_renamed_path(arg, prefix_with_slash=False)
176
208
 
177
209
  # support --myarg=file.txt
178
210
  elif os.path.isfile(arg.split('=')[-1]) or os.path.isdir(arg.split('=')[-1]):
179
- files.append(arg.split('=')[-1])
180
- args[idx] = arg.split('=')[0] + '=' + Path(arg.split('=')[-1]).name
211
+ file_path = arg.split('=')[-1]
212
+ if os.path.isfile(file_path):
213
+ with open(file_path, 'rb') as f:
214
+ files_dict[path_to_renamed_path(file_path)] = f.read()
215
+ elif os.path.isdir(file_path):
216
+ path = Path(file_path)
217
+ for filename in path.rglob('*'):
218
+ if filename.is_dir():
219
+ continue
220
+ with open(filename, 'rb') as f:
221
+ files_dict[path_to_renamed_path(str(filename))] = f.read()
222
+ args[idx] = (
223
+ arg.split('=')[0] + '=' +
224
+ path_to_renamed_path(file_path, prefix_with_slash=False)
225
+ )
181
226
  else:
182
227
  pass # a normal string arg was given
183
228
  else:
@@ -191,33 +236,6 @@ Example: "app.cli('--help')"
191
236
  files_dict[f'/{tmp_filename}'] = file_data
192
237
  args[idx] = tmp_filename
193
238
 
194
- if isinstance(files, list):
195
- for file in files:
196
- path = Path(file).absolute()
197
-
198
- # Recursively add data from files if dir
199
- if path.is_dir():
200
- for filename in path.rglob('*'):
201
- if filename.is_dir():
202
- continue
203
- file = open(filename, 'rb')
204
- relative_path = '/' + path.name + '/' + '/'.join(filename.relative_to(path).parts)
205
- files_dict[relative_path] = file.read()
206
- file.close()
207
-
208
- # Add file data
209
- else:
210
- file = open(path, 'rb')
211
- path_short = '/' + path.name
212
-
213
- files_dict[path_short] = file.read()
214
- file.close()
215
-
216
- elif isinstance(files, dict):
217
- files_dict.update(files)
218
- else:
219
- raise Exception('The given files input must be list or dict or None')
220
-
221
239
  module_input_serialized: bytes = ModuleInput().serialize(
222
240
  stdin=stdin,
223
241
  arguments=args,
biolib/cli/init.py CHANGED
@@ -23,8 +23,13 @@ def init() -> None:
23
23
  'Remember to set the app URI in the .biolib/config.yml file later, '
24
24
  'and docker image name in the .biolib/config.yml and .github/workflows/biolib.yml files.'
25
25
  )
26
- copilot_input = input('Do you want to include Copilot style prompts? [y/N]: ')
27
- include_copilot_style = copilot_input.lower() == 'y'
26
+ copilot_enabled_input = input('Do you want to include Copilot instructions and prompts? [y/N]: ')
27
+ include_copilot_enabled = copilot_enabled_input.lower() == 'y'
28
+
29
+ include_copilot_style = True # Default to True if copilot is enabled
30
+ if include_copilot_enabled:
31
+ copilot_style_input = input('Do you want to include Copilot style prompts? [Y/n]: ')
32
+ include_copilot_style = copilot_style_input.lower() != 'n'
28
33
 
29
34
  template_dir = templates.init_template()
30
35
  conflicting_files = []
@@ -94,7 +99,8 @@ def init() -> None:
94
99
  with open(readme_path, 'w') as readme_file:
95
100
  readme_file.write(f'# {app_name}\n')
96
101
 
97
- add_copilot_prompts(force=False, style=include_copilot_style, silent=True)
102
+ if include_copilot_enabled:
103
+ add_copilot_prompts(force=False, style=include_copilot_style, silent=True)
98
104
 
99
105
  except KeyboardInterrupt:
100
106
  print('\nInit command cancelled.', file=sys.stderr)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pybiolib
3
- Version: 1.2.931
3
+ Version: 1.2.942
4
4
  Summary: BioLib Python Client
5
5
  License: MIT
6
6
  Keywords: biolib
@@ -7,7 +7,7 @@ biolib/_internal/data_record/data_record.py,sha256=SD3-tKQY2RZv9ZSVNUhd2ISDYV64F
7
7
  biolib/_internal/data_record/push_data.py,sha256=-L3a_7zZzDCXabBu3O4lWPMAMeBbeRPTrBlEM-_5SCI,2693
8
8
  biolib/_internal/data_record/remote_storage_endpoint.py,sha256=eCptuZ4DMAPnaNCVDvpWXwXGI6Jac9U1N5dqU8Cj95Q,1732
9
9
  biolib/_internal/errors.py,sha256=AokI6Dvaa22B__LTfSZUVdDsm0ye7lgBFv_aD9O_kbs,163
10
- biolib/_internal/file_utils.py,sha256=4jT6j7bB21c0JNn5BfnyWQib_zt0CVtJ_TiOFOStRcE,2604
10
+ biolib/_internal/file_utils.py,sha256=u_fD4aAWpLtvPlvcnz_iP4cRsFBjfnE6MWJUFPbTQHQ,4276
11
11
  biolib/_internal/fuse_mount/__init__.py,sha256=B_tM6RM2dBw-vbpoHJC4X3tOAaN1H2RDvqYJOw3xFwg,55
12
12
  biolib/_internal/fuse_mount/experiment_fuse_mount.py,sha256=08aUdEq_bvqLBft_gSLjOClKDy5sBnMts1RfJf7AP_U,7012
13
13
  biolib/_internal/http_client.py,sha256=9-3HG6LnLwJfrwjCeFj5XigHVH8Dzz6Dpr58IjQJHDo,6221
@@ -56,7 +56,7 @@ biolib/_session/session.py,sha256=US1Y1jfFIAm86-Lq3C7nCXpZXUJXXBVBkND9djMNYxI,16
56
56
  biolib/api/__init__.py,sha256=mQ4u8FijqyLzjYMezMUUbbBGNB3iFmkNdjXnWPZ7Jlw,138
57
57
  biolib/api/client.py,sha256=2GpKE7QrPgyPdgJgrV7XnZByIJf1n26UCy3aoaHBs1M,7881
58
58
  biolib/app/__init__.py,sha256=cdPtcfb_U-bxb9iSL4fCEq2rpD9OjkyY4W-Zw60B0LI,37
59
- biolib/app/app.py,sha256=7AD0S1ih_drWbWXFKixGXyOKwQurt3ecND4m0Vb-Aik,10554
59
+ biolib/app/app.py,sha256=E4PuwMWiWujQQzHQcq7MfVEZV-q6uKAbwBLr0ZPY5Dk,11825
60
60
  biolib/app/search_apps.py,sha256=K4a41f5XIWth2BWI7OffASgIsD0ko8elCax8YL2igaY,1470
61
61
  biolib/biolib_api_client/__init__.py,sha256=E5EMa19wJoblwSdQPYrxc_BtIeRsAuO0L_jQweWw-Yk,182
62
62
  biolib/biolib_api_client/api_client.py,sha256=IONzXeFCHl4wuct6fqOC_7NiTv_zFy6ys0hsAtvLzTA,7578
@@ -88,7 +88,7 @@ biolib/cli/__init__.py,sha256=IHC2bEyA27pvgp-18SGfFVJOP456elanz7suDP8D084,1316
88
88
  biolib/cli/auth.py,sha256=rpWGmXs6Fz6CGrO9K8ibPRszOdXG78Vig_boKaVCD9A,2082
89
89
  biolib/cli/data_record.py,sha256=t8DfJK2EZ_SNZ9drDA_N5Jqy8DNwf9f5SlFrIaOvtv0,3501
90
90
  biolib/cli/download_container.py,sha256=HIZVHOPmslGE5M2Dsp9r2cCkAEJx__vcsDz5Wt5LRos,483
91
- biolib/cli/init.py,sha256=OMYIltLJfF8q9VAvzDwNG0-1VixDkFGEN1ic2VhrW7c,4583
91
+ biolib/cli/init.py,sha256=GH_9GxfihhTKqn9-aAX6eFJR5GU2lCbKhpVeVcIccN0,4919
92
92
  biolib/cli/lfs.py,sha256=z2qHUwink85mv9yDgifbVKkVwuyknGhMDTfly_gLKJM,4151
93
93
  biolib/cli/push.py,sha256=J8BswMYVeTacZBHbm4K4a2XbS_I8kvfgRZLoby2wi3I,1695
94
94
  biolib/cli/run.py,sha256=RAAXbIx8Bi-4fNkEoz2ODJ0fEtyS7VxD3dkc2fVZwjY,2150
@@ -145,8 +145,8 @@ biolib/utils/cache_state.py,sha256=u256F37QSRIVwqKlbnCyzAX4EMI-kl6Dwu6qwj-Qmag,3
145
145
  biolib/utils/multipart_uploader.py,sha256=XvGP1I8tQuKhAH-QugPRoEsCi9qvbRk-DVBs5PNwwJo,8452
146
146
  biolib/utils/seq_util.py,sha256=Ozk0blGtPur_D9MwShD02r_mphyQmgZkx-lOHOwnlIM,6730
147
147
  biolib/utils/zip/remote_zip.py,sha256=0wErYlxir5921agfFeV1xVjf29l9VNgGQvNlWOlj2Yc,23232
148
- pybiolib-1.2.931.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
149
- pybiolib-1.2.931.dist-info/METADATA,sha256=hYj-LjppTQ0jEsBW9R2ViJhTCZ8OCPDntrR6mYiIXEg,1570
150
- pybiolib-1.2.931.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
151
- pybiolib-1.2.931.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
152
- pybiolib-1.2.931.dist-info/RECORD,,
148
+ pybiolib-1.2.942.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
149
+ pybiolib-1.2.942.dist-info/METADATA,sha256=tz9k4DMqK5D-cE76rso9xl3k6c0w6hTSBDkYqQXJqaM,1570
150
+ pybiolib-1.2.942.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
151
+ pybiolib-1.2.942.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
152
+ pybiolib-1.2.942.dist-info/RECORD,,