From d90d7d6106f9e9efec0464fe01c926441393e05a Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Fri, 15 May 2026 12:01:49 -0500 Subject: [PATCH 1/3] v2.1.9: include *.usg in package data Adds [tool.setuptools.package-data] so pgpassword.usg (and any future .usg files) are bundled into the built wheel/sdist and installed alongside the package. Bumps version to 2.1.9 in pyproject.toml, __init__.py, and README. Co-Authored-By: Claude Opus 4.6 --- README.md | 2 +- pyproject.toml | 5 ++++- src/rda_python_common/__init__.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6258476..28febab 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN) python -c "import rda_python_common; print(rda_python_common.__version__)" ``` -You should see the installed version (currently `2.1.8`). If the import +You should see the installed version (currently `2.1.9`). If the import fails, double-check that the active Python environment is the one where you ran `pip install`. diff --git a/pyproject.toml b/pyproject.toml index 33392ab..22c94c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "rda_python_common" -version = "2.1.8" +version = "2.1.9" authors = [ { name="Zaihua Ji", email="zji@ucar.edu" }, ] @@ -32,5 +32,8 @@ pythonpath = [ "src" ] +[tool.setuptools.package-data] +rda_python_common = ["*.usg"] + [project.scripts] pgpassword = "rda_python_common.pgpassword:main" diff --git a/src/rda_python_common/__init__.py b/src/rda_python_common/__init__.py index 2914849..1ad368a 100644 --- a/src/rda_python_common/__init__.py +++ b/src/rda_python_common/__init__.py @@ -22,7 +22,7 @@ from . import PgLOG, PgUtil, PgDBI, PgFile, PgLock, PgCMD, PgSIG, PgOPT, PgSplit -__version__ = "2.1.8" +__version__ = "2.1.9" __all__ = [ "PgLOG", From 7876f4a0bf210b2ebcf8e57d9f87cd21136391ae Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Fri, 15 May 2026 12:06:24 -0500 Subject: [PATCH 2/3] fix pgpassword arg parsing: defaults with no args, explicit help flag Previously running pgpassword with no arguments triggered the usage display, so users could not get the password using all defaults. The no-args path now falls through to start_actions(), which performs the lookup with the PgDBI/PgLOG defaults (rdadb/dssdb/etc.). Usage is now requested explicitly via -?, -help, or --help. Also detects an option supplied without its required value (e.g. -d with nothing after it) and reports it as an error instead of silently falling into the help path. Co-Authored-By: Claude Opus 4.6 --- src/rda_python_common/pgpassword.py | 41 ++++++++++++++++------------ src/rda_python_common/pgpassword.usg | 11 ++++++-- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/rda_python_common/pgpassword.py b/src/rda_python_common/pgpassword.py index ff69e40..a27939a 100644 --- a/src/rda_python_common/pgpassword.py +++ b/src/rda_python_common/pgpassword.py @@ -64,23 +64,29 @@ def read_parameters(self): Parse ``sys.argv`` and apply CLI overrides. Recognized options: - -l URL -- OpenBao URL (stored in self.PGDBI['BAOURL']) - -k TOKEN -- OpenBao token name (stored in self.PGDBI['BAOTOKEN']) - -d NAME -- PostgreSQL database name - -c NAME -- PostgreSQL schema name - -u NAME -- PostgreSQL login user name - -h HOST -- PostgreSQL server host name - -p PORT -- PostgreSQL port number + -? / --help -- show usage and exit + -l URL -- OpenBao URL (stored in self.PGDBI['BAOURL']) + -k TOKEN -- OpenBao token name (stored in self.PGDBI['BAOTOKEN']) + -d NAME -- PostgreSQL database name + -c NAME -- PostgreSQL schema name + -u NAME -- PostgreSQL login user name + -h HOST -- PostgreSQL server host name + -p PORT -- PostgreSQL port number - If no arguments are supplied a usage message is printed and the - process exits with status 0. Unknown options or stray values - cause an immediate error exit via ``self.pglog(..., LGEREX)``. + With no arguments, all defaults inherited from PgDBI/PgLOG are + used and the password lookup proceeds. Unknown options, stray + values, or an option without its required value cause an + immediate error exit via ``self.pglog(..., LGEREX)``. """ argv = sys.argv[1:] opt = None - dohelp = True for arg in argv: - if re.match(r'^-[a-zA-Z]$', arg): + if arg in ('-?', '-help', '--help'): + self.set_help_path(__file__) + self.show_usage("pgpassword") + elif re.match(r'^-[a-zA-Z]$', arg): + if opt: + self.pglog("-" + opt + ": missing option value", self.LGEREX) opt = arg[1:] elif opt: if opt == 'l': @@ -91,13 +97,12 @@ def read_parameters(self): self.dbopt = True self.DBINFO[self.DBFLDS[opt]] = arg else: - self.pglog(arg + ": Unknown option", self.LGEREX) - dohelp = False + self.pglog("-" + opt + ": Unknown option", self.LGEREX) + opt = None else: - self.pglog(arg + ": Value provided without option", self.LGEREX) - if dohelp: - self.set_help_path(__file__) - self.show_usage("pgpassword") + self.pglog(arg + ": value provided without option", self.LGEREX) + if opt: + self.pglog("-" + opt + ": missing option value", self.LGEREX) # get the pgpassword def start_actions(self): diff --git a/src/rda_python_common/pgpassword.usg b/src/rda_python_common/pgpassword.usg index 1661040..2ab8eaf 100644 --- a/src/rda_python_common/pgpassword.usg +++ b/src/rda_python_common/pgpassword.usg @@ -5,9 +5,15 @@ file. The retrieved password is printed to stdout so that shell wrappers and other RDA utilities can capture it. - Usage: pgpassword [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \ + Usage: pgpassword [-?] [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \ [-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT] + With no options, pgpassword retrieves the password using all defaults + inherited from PgDBI/PgLOG (see per-option defaults below). + + - Option -?, show this usage information and exit (also -help + and --help); + - Option -l, OpenBao URL used to retrieve passwords. Overrides the BAOURL value from the PgDBI configuration. Default: https://bao.k8s.ucar.edu/ @@ -33,8 +39,7 @@ Default: 5432 If any of -d, -c, -u, -h, or -p is supplied, the values are applied - via default_scinfo() before the password lookup is performed. With no - arguments, this usage information is displayed and the program exits. + via default_scinfo() before the password lookup is performed. Examples: From 593b190be785859f690b938123d54cb063b595d7 Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Fri, 15 May 2026 12:15:00 -0500 Subject: [PATCH 3/3] save --- src/rda_python_common/pgpassword.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rda_python_common/pgpassword.py b/src/rda_python_common/pgpassword.py index a27939a..43b59dd 100644 --- a/src/rda_python_common/pgpassword.py +++ b/src/rda_python_common/pgpassword.py @@ -119,7 +119,7 @@ def start_actions(self): self.password = self.get_baopassword() if not self.password: self.password = self.get_pgpassword() -# main function to excecute this script +# main function to execute this script def main(): """Entry point for the ``pgpassword`` console script: print the retrieved password to stdout.""" object = PgPassword()