ducktools-env 0.2.0__tar.gz → 0.2.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 (74) hide show
  1. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/.github/workflows/auto_test.yml +1 -2
  2. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/PKG-INFO +50 -20
  3. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/README.md +49 -19
  4. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/pyproject.toml +1 -0
  5. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/__main__.py +104 -53
  6. ducktools_env-0.2.2/src/ducktools/env/_run.py +55 -0
  7. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/_sqlclasses.py +29 -0
  8. ducktools_env-0.2.2/src/ducktools/env/_version.py +2 -0
  9. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/bootstrapping/bootstrap.py +2 -6
  10. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/catalogue.py +1 -16
  11. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/manager.py +203 -43
  12. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/platform_paths.py +7 -0
  13. ducktools_env-0.2.2/src/ducktools/env/register.py +111 -0
  14. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/scripts/get_uv.py +1 -1
  15. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools_env.egg-info/PKG-INFO +50 -20
  16. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools_env.egg-info/SOURCES.txt +3 -0
  17. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools_env.egg-info/entry_points.txt +1 -0
  18. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_get_uv.py +1 -1
  19. ducktools_env-0.2.2/tests/test_register.py +147 -0
  20. ducktools_env-0.2.0/src/ducktools/env/_version.py +0 -2
  21. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/.github/dependabot.yml +0 -0
  22. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/.github/workflows/build_zipapp.yml +0 -0
  23. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/.github/workflows/publish_to_pypi.yml +0 -0
  24. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/.github/workflows/publish_to_testpypi.yml +0 -0
  25. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/.gitignore +0 -0
  26. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/LICENSE +0 -0
  27. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/examples/application/cowsay_app.py +0 -0
  28. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/examples/inline/cowsay_ex.py +0 -0
  29. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/examples/inline/empty_311_env.py +0 -0
  30. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/examples/inline/empty_312_env.py +0 -0
  31. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/examples/inline/pep_723_example.py +0 -0
  32. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/examples/inline/print_environment_variables.py +0 -0
  33. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/setup.cfg +0 -0
  34. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/__init__.py +0 -0
  35. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/_lazy_imports.py +0 -0
  36. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/_logger.py +0 -0
  37. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/bootstrapping/bundle_main.py +0 -0
  38. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/bootstrapping/version_check.py +0 -0
  39. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/bootstrapping/zipapp_main.py +0 -0
  40. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/bundle.py +0 -0
  41. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/bundled_data.py +0 -0
  42. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/config.py +0 -0
  43. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/environment_specs.py +0 -0
  44. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/exceptions.py +0 -0
  45. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/scripts/__init__.py +0 -0
  46. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/scripts/create_zipapp.py +0 -0
  47. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools/env/scripts/get_pip.py +0 -0
  48. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools_env.egg-info/dependency_links.txt +0 -0
  49. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools_env.egg-info/requires.txt +0 -0
  50. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/src/ducktools_env.egg-info/top_level.txt +0 -0
  51. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/conftest.py +0 -0
  52. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/data/pip-24.1.pyz +0 -0
  53. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/data/pip-24.2.pyz +0 -0
  54. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/data/uv_python_versions_list.txt +0 -0
  55. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/cowsay_app.py +0 -0
  56. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/cowsay_app.py.lock +0 -0
  57. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/cowsay_ex.py +0 -0
  58. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/cowsay_ex.py.lock +0 -0
  59. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/cowsay_ex_nolock.py +0 -0
  60. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/invalid_app.py +0 -0
  61. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/pep_723_example.py +0 -0
  62. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/pep_723_example_subset.py +0 -0
  63. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/print_environment_variables.py +0 -0
  64. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/example_scripts/spec_error.py +0 -0
  65. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_bundled_data.py +0 -0
  66. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_catalogue.py +0 -0
  67. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_config.py +0 -0
  68. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_environmentspec.py +0 -0
  69. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_fixtures_active.py +0 -0
  70. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_get_pip.py +0 -0
  71. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_integration/test_build_retrieve.py +0 -0
  72. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_logger.py +0 -0
  73. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_manager.py +0 -0
  74. {ducktools_env-0.2.0 → ducktools_env-0.2.2}/tests/test_platform_paths.py +0 -0
