ivaldi 0.3.2__tar.gz → 0.3.4__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.4
4
4
  Summary: Create a portable version of your Python Project
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -89,7 +89,7 @@ version = "3.14.5"
89
89
 
90
90
  ```
91
91
 
92
- When no standalone configuration exists, Ivaldi extracts only `[tool.ivaldi]` and writes it to a project-root `ivaldi.toml` before building. Generated files include a schema directive and are refreshed when `[tool.ivaldi]` changes; a hand-written standalone file remains authoritative. The formal configuration definition is available in [`ivaldi.schema.json`](ivaldi.schema.json), and the same schema describes the object nested under `[tool.ivaldi]`.
92
+ When no standalone configuration exists, Ivaldi extracts only `[tool.ivaldi]` and writes it to a project-root `ivaldi.toml` before building. Generated files include a schema directive and are refreshed when `[tool.ivaldi]` changes; a hand-written standalone file remains authoritative. The formal configuration definition is available in [`ivaldi.schema.json`](https://github.com/FionnT/Ivaldi/blob/main/ivaldi.schema.json), and the same schema describes the object nested under `[tool.ivaldi]`.
93
93
 
94
94
  ---
95
95
 
@@ -97,56 +97,64 @@ When no standalone configuration exists, Ivaldi extracts only `[tool.ivaldi]` an
97
97
 
98
98
  ## Configuration Flags
99
99
 
100
- All default settings and flags are visible in [the ivaldi settings dataclass](/ivaldi/types/settings.py)
100
+ All default settings and flags are visible in [the ivaldi settings dataclass](https://github.com/FionnT/Ivaldi/blob/main/ivaldi/types/settings.py)
101
101
 
102
102
 
103
103
  ```yaml
104
- app.entrypoint:
105
- description: The entrypoint for your application. Can be a module e.g. `mycli` or a specific command, e.g. `mycli:main`
106
- type: str
107
- example: mycli:main
108
- app.include:
109
- description: Controls which source files are copied to Ivaldi's clean wheel-build stage.
110
- note: `pyproject.toml` is always included. Add any files referenced by the build configuration, such as a README or license.
111
- type: list[glob]
112
- example: ["*.py"]
113
- app.exclude:
114
- description: Specify files to exclude by a matching pattern.
115
- note: If a file would be excluded, but a more specific include would include it, it is superseded by include
116
- type: list[glob]
117
- example: ["*.pyc"]
118
- [uv,python].version:
119
- description: Which Python or UVX version to use for your application.
120
- No compatability checks are performed, and the wrapped executable does not compile with these versions.
121
- `ivaldi build` will use local Python and UV, fetching only UV if required.
122
- [uv,uvx,python].install_args:
123
- description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
124
- note: Overwrites defaults, does not merge them.
125
- type: list[flag]
126
- example: ["--compile",]
127
- [uv,uvx,python].build_args:
128
- description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
129
- note: Overwrites defaults, does not merge them.
130
- type: list[flag]
131
- example: ["--compile",]
132
- add_to_path:
133
- description: When true, Ivaldi copies the launcher into the platform bin directory (e.g. `~/.local/bin`, `~/.bin`)
134
- type: bool
135
- alias:
136
- description: In Unix-like systems, adds an idempotent managed alias pointing to that copy.
137
- note: Attempts to locate the active shell's startup file (`.zshrc`, `.bash_profile`, `.bashrc`, Fish's `config.fish`, or `.profile` as applicable).
138
- When false, no command alias is installed. Your command might still be accessible if `add_to_path` was `true`
139
- type: string
140
- admin:
141
- description: Requires sudo/administrator privileges for installation or application runs.
142
- note: Ivaldi does not elevate itself. It stops and asks to be rerun with sudo (or as Administrator on Windows).
143
- values:
144
- - `install` requires sudo only for first-run installation. exits after installation so the application can subsequently be run without elevation.
145
- - `run` requires sudo only for running the installed application.
146
- - `true` requires sudo for running and installation.
147
- - `false` never requires them.
148
- type: Literal[true, false, 'install', 'run']
149
- nuitka:
104
+ [app]
105
+ entrypoint:
106
+ description: The entrypoint for your application. Can be a module e.g. `mycli` or a specific command, e.g. `mycli:main`
107
+ type: str
108
+ example: mycli:main
109
+ include:
110
+ description: Controls which source files are copied to Ivaldi's clean wheel-build stage.
111
+ note: `pyproject.toml` is always included. Add any files referenced by the build configuration, such as a README or license.
112
+ type: list[glob]
113
+ example: ["*.py"]
114
+ exclude:
115
+ description: Specify files to exclude by a matching pattern.
116
+ note: If a file would be excluded, but a more specific include would include it, it is superseded by include
117
+ type: list[glob]
118
+ example: ["*.pyc"]
119
+ [uv,python]
120
+ version:
121
+ description: Which Python or UVX version to use for your application.
122
+ No compatability checks are performed, and the wrapped executable does not compile with these versions.
123
+ `ivaldi build` will use local Python and UV, fetching only UV if required.
124
+ install_args:
125
+ description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
126
+ note: Overwrites defaults, does not merge them.
127
+ type: list[flag]
128
+ example: ["--compile"]
129
+ [uv,uvx,python,nuitka]:
130
+ build_args:
131
+ description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
132
+ note: Overwrites defaults, does not merge them.
133
+ type: list[flag]
134
+ example: ["--compile",]
135
+ [darwin, windows, linux]:
136
+ location:
137
+ description: The name for a specific subdirectory to install the project to, inside cache directory for that platform (e.g. $HOME/local/.bin)
138
+ type: str
139
+ example: mycli
140
+ add_to_path:
141
+ description: When true, Ivaldi copies the launcher into the platform bin directory (e.g. `~/.local/bin`, `~/.bin`)
142
+ type: bool
143
+ alias:
144
+ description: In Unix-like systems, adds an idempotent managed alias pointing to that copy.
145
+ note: Attempts to locate the active shell's startup file (`.zshrc`, `.bash_profile`, `.bashrc`, Fish's `config.fish`, or `.profile` as applicable).
146
+ When false, no command alias is installed. Your command might still be accessible if `add_to_path` was `true`
147
+ type: string
148
+ admin:
149
+ description: Requires sudo/administrator privileges for installation or application runs.
150
+ note: Ivaldi does not elevate itself. It stops and asks to be rerun with sudo (or as Administrator on Windows).
151
+ values:
152
+ - `install` requires sudo only for first-run installation. exits after installation so the application can subsequently be run without elevation.
153
+ - `run` requires sudo only for running the installed application.
154
+ - `true` requires sudo for running and installation.
155
+ - `false` never requires them.
156
+ type: Literal[true, false, 'install', 'run']
157
+ [nuitka]:
150
158
  description: Nuitka metadata is passed as `--company-name`, `--product-name`, and `--file-description`.
