Skip to content

Commit

Permalink
Merge pull request #386 from European-XFEL/feat/damnit-cli
Browse files Browse the repository at this point in the history
feat: Rename CLI from 'amore-proto' to 'damnit'
  • Loading branch information
tmichela authored Feb 7, 2025
2 parents 9c7025c + ecc31f5 commit 88824dd
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 24 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ RUN set -eux; \
python3 -m pip check; \
python3 -c "import damnit; print(damnit.__version__)"

CMD ["/app/bin/amore-proto", "gui"]

CMD ["/app/bin/damnit", "gui"]
2 changes: 1 addition & 1 deletion damnit/backend/extraction_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _slurm_cluster_opts(self):


def reprocess(runs, proposal=None, match=(), mock=False, watch=False, direct=False, limit_running=30):
"""Called by the 'amore-proto reprocess' subcommand"""
"""Called by the 'damnit reprocess' subcommand"""
submitter = ExtractionSubmitter(Path.cwd())
if proposal is None:
proposal = submitter.proposal
Expand Down
2 changes: 1 addition & 1 deletion damnit/backend/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ username=
password=

[program:damnit]
command=amore-proto listen .
command=damnit listen .
stopasgroup=true
directory=
stderr_logfile=NONE
Expand Down
6 changes: 5 additions & 1 deletion damnit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def excepthook(exc_type, value, tb):


def main(argv=None):
# Check if script was called as amore-proto and show deprecation warning
if Path(sys.argv[0]).name == 'amore-proto':
print(colored("Warning: 'amore-proto' has been renamed to 'damnit'. Please update your scripts.", 'yellow'), file=sys.stderr)

ap = ArgumentParser()
ap.add_argument('--debug', action='store_true',
help="Show debug logs.")
Expand Down Expand Up @@ -212,7 +216,7 @@ def main(argv=None):

if args.daemonize:
if not db_path(args.context_dir).is_file():
sys.exit("You must create a database with `amore-proto proposal` before starting the listener.")
sys.exit("You must create a database with `damnit proposal` before starting the listener.")

return initialize_and_start_backend(args.context_dir)
else:
Expand Down
30 changes: 15 additions & 15 deletions docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ change the limits for non-cluster variables:

```bash
# Allow 8 CPU cores
$ amore-proto db-config noncluster_cpus 8
$ damnit db-config noncluster_cpus 8

# Allow 50 GB memory
$ amore-proto db-config noncluster_mem 50G
$ damnit db-config noncluster_mem 50G
```

## Cell
Expand Down Expand Up @@ -191,10 +191,10 @@ DAMNIT will figure out an appropriate partition that user has access to, but
that can be overridden by explicitly setting a partition or reservation:
```bash
# Set a reservation
$ amore-proto db-config slurm_reservation upex_001234
$ damnit db-config slurm_reservation upex_001234

# Set a partition
$ amore-proto db-config slurm_partition allgpu
$ damnit db-config slurm_partition allgpu
```

If both `slurm_reservation` and `slurm_partition` are set, the reservation will
Expand All @@ -208,7 +208,7 @@ stderr) in the `slurm_logs/` directory.
expired, otherwise Slurm jobs will fail to launch.

```bash
$ amore-proto db-config slurm_reservation --delete
$ damnit db-config slurm_reservation --delete
```

## Reprocessing
Expand All @@ -217,8 +217,8 @@ context file the changes will only take effect for the runs coming later. But,
it is possible to reprocess runs using a command line tool:
```bash
$ module load exfel amore
$ amore-proto reprocess -h
usage: amore-proto reprocess [-h] [--mock] [--proposal PROPOSAL] [--match MATCH] run [run ...]
$ damnit reprocess -h
usage: damnit reprocess [-h] [--mock] [--proposal PROPOSAL] [--match MATCH] run [run ...]

positional arguments:
run Run number, e.g. 96. Multiple runs can be specified at once, or pass 'all' to reprocess all runs in the database.
Expand All @@ -234,19 +234,19 @@ Note that you *must* run the tool from a database directory
(`usr/Shared/amore`). Here are some examples of using it:
```bash
# Reprocess all variables for a single run
$ amore-proto reprocess 100
$ damnit reprocess 100

