Ayon-Python-Api 0.3.0__tar.gz → 0.3.2__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.
Files changed (24) hide show
  1. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/PKG-INFO +1 -1
  2. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/__init__.py +5 -0
  3. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/server_api.py +85 -63
  4. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/utils.py +20 -0
  5. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/version.py +1 -1
  6. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_python_api.egg-info/PKG-INFO +1 -1
  7. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/pyproject.toml +1 -1
  8. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/LICENSE +0 -0
  9. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/README.md +0 -0
  10. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/_api.py +0 -0
  11. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/constants.py +0 -0
  12. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/entity_hub.py +0 -0
  13. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/events.py +0 -0
  14. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/exceptions.py +0 -0
  15. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/graphql.py +0 -0
  16. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/graphql_queries.py +0 -0
  17. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/operations.py +0 -0
  18. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_api/thumbnails.py +0 -0
  19. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_python_api.egg-info/SOURCES.txt +0 -0
  20. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_python_api.egg-info/dependency_links.txt +0 -0
  21. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_python_api.egg-info/requires.txt +0 -0
  22. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/ayon_python_api.egg-info/top_level.txt +0 -0
  23. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/setup.cfg +0 -0
  24. {ayon-python-api-0.3.0 → ayon-python-api-0.3.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: AYON Python API
5
5
  Home-page: https://github.com/ynput/ayon-python-api
6
6
  Author: ynput.io
@@ -1,6 +1,8 @@
1
+ from .version import __version__
1
2
  from .utils import (
2
3
  TransferProgress,
3
4
  slugify_string,
5
+ create_dependency_package_basename,
4
6
  )
5
7
  from .server_api import (
6
8
  ServerAPI,
@@ -183,8 +185,11 @@ from ._api import (
183
185
 
184
186
 
185
187
  __all__ = (
188
+ "__version__",
189
+
186
190
  "TransferProgress",
187
191
  "slugify_string",
192
+ "create_dependency_package_basename",
188
193
 
189
194
  "ServerAPI",
190
195
 
@@ -61,6 +61,7 @@ from .utils import (
61
61
  entity_data_json_default,
62
62
  failed_json_default,
63
63
  TransferProgress,
64
+ create_dependency_package_basename,
64
65
  )
65
66
 
66
67
  PatternType = type(re.compile(""))
@@ -114,6 +115,10 @@ class RestApiResponse(object):
114
115
  self.status = status_code
115
116
  self._data = data
116
117
 
118
+ @property
119
+ def text(self):
120
+ return self._response.text
121
+
117
122
  @property
118
123
  def orig_response(self):
119
124
  return self._response
@@ -150,11 +155,13 @@ class RestApiResponse(object):
150
155
  def status_code(self):
151
156
  return self.status
152
157
 
153
- def raise_for_status(self):
158
+ def raise_for_status(self, message=None):
154
159
  try:
155
160
  self._response.raise_for_status()
156
161
  except requests.exceptions.HTTPError as exc:
157
- raise HTTPRequestError(str(exc), exc.response)
162
+ if message is None:
163
+ message = str(exc)
164
+ raise HTTPRequestError(message, exc.response)
158
165
 
159
166
  def __enter__(self, *args, **kwargs):
160
167
  return self._response.__enter__(*args, **kwargs)
@@ -1303,13 +1310,15 @@ class ServerAPI(object):
1303
1310
  progress.set_transfer_done()
1304
1311
  return progress
1305
1312
 
1306
- def _upload_file(self, url, filepath, progress):
1313
+ def _upload_file(self, url, filepath, progress, request_type=None):
1314
+ if request_type is None:
1315
+ request_type = RequestTypes.put
1307
1316
  kwargs = {}
1308
1317
  if self._session is None:
1309
1318
  kwargs["headers"] = self.get_headers()
1310
- post_func = self._base_functions_mapping[RequestTypes.post]
1319
+ post_func = self._base_functions_mapping[request_type]
1311
1320
  else:
1312
- post_func = self._session_functions_mapping[RequestTypes.post]
1321
+ post_func = self._session_functions_mapping[request_type]
1313
1322
 
1314
1323
  with open(filepath, "rb") as stream:
1315
1324
  stream.seek(0, io.SEEK_END)
@@ -1320,7 +1329,9 @@ class ServerAPI(object):
1320
1329
  response.raise_for_status()
1321
1330
  progress.set_transferred_size(size)
1322
1331
 
1323
- def upload_file(self, endpoint, filepath, progress=None):
1332
+ def upload_file(
1333
+ self, endpoint, filepath, progress=None, request_type=None
1334
+ ):
1324
1335
  """Upload file to server.
1325
1336
 
1326
1337
  Todos:
@@ -1331,6 +1342,8 @@ class ServerAPI(object):
1331
1342
  filepath (str): Source filepath.
1332
1343
  progress (Optional[TransferProgress]): Object that gives ability
1333
1344
  to track upload progress.
1345
+ request_type (Optional[RequestType]): Type of request that will
1346
+ be used to upload file.
1334
1347
  """
1335
1348
 
1336
1349
  if endpoint.startswith(self._base_url):
@@ -1349,7 +1362,7 @@ class ServerAPI(object):
1349
1362
  progress.set_started()
1350
1363
 
1351
1364
  try:
1352
- self._upload_file(url, filepath, progress)
1365
+ self._upload_file(url, filepath, progress, request_type)
1353
1366
 
1354
1367
  except Exception as exc:
1355
1368
  progress.set_failed(str(exc))
@@ -1486,13 +1499,11 @@ class ServerAPI(object):
1486
1499
  """
1487
1500
 
1488
1501
  response = self.delete("attributes/{}".format(attribute_name))
1489
- if response.status_code != 204:
1490
- # TODO raise different exception
1491
- raise ValueError(
1492
- "Attribute \"{}\" was not created/updated. {}".format(
1493
- attribute_name, response.detail
1494
- )
1502
+ response.raise_for_status(
1503
+ "Attribute \"{}\" was not created/updated. {}".format(
1504
+ attribute_name, response.detail
1495
1505
  )
1506
+ )
1496
1507
 
1497
1508
  self.reset_attributes_schema()
1498
1509
 
@@ -1732,8 +1743,9 @@ class ServerAPI(object):
1732
1743
  python_version,
1733
1744
  platform_name,
1734
1745
  python_modules,
1746
+ runtime_python_modules,
1735
1747
  checksum,
1736
- checksum_type,
1748
+ checksum_algorithm,
1737
1749
  file_size,
1738
1750
  sources=None,
1739
1751
  ):
@@ -1742,6 +1754,10 @@ class ServerAPI(object):
1742
1754
  This step will create only metadata. Make sure to upload installer
1743
1755
  to the server using 'upload_installer' method.
1744
1756
 
1757
+ Runtime python modules are modules that are required to run AYON
1758
+ desktop application, but are not added to PYTHONPATH for any
1759
+ subprocess.
1760
+
1745
1761
  Args:
1746
1762
  filename (str): Installer filename.
1747
1763
  version (str): Version of installer.
@@ -1749,8 +1765,10 @@ class ServerAPI(object):
1749
1765
  platform_name (str): Name of platform.
1750
1766
  python_modules (dict[str, str]): Python modules that are available
1751
1767
  in installer.
1768
+ runtime_python_modules (dict[str, str]): Runtime python modules
1769
+ that are available in installer.
1752
1770
  checksum (str): Installer file checksum.
1753
- checksum_type (str): Type of checksum used to create checksum.
1771
+ checksum_algorithm (str): Type of checksum used to create checksum.
1754
1772
  file_size (int): File size.
1755
1773
  sources (Optional[list[dict[str, Any]]]): List of sources that
1756
1774
  can be used to download file.
@@ -1762,8 +1780,9 @@ class ServerAPI(object):
1762
1780
  "pythonVersion": python_version,
1763
1781
  "platform": platform_name,
1764
1782
  "pythonModules": python_modules,
1783
+ "runtimePythonModules": runtime_python_modules,
1765
1784
  "checksum": checksum,
1766
- "checksumType": checksum_type,
1785
+ "checksumAlgorithm": checksum_algorithm,
1767
1786
  "size": file_size,
1768
1787
  }
1769
1788
  if sources:
@@ -1781,7 +1800,7 @@ class ServerAPI(object):
1781
1800
  can be used to download file. Fully replaces existing sources.
1782
1801
  """
1783
1802
 
1784
- response = self.post(
1803
+ response = self.patch(
1785
1804
  "desktop/installers/{}".format(filename),
1786
1805
  sources=sources
1787
1806
  )
@@ -1794,7 +1813,7 @@ class ServerAPI(object):
1794
1813
  filename (str): Installer filename.
1795
1814
  """
1796
1815
 
1797
- response = self.delete("dekstop/installers/{}".format(filename))
1816
+ response = self.delete("desktop/installers/{}".format(filename))
1798
1817
  response.raise_for_status()
1799
1818
 
1800
1819
  def download_installer(
@@ -1929,8 +1948,7 @@ class ServerAPI(object):
1929
1948
  checksum=checksum,
1930
1949
  **kwargs
1931
1950
  )
1932
- if response.status not in (200, 201, 204):
1933
- raise ServerError("Failed to create/update dependency")
1951
+ response.raise_for_status("Failed to create/update dependency")
1934
1952
  return response.data
1935
1953
 
1936
1954
  def get_dependency_packages(self):
@@ -1964,6 +1982,24 @@ class ServerAPI(object):
1964
1982
  result.raise_for_status()
1965
1983
  return result.data
1966
1984
 
1985
+ def _get_dependency_package_route(
1986
+ self, filename=None, platform_name=None
1987
+ ):
1988
+ major, minor, patch, _, _ = self.server_version_tuple
1989
+ if major == 0 and (minor > 2 or (minor == 2 and patch >= 1)):
1990
+ base = "desktop/dependency_packages"
1991
+ if not filename:
1992
+ return base
1993
+ return "{}/{}".format(base, filename)
1994
+
1995
+ # Backwards compatibility for AYON server 0.2.0 and lower
1996
+ if platform_name is None:
1997
+ platform_name = platform.system().lower()
1998
+ base = "dependencies"
1999
+ if not filename:
2000
+ return base
2001
+ return "{}/{}/{}".format(base, filename, platform_name)
2002
+
1967
2003
  def create_dependency_package(
1968
2004
  self,
1969
2005
  filename,
@@ -2014,7 +2050,8 @@ class ServerAPI(object):
2014
2050
  if sources:
2015
2051
  post_body["sources"] = sources
2016
2052
 
2017
- response = self.post("desktop/dependency_packages", **post_body)
2053
+ route = self._get_dependency_package_route()
2054
+ response = self.post(route, **post_body)
2018
2055
  response.raise_for_status()
2019
2056
 
2020
2057
  def update_dependency_package(self, filename, sources):
@@ -2028,7 +2065,7 @@ class ServerAPI(object):
2028
2065
  """
2029
2066
 
2030
2067
  response = self.patch(
2031
- "desktop/dependency_packages/{}".format(filename),
2068
+ self._get_dependency_package_route(filename),
2032
2069
  sources=sources
2033
2070
  )
2034
2071
  response.raise_for_status()
@@ -2044,18 +2081,9 @@ class ServerAPI(object):
2044
2081
  Deprecated since version 0.2.1
2045
2082
  """
2046
2083
 
2047
- major, minor, patch, _, _ = self.server_version_tuple
2048
- if major == 0 and (minor > 2 or (minor == 2 and patch >= 1)):
2049
- url = "desktop/dependency_packages/{}".format(filename)
2050
- else:
2051
- # Backwards compatibility for AYON server 0.2.0 and lower
2052
- if platform_name is None:
2053
- platform_name = platform.system().lower()
2054
- url = "dependencies/{}/{}".format(filename, platform_name)
2055
-
2056
- response = self.delete(url)
2057
- if response.status != 200:
2058
- raise ServerError("Failed to delete dependency file")
2084
+ route = self._get_dependency_package_route(filename, platform_name)
2085
+ response = self.delete(route)
2086
+ response.raise_for_status("Failed to delete dependency file")
2059
2087
  return response.data
2060
2088
 
2061
2089
  def download_dependency_package(
@@ -2089,18 +2117,10 @@ class ServerAPI(object):
2089
2117
  str: Filepath to downloaded file.
2090
2118
  """
2091
2119
 
2092
- major, minor, patch, _, _ = self.server_version_tuple
2093
- if major == 0 and (minor > 2 or (minor == 2 and patch >= 1)):
2094
- url = "desktop/dependency_packages/{}".format(src_filename)
2095
- else:
2096
- # Backwards compatibility for AYON server 0.2.0 and lower
2097
- if platform_name is None:
2098
- platform_name = platform.system().lower()
2099
- url = "dependencies/{}/{}".format(src_filename, platform_name)
2100
-
2120
+ route = self._get_dependency_package_route(src_filename, platform_name)
2101
2121
  package_filepath = os.path.join(dst_directory, dst_filename)
2102
2122
  self.download_file(
2103
- url,
2123
+ route,
2104
2124
  package_filepath,
2105
2125
  chunk_size=chunk_size,
2106
2126
  progress=progress
@@ -2122,20 +2142,16 @@ class ServerAPI(object):
2122
2142
  upload state.
2123
2143
  """
2124
2144
 
2125
- major, minor, patch, _, _ = self.server_version_tuple
2126
- if major == 0 and (minor > 2 or (minor == 2 and patch >= 1)):
2127
- url = "desktop/dependency_packages/{}".format(dst_filename)
2128
- else:
2129
- # Backwards compatibility for AYON server 0.2.0 and lower
2130
- if platform_name is None:
2131
- platform_name = platform.system().lower()
2132
- url = "dependencies/{}/{}".format(dst_filename, platform_name)
2133
-
2134
- self.upload_file(url, src_filepath, progress=progress)
2145
+ route = self._get_dependency_package_route(dst_filename, platform_name)
2146
+ self.upload_file(route, src_filepath, progress=progress)
2135
2147
 
2136
2148
  def create_dependency_package_basename(self, platform_name=None):
2137
2149
  """Create basename for dependency package file.
2138
2150
 
2151
+ Deprecated:
2152
+ Use 'create_dependency_package_basename' from `ayon_api` or
2153
+ `ayon_api.utils` instead.
2154
+
2139
2155
  Args:
2140
2156
  platform_name (Optional[str]): Name of platform for which the
2141
2157
  bundle is targeted. Default value is current platform.
@@ -2144,12 +2160,15 @@ class ServerAPI(object):
2144
2160
  str: Dependency package name with timestamp and platform.
2145
2161
  """
2146
2162
 
2147
- if platform_name is None:
2148
- platform_name = platform.system().lower()
2163
+ return create_dependency_package_basename(platform_name)
2149
2164
 
2150
- now_date = datetime.datetime.now()
2151
- time_stamp = now_date.strftime("%y%m%d%H%M")
2152
- return "ayon_{}_{}".format(time_stamp, platform_name)
2165
+ def _get_bundles_route(self):
2166
+ major, minor, patch, _, _ = self.server_version_tuple
2167
+ # Backwards compatibility for AYON server 0.3.0
2168
+ # - first version where bundles were available
2169
+ if major == 0 and minor == 3 and patch == 0:
2170
+ return "desktop/bundles"
2171
+ return "bundles"
2153
2172
 
2154
2173
  def get_bundles(self):
2155
2174
  """Server bundles with basic information.
@@ -2181,7 +2200,7 @@ class ServerAPI(object):
2181
2200
  dict[str, Any]: Server bundles with basic information.
2182
2201
  """
2183
2202
 
2184
- response = self.get("desktop/bundles")
2203
+ response = self.get(self._get_bundles_route())
2185
2204
  response.raise_for_status()
2186
2205
  return response.data
2187
2206
 
@@ -2224,7 +2243,7 @@ class ServerAPI(object):
2224
2243
  if value is not None:
2225
2244
  body[key] = value
2226
2245
 
2227
- response = self.post("desktop/bundles", **body)
2246
+ response = self.post(self._get_bundles_route(), **body)
2228
2247
  response.raise_for_status()
2229
2248
 
2230
2249
  def update_bundle(
@@ -2259,7 +2278,8 @@ class ServerAPI(object):
2259
2278
  if value is not None
2260
2279
  }
2261
2280
  response = self.patch(
2262
- "desktop/bundles/{}".format(bundle_name), **body
2281
+ "{}/{}".format(self._get_bundles_route(), bundle_name),
2282
+ **body
2263
2283
  )
2264
2284
  response.raise_for_status()
2265
2285
 
@@ -2270,7 +2290,9 @@ class ServerAPI(object):
2270
2290
  bundle_name (str): Name of bundle to delete.
2271
2291
  """
2272
2292
 
2273
- response = self.delete("desktop/bundles/{}".format(bundle_name))
2293
+ response = self.delete(
2294
+ "{}/{}".format(self._get_bundles_route(), bundle_name)
2295
+ )
2274
2296
  response.raise_for_status()
2275
2297
 
2276
2298
  # Anatomy presets
@@ -2,6 +2,7 @@ import re
2
2
  import datetime
3
3
  import uuid
4
4
  import string
5
+ import platform
5
6
  import collections
6
7
  try:
7
8
  # Python 3
@@ -449,3 +450,22 @@ class TransferProgress:
449
450
  destination_url = property(get_destination_url, set_destination_url)
450
451
  content_size = property(get_content_size, set_content_size)
451
452
  transferred_size = property(get_transferred_size, set_transferred_size)
453
+
454
+
455
+ def create_dependency_package_basename(platform_name=None):
456
+ """Create basename for dependency package file.
457
+
458
+ Args:
459
+ platform_name (Optional[str]): Name of platform for which the
460
+ bundle is targeted. Default value is current platform.
461
+
462
+ Returns:
463
+ str: Dependency package name with timestamp and platform.
464
+ """
465
+
466
+ if platform_name is None:
467
+ platform_name = platform.system().lower()
468
+
469
+ now_date = datetime.datetime.now()
470
+ time_stamp = now_date.strftime("%y%m%d%H%M")
471
+ return "ayon_{}_{}".format(time_stamp, platform_name)
@@ -1,2 +1,2 @@
1
1
  """Package declaring Python API for Ayon server."""
2
- __version__ = "0.3.0"
2
+ __version__ = "0.3.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: AYON Python API
5
5
  Home-page: https://github.com/ynput/ayon-python-api
6
6
  Author: ynput.io
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ayon-python-api"
3
- version = "0.3.0"
3
+ version = "0.3.2"
4
4
  description = "AYON Python API"
5
5
  license = {file = "LICENSE"}
6
6
  readme = {file = "README.md", content-type = "text/markdown"}
File without changes