@@ -14,8 +14,7 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  os: [ubuntu-latest, windows-latest]
17
- python-version: ["3.13-dev", "3.12", "3.11", "3.10"]
18
- # python-version: ["3.12", "3.11", "3.10", "3.9", "3.8"]
17
+ python-version: ["3.13", "3.12", "3.11", "3.10"]
19
18
 
20
19
  steps:
21
20
  - uses: actions/checkout@v4
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ducktools-env
3
- Version: 0.2.0
3
+ Version: 0.2.2
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
@@ -55,11 +55,11 @@ specific script running tool installed.
55
55
 
56
56
  To aid this, `ducktools.env` provides the `bundle` and `run` commands.
57
57
 
58
- `python ducktools.pyz run my_script.py`
58
+ `ducktools.pyz run my_script.py`
59
59
 
60
60
  Will run your script much like some of the other script runners.
61
61
 
62
- `python ducktools.pyz bundle my_script.py`
62
+ `ducktools.pyz 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.
@@ -91,31 +91,58 @@ Environment data and the application itself will be stored in the following loca
91
91
 
92
92
  ## Usage ##
93
93
 
94
- Either install the tool from PyPI or simply download the zipapp from github.
94
+ The tool can be used in multiple ways:
95
95
 
96
- If using the tool from PyPI the commands are `python -m ducktools.env <command>`
97
- with the zipapp they are `python ducktools.pyz <command>`
96
+ * Installed via `uv tool` (or `pipx`)
97
+ * `uv tool install ducktools-env`
98
+ * `ducktools-env <command>`
99
+ * This adds the `dtrun` shortcut for `ducktools-env run`
100
+ * Executed from the zipapp
101
+ * Download from: https://github.com/DavidCEllis/ducktools-env/releases/latest
102
+ * Run with: `ducktools.pyz <command>`
103
+ * Installed in an environment
104
+ * Download with `pip` or `uv` in a virtual environment: `pip install ducktools-env`
105
+ * Run with: `ducktools-env <command>`
106
+ * Accessed directly via `uvx` with uv
107
+ * `uvx ducktools-env <command>`
108
+
109
+ These examples will use the ducktools-env as the base as if installed via `uv tool` or a similar tool.
98
110
 
99
111
  Run a script that uses inline script metadata:
100
112
 
101
- `python ducktools.pyz run my_script.py`
113
+ `ducktools-env run my_script.py`
114
+
115
+ If installed via `uv`, `pipx` or `pip` there is an alias `dtrun` for this command.
116
+ Unlike the full command it does not accept optional arguments and all arguments are passed
117
+ on to the script.
118
+
119
+ `dtrun my_script.py`
102
120
 
103
121
  Bundle the script into a zipapp:
104
122
 
105
- `python ducktools.pyz bundle my_script.py`
123
+ `ducktools-env bundle my_script.py`
106
124
 
107
125
  Clear the temporary environment cache:
108
126
 
109
- `python ducktools.pyz clear_cache`
127
+ `ducktools-env clear_cache`
110
128
 
111
129
  Clear the full `ducktools/env` install directory:
112
130
 
113
- `python ducktools.pyz clear_cache --full`
131
+ `ducktools-env clear_cache --full`
132
+
133
+ Build the env folder from the installed package:
134
+
135
+ `ducktools-env rebuild_env`
114
136
 
115
- Build the env folder from the installed package
116
- (**Generally you should not need to do this from the zipapp**)
137
+ ### Registering scripts ###
117
138
 
118
- `python -m ducktools.env rebuild_env`
139
+ It is also now possible to register scripts with `ducktools-env`.
140
+
141
+ `ducktools-env register path/to/my_script.py`
142
+
143
+ which can then be run by using the script name without the extension:
144
+
145
+ `ducktools-env run my_script` or `dtrun my_script`
119
146
 
120
147
  ## Locking environments ##
121
148
 
@@ -129,23 +156,26 @@ This generation feature uses `uv` which will be automatically installed.
129
156
 
130
157
  Create a lockfile without running a script:
131
158
 
132
- `python ducktools.pyz generate_lock my_script.py`
159
+ `ducktools-env generate_lock my_script.py`
133
160
 
134
161
  Run a script and output the generated lockfile (output as my_script.py.lock):
135
162
 
136
- `python ducktools.pyz run --generate-lock my_script.py`
163
+ `ducktools-env run --generate-lock my_script.py` (--generate-lock does not work with `dtrun`)
137
164
 
138
165
  Run a script using a pre-generated lockfile:
139
166
 
140
- `python ducktools.pyz run --with-lock my_script.py.lock my_script.py`
167
+ `ducktools-env run --with-lock my_script.py.lock my_script.py`
168
+
169
+ **If a `my_script.py.lock` file is found for a script it will automatically be used without
170
+ needing to be specified**
141
171
 
142
172
  Bundle a script and generate a lockfile (that will be bundled):
143
173
 
144
- `python ducktools.pyz bundle --generate-lock my_script.py`
174
+ `ducktools-env bundle --generate-lock my_script.py`
145
175
 
146
176
  Bundle a script with a pre-generated lockfile:
147
177
 
148
- `python ducktools.pyz bundle --with-lock my_script.py.lock my_script.py`
178
+ `ducktools-env bundle --with-lock my_script.py.lock my_script.py`
149
179
 
150
180
  **If a `my_script.py.lock` file exists it will automatically be used.**
151
181
 
@@ -227,11 +257,11 @@ if __name__ == "__main__":
227
257
 
228
258
  Existing environments can be listed with the command
229
259
 
230
- `python ducktools.pyz list`
260
+ `ducktools-env list`
231
261
 
232
262
  and deleted with
233
263
 
234
- `python ducktools.pyz delete_env <envname>`
264
+ `ducktools-env delete_env <envname>`
235
265
 
236
266
  where `<envname>` is the `name` of a temporary environment or the combination
237
267
  `owner/name` of an application environment as shown in the list.
@@ -28,11 +28,11 @@ specific script running tool installed.
28
28
 
29
29
  To aid this, `ducktools.env` provides the `bundle` and `run` commands.
30
30
 
31
- `python ducktools.pyz run my_script.py`
31
+ `ducktools.pyz run my_script.py`
32
32
 
33
33
  Will run your script much like some of the other script runners.
34
34
 
35
- `python ducktools.pyz bundle my_script.py`
35
+ `ducktools.pyz 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.
@@ -64,31 +64,58 @@ Environment data and the application itself will be stored in the following loca
64
64
 
