Skip to content

CLI: fix SPICE table print issue - #370

Merged
leowerneck merged 2 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:369-bug---cli--display-only-filenames-when-querying
Oct 23, 2026
Merged

leowerneck merged 2 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:369-bug---cli--display-only-filenames-when-querying

Conversation

@leowerneck

@leowerneck leowerneck commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Change Summary

Closes #369.

Overview

Fix issue when printing results from a SPICE table query.

File changes

  • imap_data_access/cli.py: replaced str() with os.path.basename() when printing SPICE filename.
  • tests/test_cli.py: added regression test.

Testing

Running:

imap-data-access query --table spice --type leapseconds

produces the expected output:

---------------|
| Filename     |
---------------|
| naif0012.tls |
---------------|

Other tables continue to work. Running:

imap-data-access query --table ancillary --instrument swe --start-date 20260921

results in:

imap_swe_l1b-in-flight-cal_20260921_v001.csv

and

imap-data-access query --instrument swe --data-level l3 --version latest --start-date 20261022

results in:

imap_swe_l3_sci_20261020_v002.0001.cdf

@leowerneck leowerneck self-assigned this Oct 23, 2026
@leowerneck leowerneck added the bug Something isn't working label Oct 23, 2026
@leowerneck leowerneck added this to IMAP Oct 23, 2026
@leowerneck
leowerneck requested a lite review from Copilot October 23, 2026 15:11
@leowerneck leowerneck moved this to PR Open in IMAP Oct 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Add regression coverage for path-valued table output and move normalization outside the per-column loop to avoid repeated work.

1 open issue
What changed in this PR

This pull request fixes CLI table rendering for SPICE query results by normalizing returned paths to filenames before output.

Changes:

  • Falls back from file_path to file_name.
  • Uses Path(...).name to display filename-only values.
  • Applies normalized filenames consistently across query table types.
File Description
imap_data_access/​cli.py Normalizes query result paths and renders consistent filename-only values.

Review effort: Lite

Comment thread imap_data_access/cli.py Resolved
@leowerneck
leowerneck force-pushed the 369-bug---cli--display-only-filenames-when-querying branch from 40afc37 to 132aebb Compare October 23, 2026 15:24
@leowerneck
leowerneck requested a lite review from Copilot October 23, 2026 15:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Add regression coverage for SPICE table output containing a nested filename path.

1 open issue
1 resolved since last review

Review effort: Lite

Comment thread imap_data_access/cli.py Resolved
@jaredclaypoole

Copy link
Copy Markdown
Contributor

This looks good to me, but I wonder whether the existing behavior (showing the category of spice kernel via the parent directory) is at all desired. Curious to hear from @tmplummer.

@leowerneck

Copy link
Copy Markdown
Contributor Author

I remember bringing this up during a telecon and someone said it was a bug, which is why I had it in my radar to fix it at some point. But I don't recall who it was, so I'll wait for some input from other developers before merging.

@tmplummer

Copy link
Copy Markdown
Contributor

This looks good to me, but I wonder whether the existing behavior (showing the category of spice kernel via the parent directory) is at all desired. Curious to hear from @tmplummer.

I don't see a reason to report the parent directory. We don't do that for any of the science products and I would think if someone is versed enough in SPICE to understand what the type of kernel means, they will be able to identify the kernel type from the extension. I think the current behavior was causing issues being able to use the result to download files from imap-data-access?

@leowerneck

leowerneck commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

I think the current behavior was causing issues being able to use the result to download files from imap-data-access?

I'm not sure there is an issue downloading the file, at least not one I'm aware of. I'm able to download using both:

rm -f $IMAP_DATA_DIR/imap/spice/lsk/naif0012.tls
imap-data-access download lsk/naif0012.tls

and

rm -f $IMAP_DATA_DIR/imap/spice/lsk/naif0012.tls
imap-data-access download naif0012.tls

When scripting I can do:

import imap_data_access

query_results = imap_data_access.spice_query(type="leapseconds")
for result in query_results:
    if not result:
        raise ValueError("Got empty result.")
    print(f"Downloading {result['file_name']!r}... ", end="")
    filepath = imap_data_access.download(result["file_name"])
    if filepath.exists():
        print("OK")
        filepath.unlink()
    else:
        print("Something went wrong")

and I get the message:

Downloading 'lsk/naif0012.tls'... OK

All of this is in the current main btw.

@jaredclaypoole jaredclaypoole left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like the change is desirable. Looks good.

@leowerneck
leowerneck merged commit 5079acb into IMAP-Science-Operations-Center:main Oct 23, 2026
16 checks passed
@leowerneck
leowerneck deleted the 369-bug---cli--display-only-filenames-when-querying branch October 23, 2026 18:53
@github-project-automation github-project-automation Bot moved this from PR Open to Done in IMAP Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

BUG - CLI: display only filenames when querying

4 participants