Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix return code for asn_from_list and skycell_asn, remove unused scripts, cleanup skycell_asn #1538

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
mairanteodoro marked this conversation as resolved.
Show resolved Hide resolved
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 @@
return asn


class Main:
def _cli(args=None):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Including a class as a script in pyproject.toml as is done on main:

asn_from_list = "romancal.associations.asn_from_list:Main"

results in an installed script containing the following line:

sys.exit(Main())

This is problematic because Main() is "truthy" resulting in the script returning 1 on success. By switching this to a function (with no return value) the script becomes:

sys.exit(main())

and the no return value (None) is "falsey" leading to a return code of 0 (success) when the script succeeds.

"""Command-line interface for list_to_asn

Parameters
Expand All @@ -55,93 +55,90 @@
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:]

Check warning on line 59 in romancal/associations/asn_from_list.py

View check run for this annotation

Codecov / codecov/patch

romancal/associations/asn_from_list.py#L59

Added line #L59 was not covered by tests
if isinstance(args, str):
args = args.split(" ")

Check warning on line 61 in romancal/associations/asn_from_list.py

View check run for this annotation

Codecov / codecov/patch

romancal/associations/asn_from_list.py#L61

Added line #L61 was not covered by tests

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
Loading