# Reprocess all variables with a title matching 'agipd' for a single run
$ amore-proto reprocess 100 --match agipd
$ damnit reprocess 100 --match agipd

# Reprocess variables for multiple runs
$ amore-proto reprocess 1 10 100 --match agipd
$ damnit reprocess 1 10 100 --match agipd

# Reprocess variables for a sequence of runs
$ amore-proto reprocess $(seq 1 100) --match agipd
$ damnit reprocess $(seq 1 100) --match agipd

# Reprocess all variables for all runs
$ amore-proto reprocess all
$ damnit reprocess all
```

## Using custom environments
Expand All @@ -256,7 +256,7 @@ a certain environment. At some point the setting for this will be exposed
in the GUI, but right now you'll have to change it on the command line by
passing the path to the `python` executable of the required environment:
```bash
$ amore-proto db-config context_python /path/to/your/python
$ damnit db-config context_python /path/to/your/python
```

The environment *must* have these dependencies installed for DAMNIT to work:
Expand Down Expand Up @@ -314,8 +314,8 @@ The steps to delete all existing data are:

1. `rm runs.sqlite` to delete the database used by the GUI.
1. `rm -rf extracted_data/` to delete the HDF5 files created by the backend.
1. `amore-proto proposal 1234` to create a blank database for the given
1. `damnit proposal 1234` to create a blank database for the given
proposal.

And then you can reprocess runs with `amore-proto reprocess` to restore
And then you can reprocess runs with `damnit reprocess` to restore
their data.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Changed:
- Status column can be hidden (!324).
- Activate software OpenGL by default on maxwell nodes (!332).
- Use Slurm array jobs to limit concurrent extraction jobs (!335).
- Renamed the 'amore-proto' command to 'damnit' (!386).

Fixed:

Expand Down
8 changes: 4 additions & 4 deletions docs/gui.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
2. Open a terminal and run:
```bash
$ module load exfel amore
$ amore-proto gui
$ damnit gui
```
3. If you want to work with the shared database for a proposal you can enter the
proposal number directly (it will prompt you to create one if it doesn't
Expand All @@ -23,12 +23,12 @@ $ mkdir mydb
$ cd mydb

# Initialize the database for a certain proposal
$ amore-proto proposal 1234
$ damnit proposal 1234
# Start the backend and create a default context file
$ amore-proto listen . --daemonize
$ damnit listen . --daemonize

# Start the GUI
$ amore-proto gui .
$ damnit gui .
```

## Exploring variables
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Home = "https://github.com/European-XFEL/DAMNIT"

[project.scripts]
amore-proto = "damnit.cli:main"
damnit = "damnit.cli:main"

[tool.pytest.ini_options]
timeout = 120
Expand Down
20 changes: 20 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,23 @@ def mock_sbatch():
main(["reprocess", "10"])

assert sbatch.get_calls() == []


def test_cli_command_name(capsys, monkeypatch):
"""Test that the CLI works with both 'damnit' and 'amore-proto' names,
and shows deprecation warning for 'amore-proto'."""
with patch('sys.argv', ['damnit', '--help']):
with pytest.raises(SystemExit) as exc:
main()
assert exc.value.code == 0
captured = capsys.readouterr()
assert 'Warning:' not in captured.err # No warning for 'damnit'
assert 'usage:' in captured.out # Help text is shown

with patch('sys.argv', ['amore-proto', '--help']):
with pytest.raises(SystemExit) as exc:
main()
assert exc.value.code == 0
captured = capsys.readouterr()
assert "Warning: 'amore-proto' has been renamed to 'damnit'" in captured.err # Shows deprecation
assert 'usage:' in captured.out # Help text is shown

0 comments on commit 88824dd

Please sign in to comment.