pybiolib 1.1.1666__py3-none-any.whl → 1.1.1682__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,6 +1,9 @@
1
1
  import json
2
+ import platform
2
3
  import time
3
4
  import socket
5
+ import ssl
6
+ import subprocess
4
7
  import urllib.request
5
8
  import urllib.error
6
9
  import urllib.parse
@@ -8,6 +11,19 @@ import urllib.parse
8
11
  from biolib.biolib_logging import logger_no_user_data
9
12
  from biolib.typing_utils import Dict, Optional, Union, Literal, cast
10
13
 
14
+ def create_ssl_context():
15
+ context = ssl.create_default_context()
16
+ try:
17
+ if platform.system() == 'Darwin':
18
+ certificates = subprocess.check_output(
19
+ "security find-certificate -a -p",
20
+ shell=True
21
+ ).decode('utf-8')
22
+ context.load_verify_locations(cadata=certificates)
23
+ except BaseException:
24
+ pass
25
+ return context
26
+
11
27
 
12
28
  class HttpError(urllib.error.HTTPError):
13
29
  def __init__(self, http_error: urllib.error.HTTPError):
@@ -39,6 +55,8 @@ class HttpResponse:
39
55
 
40
56
 
41
57
  class HttpClient:
58
+ ssl_context = None
59
+
42
60
  @staticmethod
43
61
  def request(
44
62
  url: str,
@@ -47,6 +65,8 @@ class HttpClient:
47
65
  headers: Optional[Dict[str, str]] = None,
48
66
  retries: int = 0,
49
67
  ) -> HttpResponse:
68
+ if not HttpClient.ssl_context:
69
+ HttpClient.ssl_context = create_ssl_context()
50
70
  headers_to_send = headers or {}
51
71
  if isinstance(data, dict):
52
72
  headers_to_send['Accept'] = 'application/json'
@@ -66,7 +86,11 @@ class HttpClient:
66
86
  time.sleep(5 * retry_count)
67
87
  logger_no_user_data.debug(f'Retrying HTTP {method} request...')
68
88
  try:
69
- with urllib.request.urlopen(request, timeout=timeout_in_seconds) as response:
89
+ with urllib.request.urlopen(
90
+ request,
91
+ context=HttpClient.ssl_context,
92
+ timeout=timeout_in_seconds
93
+ ) as response:
70
94
  return HttpResponse(response)
71
95
 
72
96
  except urllib.error.HTTPError as error:
@@ -1,17 +1,42 @@
1
+ import mimetypes
2
+ import random
1
3
  import re
2
4
  import os
3
5
  import subprocess
4
6
 
5
- import requests
7
+ from requests.exceptions import HTTPError
6
8
 
7
9
  import biolib.api
8
10
  from biolib import biolib_errors
9
11
  from biolib.typing_utils import Optional
10
- from biolib.biolib_api_client.auth import BearerAuth
11
- from biolib.biolib_api_client import BiolibApiClient, AppGetResponse
12
- from biolib.biolib_errors import BioLibError
12
+ from biolib.biolib_api_client import AppGetResponse
13
13
  from biolib.biolib_logging import logger
14
14
 
15
+ def encode_multipart(data, files):
16
+ boundary = f'----------{random.randint(0, 1000000000)}'
17
+ line_array = []
18
+
19
+ for (key, value) in data.items():
20
+ if not value is None:
21
+ line_array.append(f'--{boundary}')
22
+ line_array.append(f'Content-Disposition: form-data; name="{key}"')
23
+ line_array.append('')
24
+ line_array.append(value)
25
+
26
+ for (key, (filename, value)) in files.items():
27
+ line_array.append(f'--{boundary}')
28
+ line_array.append(f'Content-Disposition: form-data; name="{key}"; filename="{filename}"')
29
+ line_array.append(f'Content-Type: {mimetypes.guess_type(filename)[0] or "application/octet-stream"}')
30
+ line_array.append('')
31
+ line_array.append('')
32
+ line_array.append(value)
33
+
34
+ line_array.append(f'--{boundary}--')
35
+ line_array.append('')
36
+
37
+ data_encoded = b'\r\n'.join([line.encode() if isinstance(line, str) else line for line in line_array])
38
+ return 'multipart/form-data; boundary={}'.format(boundary), data_encoded
39
+
15
40
 
16
41
  def _get_git_branch_name() -> str:
17
42
  try:
@@ -51,7 +76,7 @@ class BiolibAppApi:
51
76
  app_response: AppGetResponse = response.json()
52
77
  return app_response
53
78
 
54
- except requests.exceptions.HTTPError as error:
79
+ except HTTPError as error:
55
80
  if error.response.status_code == 404:
56
81
  raise biolib_errors.NotFound(f'Application {uri} not found.') from None
57
82
 
@@ -69,24 +94,28 @@ class BiolibAppApi:
69
94
  set_as_active,
70
95
  app_version_id_to_copy_images_from: Optional[str],
71
96
  ):
