Skip to content

Scour used procedurally does not run #320

Description

@Trixx-Darthor

TL;DR: Scour works from terminal, but doesn't work when called procedurally.

Hey,

I tried importing scour into my script to use it procedurally and after it ran once and crashed on wrong input (accidentally passed a list instead of a string to IO), it strangely hangs when I run it ever since.
I tried restarting IDE (Pycharm 2023.2.4 CE), re-installing Scorn, changing absolute paths for only filenames with changed working directory.

The problem happens exactly at the moment of calling scour.scour.start(), when the IDE just freezes and doesn't make a step into the function. When I remove the Scour call from my project, everything works smoothly, so it seems to be a problem of Scour. Weird thing is I got it to work once and it only broke after that.

Below I attach the code I use to call Scour (debugging is just my custom console output, basicaly just glorified prints with some colors):

import os
from scour.scour import start as scour, parse_args as scour_args, getInOut as scourIO
import debugging as dbg


def _scour_svg(input_path: os.PathLike,
               output_path: os.PathLike):
    options = scour_args()
    options.input_fname = input_path
    options.output_fname = output_path
    (_input, _output) = scourIO(options)
    scour(options, _input, _output)


def _get_files_from_dir() -> [os.PathLike]:
    return [fname
            for fname in os.listdir(os.getcwd())
            if os.path.splitext(fname)[1] == ".svg" and "scoured" not in fname]


def optimize_figures(figures_dir_path: os.PathLike | str) -> None:
    original_cwd = os.getcwd()
    os.chdir(figures_dir_path)
    fnames = _get_files_from_dir()
    dbg.normal(f"{len(fnames)} un-optimized svg files found")
    for count, fname in enumerate(fnames):
        out_fname = os.path.splitext(fname)[0] + '_scoured.svg'
        _scour_svg(input_path=fname,
                   output_path=out_fname)
        dbg.normal(f"File {count} / {len(fnames)} optimized.")

I then tried running scour from terminal by cd-ing to the directory and running Scour as:

scour -i chart1.svg -o chart1_scoured.svg

which worked. What do I do wrong in the procedural approach?
Also, it would be practical, if you could provide some simple way to perform procedural call. I imagine I can'T be the first one to need this and blunder.

Thanks. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions