Skip to content

Commit 06ec134

Browse files
authored
Merge pull request #94 from AiDAPT-A/93-error-settings
Fix error when invokin settings from CLI
2 parents d126cd0 + c336d98 commit 06ec134

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "visarchpy"
7-
version = "1.0.3"
7+
version = "1.0.4"
88
authors = [
99
{name = "Manuel Garcia", email = "m.g.garciaalvarez@tudelft.nl"},
1010
]
@@ -68,4 +68,3 @@ addopts = [
6868

6969
[project.scripts]
7070
visarch = "visarchpy.cli.main:app"
71-

src/visarchpy/cli/layout.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
from visarchpy.utils import create_output_dir
99
import shutil
10-
import visarchpy.cli.settings as settings
10+
import visarchpy.cli.settings as default_settings
1111

1212

1313
app = typer.Typer(help="Extract images from PDF files using layout \
@@ -20,12 +20,12 @@
2020
def from_file(
2121
pdf_file: str = typer.Argument(help="Path to directory containing PDF files."),
2222
output_directory: str = typer.Argument(help="Path to directory where results will be saved."),
23-
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings will be used. Use: [COMMAND] settings, to see current settings.")] = None,
23+
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings are used. Use: [COMMAND] settings, to see current settings.")] = None,
2424
mods: Annotated[str, typer.Option(help="Path to MODS file. If None, metadata extraction will be skiped.")] = None
2525
) -> None:
2626

2727
if settings is None:
28-
settings = settings.init()
28+
settings = default_settings.init()
2929
else:
3030
with open(settings, "r") as f:
3131
settings = json.load(f)
@@ -54,13 +54,13 @@ def from_file(
5454
def from_dir(
5555
data_directory: str = typer.Argument(help="Path to directory containing PDF files."),
5656
output_directory: str = typer.Argument(help="Path to directory where results will be saved."),
57-
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings will be used. Use: [COMMAND] settings, to see current settings.")] = None,
57+
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings are used. Use: [COMMAND] settings, to see current settings.")] = None,
5858
mods: Annotated[str, typer.Option(help="Path to MODS file. If None, metadata extraction will be skiped.")] = None,
5959
tmp: Annotated[str, typer.Option(help="If provided, PDF files in the data directory will be copied to this directory.")
6060
] = None) -> None:
6161

6262
if settings is None:
63-
settings = settings.init()
63+
settings = default_settings.init()
6464
else:
6565
with open(settings, "r") as f:
6666
settings = json.load(f)
@@ -76,7 +76,7 @@ def from_dir(
7676
@app.command(help="Show default settings for the pipeline.")
7777
def settings() -> None:
7878
"""Show default settings for the pipeline."""
79-
typer.echo(default_settings)
79+
typer.echo(default_settings.init())
8080

8181

8282
if __name__ == "__main__":

src/visarchpy/cli/layout_ocr.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
from visarchpy.utils import create_output_dir
99
import shutil
10-
import visarchpy.cli.settings as settings
10+
import visarchpy.cli.settings as default_settings
1111

1212
app = typer.Typer(help="Extract images from PDF files using layout and \
1313
OCR analysis.",
@@ -19,12 +19,12 @@
1919
def from_file(
2020
pdf_file: str = typer.Argument(help="Path to directory containing PDF files."),
2121
output_directory: str = typer.Argument(help="Path to directory where results will be saved."),
22-
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings will be used. Use: [COMMAND] settings, to see current settings.")] = None,
22+
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings are used. Use: [COMMAND] settings, to see current settings.")] = None,
2323
mods: Annotated[str, typer.Option(help="Path to MODS file. If None, metadata extraction will be skiped.")] = None
2424
) -> None:
2525

2626
if settings is None:
27-
settings = settings.init()
27+
settings = default_settings.init()
2828
else:
2929
with open(settings, "r") as f:
3030
settings = json.load(f)
@@ -53,13 +53,13 @@ def from_file(
5353
def from_dir(
5454
data_directory: str = typer.Argument(help="Path to directory containing PDF files."),
5555
output_directory: str = typer.Argument(help="Path to directory where results will be saved."),
56-
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings will be used. Use: [COMMAND] settings, to see current settings.")] = None,
56+
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings are used. Use: [COMMAND] settings, to see current settings.")] = None,
5757
mods: Annotated[str, typer.Option(help="Path to MODS file. If None, metadata extraction will be skiped.")] = None,
5858
tmp: Annotated[str, typer.Option(help="If provided, PDF files in the data directory will be copied to this directory.")
5959
] = None) -> None:
6060

6161
if settings is None:
62-
settings = settings.init()
62+
settings = default_settings.init()
6363
else:
6464
with open(settings, "r") as f:
6565
settings = json.load(f)
@@ -75,21 +75,21 @@ def from_dir(
7575
@app.command(help="Show default settings for the pipeline.")
7676
def settings() -> None:
7777
"""Show default settings for the pipeline."""
78-
typer.echo(default_settings)
78+
typer.echo(default_settings.init())
7979

8080

8181
@app.command(help="batch processing for TU Delft's dataset.")
8282
def batch(entry_range: str = typer.Argument(help="Range of entries to process, e.g.: 1-10."),
8383
data_directory: str = typer.Argument(help="path to directory containing MODS and PDF files."),
8484
output_directory: str = typer.Argument(help="path to directory where results will be saved."),
85-
settings: Annotated[str, typer.Option(help="path to pipeline JSON setting file. If None default settings will be used. Use: [COMMAND] settings, to see current settings.")] = None,
85+
settings: Annotated[str, typer.Option(help="path to pipeline JSON setting file. If None default settings are used. Use: [COMMAND] settings, to see current settings.")] = None,
8686
tmp: Annotated[str, typer.Option(help="If provided, PDF files in the data directory will be copied to this directory.")
8787
] = None) -> None:
8888
"""Extracts metadata from MODS files and images from PDF files
8989
using layout and OCR pipeline"""
9090

9191
if settings is None:
92-
settings = default_settings
92+
settings = default_settings.init()
9393
else:
9494
with open(settings, "r") as f:
9595
settings = json.load(f)

src/visarchpy/cli/ocr.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
from visarchpy.utils import create_output_dir
99
import shutil
10-
import visarchpy.cli.settings as settings
10+
import visarchpy.cli.settings as default_settings
1111

1212

1313
app = typer.Typer(help="Extract images from PDF files using OCR \
@@ -20,12 +20,12 @@
2020
def from_file(
2121
pdf_file: str = typer.Argument(help="Path to directory containing PDF files."),
2222
output_directory: str = typer.Argument(help="Path to directory where results will be saved."),
23-
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings will be used. Use: [COMMAND] settings, to see current settings.")] = None,
23+
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings are used. Use: [COMMAND] settings, to see current settings.")] = None,
2424
mods: Annotated[str, typer.Option(help="Path to MODS file. If None, metadata extraction will be skiped.")] = None
2525
) -> None:
2626

2727
if settings is None:
28-
settings = settings.init()
28+
settings = default_settings.init()
2929
else:
3030
with open(settings, "r") as f:
3131
settings = json.load(f)
@@ -54,13 +54,13 @@ def from_file(
5454
def from_dir(
5555
data_directory: str = typer.Argument(help="Path to directory containing PDF files."),
5656
output_directory: str = typer.Argument(help="Path to directory where results will be saved."),
57-
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings will be used. Use: [COMMAND] settings, to see current settings.")] = None,
57+
settings: Annotated[str, typer.Option(help="Path to pipeline JSON setting file. If None default settings are used. Use: [COMMAND] settings, to see current settings.")] = None,
5858
mods: Annotated[str, typer.Option(help="Path to MODS file. If None, metadata extraction will be skiped.")] = None,
5959
tmp: Annotated[str, typer.Option(help="If provided, PDF files in the data directory will be copied to this directory.")
6060
] = None) -> None:
6161

6262
if settings is None:
63-
settings = settings.init()
63+
settings = default_settings.init()
6464
else:
6565
with open(settings, "r") as f:
6666
settings = json.load(f)
@@ -76,7 +76,7 @@ def from_dir(
7676
@app.command(help="Show default settings for the pipeline.")
7777
def settings() -> None:
7878
"""Show default settings for the pipeline."""
79-
typer.echo(default_settings)
79+
typer.echo(default_settings.init())
8080

8181

8282
if __name__ == "__main__":

src/visarchpy/cli/settings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2+
import json
23

34
def init():
4-
default_settings_file = os.path.join(current_dir, "../default-settings.json")
55
current_dir = os.path.dirname(os.path.realpath(__file__))
6+
default_settings_file = os.path.join(current_dir, "../default-settings.json")
67
with open(default_settings_file, "r") as f:
7-
global default_settings
8-
dafault_settings = json.load(f)
8+
default_settings = json.load(f)
9+
10+
return default_settings

0 commit comments

Comments
 (0)