sdv-installer 0.2.1.dev0__tar.gz → 0.3.1.dev0__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 (26) hide show
  1. {sdv_installer-0.2.1.dev0/sdv_installer.egg-info → sdv_installer-0.3.1.dev0}/PKG-INFO +1 -1
  2. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/pyproject.toml +1 -1
  3. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/__init__.py +1 -1
  4. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/cli/__main__.py +25 -2
  5. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/config.py +1 -0
  6. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/constants.py +1 -0
  7. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/installation/__init__.py +2 -0
  8. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/installation/installer.py +87 -0
  9. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0/sdv_installer.egg-info}/PKG-INFO +1 -1
  10. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/LICENSE +0 -0
  11. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/README.md +0 -0
  12. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/authentication/__init__.py +0 -0
  13. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/authentication/authentication.py +4 -4
  14. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/cli/__init__.py +0 -0
  15. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/utils/__init__.py +0 -0
  16. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/utils/console_utils.py +0 -0
  17. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/utils/data_storage.py +0 -0
  18. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/utils/package_utils.py +0 -0
  19. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/utils/request_error_handling.py +0 -0
  20. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer/utils/system_requirements.py +0 -0
  21. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer.egg-info/SOURCES.txt +0 -0
  22. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer.egg-info/dependency_links.txt +0 -0
  23. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer.egg-info/entry_points.txt +0 -0
  24. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer.egg-info/requires.txt +0 -0
  25. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/sdv_installer.egg-info/top_level.txt +0 -0
  26. {sdv_installer-0.2.1.dev0 → sdv_installer-0.3.1.dev0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdv-installer
3
- Version: 0.2.1.dev0
3
+ Version: 0.3.1.dev0
4
4
  Summary: Package to install SDV Enterprise packages.
5
5
  Author-email: "DataCebo, Inc." <info@datacebo.com>
6
6
  License-Expression: MIT
@@ -165,7 +165,7 @@ max-doc-length = 100
165
165
  max-line-length = 100
166
166
 
167
167
  [tool.bumpversion]
168
- current_version = "0.2.1.dev0"
168
+ current_version = "0.3.1.dev0"
169
169
  parse = '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<candidate>\d+))?'
170
170
  serialize = [
171
171
  '{major}.{minor}.{patch}.{release}{candidate}',
@@ -4,4 +4,4 @@ from sdv_installer import config, constants
4
4
 
5
5
 
6
6
  __all__ = ('config', 'constants')
7
- __version__ = '0.2.1.dev0'
7
+ __version__ = '0.3.1.dev0'
@@ -5,6 +5,7 @@ import sys
5
5
 
6
6
  from sdv_installer.installation import (
7
7
  download_packages,
8
+ get_auth_file,
8
9
  install_packages,
9
10
  install_packages_from_folder,
10
11
  list_packages,
@@ -13,7 +14,7 @@ from sdv_installer.installation import (
13
14
  from sdv_installer.utils.system_requirements import print_check_results
14
15
 
15
16
  # Adding a new version here to avoid circular imports
16
- SDV_INSTALLER_VERSION = '0.2.1.dev0'
17
+ SDV_INSTALLER_VERSION = '0.3.1.dev0'
17
18
 
18
19
 
19
20
  def install_action(args):
@@ -67,6 +68,16 @@ def list_action(args, parser=None):
67
68
  )
68
69
 
69
70
 
71
+ def authenticate_action(args):
72
+ """Download auth file."""
73
+ get_auth_file(
74
+ username=args.username,
75
+ license_key=args.license_key,
76
+ folder=args.folder,
77
+ credentials=args.credentials,
78
+ )
79
+
80
+
70
81
  def perform_check_action(args):
71
82
  """Perform a check on the user's system to verify compatibility with SDV-Enterprise."""
72
83
  print_check_results()
@@ -130,7 +141,7 @@ def get_parser():
130
141
  required=False,
131
142
  help=(
132
143
  'The package that you want to download. If not provided, all '
133
- 'packages will be downloaded',
144
+ 'packages will be downloaded'
134
145
  ),
135
146
  )
136
147
  download_parser.add_argument(
@@ -171,6 +182,18 @@ def get_parser():
171
182
  '--credentials', required=False, help='Path to a credentials json file.'
172
183
  )
173
184
 
185
+ # Authenticate
186
+ auth_parser = action.add_parser(
187
+ 'authenticate', help='Download auth file to required destination or specified folder.'
188
+ )
189
+ auth_parser.set_defaults(action=authenticate_action)
190
+ auth_parser.add_argument('--username', required=False, help='SDV-Enterprise username.')
191
+ auth_parser.add_argument('--license-key', required=False, help='SDV-Enterprise license key.')
192
+ auth_parser.add_argument('--folder', required=False, help='Destination folder for auth file.')
193
+ auth_parser.add_argument(
194
+ '--credentials', required=False, help='Path to a credentials json file.'
195
+ )
196
+
174
197
  # Check Requirements
175
198
  check_parser = action.add_parser(
176
199
  'check-requirements', help='Check if your system meets SDV Enterprise requirements.'
@@ -8,6 +8,7 @@ LKS_URL = os.getenv('LKS_URL', 'https://lks.datacebo.com')
8
8
  # Endpoints
9
9
  API_PACKAGE_PERMISSIONS = f'{LKS_URL}/api/v1/package_permissions/active'
10
10
  API_VALIDATE = f'{LKS_URL}/api/v1/licenses/validate'
11
+ API_AUTH_FILE = f'{LKS_URL}/api/v1/licenses/auth_file'
11
12
 
12
13
  # Pypi Server to be used
13
14
  PYPI_URL = os.getenv('PYPI_URL', 'pypi.datacebo.com')
@@ -17,6 +17,7 @@ from sdv_installer.config import PYPI_URL
17
17
  MIN_PYTHON_VERSION = Version('3.9')
18
18
  MAX_PYTHON_VERSION = Version('3.14')
19
19
  REQUIRED_BITNESS = '64-bit'
20
+ AUTH_FILE_NAME = 'auth.json'
20
21
 
21
22
  SUPPORTED_PLATFORM_TAGS = [
22
23
  'macosx_10_9_x86_64',
@@ -2,6 +2,7 @@
2
2
 
3
3
  from sdv_installer.installation.installer import (
4
4
  download_packages,
5
+ get_auth_file,
5
6
  install_packages_from_folder,
6
7
  install_packages,
7
8
  list_packages,
@@ -10,6 +11,7 @@ from sdv_installer.installation.installer import (
10
11
 
11
12
  __all__ = (
12
13
  'download_packages',
14
+ 'get_auth_file',
13
15
  'install_packages',
14
16
  'install_packages_from_folder',
15
17
  'list_packages',
@@ -3,16 +3,21 @@
3
3
  import glob
4
4
  import json
5
5
  import logging
6
+ import os
7
+ import pathlib
8
+ import shutil
6
9
  import subprocess
7
10
  import sys
8
11
  from typing import Dict, List, Optional, Union
9
12
 
10
13
  import requests
14
+ from platformdirs import user_data_dir
11
15
  from requests.exceptions import RequestException
12
16
 
13
17
  from sdv_installer import config
14
18
  from sdv_installer.authentication import authenticate
15
19
  from sdv_installer.constants import (
20
+ AUTH_FILE_NAME,
16
21
  CONNECTORS_PACKAGES,
17
22
  EXPECTED_PACKAGES,
18
23
  TRUSTED_HOSTS,
@@ -336,6 +341,85 @@ def _get_packages(username, license_key, package=None, options=None):
336
341
  return package_to_product_type
337
342
 
338
343
 
344
+ def _create_user_data_dir(data_dir, error_message=None):
345
+ if not error_message:
346
+ error_message = "Unable to write auth file to user's data directory. Permissions required."
347
+ try:
348
+ data_dir_path = pathlib.Path(data_dir)
349
+ data_dir_path.mkdir(parents=True, exist_ok=True)
350
+ except PermissionError:
351
+ raise RuntimeError(error_message)
352
+
353
+
354
+ def _save_auth_file(username, license_key, folder=None):
355
+ """Retrieve the auth file for a user and save it to their appdata folder.
356
+
357
+ Args:
358
+ username (str):
359
+ Username of user to get auth file for.
360
+ license_key (str):
361
+ User's license key.
362
+ folder (str | None):
363
+ Folder to save the auth file to.
364
+ """
365
+ error_message = None
366
+ if folder:
367
+ data_dir = folder
368
+ error_message = 'Unable to create specified folder. Permissions required.'
369
+ else:
370
+ data_dir = user_data_dir(appname='sdv-enterprise', appauthor='Datacebo')
371
+
372
+ _create_user_data_dir(data_dir, error_message)
373
+ auth_file_path = pathlib.Path(data_dir, AUTH_FILE_NAME)
374
+ try:
375
+ response = requests.post(
376
+ config.API_AUTH_FILE,
377
+ data=json.dumps({'username': username, 'license_key': license_key}),
378
+ headers=config.HEADERS,
379
+ )
380
+ response.raise_for_status()
381
+ except requests.HTTPError as e:
382
+ raise RuntimeError('Could not fetch auth file') from e
383
+
384
+ auth_json = response.json()
385
+ with open(auth_file_path, 'w') as f:
386
+ json.dump(auth_json, f)
387
+
388
+
389
+ def _move_auth_file(source_folder, destination=None):
390
+ """Move the auth file to the required location.
391
+
392
+ Args:
393
+ source_folder (str):
394
+ The folder the auth file is in.
395
+ destination (str | None):
396
+ The path to move the file to. If None, then move to the user data dir.
397
+ """
398
+ if destination is None:
399
+ destination = user_data_dir(appname='sdv-enterprise', appauthor='Datacebo')
400
+ _create_user_data_dir(destination)
401
+
402
+ auth_file_path = pathlib.Path(source_folder, AUTH_FILE_NAME)
403
+ if os.path.exists(auth_file_path):
404
+ shutil.copy(auth_file_path, pathlib.Path(destination) / AUTH_FILE_NAME)
405
+
406
+
407
+ @authenticate
408
+ def get_auth_file(username=None, license_key=None, folder=None, **kwargs):
409
+ """Retrieve the auth file from the license key service.
410
+
411
+ Args:
412
+ username (str):
413
+ The username for SDV Enterprise.
414
+ license_key (str):
415
+ The license key.
416
+ folder (str):
417
+ The folder path to save the auth file to. If None, it will save to the
418
+ location SDV Enterprise requires.
419
+ """
420
+ _save_auth_file(username=username, license_key=license_key, folder=folder)
421
+
422
+
339
423
  @authenticate
340
424
  def install_packages(
341
425
  username=None,
@@ -348,6 +432,7 @@ def install_packages(
348
432
  **kwargs,
349
433
  ):
350
434
  """Install packages in the current environment (online)."""
435
+ _save_auth_file(username, license_key)
351
436
  all_sdv_enterprise_related_pkgs = _get_accessible_packages(username, license_key)
352
437
  packages_before_install = list_current_installed_packages()
353
438
 
@@ -381,6 +466,7 @@ def install_packages(
381
466
  def install_packages_from_folder(folder, package=None, options=None, debug=False):
382
467
  """Install packages from a folder (offline)."""
383
468
  wheels = glob.glob(f'{folder}/*.whl')
469
+ _move_auth_file(folder)
384
470
  packages = set()
385
471
  for wheel in wheels:
386
472
  package_name = get_package_name(wheel)
@@ -468,6 +554,7 @@ def download_packages(
468
554
  **kwargs,
469
555
  ):
470
556
  """Download packages into a local folder for offline installation."""
557
+ _save_auth_file(username, license_key, folder=folder)
471
558
  packages = _get_packages(
472
559
  username=username, license_key=license_key, package=package, options=options
473
560
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdv-installer
3
- Version: 0.2.1.dev0
3
+ Version: 0.3.1.dev0
4
4
  Summary: Package to install SDV Enterprise packages.
5
5
  Author-email: "DataCebo, Inc." <info@datacebo.com>
6
6
  License-Expression: MIT
@@ -28,13 +28,13 @@ def authenticate_user_and_license_key(username, license_key):
28
28
  license_key (str):
29
29
  The license key to authenticate.
30
30
 
31
- Raises:
32
- InvalidLoginCredentials:
33
- If the user has provided invalid login credentials.
34
-
35
31
  Returns:
36
32
  bool:
37
33
  True if authentication is successful, False otherwise.
34
+
35
+ Raises:
36
+ InvalidLoginCredentials:
37
+ If the user has provided invalid login credentials.
38
38
  """
39
39
  post_data = {'username': username, 'license_key': license_key}
40
40
  try: