Skip to content

Commit 897f65c

Browse files
Merge branch 'main' into inclusive-naming-action
2 parents 34193f9 + 8a08e8e commit 897f65c

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

HACKING.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,79 @@ source .tox/unit/bin/activate
7979
pytest -v test/test_real_pebble.py
8080
```
8181

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+
82155
# Documentation
83156

84157
In general, new functionality

ops/model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,11 @@ def push(self,
22522252
group: Optional[str] = None):
22532253
"""Write content to a given file path on the remote system.
22542254
2255+
Note that if another process has the file open on the remote system,
2256+
or if the remote file is a bind mount, pushing will fail with a
2257+
:class:`pebble.PathError`. Use :meth:`Container.exec` for full
2258+
control.
2259+
22552260
Args:
22562261
path: Path of the file to write to on the remote system.
22572262
source: Source of data to write. This is either a concrete str or

0 commit comments

Comments
 (0)