Skip to content

Refactor PDBList CLI to use argparse while preserving legacy behavior#5167

Open
MANICHELLURII wants to merge 3 commits intobiopython:masterfrom
MANICHELLURII:improve-pdblist-argparse
Open

Refactor PDBList CLI to use argparse while preserving legacy behavior#5167
MANICHELLURII wants to merge 3 commits intobiopython:masterfrom
MANICHELLURII:improve-pdblist-argparse

Conversation

@MANICHELLURII
Copy link
Copy Markdown

Summary

This PR replaces manual sys.argv parsing in Bio/PDB/PDBList.py with argparse.

Improvements

  • Replaces manual argument handling with structured argparse
  • Adds automatic --help generation
  • Preserves original usage documentation via epilog
  • Maintains backward compatibility with legacy flags:
    • -pdb
    • -xml
    • -mmtf
  • Preserves support for:
    • update, all, obsol, assemb
    • Single PDB IDs
    • Multiple PDB IDs (1ABC,2XYZ)
    • --with-assemblies
  • No functional changes intended

Motivation

Improves maintainability, clarity, and future extensibility of CLI handling while preserving existing behavior.

@MANICHELLURII MANICHELLURII marked this pull request as ready for review February 21, 2026 19:15
@MANICHELLURII
Copy link
Copy Markdown
Author

I would appreciate feedback on whether the updated CLI structure aligns with current Biopython conventions and if any additional backward compatibility concerns should be addressed. Please let me know if dedicated CLI tests are expected or if the argument-handling logic would be better placed in a separate entry-point script. I’m happy to refine the implementation further.

Comment thread Bio/PDB/PDBList.py
parser.add_argument(
"action",
help="update | all | obsol | assemb | PDB ID | (PDB1,PDB2,...)"
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can't list the valid actions here can you (in plain argparse)? I've been using a more fancy command line API lately so my expectations have changed 😅

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@peterjc it was my first PR so it took me somewhile to understand properly & i can resolve above issue clean & clear,
thank you for the review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There isn't a better way here because while the 'named actions' (all, update, etc) can be checked, the wildcard PDB-ID arguments cannot.. The correct way here would be to move all those named actions to options and make the only argument pdb ids, but that breaks the current interface.

I'm OK doing that and it's a much better QoL improvement, but it'll need a deprecation warning for a couple of releases.

@peterjc
Copy link
Copy Markdown
Member

peterjc commented Feb 21, 2026

You'll need to run black on this.

Otherwise, at first skim-read you've done a nice job: this looks like a faithfull backward compatible re-write using argparse.

Comment thread Bio/PDB/PDBList.py
parser.add_argument(
"action",
help="update | all | obsol | assemb | PDB ID | (PDB1,PDB2,...)"
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There isn't a better way here because while the 'named actions' (all, update, etc) can be checked, the wildcard PDB-ID arguments cannot.. The correct way here would be to move all those named actions to options and make the only argument pdb ids, but that breaks the current interface.

I'm OK doing that and it's a much better QoL improvement, but it'll need a deprecation warning for a couple of releases.

Comment thread Bio/PDB/PDBList.py

args = parser.parse_args()
# Backward compatibility for legacy format flags
if args.pdb:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd slap a deprecation warning on whoever is using these flags and direct them to the --format option. Otherwise we'll live with this forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants