@@ -79,6 +79,79 @@ source .tox/unit/bin/activate
79
79
pytest -v test/test_real_pebble.py
80
80
```
81
81
82
+ ## Using an ` ops ` branch in a charm
83
+
84
+ When making changes to ` ops ` , you'll commonly want to try those changes out in
85
+ a charm.
86
+
87
+ ### From a Git branch
88
+
89
+ If your changes are in a Git branch, you can simply replace your ` ops ` version
90
+ in ` requirements.txt ` (or ` pyproject.toml ` ) with a reference to the branch, like:
91
+
92
+ ```
93
+ #ops ~= 2.9
94
+ git+https://github.com/{your-username}/operator@{your-branch-name}
95
+ ```
96
+
97
+ ` git ` is not normally available when ` charmcraft ` is packing the charm, so you'll
98
+ need to also tell ` charmcraft ` that it's required for the build, by adding
99
+ something like this to your ` charmcraft.yaml ` :
100
+
101
+ ``` yaml
102
+ parts :
103
+ charm :
104
+ build-packages :
105
+ - git
106
+ ` ` `
107
+
108
+ ### From local code
109
+
110
+ If your changes are only on your local device, you can inject your local ` ops`
111
+ into the charm after it has packed, and before you deploy it, by unzipping the
112
+ ` .charm` file and replacing the `ops` folder in the virtualenv. This small
113
+ script will handle that for you :
114
+
115
+ ` ` ` shell-script
116
+ #!/usr/bin/env bash
117
+
118
+ if [ "$#" -lt 2 ]
119
+ then
120
+ echo "Inject local copy of Python Operator Framework source into charm"
121
+ echo
122
+ echo "usage: inject-ops.sh file.charm /path/to/ops/dir" >&2
123
+ exit 1
124
+ fi
125
+
126
+ if [ ! -f "$2/framework.py" ]; then
127
+ echo "$2/framework.py not found; arg 2 should be path to 'ops' directory"
128
+ exit 1
129
+ fi
130
+
131
+ set -ex
132
+
133
+ mkdir inject-ops-tmp
134
+ unzip -q $1 -d inject-ops-tmp
135
+ rm -rf inject-ops-tmp/venv/ops
136
+ cp -r $2 inject-ops-tmp/venv/ops
137
+ cd inject-ops-tmp
138
+ zip -q -r ../inject-ops-new.charm .
139
+ cd ..
140
+ rm -rf inject-ops-tmp
141
+ rm $1
142
+ mv inject-ops-new.charm $1
143
+ ` ` `
144
+
145
+ # ## Using a Juju branch
146
+
147
+ If your `ops` change relies on a change in a Juju branch, you'll need to deploy
148
+ your charm to a controller using that version of Juju. For example, with microk8s :
149
+
150
+ 1. [Build Juju and its dependencies](https://github.com/juju/juju/blob/3.4/CONTRIBUTING.md#build-juju-and-its-dependencies)
151
+ 2. Run `make microk8s-operator-update`
152
+ 3. Run `GOBIN=/path/to/your/juju/_build/linux_amd64/bin:$GOBIN /path/to/your/juju bootstrap`
153
+ 4. Add a model and deploy your charm as normal
154
+
82
155
# Documentation
83
156
84
157
In general, new functionality
0 commit comments