151
159
  note: Relative icon paths are resolved from the wrapped project and translated to the platform-specific Nuitka icon option.
152
160
  name:
@@ -69,7 +69,7 @@ version = "3.14.5"
69
69
 
70
70
  ```
71
71
 
72
- When no standalone configuration exists, Ivaldi extracts only `[tool.ivaldi]` and writes it to a project-root `ivaldi.toml` before building. Generated files include a schema directive and are refreshed when `[tool.ivaldi]` changes; a hand-written standalone file remains authoritative. The formal configuration definition is available in [`ivaldi.schema.json`](ivaldi.schema.json), and the same schema describes the object nested under `[tool.ivaldi]`.
72
+ When no standalone configuration exists, Ivaldi extracts only `[tool.ivaldi]` and writes it to a project-root `ivaldi.toml` before building. Generated files include a schema directive and are refreshed when `[tool.ivaldi]` changes; a hand-written standalone file remains authoritative. The formal configuration definition is available in [`ivaldi.schema.json`](https://github.com/FionnT/Ivaldi/blob/main/ivaldi.schema.json), and the same schema describes the object nested under `[tool.ivaldi]`.
73
73
 
74
74
  ---
75
75
 
@@ -77,56 +77,64 @@ When no standalone configuration exists, Ivaldi extracts only `[tool.ivaldi]` an
77
77
 
78
78
  ## Configuration Flags
79
79
 
80
- All default settings and flags are visible in [the ivaldi settings dataclass](/ivaldi/types/settings.py)
80
+ All default settings and flags are visible in [the ivaldi settings dataclass](https://github.com/FionnT/Ivaldi/blob/main/ivaldi/types/settings.py)
81
81
 
82
82
 
83
83
  ```yaml
