Skip to content

Commit

Permalink
fix return code for asn_from_list and skycell_asn, remove unused scri…
Browse files Browse the repository at this point in the history
…pts, cleanup skycell_asn (#1538)
  • Loading branch information
braingram authored Dec 10, 2024
2 parents 5c515b8 + 800fd01 commit 6cb4b51
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 191 deletions.
1 change: 1 addition & 0 deletions changes/1538.associations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch association scripts from using ``Main`` class to ``_cli`` function to fix return code.
1 change: 1 addition & 0 deletions changes/1538.scripts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove install of missing scripts "schema_editor" and "schemadoc".
3 changes: 1 addition & 2 deletions docs/roman/associations/asn_from_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ asn_from_list
=============

Create an association using either the command line tool
``asn_from_list`` or through the Python API using either
:class:`romancal.associations.asn_from_list.Main` or
``asn_from_list`` or through the Python API using
:func:`romancal.associations.asn_from_list.asn_from_list`


Expand Down
3 changes: 1 addition & 2 deletions docs/roman/associations/skycell_asn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ skycell_asn
===========

Create an association using either the command line tool
``skycell_asn`` or through the Python API using either
:class:`romancal.associations.skycell_asn.Main` or
``skycell_asn`` or through the Python API using
:func:`romancal.associations.skycellasn.skycell_asn`


Expand Down
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ webbpsf = "pytest_plugin.webbpsf_plugin"

[project.scripts]
roman_static_preview = "romancal.scripts.static_preview:command"
schema_editor = "romancal.scripts.schema_editor:main"
schemadoc = "romancal.scripts.schemadoc:main"
verify_install_requires = "romancal.scripts.verify_install_requires:main"
asn_from_list = "romancal.associations.asn_from_list:Main"
skycell_asn = "romancal.associations.skycell_asn:Main"
asn_from_list = "romancal.associations.asn_from_list:_cli"
skycell_asn = "romancal.associations.skycell_asn:_cli"

[build-system]
requires = [
Expand Down
177 changes: 87 additions & 90 deletions romancal/associations/asn_from_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def asn_from_list(items, rule=DMS_ELPP_Base, **kwargs):
return asn


class Main:
def _cli(args=None):
"""Command-line interface for list_to_asn
Parameters
Expand All @@ -55,93 +55,90 @@ class Main:
with the similar structure as `sys.argv`
"""

def __init__(self, args=None):
if args is None:
args = sys.argv[1:]
if isinstance(args, str):
args = args.split(" ")

parser = argparse.ArgumentParser(
description="Create an association from a list of files",
usage="asn_from_list -o mosaic_asn.json\n--product-name my_mosaic *.fits",
)

parser.add_argument(
"-o",
"--output-file",
type=str,
required=True,
help="File to write association to",
)

parser.add_argument(
"-f",
"--format",
type=str,
default="json",
help='Format of the association files. Default: "%(default)s"',
)

parser.add_argument(
"--product-name",
type=str,
help="The product name when creating a Level 3 association",
if args is None:
args = sys.argv[1:]
if isinstance(args, str):
args = args.split(" ")

parser = argparse.ArgumentParser(
description="Create an association from a list of files",
usage="asn_from_list -o mosaic_asn.json\n--product-name my_mosaic *.asdf",
)

parser.add_argument(
"-o",
"--output-file",
type=str,
required=True,
help="File to write association to",
)

parser.add_argument(
"-f",
"--format",
type=str,
default="json",
help='Format of the association files. Default: "%(default)s"',
)

parser.add_argument(
"--product-name",
type=str,
help="The product name when creating a Level 3 association",
)

parser.add_argument(
"-r",
"--rule",
type=str,
default="DMS_ELPP_Base",
help=('The rule to base the association structure on. Default: "%(default)s"'),
)
parser.add_argument(
"--ruledefs",
action="append",
help=(
"Association rules definition file(s) If not specified, the default"
" rules will be searched."
),
)
parser.add_argument(
"-i",
"--id",
type=str,
default="o999",
help='The association candidate id to use. Default: "%(default)s"',
dest="acid",
)
parser.add_argument(
"-t",
"--target",
type=str,
default="None",
help='The target name for the association. Default: "%(default)s"',
dest="target",
)

parser.add_argument(
"filelist",
type=str,
nargs="+",
help="File list to include in the association",
)

parsed = parser.parse_args(args=args)
print("Parsed args:", parsed)

# Get the rule
rule = AssociationRegistry(parsed.ruledefs, include_bases=True)[parsed.rule]

with open(parsed.output_file, "w") as outfile:
asn = asn_from_list(
parsed.filelist,
rule=rule,
product_name=parsed.product_name,
acid=parsed.acid,
target=parsed.target,
)

parser.add_argument(
"-r",
"--rule",
type=str,
default="DMS_ELPP_Base",
help=(
'The rule to base the association structure on. Default: "%(default)s"'
),
)
parser.add_argument(
"--ruledefs",
action="append",
help=(
"Association rules definition file(s) If not specified, the default"
" rules will be searched."
),
)
parser.add_argument(
"-i",
"--id",
type=str,
default="o999",
help='The association candidate id to use. Default: "%(default)s"',
dest="acid",
)
parser.add_argument(
"-t",
"--target",
type=str,
default="None",
help='The target name for the association. Default: "%(default)s"',
dest="target",
)

parser.add_argument(
"filelist",
type=str,
nargs="+",
help="File list to include in the association",
)

parsed = parser.parse_args(args=args)
print("Parsed args:", parsed)

# Get the rule
rule = AssociationRegistry(parsed.ruledefs, include_bases=True)[parsed.rule]

with open(parsed.output_file, "w") as outfile:
asn = asn_from_list(
parsed.filelist,
rule=rule,
product_name=parsed.product_name,
acid=parsed.acid,
target=parsed.target,
)
_, serialized = asn.dump(format=parsed.format)
outfile.write(serialized)
_, serialized = asn.dump(format=parsed.format)
outfile.write(serialized)
Loading

0 comments on commit 6cb4b51

Please sign in to comment.