|
31 | 31 |
|
32 | 32 | from charmcraft import instrum |
33 | 33 | from charmcraft.commands.store.charmlibs import collect_charmlib_pydeps |
| 34 | +from charmcraft.const import ( |
| 35 | + DEPENDENCIES_HASH_FILENAME, |
| 36 | + DISPATCH_CONTENT, |
| 37 | + DISPATCH_FILENAME, |
| 38 | + HOOKS_DIRNAME, |
| 39 | + MANDATORY_HOOK_NAMES, |
| 40 | + STAGING_VENV_DIRNAME, |
| 41 | + VENV_DIRNAME, |
| 42 | +) |
34 | 43 | from charmcraft.env import get_charm_builder_metrics_path |
35 | 44 | from charmcraft.jujuignore import JujuIgnore, default_juju_ignore |
36 | 45 | from charmcraft.utils import make_executable |
37 | 46 |
|
38 | | -# Some constants that are used through the code. |
39 | | -WORK_DIRNAME = "work_dir" |
40 | | -VENV_DIRNAME = "venv" |
41 | | -STAGING_VENV_DIRNAME = "staging-venv" |
42 | | -DEPENDENCIES_HASH_FILENAME = "charmcraft-dependencies-hash.txt" |
43 | | - |
44 | | -# The file name and template for the dispatch script |
45 | | -DISPATCH_FILENAME = "dispatch" |
46 | | -# If Juju doesn't support the dispatch mechanism, it will execute the |
47 | | -# hook, and we'd need sys.argv[0] to be the name of the hook but it's |
48 | | -# getting lost by calling this dispatch, so we fake JUJU_DISPATCH_PATH |
49 | | -# to be the value it would've otherwise been. |
50 | | -DISPATCH_CONTENT = """#!/bin/sh |
51 | | -
|
52 | | -JUJU_DISPATCH_PATH="${{JUJU_DISPATCH_PATH:-$0}}" PYTHONPATH=lib:venv \\ |
53 | | - exec ./{entrypoint_relative_path} |
54 | | -""" |
55 | | - |
56 | | -# The minimum set of hooks to be provided for compatibility with old Juju |
57 | | -MANDATORY_HOOK_NAMES = {"install", "start", "upgrade-charm"} |
58 | | -HOOKS_DIR = "hooks" |
59 | | - |
60 | 47 |
|
61 | 48 | def relativise(src, dst): |
62 | 49 | """Build a relative path from src to dst.""" |
@@ -204,7 +191,7 @@ def handle_dispatcher(self, linked_entrypoint): |
204 | 191 | # bunch of symlinks, to support old juju: verify that any of the already included hooks |
205 | 192 | # in the directory is not linking directly to the entrypoint, and also check all the |
206 | 193 | # mandatory ones are present |
207 | | - dest_hookpath = self.installdir / HOOKS_DIR |
| 194 | + dest_hookpath = self.installdir / HOOKS_DIRNAME |
208 | 195 | if not dest_hookpath.exists(): |
209 | 196 | dest_hookpath.mkdir() |
210 | 197 |
|
|
0 commit comments