84
- app.entrypoint:
85
- description: The entrypoint for your application. Can be a module e.g. `mycli` or a specific command, e.g. `mycli:main`
86
- type: str
87
- example: mycli:main
88
- app.include:
89
- description: Controls which source files are copied to Ivaldi's clean wheel-build stage.
90
- note: `pyproject.toml` is always included. Add any files referenced by the build configuration, such as a README or license.
91
- type: list[glob]
92
- example: ["*.py"]
93
- app.exclude:
94
- description: Specify files to exclude by a matching pattern.
95
- note: If a file would be excluded, but a more specific include would include it, it is superseded by include
96
- type: list[glob]
97
- example: ["*.pyc"]
98
- [uv,python].version:
99
- description: Which Python or UVX version to use for your application.
100
- No compatability checks are performed, and the wrapped executable does not compile with these versions.
101
- `ivaldi build` will use local Python and UV, fetching only UV if required.
102
- [uv,uvx,python].install_args:
103
- description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
104
- note: Overwrites defaults, does not merge them.
105
- type: list[flag]
106
- example: ["--compile",]
107
- [uv,uvx,python].build_args:
108
- description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
109
- note: Overwrites defaults, does not merge them.
110
- type: list[flag]
111
- example: ["--compile",]
112
- add_to_path:
113
- description: When true, Ivaldi copies the launcher into the platform bin directory (e.g. `~/.local/bin`, `~/.bin`)
114
- type: bool
115
- alias:
116
- description: In Unix-like systems, adds an idempotent managed alias pointing to that copy.
117
- note: Attempts to locate the active shell's startup file (`.zshrc`, `.bash_profile`, `.bashrc`, Fish's `config.fish`, or `.profile` as applicable).
118
- When false, no command alias is installed. Your command might still be accessible if `add_to_path` was `true`
119
- type: string
120
- admin:
121
- description: Requires sudo/administrator privileges for installation or application runs.
122
- note: Ivaldi does not elevate itself. It stops and asks to be rerun with sudo (or as Administrator on Windows).
123
- values:
124
- - `install` requires sudo only for first-run installation. exits after installation so the application can subsequently be run without elevation.
125
- - `run` requires sudo only for running the installed application.
126
- - `true` requires sudo for running and installation.
127
- - `false` never requires them.
128
- type: Literal[true, false, 'install', 'run']
129
- nuitka:
84
+ [app]
85
+ entrypoint:
86
+ description: The entrypoint for your application. Can be a module e.g. `mycli` or a specific command, e.g. `mycli:main`
87
+ type: str
88
+ example: mycli:main
89
+ include:
90
+ description: Controls which source files are copied to Ivaldi's clean wheel-build stage.
91
+ note: `pyproject.toml` is always included. Add any files referenced by the build configuration, such as a README or license.
92
+ type: list[glob]
93
+ example: ["*.py"]
94
+ exclude:
95
+ description: Specify files to exclude by a matching pattern.
96
+ note: If a file would be excluded, but a more specific include would include it, it is superseded by include
97
+ type: list[glob]
98
+ example: ["*.pyc"]
99
+ [uv,python]
100
+ version:
101
+ description: Which Python or UVX version to use for your application.
102
+ No compatability checks are performed, and the wrapped executable does not compile with these versions.
103
+ `ivaldi build` will use local Python and UV, fetching only UV if required.
104
+ install_args:
105
+ description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
106
+ note: Overwrites defaults, does not merge them.
107
+ type: list[flag]
108
+ example: ["--compile"]
109
+ [uv,uvx,python,nuitka]:
110
+ build_args:
111
+ description: Are passed through to the corresponding UV, UVX, Python, and Nuitka commands.
112
+ note: Overwrites defaults, does not merge them.
113
+ type: list[flag]
114
+ example: ["--compile",]
115
+ [darwin, windows, linux]:
116
+ location:
117
+ description: The name for a specific subdirectory to install the project to, inside cache directory for that platform (e.g. $HOME/local/.bin)
118
+ type: str
119
+ example: mycli
120
+ add_to_path:
121
+ description: When true, Ivaldi copies the launcher into the platform bin directory (e.g. `~/.local/bin`, `~/.bin`)
122
+ type: bool
123
+ alias:
124
+ description: In Unix-like systems, adds an idempotent managed alias pointing to that copy.
125
+ note: Attempts to locate the active shell's startup file (`.zshrc`, `.bash_profile`, `.bashrc`, Fish's `config.fish`, or `.profile` as applicable).
126
+ When false, no command alias is installed. Your command might still be accessible if `add_to_path` was `true`
127
+ type: string
128
+ admin:
129
+ description: Requires sudo/administrator privileges for installation or application runs.
130
+ note: Ivaldi does not elevate itself. It stops and asks to be rerun with sudo (or as Administrator on Windows).
131
+ values:
132
+ - `install` requires sudo only for first-run installation. exits after installation so the application can subsequently be run without elevation.
133
+ - `run` requires sudo only for running the installed application.
134
+ - `true` requires sudo for running and installation.
135
+ - `false` never requires them.
136
+ type: Literal[true, false, 'install', 'run']
137
+ [nuitka]:
130
138
  description: Nuitka metadata is passed as `--company-name`, `--product-name`, and `--file-description`.
131
139
  note: Relative icon paths are resolved from the wrapped project and translated to the platform-specific Nuitka icon option.
132
140
  name:
@@ -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.4"
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