Skip to content

Commit 526fa72

Browse files
authored
fix: hugr encoding (#147)
1 parent d2a52ed commit 526fa72

File tree

4 files changed

+39
-42
lines changed

4 files changed

+39
-42
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
action: ['lint', 'type', 'format']
2020
steps:
2121
- name: Checkout code
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323
with:
2424
fetch-depth: '0'
2525

2626
- name: Cache poetry
27-
uses: actions/cache@v3.3.1
27+
uses: actions/cache@v4
2828
with:
2929
path: ~/.cache/pypoetry/virtualenvs
3030
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}
@@ -71,12 +71,12 @@ jobs:
7171

7272
steps:
7373
- name: Checkout code
74-
uses: actions/checkout@v3
74+
uses: actions/checkout@v4
7575
with:
7676
fetch-depth: '0'
7777

7878
- name: Cache poetry
79-
uses: actions/cache@v3.3.1
79+
uses: actions/cache@v4
8080
with:
8181
path: ~/.cache/pypoetry/virtualenvs
8282
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}

.github/workflows/integration.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
matrix:
2020
python-version: ['3.10', '3.11']
2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- name: Cache poetry
24-
uses: actions/cache@v3.3.1
24+
uses: actions/cache@v4
2525
with:
2626
path: ~/.cache/pypoetry/virtualenvs
2727
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}
@@ -62,14 +62,14 @@ jobs:
6262
pr-number: ${{ github.event.inputs.pr_number }}
6363

6464
- name: Checkout code
65-
uses: actions/checkout@v3
65+
uses: actions/checkout@v4
6666
with:
6767
fetch-depth: '0'
6868
# Use the pull request merge commit ref if one is provided
6969
ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/merge', github.event.inputs.pr_number) || 'main' }}
7070

7171
- name: Cache poetry
72-
uses: actions/cache@v3.3.1
72+
uses: actions/cache@v4
7373
with:
7474
path: ~/.cache/pypoetry/virtualenvs
7575
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}

devenv.lock

+26-23
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,31 @@
3131
"type": "github"
3232
}
3333
},
34+
"git-hooks": {
35+
"inputs": {
36+
"flake-compat": "flake-compat",
37+
"gitignore": "gitignore",
38+
"nixpkgs": [
39+
"nixpkgs"
40+
]
41+
},
42+
"locked": {
43+
"lastModified": 1742058297,
44+
"owner": "cachix",
45+
"repo": "git-hooks.nix",
46+
"rev": "59f17850021620cd348ad2e9c0c64f4e6325ce2a",
47+
"type": "github"
48+
},
49+
"original": {
50+
"owner": "cachix",
51+
"repo": "git-hooks.nix",
52+
"type": "github"
53+
}
54+
},
3455
"gitignore": {
3556
"inputs": {
3657
"nixpkgs": [
37-
"pre-commit-hooks",
58+
"git-hooks",
3859
"nixpkgs"
3960
]
4061
},
@@ -66,32 +87,14 @@
6687
"type": "github"
6788
}
6889
},
69-
"pre-commit-hooks": {
70-
"inputs": {
71-
"flake-compat": "flake-compat",
72-
"gitignore": "gitignore",
73-
"nixpkgs": [
74-
"nixpkgs"
75-
]
76-
},
77-
"locked": {
78-
"lastModified": 1737465171,
79-
"owner": "cachix",
80-
"repo": "pre-commit-hooks.nix",
81-
"rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17",
82-
"type": "github"
83-
},
84-
"original": {
85-
"owner": "cachix",
86-
"repo": "pre-commit-hooks.nix",
87-
"type": "github"
88-
}
89-
},
9090
"root": {
9191
"inputs": {
9292
"devenv": "devenv",
93+
"git-hooks": "git-hooks",
9394
"nixpkgs": "nixpkgs",
94-
"pre-commit-hooks": "pre-commit-hooks"
95+
"pre-commit-hooks": [
96+
"git-hooks"
97+
]
9598
}
9699
}
97100
},

qnexus/client/hugr.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ def upload(
175175
project = cast(ProjectRef, project)
176176

177177
attributes = {
178-
"contents": str(base64.b64encode(bytes(hugr_package.to_json(), "utf-8")))
178+
"contents": base64.b64encode(bytes(hugr_package.to_json(), "utf-8")).decode(
179+
"utf-8"
180+
)
179181
}
180182

181183
annotations = CreateAnnotations(
@@ -287,15 +289,7 @@ def _fetch_hugr_package(handle: HUGRRef) -> Package:
287289
if res.status_code != 200:
288290
raise qnx_exc.ResourceFetchFailed(message=res.text, status_code=res.status_code)
289291

290-
hugr_base_64_bytes = res.json()["data"]["attributes"]["contents"]
291-
encoded_bytes = hugr_base_64_bytes.strip()
292-
# remove leading b'
293-
encoded_bytes = encoded_bytes[1:]
294-
# add a trailing '='
295-
encoded_bytes += "="
296-
297-
# Step 2: Decode the base64 bytes back into the original bytes
298-
# Step 3: Convert the bytes back into the original string
299-
decoded_hugr_str = base64.b64decode(encoded_bytes).decode("utf-8")
292+
contents: str = res.json()["data"]["attributes"]["contents"]
293+
decoded_hugr_str = base64.b64decode(contents).decode("utf-8")
300294

301295
return Package.from_json(decoded_hugr_str)

0 commit comments

Comments
 (0)