Skip to content

Commit e89f884

Browse files
authored
Merge pull request #1813 from wkentaro/refactor/simplify_output_to_always_mean_directory
refactor!: simplify --output to always mean directory
2 parents 5243c35 + a6684d6 commit e89f884

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

.claude/CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Project Rules
2+
3+
- use `uv` to run Python commands (e.g., `uv run python`, `uv run pytest`).

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ labelme # just open gui
9797
# tutorial (single image example)
9898
cd examples/tutorial
9999
labelme apc2016_obj3.jpg # specify image file
100-
labelme apc2016_obj3.jpg -O apc2016_obj3.json # close window after the save
100+
labelme apc2016_obj3.jpg --output annotations/ # save annotation JSON files to a directory
101101
labelme apc2016_obj3.jpg --nodata # not include image data but relative image path in JSON file
102102
labelme apc2016_obj3.jpg \
103103
--labels highland_6539_self_stick_notes,mead_index_cards,kong_air_dog_squeakair_tennis_ball # specify label list

labelme/__main__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ def main():
111111
parser.add_argument("filename", nargs="?", help="image or label filename")
112112
parser.add_argument(
113113
"--output",
114-
"-O",
115-
"-o",
116-
help="output file or directory (if it ends with .json it is "
117-
"recognized as file, else as directory)",
114+
help="output directory for saving annotation JSON files",
118115
)
119116
default_config_file = get_user_config_file()
120117
parser.add_argument(
@@ -237,13 +234,14 @@ def main():
237234
del config_str
238235
config_overrides.update(config_from_args)
239236

240-
output_file = None
241237
output_dir = None
242238
if output is not None:
243239
if output.endswith(".json"):
244-
output_file = output
245-
else:
246-
output_dir = output
240+
parser.error(
241+
f"--output expects a directory path, but '{output}' looks like a file."
242+
" Remove the .json extension or provide a directory path."
243+
)
244+
output_dir = output
247245

248246
translator = QtCore.QTranslator()
249247
translator.load(
@@ -261,7 +259,6 @@ def main():
261259
config_file=config_file,
262260
config_overrides=config_overrides,
263261
filename=filename,
264-
output_file=output_file,
265262
output_dir=output_dir,
266263
)
267264

labelme/app.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,8 @@ def __init__(
109109
config_file: Path | None = None,
110110
config_overrides: dict | None = None,
111111
filename: str | None = None,
112-
output: str | None = None,
113-
output_file: str | None = None,
114112
output_dir: str | None = None,
115113
) -> None:
116-
if output is not None:
117-
logger.warning("argument output is deprecated, use output_file instead")
118-
if output_file is None:
119-
output_file = output
120-
del output
121-
122114
super().__init__()
123115
self.setWindowTitle(__appname__)
124116

@@ -917,13 +909,6 @@ def __init__(
917909
self.statusBar().addWidget(self.status_right, 0)
918910
self.statusBar().show()
919911

920-
if output_file is not None and self._config["auto_save"]:
921-
logger.warning(
922-
"If `auto_save` argument is True, `output_file` argument "
923-
"is ignored and output filename is automatically "
924-
"set as IMAGE_BASENAME.json."
925-
)
926-
self.output_file = output_file
927912
self.output_dir = output_dir
928913

929914
# Application state.
@@ -2067,11 +2052,7 @@ def changeOutputDirDialog(self, _value=False):
20672052
def saveFile(self, _value=False):
20682053
assert not self.image.isNull(), "cannot save empty image"
20692054
if self.labelFile:
2070-
# DL20180323 - overwrite when in directory
20712055
self._saveFile(self.labelFile.filename)
2072-
elif self.output_file:
2073-
self._saveFile(self.output_file)
2074-
self.close()
20752056
else:
20762057
self._saveFile(self.saveFileDialog())
20772058

tests/e2e/annotation_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def test_MainWindow_annotate_jpg(
2626

2727
win: labelme.app.MainWindow = labelme.app.MainWindow(
2828
filename=input_file,
29-
output_file=out_file,
29+
config_overrides=dict(auto_save=True),
30+
output_dir=str(tmp_path),
3031
)
3132
qtbot.addWidget(win)
3233
show_window_and_wait_for_imagedata(qtbot=qtbot, win=win)

0 commit comments

Comments
 (0)