65
65
  ## Usage ##
66
66
 
67
- Either install the tool from PyPI or simply download the zipapp from github.
67
+ The tool can be used in multiple ways:
68
68
 
69
- If using the tool from PyPI the commands are `python -m ducktools.env <command>`
70
- with the zipapp they are `python ducktools.pyz <command>`
69
+ * Installed via `uv tool` (or `pipx`)
70
+ * `uv tool install ducktools-env`
71
+ * `ducktools-env <command>`
72
+ * This adds the `dtrun` shortcut for `ducktools-env run`
73
+ * Executed from the zipapp
74
+ * Download from: https://github.com/DavidCEllis/ducktools-env/releases/latest
75
+ * Run with: `ducktools.pyz <command>`
76
+ * Installed in an environment
77
+ * Download with `pip` or `uv` in a virtual environment: `pip install ducktools-env`
78
+ * Run with: `ducktools-env <command>`
79
+ * Accessed directly via `uvx` with uv
80
+ * `uvx ducktools-env <command>`
81
+
82
+ These examples will use the ducktools-env as the base as if installed via `uv tool` or a similar tool.
71
83
 
72
84
  Run a script that uses inline script metadata:
73
85
 
74
- `python ducktools.pyz run my_script.py`
86
+ `ducktools-env run my_script.py`
87
+
88
+ If installed via `uv`, `pipx` or `pip` there is an alias `dtrun` for this command.
89
+ Unlike the full command it does not accept optional arguments and all arguments are passed
90
+ on to the script.
91
+
92
+ `dtrun my_script.py`
75
93
 
76
94
  Bundle the script into a zipapp:
77
95
 
78
- `python ducktools.pyz bundle my_script.py`
96
+ `ducktools-env bundle my_script.py`
79
97
 