72
- response = requests.post(
73
- f'{BiolibApiClient.get().base_url}/api/app_versions/',
74
- files={
75
- 'source_files_zip': zip_binary,
76
- },
77
- data={
78
- 'app': app_id,
79
- 'set_as_active': 'true' if set_as_active else 'false',
80
- 'state': 'published',
81
- 'app_version_id_to_copy_images_from': app_version_id_to_copy_images_from,
82
- 'git_branch_name': _get_git_branch_name(),
83
- 'git_repository_url': _get_git_repository_url(),
84
- },
85
- auth=BearerAuth(BiolibApiClient.get().access_token)
86
- )
87
- if not response.ok:
97
+ try:
98
+ content_type, data_encoded = encode_multipart(
99
+ data={
100
+ 'app': app_id,
101
+ 'set_as_active': 'true' if set_as_active else 'false',
102
+ 'state': 'published',
103
+ 'app_version_id_to_copy_images_from': app_version_id_to_copy_images_from,
104
+ 'git_branch_name': _get_git_branch_name(),
105
+ 'git_repository_url': _get_git_repository_url(),
106
+ },
107
+ files={
108
+ 'source_files_zip': ('source_files.zip', zip_binary),
109
+ }
110
+ )
111
+ response = biolib.api.client.post(
112
+ path='/app_versions/',
113
+ data=data_encoded,
114
+ headers={'Content-Type': content_type},
115
+ )
116
+ except Exception as error:
88
117
  logger.error(f'Push failed for {author}/{app_name}:')
89
- raise BioLibError(response.text)
118
+ raise error
90
119
 
91
120
  # TODO: When response includes the version number, print the URL for the new app version
92
121
  logger.info(f'Initialized new app version for {author}/{app_name}.')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pybiolib
3
- Version: 1.1.1666
3
+ Version: 1.1.1682
4
4
  Summary: BioLib Python Client
5
5
  Home-page: https://github.com/biolib
6
6
  License: MIT
@@ -2,7 +2,7 @@ LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
2
2
  README.md,sha256=_IH7pxFiqy2bIAmaVeA-iVTyUwWRjMIlfgtUbYTtmls,368
3
3
  biolib/__init__.py,sha256=_ydjlp3Kyqr4iWkT63ZdiiwTbqtHjPS2S51EdU0UTk4,3690
4
4
  biolib/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- biolib/_internal/http_client.py,sha256=QlOXLeXIHHmgeIQuNMowD4XFzkTq-Pz_67-HyLmFxHM,3042
5
+ biolib/_internal/http_client.py,sha256=TS_TNwAiY73KKkIjlXEvt48JxghUz76C5S76bQ9Kj9Q,3720
6
6
  biolib/_internal/push_application.py,sha256=NXQNLPucqkq7eKbNCJQA8OYx4CXYHRJ1CG1ViPAJJH4,10680
7
7
  biolib/api/__init__.py,sha256=iIO8ZRdn7YDhY5cR47-Wo1YsNOK8H6RN6jn8yor5WJI,137
8
8
  biolib/api/client.py,sha256=jts2QbR-pPU0pAuUaYfWsK4q1O4Nu1nQKv6LYu0T0L0,2754
@@ -14,7 +14,7 @@ biolib/biolib_api_client/api_client.py,sha256=oaLqTb208TLRVW4-h_va734TrVDRD3kLpF
14
14
  biolib/biolib_api_client/app_types.py,sha256=vEjkpMwaMfz8MxBBZQfWCkxqT7NXxWocB_Oe9WHjJ_g,2425
15
15
  biolib/biolib_api_client/auth.py,sha256=BAXtic6DdaA2QjoDVglnO3PFPoBETQbSraTpIwsZbFc,1267
16
16
  biolib/biolib_api_client/biolib_account_api.py,sha256=2Mc6SbmjBSsz8lF2H3iiaZHEm47LyI0B4rjmvzxKHt4,580
17
- biolib/biolib_api_client/biolib_app_api.py,sha256=naEy1tShrVkL8yCd1n9Q-gNrq6lAcNEAnt7qNl0KJyY,3291
17
+ biolib/biolib_api_client/biolib_app_api.py,sha256=pr52ARrDeB5ioEA7NAjMdmBYb9V2FPy0_URCwdCRZ0A,4397
18
18
  biolib/biolib_api_client/biolib_job_api.py,sha256=AvNvflEeCBjG2ZTaFcwvRU-61GdNodFCZQNe50491RM,7823
19
19
  biolib/biolib_api_client/biolib_large_file_system_api.py,sha256=5q4UlRw-OB2bRu7CeB14fy-azz2YeSgem5DbvMSaS44,1777
20
20
  biolib/biolib_api_client/common_types.py,sha256=RH-1KNHqUF-EkTpfPOSTt5Mq1GPdfju_cqXDesscO1I,123
@@ -101,8 +101,8 @@ biolib/utils/cache_state.py,sha256=BFrZlV4XZIueIFzAFiPidX4hmwADKY5Y5ZuqlerF5l0,3
101
101
  biolib/utils/multipart_uploader.py,sha256=PEorMsTNg5f72e3Y-KA3LrI-F6EAnsD9vENV-5EuiX0,9896
102
102
  biolib/utils/seq_util.py,sha256=gLnqCr_mcLcxakO44vGBqUn76VI7kLHgXKqyManjd24,4292
103
103
  biolib/utils/zip/remote_zip.py,sha256=NCdUnVbGCv7SfXCI-yVU-is_OnyWmLAnVpIdSvo-W4k,23500
104
- pybiolib-1.1.1666.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
105
- pybiolib-1.1.1666.dist-info/METADATA,sha256=sFQrMV8cWV9JJsuhP8ZSMPsf6fIDva5Kqbe29B2BSRw,1543
106
- pybiolib-1.1.1666.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
107
- pybiolib-1.1.1666.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
108
- pybiolib-1.1.1666.dist-info/RECORD,,
104
+ pybiolib-1.1.1682.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
105
+ pybiolib-1.1.1682.dist-info/METADATA,sha256=TKjdi5d96iH3SiJWvhNp0joJ-6MI10aT2M3VCa6m0IE,1543
106
+ pybiolib-1.1.1682.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
107
+ pybiolib-1.1.1682.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
108
+ pybiolib-1.1.1682.dist-info/RECORD,,