Skip to content

Commit

Permalink
fix launching as a module
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Feb 7, 2025
1 parent 67c7acd commit 78a52f4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 41 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} AS developer

# Add any system dependencies for the developer/build environment here
RUN apt-get update && apt-get install -y --no-install-recommends \
graphviz \
&& rm -rf /var/lib/apt/lists/*

# Set up a virtual environment and put it in PATH
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH
Expand All @@ -20,7 +15,12 @@ RUN touch dev-requirements.txt && pip install -c dev-requirements.txt .

# The runtime stage copies the built venv into a slim runtime container
FROM python:${PYTHON_VERSION}-slim AS runtime

# Add apt-get system dependecies for runtime here if needed
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*

COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH

Expand Down
23 changes: 1 addition & 22 deletions src/dls_backup_bl/__main__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
"""Interface for ``python -m dls_backup_bl``."""

from argparse import ArgumentParser
from collections.abc import Sequence

from dls_backup_bl.backup import main as backup_main

from . import __version__

__all__ = ["main"]


def main(args: Sequence[str] | None = None) -> None:
"""Argument parser for the CLI."""
parser = ArgumentParser()
parser.add_argument(
"-v",
"--version",
action="version",
version=__version__,
)
parser.parse_args(args)
backup_main()


if __name__ == "__main__":
main()
backup_main()
16 changes: 11 additions & 5 deletions src/dls_backup_bl/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from multiprocessing.pool import ThreadPool
from pathlib import Path

from . import __version__
from .brick import Brick
from .config import BackupsConfig
from .defaults import Defaults
Expand Down Expand Up @@ -122,6 +123,12 @@ def parse_args(self):
"defaults).",
usage="%(prog)s [options]",
)
parser.add_argument(
"-v",
"--version",
action="version",
version=__version__,
)
parser.add_argument(
"-i",
"--import-cfg",
Expand Down Expand Up @@ -162,7 +169,7 @@ def parse_args(self):
action="store",
type=int,
default=4,
help="Number of times to attempt backup. " "Defaults to 4",
help="Number of times to attempt backup. Defaults to 4",
)
parser.add_argument(
"-t",
Expand Down Expand Up @@ -206,7 +213,7 @@ def parse_args(self):
parser.add_argument(
"--folder",
action="store_true",
help="report the motion backup folder that the " "tool will use.",
help="report the motion backup folder that the tool will use.",
)

# Parse the command line arguments
Expand Down Expand Up @@ -336,7 +343,7 @@ def do_backups(self):
# finish up
self.sort_log()
if total == 0:
log.critical("Nothing was backed up " "(incorrect --devices argument?)")
log.critical("Nothing was backed up (incorrect --devices argument?)")

if not self.args.positions:
commit_changes(self.defaults, do_positions=False)
Expand All @@ -352,8 +359,7 @@ def do_backups(self):
if self.args.positions:
print("The following command reviews the position files")
print(
f"more {self.defaults.motion_folder}/*"
f"{self.defaults.positions_suffix}"
f"more {self.defaults.motion_folder}/*{self.defaults.positions_suffix}"
)

def cancel(self, sig, frame):
Expand Down
12 changes: 4 additions & 8 deletions src/dls_backup_bl/brick.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def restore_positions(self):
if newL[0] == "M" or "m":
axisNo = int(int(newL[0][1:]) / 100)
newL[1] = int(newL[1]) * (1 / positionSFList[axisNo])
newL[1] = f"{int(newL[1])}/{1/positionSFList[axisNo]}"
newL[1] = f"{int(newL[1])}/{1 / positionSFList[axisNo]}"
lines[i] = f"{newL[0]} = {newL[1]}\n"

pmc = [
Expand Down Expand Up @@ -189,8 +189,7 @@ def restore_positions(self):
break
else:
msg = (
f"ERROR: {self.desc} all {self.defaults.retries} "
f"backup attempts failed"
f"ERROR: {self.desc} all {self.defaults.retries} backup attempts failed"
)
log.critical(msg)

Expand Down Expand Up @@ -230,8 +229,7 @@ def backup_controller(self):
break
else:
msg = (
f"ERROR: {self.desc} all {self.defaults.retries} "
f"backup attempts failed"
f"ERROR: {self.desc} all {self.defaults.retries} backup attempts failed"
)
log.critical(msg)

Expand All @@ -248,9 +246,7 @@ def getPositionSF(cls, brick, defaults: Defaults):
with pmc_file.open("r") as f:
pmc = f.read()
except (FileNotFoundError, LookupError):
log.error(
f"could not read i08 for {brick} " f"assuming i08 == 32 for all axes"
)
log.error(f"could not read i08 for {brick} assuming i08 == 32 for all axes")
pmc = ""

for axis in range(1, 33):
Expand Down
2 changes: 1 addition & 1 deletion src/dls_backup_bl/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def compare_changes(defaults: Defaults, pmacs):
file_out += f"\n{name}\n{patch}"

if len(diff) == 0:
output += "\nThere are no changes to positions since the last " "commit"
output += "\nThere are no changes to positions since the last commit"
filepath = defaults.motion_folder / defaults.positions_file
with filepath.open("w") as f:
f.write(f"{output}\n{file_out}")
Expand Down

0 comments on commit 78a52f4

Please sign in to comment.