ivaldi 0.3.2__tar.gz → 0.3.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ivaldi
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Create a portable version of your Python Project
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -1,6 +1,7 @@
1
1
  import platform
2
2
  from pathlib import Path
3
3
 
4
+ from ivaldi.shared.admin import restore_sudo_ownership
4
5
  from ivaldi.shared.alias import install_alias
5
6
  from ivaldi.shared.project import install_project, mark_installed
6
7
  from ivaldi.shared.python import install_python
@@ -12,13 +13,17 @@ system = platform.system()
12
13
 
13
14
  def install(location, executable: Path | None = None):
14
15
  settings = load_settings(location=location, build=False)
15
- settings = load_install_directories(settings)
16
16
 
17
- install_uv(settings)
18
- install_python(settings)
19
- install_project(settings)
17
+ try:
18
+ settings = load_install_directories(settings)
19
+ install_uv(settings)
20
+ install_python(settings)
21
+ install_project(settings)
20
22
 
21
- alias = install_alias(settings, executable)
22
- if not settings.platform.add_to_path or alias is not None:
23
- mark_installed(settings)
23
+ alias = install_alias(settings, executable)
24
+ if not settings.platform.add_to_path or alias is not None:
25
+ mark_installed(settings)
26
+ finally:
27
+ if settings.dirs.app is not None:
28
+ restore_sudo_ownership(settings.dirs.app)
24
29
  return settings
@@ -0,0 +1,77 @@
1
+ import os
2
+ from dataclasses import dataclass
3
+ from pathlib import Path
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class User:
8
+ uid: int
9
+ gid: int
10
+ home: Path
11
+
12
+
13
+ def sudo_user() -> User | None:
14
+ """Return the user who invoked sudo, when running elevated on POSIX."""
15
+ if os.name == "nt" or os.geteuid() != 0:
16
+ return None
17
+
18
+ try:
19
+ uid = int(os.environ["SUDO_UID"])
20
+ gid = int(os.environ["SUDO_GID"])
21
+ except KeyError:
22
+ return None
23
+ except ValueError:
24
+ return None
25
+
26
+ if uid <= 0 or gid < 0:
27
+ return None
28
+
29
+ import pwd
30
+
31
+ try:
32
+ home = Path(pwd.getpwuid(uid).pw_dir)
33
+ except KeyError:
34
+ return None
35
+ return User(uid=uid, gid=gid, home=home)
36
+
37
+
38
+ def user_home() -> Path:
39
+ """Return the invoking user's home, rather than root's home under sudo."""
40
+ user = sudo_user()
41
+ return user.home if user is not None else Path.home()
42
+
43
+
44
+ def restore_sudo_ownership(path: Path) -> None:
45
+ """Return an elevated install tree to the user who invoked sudo.
46
+
47
+ Windows elevation retains the user's SID and files created below AppData
48
+ inherit that user's ACL, so no ownership repair is necessary there.
49
+ """
50
+ user = sudo_user()
51
+ if user is None or not path.exists():
52
+ return
53
+
54
+ for directory, directories, files in os.walk(path, topdown=False, followlinks=False):
55
+ for name in (*directories, *files):
56
+ os.chown(Path(directory) / name, user.uid, user.gid, follow_symlinks=False)
57
+ os.chown(directory, user.uid, user.gid, follow_symlinks=False)
58
+
59
+
60
+ def needs_admin(admin: bool | str, phase: str) -> bool:
61
+ """Return whether a configured phase requires administrator privileges."""
62
+ return admin is True or admin == phase
63
+
64
+
65
+ def is_admin() -> bool:
66
+ if os.name == "nt":
67
+ import ctypes
68
+
69
+ return bool(ctypes.windll.shell32.IsUserAnAdmin())
70
+ return os.geteuid() == 0
71
+
72
+
73
+ def run_elevated(*_args, **_kwargs):
74
+ """Stop and ask the user to restart the launcher with elevated privileges."""
75
+ if os.name == "nt":
76
+ raise SystemExit("Administrator privileges are required; rerun this command as Administrator")
77
+ raise SystemExit("Administrator privileges are required; rerun this command with sudo")
@@ -6,6 +6,7 @@ import shutil
6
6
  import tomllib
7
7
  from pathlib import Path
8
8
 
9
+ from ivaldi.shared.admin import user_home
9
10
  from ivaldi.types.enums import IVALDI
10
11
  from ivaldi.types.settings import UV, UVX, App, Directories, Nuitka, Platform, Python, Settings
11
12
 
@@ -18,7 +19,7 @@ GENERATED_CONFIG_HEADER = "# Generated from [tool.ivaldi] in pyproject.toml"
18
19
  def set_platform_home(settings):
19
20
 
20
21
  if system == "Darwin":
21
- home = Path.home()
22
+ home = user_home()
22
23
  settings.dirs.exec = (home / "bin").resolve()
23
24
  settings.dirs.app = home / "Library" / "Application Support" / settings.platform.location
24
25
  elif system == "Windows":
@@ -26,7 +27,7 @@ def set_platform_home(settings):
26
27
  settings.dirs.exec = (Path(os.environ["LOCALAPPDATA"]) / "Microsoft" / "WindowsApps").resolve()
27
28
 
28
29
  elif system == "Linux":
29
- home = Path.home()
30
+ home = user_home()
30
31
  settings.dirs.exec = home / ".local" / "bin"
31
32
  settings.dirs.app = Path(os.environ.get("XDG_DATA_HOME", home / ".local" / "share")) / settings.platform.location
32
33
  else:
@@ -23,7 +23,6 @@ class App:
23
23
  if isinstance(self.install, dict):
24
24
  self.install = AppInstall(**self.install)
25
25
 
26
- version: str = "0.8.9"
27
26
  entrypoint: str = None
28
27
  include: list[str] = field(default_factory=list)
29
28
  exclude: list[str] = field(
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ivaldi"
3
- version = "0.3.2"
3
+ version = "0.3.3"
4
4
  description = "Create a portable version of your Python Project"
5
5
  authors = [
6
6
  {name = "Fionn Tolster (@FionnT)"}
@@ -1,21 +0,0 @@
1
- import os
2
-
3
-
4
- def needs_admin(admin: bool | str, phase: str) -> bool:
5
- """Return whether a configured phase requires administrator privileges."""
6
- return admin is True or admin == phase
7
-
8
-
9
- def is_admin() -> bool:
10
- if os.name == "nt":
11
- import ctypes
12
-
13
- return bool(ctypes.windll.shell32.IsUserAnAdmin())
14
- return os.geteuid() == 0
15
-
16
-
17
- def run_elevated(*_args, **_kwargs):
18
- """Stop and ask the user to restart the launcher with elevated privileges."""
19
- if os.name == "nt":
20
- raise SystemExit("Administrator privileges are required; rerun this command as Administrator")
21
- raise SystemExit("Administrator privileges are required; rerun this command with sudo")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes