ducktools-env 0.2.2__tar.gz → 0.2.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.
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/PKG-INFO +6 -6
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/README.md +5 -5
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/__init__.py +5 -1
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/__main__.py +24 -9
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/_run.py +26 -12
- ducktools_env-0.2.4/src/ducktools/env/_version.py +2 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/bootstrapping/bootstrap.py +1 -2
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/bootstrapping/bundle_main.py +4 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/catalogue.py +1 -1
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/exceptions.py +6 -6
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/manager.py +22 -9
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/register.py +3 -3
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/scripts/get_pip.py +10 -10
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/scripts/get_uv.py +1 -1
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools_env.egg-info/PKG-INFO +6 -6
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_get_uv.py +3 -1
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_register.py +2 -1
- ducktools_env-0.2.2/src/ducktools/env/_version.py +0 -2
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/.github/dependabot.yml +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/.github/workflows/auto_test.yml +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/.github/workflows/build_zipapp.yml +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/.github/workflows/publish_to_pypi.yml +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/.github/workflows/publish_to_testpypi.yml +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/.gitignore +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/LICENSE +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/examples/application/cowsay_app.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/examples/inline/cowsay_ex.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/examples/inline/empty_311_env.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/examples/inline/empty_312_env.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/examples/inline/pep_723_example.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/examples/inline/print_environment_variables.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/pyproject.toml +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/setup.cfg +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/_lazy_imports.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/_logger.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/_sqlclasses.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/bootstrapping/version_check.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/bootstrapping/zipapp_main.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/bundle.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/bundled_data.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/config.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/environment_specs.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/platform_paths.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/scripts/__init__.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/scripts/create_zipapp.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools_env.egg-info/SOURCES.txt +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools_env.egg-info/dependency_links.txt +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools_env.egg-info/entry_points.txt +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools_env.egg-info/requires.txt +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools_env.egg-info/top_level.txt +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/conftest.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/data/pip-24.1.pyz +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/data/pip-24.2.pyz +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/data/uv_python_versions_list.txt +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/cowsay_app.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/cowsay_app.py.lock +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/cowsay_ex.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/cowsay_ex.py.lock +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/cowsay_ex_nolock.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/invalid_app.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/pep_723_example.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/pep_723_example_subset.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/print_environment_variables.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/spec_error.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_bundled_data.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_catalogue.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_config.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_environmentspec.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_fixtures_active.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_get_pip.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_integration/test_build_retrieve.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_logger.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_manager.py +0 -0
- {ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/test_platform_paths.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ducktools-env
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Virtual environment management tools and application bundle builder
|
|
5
5
|
Author: David C Ellis
|
|
6
6
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
@@ -47,19 +47,19 @@ can define its own requirements.
|
|
|
47
47
|
However, using this format requires the use of an extra package such as 'UV' or 'hatch'
|
|
48
48
|
using a specific command such as `uv run my_script.py` or `hatch run my_script.py`.
|
|
49
49
|
|
|
50
|
-
`ducktools
|
|
50
|
+
`ducktools-env` is designed to bundle your script into a Python
|
|
51
51
|
[zipapp](https://docs.python.org/3/library/zipapp.html) which can be run by any
|
|
52
52
|
Python 3.10+ install and will handle creating the virtualenv and launching the script
|
|
53
53
|
with the appropriate dependencies *without* needing the other user to have any
|
|
54
54
|
specific script running tool installed.
|
|
55
55
|
|
|
56
|
-
To aid this, `ducktools
|
|
56
|
+
To aid this, `ducktools-env` provides the `bundle` and `run` commands.
|
|
57
57
|
|
|
58
|
-
`ducktools
|
|
58
|
+
`ducktools-env run my_script.py`
|
|
59
59
|
|
|
60
60
|
Will run your script much like some of the other script runners.
|
|
61
61
|
|
|
62
|
-
`ducktools
|
|
62
|
+
`ducktools-env bundle my_script.py`
|
|
63
63
|
|
|
64
64
|
Will then generate a zipapp bundle of your script and the required tools to extract and
|
|
65
65
|
execute it in the same way as it is executed via the `run` command.
|
|
@@ -106,7 +106,7 @@ The tool can be used in multiple ways:
|
|
|
106
106
|
* Accessed directly via `uvx` with uv
|
|
107
107
|
* `uvx ducktools-env <command>`
|
|
108
108
|
|
|
109
|
-
These examples will use the ducktools-env as the base as if installed via `uv tool` or a similar tool.
|
|
109
|
+
These examples will use the `ducktools-env` command as the base as if installed via `uv tool` or a similar tool.
|
|
110
110
|
|
|
111
111
|
Run a script that uses inline script metadata:
|
|
112
112
|
|
|
@@ -20,19 +20,19 @@ can define its own requirements.
|
|
|
20
20
|
However, using this format requires the use of an extra package such as 'UV' or 'hatch'
|
|
21
21
|
using a specific command such as `uv run my_script.py` or `hatch run my_script.py`.
|
|
22
22
|
|
|
23
|
-
`ducktools
|
|
23
|
+
`ducktools-env` is designed to bundle your script into a Python
|
|
24
24
|
[zipapp](https://docs.python.org/3/library/zipapp.html) which can be run by any
|
|
25
25
|
Python 3.10+ install and will handle creating the virtualenv and launching the script
|
|
26
26
|
with the appropriate dependencies *without* needing the other user to have any
|
|
27
27
|
specific script running tool installed.
|
|
28
28
|
|
|
29
|
-
To aid this, `ducktools
|
|
29
|
+
To aid this, `ducktools-env` provides the `bundle` and `run` commands.
|
|
30
30
|
|
|
31
|
-
`ducktools
|
|
31
|
+
`ducktools-env run my_script.py`
|
|
32
32
|
|
|
33
33
|
Will run your script much like some of the other script runners.
|
|
34
34
|
|
|
35
|
-
`ducktools
|
|
35
|
+
`ducktools-env bundle my_script.py`
|
|
36
36
|
|
|
37
37
|
Will then generate a zipapp bundle of your script and the required tools to extract and
|
|
38
38
|
execute it in the same way as it is executed via the `run` command.
|
|
@@ -79,7 +79,7 @@ The tool can be used in multiple ways:
|
|
|
79
79
|
* Accessed directly via `uvx` with uv
|
|
80
80
|
* `uvx ducktools-env <command>`
|
|
81
81
|
|
|
82
|
-
These examples will use the ducktools-env as the base as if installed via `uv tool` or a similar tool.
|
|
82
|
+
These examples will use the `ducktools-env` command as the base as if installed via `uv tool` or a similar tool.
|
|
83
83
|
|
|
84
84
|
Run a script that uses inline script metadata:
|
|
85
85
|
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
# SOFTWARE.
|
|
23
23
|
|
|
24
|
-
from ._version import
|
|
24
|
+
from ._version import (
|
|
25
|
+
__version__ as __version__,
|
|
26
|
+
__version_tuple__ as __version_tuple__
|
|
27
|
+
)
|
|
25
28
|
|
|
26
29
|
|
|
27
30
|
MINIMUM_PYTHON = (3, 10)
|
|
@@ -29,6 +32,7 @@ MINIMUM_PYTHON_STR = ".".join(str(v) for v in MINIMUM_PYTHON)
|
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
PROJECT_NAME = "ducktools"
|
|
35
|
+
APP_COMMAND = "ducktools-env"
|
|
32
36
|
|
|
33
37
|
FOLDER_ENVVAR = "DUCKTOOLS_ENV_FOLDER"
|
|
34
38
|
LAUNCH_TYPE_ENVVAR = "DUCKTOOLS_ENV_LAUNCH_TYPE"
|
|
@@ -64,9 +64,9 @@ class FixedArgumentParser(argparse.ArgumentParser):
|
|
|
64
64
|
return self.formatter_class(prog=self.prog, width=columns-2)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
def get_parser(exit_on_error=True) -> FixedArgumentParser:
|
|
67
|
+
def get_parser(prog, exit_on_error=True) -> FixedArgumentParser:
|
|
68
68
|
parser = FixedArgumentParser(
|
|
69
|
-
prog=
|
|
69
|
+
prog=prog,
|
|
70
70
|
description="Script runner and bundler for scripts with inline dependencies",
|
|
71
71
|
exit_on_error=exit_on_error,
|
|
72
72
|
)
|
|
@@ -285,7 +285,12 @@ def get_columns(
|
|
|
285
285
|
|
|
286
286
|
|
|
287
287
|
def main():
|
|
288
|
-
|
|
288
|
+
if __name__ == "__main__":
|
|
289
|
+
command = f"{os.path.basename(sys.executable)} -m ducktools.env"
|
|
290
|
+
else:
|
|
291
|
+
command = os.path.basename(sys.argv[0])
|
|
292
|
+
|
|
293
|
+
parser = get_parser(prog=command)
|
|
289
294
|
args, unknown = parser.parse_known_args()
|
|
290
295
|
|
|
291
296
|
if unknown:
|
|
@@ -303,12 +308,15 @@ def main():
|
|
|
303
308
|
parser.error(f"unrecognised arguments: {unknown_s}")
|
|
304
309
|
|
|
305
310
|
# Create a manager
|
|
306
|
-
manager = _laz.Manager(
|
|
311
|
+
manager = _laz.Manager(
|
|
312
|
+
project_name=PROJECT_NAME,
|
|
313
|
+
command=command,
|
|
314
|
+
)
|
|
307
315
|
|
|
308
316
|
if args.command == "run":
|
|
309
317
|
# Split on existence of the command as a file, if the file exists run it
|
|
310
318
|
# Otherwise look for it in the registered scripts database
|
|
311
|
-
if os.path.
|
|
319
|
+
if os.path.isfile(args.script_filename):
|
|
312
320
|
manager.run_script(
|
|
313
321
|
script_path=args.script_filename,
|
|
314
322
|
script_args=args.script_args,
|
|
@@ -324,14 +332,13 @@ def main():
|
|
|
324
332
|
)
|
|
325
333
|
|
|
326
334
|
elif args.command == "bundle":
|
|
327
|
-
|
|
335
|
+
manager.create_bundle(
|
|
328
336
|
script_path=args.script_filename,
|
|
329
337
|
with_lock=args.with_lock,
|
|
330
338
|
generate_lock=args.generate_lock,
|
|
331
339
|
output_file=args.output,
|
|
332
|
-
compressed=args.
|
|
340
|
+
compressed=args.compress,
|
|
333
341
|
)
|
|
334
|
-
print(f"Bundle created at '{bundle_path}'")
|
|
335
342
|
|
|
336
343
|
elif args.command == "register":
|
|
337
344
|
if args.remove:
|
|
@@ -432,4 +439,12 @@ def main():
|
|
|
432
439
|
|
|
433
440
|
|
|
434
441
|
if __name__ == "__main__":
|
|
435
|
-
|
|
442
|
+
try:
|
|
443
|
+
main()
|
|
444
|
+
except RuntimeError as e:
|
|
445
|
+
errors = "\n".join(e.args) + "\n"
|
|
446
|
+
if sys.stderr:
|
|
447
|
+
sys.stderr.write(errors)
|
|
448
|
+
sys.exit(1)
|
|
449
|
+
|
|
450
|
+
sys.exit(0)
|
|
@@ -41,15 +41,29 @@ def run():
|
|
|
41
41
|
# First argument is the path to this script
|
|
42
42
|
_, app, *args = sys.argv
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
# This has been invoked by dtrun, but errors should show ducktools-env
|
|
45
|
+
command = "ducktools-env"
|
|
46
|
+
|
|
47
|
+
manager = Manager(
|
|
48
|
+
project_name=PROJECT_NAME,
|
|
49
|
+
command=command,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
if os.path.isfile(app):
|
|
54
|
+
manager.run_script(
|
|
55
|
+
script_path=app,
|
|
56
|
+
script_args=args,
|
|
57
|
+
)
|
|
58
|
+
else:
|
|
59
|
+
manager.run_registered_script(
|
|
60
|
+
script_name=app,
|
|
61
|
+
script_args=args,
|
|
62
|
+
)
|
|
63
|
+
except RuntimeError as e:
|
|
64
|
+
msg = "\n".join(e.args) + "\n"
|
|
65
|
+
if sys.stderr:
|
|
66
|
+
sys.stderr.write(msg)
|
|
67
|
+
sys.exit(1)
|
|
68
|
+
|
|
69
|
+
sys.exit(0)
|
|
@@ -103,8 +103,7 @@ def launch_script(script_file, zipapp_path, args, lockdata=None):
|
|
|
103
103
|
sys.path.insert(0, default_paths.env_folder)
|
|
104
104
|
try:
|
|
105
105
|
from ducktools.env.manager import Manager
|
|
106
|
-
|
|
107
|
-
manager = Manager(PROJECT_NAME)
|
|
106
|
+
manager = Manager(project_name=PROJECT_NAME)
|
|
108
107
|
manager.run_bundle(
|
|
109
108
|
script_path=script_file,
|
|
110
109
|
script_args=args,
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
# SOFTWARE.
|
|
23
23
|
|
|
24
|
+
# Suppress ruff error for imports not at the top of the file,
|
|
25
|
+
# version check needs to come first.
|
|
26
|
+
# ruff: noqa: E402
|
|
27
|
+
|
|
24
28
|
# This becomes the bundler bootstrap python script
|
|
25
29
|
import sys
|
|
26
30
|
|
|
@@ -26,7 +26,7 @@ import sys
|
|
|
26
26
|
import os.path
|
|
27
27
|
from datetime import datetime as _datetime, timedelta as _timedelta
|
|
28
28
|
|
|
29
|
-
from ducktools.classbuilder.prefab import prefab
|
|
29
|
+
from ducktools.classbuilder.prefab import prefab
|
|
30
30
|
|
|
31
31
|
from ._sqlclasses import SQLAttribute, SQLClass, SQLContext
|
|
32
32
|
from .exceptions import InvalidEnvironmentSpec, VenvBuildError, ApplicationError
|
|
@@ -38,6 +38,12 @@ class InvalidBundleScript(EnvError):
|
|
|
38
38
|
pass
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
class ScriptNotFound(EnvError):
|
|
42
|
+
"""
|
|
43
|
+
Error if a registered script is not found
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
|
|
41
47
|
class ApplicationError(EnvError):
|
|
42
48
|
"""
|
|
43
49
|
Error if an outdated application attempted to run
|
|
@@ -53,9 +59,3 @@ class InvalidPipDownload(EnvError):
|
|
|
53
59
|
Error if the hash value of the downloaded `pip` does not match
|
|
54
60
|
the value this application has for that version.
|
|
55
61
|
"""
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class UVUnavailableError(EnvError):
|
|
59
|
-
"""
|
|
60
|
-
Error if UV is not available and can't be installed.
|
|
61
|
-
"""
|
|
@@ -29,6 +29,7 @@ from ducktools.classbuilder.prefab import Prefab, attribute
|
|
|
29
29
|
from . import (
|
|
30
30
|
FOLDER_ENVVAR,
|
|
31
31
|
PROJECT_NAME,
|
|
32
|
+
APP_COMMAND,
|
|
32
33
|
DATA_BUNDLE_ENVVAR,
|
|
33
34
|
DATA_BUNDLE_FOLDER,
|
|
34
35
|
LAUNCH_ENVIRONMENT_ENVVAR,
|
|
@@ -40,7 +41,11 @@ from .config import Config
|
|
|
40
41
|
from .platform_paths import ManagedPaths
|
|
41
42
|
from .catalogue import TemporaryCatalogue, ApplicationCatalogue
|
|
42
43
|
from .environment_specs import EnvironmentSpec
|
|
43
|
-
from .exceptions import
|
|
44
|
+
from .exceptions import (
|
|
45
|
+
InvalidEnvironmentSpec,
|
|
46
|
+
PythonVersionNotFound,
|
|
47
|
+
ScriptNotFound,
|
|
48
|
+
)
|
|
44
49
|
from .register import RegisterManager, RegisteredScript
|
|
45
50
|
|
|
46
51
|
from ._lazy_imports import laz as _laz
|
|
@@ -50,15 +55,17 @@ from ._logger import log
|
|
|
50
55
|
class Manager(Prefab):
|
|
51
56
|
project_name: str = PROJECT_NAME
|
|
52
57
|
config: Config = None
|
|
58
|
+
command: str | None = None
|
|
53
59
|
|
|
54
60
|
paths: ManagedPaths = attribute(init=False, repr=False)
|
|
55
61
|
_temp_catalogue: TemporaryCatalogue | None = attribute(default=None, private=True)
|
|
56
62
|
_app_catalogue: ApplicationCatalogue | None = attribute(default=None, private=True)
|
|
57
63
|
_script_registry: RegisterManager | None = attribute(default=None, private=True)
|
|
58
64
|
|
|
59
|
-
def __prefab_post_init__(self, config):
|
|
65
|
+
def __prefab_post_init__(self, config, command):
|
|
60
66
|
self.paths = ManagedPaths(self.project_name)
|
|
61
67
|
self.config = Config.load(self.paths.config_path) if config is None else config
|
|
68
|
+
self.command = command if command else APP_COMMAND
|
|
62
69
|
|
|
63
70
|
@property
|
|
64
71
|
def temp_catalogue(self) -> TemporaryCatalogue:
|
|
@@ -112,8 +119,8 @@ class Manager(Prefab):
|
|
|
112
119
|
uv_path = None
|
|
113
120
|
|
|
114
121
|
if uv_path is None and required:
|
|
115
|
-
raise
|
|
116
|
-
"UV is required for this process but is unavailable"
|
|
122
|
+
raise RuntimeError(
|
|
123
|
+
"UV is required for this process but is unavailable."
|
|
117
124
|
)
|
|
118
125
|
|
|
119
126
|
return uv_path
|
|
@@ -397,7 +404,7 @@ class Manager(Prefab):
|
|
|
397
404
|
generate_lock: bool = False,
|
|
398
405
|
output_file: str | None = None,
|
|
399
406
|
compressed: bool = False,
|
|
400
|
-
) ->
|
|
407
|
+
) -> None:
|
|
401
408
|
"""
|
|
402
409
|
Create a zipapp bundle for the provided spec
|
|
403
410
|
|
|
@@ -406,7 +413,6 @@ class Manager(Prefab):
|
|
|
406
413
|
:param generate_lock: Generate a lockfile when bundling
|
|
407
414
|
:param output_file: output path to zipapp bundle (script_file.pyz default)
|
|
408
415
|
:param compressed: Compress the resulting zipapp
|
|
409
|
-
:return: Path to the output bundle
|
|
410
416
|
"""
|
|
411
417
|
if not self.is_installed or self.install_outdated:
|
|
412
418
|
self.install()
|
|
@@ -425,8 +431,6 @@ class Manager(Prefab):
|
|
|
425
431
|
compressed=compressed,
|
|
426
432
|
)
|
|
427
433
|
|
|
428
|
-
return output_file
|
|
429
|
-
|
|
430
434
|
def generate_lockfile(
|
|
431
435
|
self,
|
|
432
436
|
script_path: str,
|
|
@@ -473,7 +477,16 @@ class Manager(Prefab):
|
|
|
473
477
|
generate_lock: bool = False,
|
|
474
478
|
lock_path: str | None = None,
|
|
475
479
|
) -> None:
|
|
476
|
-
|
|
480
|
+
try:
|
|
481
|
+
row = self.script_registry.retrieve_script(script_name=script_name)
|
|
482
|
+
except ScriptNotFound as e:
|
|
483
|
+
raise RuntimeError(
|
|
484
|
+
"\n".join(e.args),
|
|
485
|
+
f"Use '{self.command} list --scripts' to show registered scripts",
|
|
486
|
+
)
|
|
487
|
+
except FileNotFoundError as e:
|
|
488
|
+
raise RuntimeError(e.args)
|
|
489
|
+
|
|
477
490
|
script_path = row.path
|
|
478
491
|
|
|
479
492
|
self.run_script(
|
|
@@ -26,6 +26,7 @@ from ducktools.classbuilder.prefab import Prefab
|
|
|
26
26
|
|
|
27
27
|
from ._lazy_imports import laz as _laz
|
|
28
28
|
from ._sqlclasses import SQLAttribute, SQLClass, SQLContext
|
|
29
|
+
from .exceptions import ScriptNotFound
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
class RegisteredScript(SQLClass):
|
|
@@ -83,9 +84,8 @@ class RegisterManager(Prefab, kw_only=True):
|
|
|
83
84
|
row = RegisteredScript.select_row(con, row_filter)
|
|
84
85
|
|
|
85
86
|
if row is None:
|
|
86
|
-
raise
|
|
87
|
-
f"'{script_name}' is not a registered script.
|
|
88
|
-
f"Use `python -m ducktools.env list --scripts` to show registered scripts."
|
|
87
|
+
raise ScriptNotFound(
|
|
88
|
+
f"'{script_name}' is not a registered script."
|
|
89
89
|
)
|
|
90
90
|
|
|
91
91
|
if not os.path.exists(row.path):
|
|
@@ -62,21 +62,21 @@ class PipZipapp:
|
|
|
62
62
|
|
|
63
63
|
# This is mostly kept for testing.
|
|
64
64
|
PREVIOUS_PIP = PipZipapp(
|
|
65
|
-
version_str="24.1",
|
|
66
|
-
sha3_256="f4c4d76e70498762832a842d5b55e9d8c09b6d6607b30b5f4eb08e68dfc57077",
|
|
67
|
-
source_url="zipapp/pip-24.1.pyz"
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
LATEST_PIP = PipZipapp(
|
|
71
65
|
version_str="24.2",
|
|
72
66
|
sha3_256="8dc4860613c47cb2e5e55c7e1ecf4046abe18edca083073d51f1720011bed6ea",
|
|
73
67
|
source_url="zipapp/pip-24.2.pyz",
|
|
74
68
|
)
|
|
75
69
|
|
|
70
|
+
LATEST_PIP = PipZipapp(
|
|
71
|
+
version_str="24.3.1",
|
|
72
|
+
sha3_256="6dd95ab685d00abada578f2744f2b235faf5876d3f3468f0756e2b78bce050f1",
|
|
73
|
+
source_url="zipapp/pip-24.3.1.pyz"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
76
|
|
|
77
77
|
def is_pip_outdated(
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
paths: ManagedPaths,
|
|
79
|
+
latest_version: PipZipapp = LATEST_PIP
|
|
80
80
|
):
|
|
81
81
|
pip_version = paths.get_pip_version()
|
|
82
82
|
|
|
@@ -95,8 +95,8 @@ def is_pip_outdated(
|
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
def download_pip(
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
pip_destination: str,
|
|
99
|
+
latest_version: PipZipapp = LATEST_PIP
|
|
100
100
|
):
|
|
101
101
|
|
|
102
102
|
url = latest_version.full_url
|
|
@@ -76,7 +76,7 @@ def retrieve_uv(paths: ManagedPaths, reinstall: bool = False) -> str | None:
|
|
|
76
76
|
check=True,
|
|
77
77
|
)
|
|
78
78
|
except _laz.subprocess.CalledProcessError as e:
|
|
79
|
-
log("UV download failed: {e}")
|
|
79
|
+
log(f"UV download failed: {e}")
|
|
80
80
|
uv_path = None
|
|
81
81
|
else:
|
|
82
82
|
# Copy the executable out of the pip install
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ducktools-env
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Virtual environment management tools and application bundle builder
|
|
5
5
|
Author: David C Ellis
|
|
6
6
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
@@ -47,19 +47,19 @@ can define its own requirements.
|
|
|
47
47
|
However, using this format requires the use of an extra package such as 'UV' or 'hatch'
|
|
48
48
|
using a specific command such as `uv run my_script.py` or `hatch run my_script.py`.
|
|
49
49
|
|
|
50
|
-
`ducktools
|
|
50
|
+
`ducktools-env` is designed to bundle your script into a Python
|
|
51
51
|
[zipapp](https://docs.python.org/3/library/zipapp.html) which can be run by any
|
|
52
52
|
Python 3.10+ install and will handle creating the virtualenv and launching the script
|
|
53
53
|
with the appropriate dependencies *without* needing the other user to have any
|
|
54
54
|
specific script running tool installed.
|
|
55
55
|
|
|
56
|
-
To aid this, `ducktools
|
|
56
|
+
To aid this, `ducktools-env` provides the `bundle` and `run` commands.
|
|
57
57
|
|
|
58
|
-
`ducktools
|
|
58
|
+
`ducktools-env run my_script.py`
|
|
59
59
|
|
|
60
60
|
Will run your script much like some of the other script runners.
|
|
61
61
|
|
|
62
|
-
`ducktools
|
|
62
|
+
`ducktools-env bundle my_script.py`
|
|
63
63
|
|
|
64
64
|
Will then generate a zipapp bundle of your script and the required tools to extract and
|
|
65
65
|
execute it in the same way as it is executed via the `run` command.
|
|
@@ -106,7 +106,7 @@ The tool can be used in multiple ways:
|
|
|
106
106
|
* Accessed directly via `uvx` with uv
|
|
107
107
|
* `uvx ducktools-env <command>`
|
|
108
108
|
|
|
109
|
-
These examples will use the ducktools-env as the base as if installed via `uv tool` or a similar tool.
|
|
109
|
+
These examples will use the `ducktools-env` command as the base as if installed via `uv tool` or a similar tool.
|
|
110
110
|
|
|
111
111
|
Run a script that uses inline script metadata:
|
|
112
112
|
|
|
@@ -188,7 +188,9 @@ class TestRetrieveUV:
|
|
|
188
188
|
exists_mock.return_value = False
|
|
189
189
|
|
|
190
190
|
run_mock.side_effect = subprocess.CalledProcessError(
|
|
191
|
-
|
|
191
|
+
returncode=1,
|
|
192
|
+
cmd=sys.executable,
|
|
193
|
+
stderr="Could not run PIP"
|
|
192
194
|
)
|
|
193
195
|
|
|
194
196
|
uv_path = get_uv.retrieve_uv(paths=self.paths, reinstall=False)
|
|
@@ -32,6 +32,7 @@ import pytest
|
|
|
32
32
|
|
|
33
33
|
from ducktools.env._sqlclasses import SQLClass
|
|
34
34
|
from ducktools.env.register import RegisteredScript, RegisterManager
|
|
35
|
+
from ducktools.env.exceptions import ScriptNotFound
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
@pytest.fixture(scope="function")
|
|
@@ -84,7 +85,7 @@ class TestRegisterManager:
|
|
|
84
85
|
|
|
85
86
|
# Delete the row and confirm it is no longer retrievable
|
|
86
87
|
test_register.remove_script(script_name)
|
|
87
|
-
with pytest.raises(
|
|
88
|
+
with pytest.raises(ScriptNotFound):
|
|
88
89
|
test_register.retrieve_script(script_name)
|
|
89
90
|
|
|
90
91
|
def test_add_script_not_found(self, test_register):
|
|
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
|
|
File without changes
|
|
File without changes
|
{ducktools_env-0.2.2 → ducktools_env-0.2.4}/src/ducktools/env/bootstrapping/version_check.py
RENAMED
|
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
|
|
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
|
{ducktools_env-0.2.2 → ducktools_env-0.2.4}/tests/example_scripts/print_environment_variables.py
RENAMED
|
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
|