Skip to content

Commit ef9be7a

Browse files
author
Joel Collins
committed
Merge remote-tracking branch 'origin/master' into semantic-classes
2 parents ee7703c + b5c6a39 commit ef9be7a

File tree

19 files changed

+184
-550
lines changed

19 files changed

+184
-550
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Code scanning - action"
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 4 * * 3'
8+
9+
jobs:
10+
CodeQL-Build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
with:
18+
# We must fetch at least the immediate parents so that if this is
19+
# a pull request then we can checkout the head.
20+
fetch-depth: 2
21+
22+
# If this run was triggered by a pull request event, then checkout
23+
# the head of the pull request instead of the merge commit.
24+
- run: git checkout HEAD^2
25+
if: ${{ github.event_name == 'pull_request' }}
26+
27+
# Initializes the CodeQL tools for scanning.
28+
- name: Initialize CodeQL
29+
uses: github/codeql-action/init@v1
30+
# Override language selection by uncommenting this and choosing your languages
31+
# with:
32+
# languages: go, javascript, csharp, python, cpp, java
33+
34+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
35+
# If this step fails, then you should remove it and run the build manually (see below)
36+
- name: Autobuild
37+
uses: github/codeql-action/autobuild@v1
38+
39+
# ℹ️ Command-line programs to run using the OS shell.
40+
# 📚 https://git.io/JvXDl
41+
42+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
43+
# and modify them (or add more) to build your code if your project
44+
# uses a compiled language
45+
46+
#- run: |
47+
# make bootstrap
48+
# make release
49+
50+
- name: Perform CodeQL Analysis
51+
uses: github/codeql-action/analyze@v1

.github/workflows/publish.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ jobs:
2727
poetry config virtualenvs.in-project false
2828
poetry config virtualenvs.path ~/.virtualenvs
2929
30-
- name: Install Tox
31-
run: pip install tox
30+
- name: Install Dependencies
31+
run: poetry install
3232

33-
- name: Run Tox
34-
run: tox -e py # Run tox using the version of Python in `PATH`
33+
- name: Code Quality
34+
run: poetry run black . --check
35+
continue-on-error: true
36+
37+
- name: Test with pytest
38+
run: poetry run pytest
3539

3640
publish:
3741
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ jobs:
2929
poetry config virtualenvs.in-project false
3030
poetry config virtualenvs.path ~/.virtualenvs
3131
32-
- name: Install Tox
33-
run: pip install tox
32+
- name: Install Dependencies
33+
run: poetry install
3434

35-
- name: Run Tox
36-
run: tox -e py # Run tox using the version of Python in `PATH`
35+
- name: Code Quality
36+
run: poetry run black . --check
37+
continue-on-error: true
38+
39+
- name: Test with pytest
40+
run: poetry run pytest
3741

3842
- name: Upload coverage to Codecov
3943
uses: codecov/codecov-action@v1

examples/builder.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from labthings.server.quick import create_app
1010
from labthings.server import semantics
11+
from labthings.server import fields
1112

1213
from components.pdf_component import PdfComponent
1314

@@ -42,14 +43,25 @@
4243
"magic_dictionary", # Objects attribute name
4344
"/dictionary", # URL to bind the property to
4445
description="A big dictionary of little properties",
46+
schema={ # Property is a dictionary, with these value types
47+
"voltage": fields.Int(),
48+
"volume": fields.List(fields.Int()),
49+
"mode": fields.String(),
50+
"light_on": fields.Bool(),
51+
"user": {"name": fields.String(), "id": fields.Int()},
52+
"bytes": fields.Bytes(),
53+
},
4554
)
4655

4756
labthing.build_action(
4857
my_component.average_data, # Python function
4958
"/average", # URL to bind the action to
5059
description="Take an averaged measurement",
5160
safe=True, # Is the state of the Thing unchanged by calling the action?
52-
idempotent=True, # Can the action be called repeatedly with the same result?
61+
idempotent=True, # Can the action be called repeatedly with the same result?,
62+
args={ # How do we convert from the request input to function arguments?
63+
"n": fields.Int(description="Number of averages to take", example=5, default=5)
64+
},
5365
)
5466

5567

examples/components/pdf_component.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import math
33
import time
44

5-
from typing import List
6-
75
"""
86
Class for our lab component functionality. This could include serial communication,
97
equipment API calls, network requests, or a "virtual" device as seen here.
@@ -41,7 +39,7 @@ def data(self):
4139
"""Return a 1D data trace."""
4240
return [self.noisy_pdf(x) for x in self.x_range]
4341

44-
def average_data(self, n: int, optlist: List[int] = [1, 2, 3]):
42+
def average_data(self, n: int):
4543
"""Average n-sets of data. Emulates a measurement that may take a while."""
4644
summed_data = self.data
4745

poetry.lock

Lines changed: 32 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/labthings/core/lock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
sentinel = object()
99

10+
1011
class RLock(_RLock):
1112
def locked(self):
1213
return self._block.locked()

src/labthings/server/representations.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ def default(self, o):
1919
if isinstance(o, set):
2020
return list(o)
2121
if isinstance(o, bytes):
22-
return b64encode(o).decode()
22+
try: # Try unicode
23+
return o.decode()
24+
except UnicodeDecodeError: # Otherwise, base64
25+
return b64encode(o).decode()
2326
return JSONEncoder.default(self, o)
2427

2528

@@ -32,7 +35,7 @@ def output_json(data, code, headers=None):
3235
"""Makes a Flask response with a JSON encoded body, using app JSON settings"""
3336

3437
settings = current_app.config.get("LABTHINGS_JSON", {})
35-
encoder = current_app.json_encoder
38+
encoder = LabThingsJSONEncoder
3639

3740
if current_app.debug:
3841
settings.setdefault("indent", 4)
@@ -55,7 +58,6 @@ def output_cbor(data, code, headers=None):
5558
"""Makes a Flask response with a CBOR encoded body, using app CBOR settings"""
5659

5760
settings = current_app.config.get("LABTHINGS_CBOR", {})
58-
5961
dumped = encode_cbor(data, **settings)
6062

6163
resp = make_response(dumped, code)

src/labthings/server/types/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/labthings/server/types/annotations.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)