80
98
  Clear the temporary environment cache:
81
99
 
82
- `python ducktools.pyz clear_cache`
100
+ `ducktools-env clear_cache`
83
101
 
84
102
  Clear the full `ducktools/env` install directory:
85
103
 
86
- `python ducktools.pyz clear_cache --full`
104
+ `ducktools-env clear_cache --full`
105
+
106
+ Build the env folder from the installed package:
107
+
108
+ `ducktools-env rebuild_env`
87
109
 
88
- Build the env folder from the installed package
89
- (**Generally you should not need to do this from the zipapp**)
110
+ ### Registering scripts ###
90
111
 
91
- `python -m ducktools.env rebuild_env`
112
+ It is also now possible to register scripts with `ducktools-env`.
113
+
114
+ `ducktools-env register path/to/my_script.py`
115
+
116
+ which can then be run by using the script name without the extension:
117
+
118
+ `ducktools-env run my_script` or `dtrun my_script`
92
119
 
93
120
  ## Locking environments ##
94
121
 
@@ -102,23 +129,26 @@ This generation feature uses `uv` which will be automatically installed.
102
129
 
103
130
  Create a lockfile without running a script:
104
131
 
105
- `python ducktools.pyz generate_lock my_script.py`
132
+ `ducktools-env generate_lock my_script.py`
106
133
 
107
134
  Run a script and output the generated lockfile (output as my_script.py.lock):
108
135
 
109
- `python ducktools.pyz run --generate-lock my_script.py`
136
+ `ducktools-env run --generate-lock my_script.py` (--generate-lock does not work with `dtrun`)
110
137
 
111
138
  Run a script using a pre-generated lockfile:
112
139
 
113
- `python ducktools.pyz run --with-lock my_script.py.lock my_script.py`
140
+ `ducktools-env run --with-lock my_script.py.lock my_script.py`
141
+
142
+ **If a `my_script.py.lock` file is found for a script it will automatically be used without
143
+ needing to be specified**
114
144
 
115
145
  Bundle a script and generate a lockfile (that will be bundled):
116
146
 
117
- `python ducktools.pyz bundle --generate-lock my_script.py`
147
+ `ducktools-env bundle --generate-lock my_script.py`
118
148
 
119
149
  Bundle a script with a pre-generated lockfile:
120
150
 
121
- `python ducktools.pyz bundle --with-lock my_script.py.lock my_script.py`
151
+ `ducktools-env bundle --with-lock my_script.py.lock my_script.py`
122
152
 
123
153
  **If a `my_script.py.lock` file exists it will automatically be used.**
124
154
 
@@ -200,11 +230,11 @@ if __name__ == "__main__":
200
230
 
201
231
  Existing environments can be listed with the command
202
232
 
203
- `python ducktools.pyz list`
233
+ `ducktools-env list`
204
234
 
205
235
  and deleted with
206
236
 
207
- `python ducktools.pyz delete_env <envname>`
237
+ `ducktools-env delete_env <envname>`
208
238
 
209
239
  where `<envname>` is the `name` of a temporary environment or the combination
210
240
  `owner/name` of an application environment as shown in the list.
@@ -38,6 +38,7 @@ testing = ["pytest", "pytest-cov", "coverage-conditional-plugin"]
38
38
 
39
39
  [project.scripts]
40
40
  "ducktools-env" = "ducktools.env.__main__:main"
41
+ "dtrun" = "ducktools.env._run:run"
41
42
 
42
43
  [tool.setuptools.packages.find]
43
44
  where = ["src"]
@@ -133,6 +133,27 @@ def get_parser(exit_on_error=True) -> FixedArgumentParser:
133
133
  action="store_true"
134
134
  )
135
135
 
136
+ # 'register' command and args
137
+ register_parser = subparsers.add_parser(
138
+ "register",
139
+ help="Register scripts to be run by name",
140
+ )
141
+ register_parser.add_argument(
142
+ "script_filename",
143
+ action="store",
144
+ help="Path to the script to register or name of the script to unregister",
145
+ )
146
+ register_parser.add_argument(
147
+ "--remove",
148
+ action="store_true",
149
+ help="Uninstall registered script",
150
+ )
151
+ register_parser.add_argument(
152
+ "-n", "--name",
153
+ action="store",
154
+ help="Register the script with a different name to the filename"
155
+ )
156
+
136
157
  # 'generate_lock' command and args
