Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to use table packing in utils #14

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
python: ["3.9", "3.10", "3.11"]
python: ["3.9", "3.10"] # Disable 3.11 until this is fixed:https://github.com/PandABlocks/PandABlocks-client/issues/47
install: ["-e .[dev]"]
# Make one version be non-editable to test both paths of version code
include:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ venv*

# further build artifacts
lockfiles/

3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"args": [
"softioc",
"172.23.252.201",
"SOME-PREFIX"
"SOME-PREFIX",
"./screens"
],
"console": "integratedTerminal",
"justMyCode": false
Expand Down
16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ dependencies = [
"numpy",
"click",
"h5py",
"softioc>=4.1.0",
"pandablocks>=0.3.1",
"softioc>=4.3.0",
"pandablocks@git+https://github.com/evalott100/PandABlocks-client@add-seq_table2cmd",
"pvi[cli]>=0.4",
"aiohttp",
] # Add project dependencies here, e.g. ["click", "numpy"]
dynamic = ["version"]
license.file = "LICENSE"
Expand All @@ -37,6 +36,7 @@ dev = [
"Flake8-pyproject",
"pipdeptree",
"pre-commit",
"p4p",
"pydata-sphinx-theme>=0.12",
"pytest-asyncio",
"pytest-cov",
Expand Down Expand Up @@ -88,19 +88,25 @@ addopts = """
--cov=pandablocks_ioc --cov-report term --cov-report xml:cov.xml
"""
# https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings
# The ignores are all related to the test DummyServer, both async and in_thread variants,
# First ignore is due to p4p staticly linking an old numpy version and us installing
# Next is something that needs to be fixed in PandABlocks-client asyncio.py's write_and_drain function
# which triggers a deprecation warning on Python 3.9+. See https://github.com/PandABlocks/PandABlocks-client/issues/47.
# a more recent version with a different C API. See https://github.com/mdavidsaver/p4p/issues/102.
# Remaining ignores are all related to the test DummyServer, both async and in_thread variants,
# which appear to have issues cleanly shutting down and raise exceptions in their destructors.
# The issue seems like all we need is to add await asyncio.sleep(0) to allow asyncio to
# clean up its connections, but that doesn't seem to behave as expected inside pytest.
filterwarnings = """
error
ignore:numpy.ufunc size changed
ignore:The explicit passing of coroutine objects to asyncio.wait()
ignore:unclosed transport <_SelectorSocketTransport:
ignore:unclosed <socket.socket:
ignore:unclosed event loop <_UnixSelectorEventLoop:
"""
# ignore::ResourceWarning
# Doctest python code in docs, python code in src docstrings, test functions in tests
testpaths = "docs src tests"
asyncio_mode = "auto"

[tool.coverage.run]
data_file = "/tmp/pandablocks_ioc.coverage"
Expand Down
8 changes: 5 additions & 3 deletions src/pandablocks_ioc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def cli(ctx, log_level: str):
@cli.command()
@click.argument("host")
@click.argument("prefix")
def softioc(host: str, prefix: str):
@click.argument("screens_dir")
def softioc(host: str, prefix: str, screens_dir: str):
"""
Create a soft IOC, using "prefix" for the namespace of the records.
Connect to the given HOST and create an IOC with the given PREFIX.
Create .bob files for screens in the SCREENS_DIR. Directory must exist.
"""
create_softioc(host, prefix)
create_softioc(host=host, record_prefix=prefix, screens_dir=screens_dir)


# test with: python -m pandablocks_ioc
Expand Down
34 changes: 17 additions & 17 deletions src/pandablocks_ioc/_pvi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import tempfile
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -139,9 +138,13 @@ def add_positions_table_row(
class Pvi:
"""TODO: Docs"""

# pvi_info_dict: Dict[EpicsName, PviInfo] = {}
_screens_dir: Path = Path()
pvi_info_dict: Dict[str, Dict[PviGroup, List[Component]]] = {}
bob_file_dict: Dict[str, str] = {}

@staticmethod
def set_screens_dir(screens_dir: str):
Pvi._screens_dir = Path(screens_dir)
assert Pvi._screens_dir.is_dir(), "Screens directory must exist"

@staticmethod
def add_pvi_info(record_name: EpicsName, group: PviGroup, component: Component):
Expand Down Expand Up @@ -206,22 +209,19 @@ def create_pvi_records(record_prefix: str):
# Create top level Device, with references to all child Devices
device_refs = [DeviceRef(x, x) for x in pvi_records]

# # TODO: What should the label be?
device = Device("TOP", device_refs)
devices.append(device)

# TODO: label widths need some tweaking - some are pretty long right now
# TODO: Need to decide how to handle already existing directory/files.
# Could still be left over stuff from a previous run?
formatter = DLSFormatter(label_width=250)
with tempfile.TemporaryDirectory() as temp_dir:
for device in devices:
try:
formatter.format(
device,
record_prefix + ":",
Path(f"{temp_dir}/{device.label}.bob"),
)
with open(f"{temp_dir}/{device.label}.bob") as f:
Pvi.bob_file_dict.update({f"{device.label}.bob": f.read()})

except NotImplementedError:
logging.exception("Cannot create TABLES yet")
for device in devices:
try:
formatter.format(
device,
record_prefix + ":",
Pvi._screens_dir / Path(f"{device.label}.bob"),
)
except NotImplementedError:
logging.exception("Cannot create TABLES yet")
Loading