137
158
  generate_lock_parser = subparsers.add_parser(
138
159
  "generate_lock",
@@ -175,7 +196,7 @@ def get_parser(exit_on_error=True) -> FixedArgumentParser:
175
196
 
176
197
  list_parser = subparsers.add_parser(
177
198
  "list",
178
- help="List the Python virtual environments managed by ducktools-env",
199
+ help="List the Python virtual environments and scripts managed by ducktools-env",
179
200
  )
180
201
 
181
202
  list_type_group = list_parser.add_mutually_exclusive_group()
@@ -189,6 +210,11 @@ def get_parser(exit_on_error=True) -> FixedArgumentParser:
189
210
  action="store_true",
190
211
  help="Only list application environments",
191
212
  )
213
+ list_type_group.add_argument(
214
+ "--scripts",
215
+ action="store_true",
216
+ help="Only list registered scripts"
217
+ )
192
218
 
193
219
  delete_parser = subparsers.add_parser(
194
220
  "delete_env",
@@ -280,91 +306,116 @@ def main():
280
306
  manager = _laz.Manager(PROJECT_NAME)
281
307
 
282
308
  if args.command == "run":
283
- spec = _laz.EnvironmentSpec.from_script(
284
- script_path=args.script_filename
285
- )
286
- if args.generate_lock:
287
- uv_path = manager.retrieve_uv(required=True)
288
- lockdata = spec.generate_lockdata(uv_path=uv_path)
289
- lock_path = f"{args.script_filename}.lock"
290
- with open(lock_path, 'w') as f:
291
- f.write(lockdata)
292
- elif lock_path := args.with_lock:
293
- with open(lock_path, 'r') as f:
294
- lockdata = f.read()
295
- spec.lockdata = lockdata
296
-
297
- manager.run_direct_script(
298
- spec=spec,
299
- args=args.script_args,
300
- )
309
+ # Split on existence of the command as a file, if the file exists run it
310
+ # Otherwise look for it in the registered scripts database
311
+ if os.path.exists(args.script_filename):
312
+ manager.run_script(
313
+ script_path=args.script_filename,
314
+ script_args=args.script_args,
315
+ generate_lock=args.generate_lock,
316
+ lock_path=args.with_lock,
317
+ )
318
+ else:
319
+ manager.run_registered_script(
320
+ script_name=args.script_filename,
321
+ script_args=args.script_args,
322
+ generate_lock=args.generate_lock,
323
+ lock_path=args.with_lock,
324
+ )
325
+
301
326
  elif args.command == "bundle":
302
- spec = _laz.EnvironmentSpec.from_script(
303
- script_path=args.script_filename
304
- )
305
-
306
- if args.generate_lock:
307
- uv_path = manager.retrieve_uv(required=True)
308
- spec.generate_lockdata(uv_path=uv_path)
309
- elif lock_path := args.with_lock:
310
- with open(lock_path, 'r') as f:
311
- lockdata = f.read()
312
- spec.lockdata = lockdata
313
-
314
- manager.create_bundle(
315
- spec=spec,
327
+ bundle_path = manager.create_bundle(
328
+ script_path=args.script_filename,
329
+ with_lock=args.with_lock,
330
+ generate_lock=args.generate_lock,
316
331
  output_file=args.output,
317
- compressed=args.compress,
332
+ compressed=args.compressed,
318
333
  )
334
+ print(f"Bundle created at '{bundle_path}'")
335
+
336
+ elif args.command == "register":
337
+ if args.remove:
338
+ # filename should just be the script name, but it's awkward to change this
339
+ manager.remove_registered_script(
340
+ script_name=args.script_filename,
341
+ )
342
+ else:
343
+ manager.register_script(
344
+ script_path=args.script_filename,
345
+ script_name=args.name,
346
+ )
347
+
319
348
  elif args.command == "generate_lock":
320
- uv_path = manager.retrieve_uv(required=True)
321
- spec = _laz.EnvironmentSpec.from_script(
322
- script_path=args.script_filename
349
+ lock_path = manager.generate_lockfile(
350
+ script_path=args.script_filename,
351
+ lockfile_path=args.output,
323
352
  )
324
- lockdata = spec.generate_lockdata(uv_path=uv_path)
353
+ print(f"Lockfile generated at '{lock_path}'")
325
354
 
326
- out_path = args.output if args.output else f"{args.script_filename}.lock"
327
- with open(out_path, "w") as f:
328
- f.write(lockdata)
329
355
  elif args.command == "clear_cache":
330
356
  if args.full:
331
357
  manager.clear_project_folder()
332
358
  else:
333
359
  manager.clear_temporary_cache()
360
+
334
361
  elif args.command == "rebuild_env":
335
362
  manager.build_env_folder()
336
363
  if args.zipapp:
337
364
  manager.build_zipapp()
365
+
338
366
  elif args.command == "list":
339
- has_envs = False
340
- if manager.temp_catalogue.environments and not args.app:
341
- has_envs = True
367
+ has_data = False
368
+ show_temp = args.temp or not (args.app or args.scripts)
369
+ show_app = args.app or not (args.scripts or args.temp)
370
+ show_scripts = args.scripts or not (args.app or args.temp)
371
+
372
+ if (envs := manager.temp_catalogue.environments) and show_temp:
373
+ has_data = True
342
374
  print("Temporary Environments")
343
375
  print("======================")
344
376
  formatted = get_columns(
345
- data=manager.temp_catalogue.environments.values(),
377
+ data=envs.values(),
346
378
  headings=["Name", "Last Used"],
347
- attributes=["name", "last_used_simple"]
379
+ attributes=["name", "last_used_simple"],
348
380
  )
349
381
  for line in formatted:
350
382
  print(line)
351
383
  if not args.temp:
384
+ # newline if not exclusive
352
385
  print()
353
386
 
354
- if manager.app_catalogue.environments and not args.temp:
355
- has_envs = True
356
- print("Application environments")
387
+ if (envs := manager.app_catalogue.environments) and show_app:
388
+ has_data = True
389
+ print("Application Environments")
357
390
  print("========================")
358
391
  formatted = get_columns(
359
- data=manager.app_catalogue.environments.values(),
392
+ data=envs.values(),
360
393
  headings=["Owner / Name", "Last Used"],
361
- attributes=["name", "last_used_simple"]
394
+ attributes=["name", "last_used_simple"],
362
395
  )
363
396
  for line in formatted:
364
397
  print(line)
398
+ if not args.app:
399
+ # newline if not exclusive
400
+ print()
401
+
402
+ if (scripts := manager.script_registry.list_registered_scripts()) and show_scripts:
403
+ has_data = True
404
+ print("Registered Scripts")
405
+ print("==================")
406
+
407
+ formatted = get_columns(
408
+ data=scripts,
409
+ headings=["Script Name", "Path"],
410
+ attributes=["name", "path"],
411
+ )
412
+ for line in formatted:
413
+ print(line)
414
+ print()
415
+
416
+ if has_data is False:
417
+ print("No environments or scripts managed by ducktools-env")
365
418
 
366
- if has_envs is False:
367
- print("No environments managed by ducktools-env")
368
419
  elif args.command == "delete_env":
369
420
  envname = args.environment_name
370
421
  if envname in manager.temp_catalogue.environments:
@@ -0,0 +1,55 @@
1
+ # ducktools.env
2
+ # MIT License
3
+ #
4
+ # Copyright (c) 2024 David C Ellis
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ """
25
+ Short implementation of the `dtrun` command.
26
+
27
+ Unlike ducktools-env run, `dtrun` doesn't take any arguments other than the script name
28
+ and arguments to pass on to the following script.
29
+
30
+ This means it doesn't need to construct the argument parser as everything is passed
31
+ on to the script being run.
32
+ """
33
+ import sys
34
+ import os.path
35
+
36
+ from . import PROJECT_NAME
37
+ from .manager import Manager
38
+
39
+
40
+ def run():
41
+ # First argument is the path to this script
42
+ _, app, *args = sys.argv
43
+
44
+ manager = Manager(PROJECT_NAME)
45
+
46
+ if os.path.exists(app):
47
+ manager.run_script(
48
+ script_path=app,
49
+ script_args=args,
50
+ )
51
+ else:
52
+ manager.run_registered_script(
53
+ script_name=app,
54
+ script_args=args,
55
+ )
@@ -26,6 +26,8 @@
26
26
 
27
27
  import itertools
28
28
 
29
+ from ducktools.lazyimporter import LazyImporter, ModuleImport
30
+
29
31
  from ducktools.classbuilder import (
30
32
  SlotMakerMeta,
31
33
  builder,
@@ -43,6 +45,15 @@ from ducktools.classbuilder.prefab import (
43
45
  )
44
46
 
45
47
 
48
+ # Unlike the other modules this has its own lazy importer
49
+ # As it might be spun off as a separate package
50
+ _laz = LazyImporter(
51
+ [
52
+ ModuleImport("sqlite3", asname="sql")
53
+ ]
54
+ )
55
+
56
+
46
57
  TYPE_MAP = {
47
58
  None: "NULL",
48
59
  int: "INTEGER",
@@ -57,6 +68,24 @@ TYPE_MAP = {
57
68
  MAPPED_TYPES = None | int | bool | float | str | bytes | list[str]
58
69
 
59
70
 
71
+ class SQLContext:
72
+ """
73
+ A simple context manager to handle SQLite database connections
74
+ """
75
+ def __init__(self, db):
76
+ self.db = db
77
+ self.connection = None
78
+
79
+ def __enter__(self):
80
+ self.connection = _laz.sql.connect(self.db)
81
+ return self.connection
82
+
83
+ def __exit__(self, exc_type, exc_val, exc_tb):
84
+ if self.connection is not None:
85
+ self.connection.close()
86
+ self.connection = None
87
+
88
+
60
89
  class SQLAttribute(Attribute):
61
90
  """
62
91
  A Special attribute for SQL tables
@@ -0,0 +1,2 @@
1
+ __version__ = "0.2.2"
2
+ __version_tuple__ = (0, 2, 2)
@@ -105,15 +105,11 @@ def launch_script(script_file, zipapp_path, args, lockdata=None):
105
105
  from ducktools.env.manager import Manager
106
106
  from ducktools.env.environment_specs import EnvironmentSpec
107
107
  manager = Manager(PROJECT_NAME)
108
- spec = EnvironmentSpec.from_script(
108
+ manager.run_bundle(
109
109
  script_path=script_file,
110
+ script_args=args,
110
111
  lockdata=lockdata,
111
- )
112
-
113
- manager.run_bundled_script(
114
- spec=spec,
115
112
  zipapp_path=zipapp_path,
116
- args=args,
117
113
  )
118
114
  finally:
119
115
  sys.path.pop(0)
@@ -28,7 +28,7 @@ from datetime import datetime as _datetime, timedelta as _timedelta
28
28
 
29
29
  from ducktools.classbuilder.prefab import prefab, attribute
30
30
 
31
- from ._sqlclasses import SQLAttribute, SQLClass
31
+ from ._sqlclasses import SQLAttribute, SQLClass, SQLContext
32
32
  from .exceptions import InvalidEnvironmentSpec, VenvBuildError, ApplicationError
33
33
  from .environment_specs import EnvironmentSpec
34
34
  from .config import Config
@@ -46,21 +46,6 @@ def _datetime_now_iso() -> str:
46
46
  return _datetime.now().isoformat()
47
47
 
48
48
 
49
- class SQLContext:
50
- def __init__(self, db):
51
- self.db = db
52
- self.connection = None
53
-
54
- def __enter__(self):
55
- self.connection = _laz.sql.connect(self.db)
56
- return self.connection
57
-
58
- def __exit__(self, exc_type, exc_val, exc_tb):
59
- if self.connection is not None:
60
- self.connection.close()
61
- self.connection = None
62
-
63
-
64
49
  class BaseEnvironment(SQLClass):
65
50
  row_id: int = SQLAttribute(default=None, primary_key=True)
66
51
  name: str = SQLAttribute(unique=True)