Skip to content

[Code Bug]: PowerpointImage.py, _save function fails in windows when val is of type RenderControlFigureRecord #262

@e10harvey

Description

@e10harvey

Contact Details

No response

What happened?

When running the PowerpointImage.save function on RenderControlFigureRecord, the following error occurs in windows

================================== FAILURES ===================================
_______________________ test_PowerpointImage.test_save ________________________

self = <opencsp.common.lib.render.lib.PowerpointImage.PowerpointImage object at 0x0000026736ED9F30>
from_dir_name_ext = 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\tmpz2g6pzzq.png'
to_dir_name_ext = 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\PowerpointImage/images/tmp\\0_3.png'

    def _move_file(self, from_dir_name_ext: str, to_dir_name_ext: str):
        """Move a file from one location to another.
    
        Args:
            from_dir_name_ext (str): The source file path.
            to_dir_name_ext (str): The destination file path.
    
        Raises
        ------
        OSError
            If the file cannot be moved.
        """
        # ChatGPT 4o-mini assisted with generating this doc string
        try:
>           ft.rename_file(from_dir_name_ext, to_dir_name_ext)

common\lib\render\lib\PowerpointImage.py:358: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

input_dir_body_ext = 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\tmpz2g6pzzq.png'
output_dir_body_ext = 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\PowerpointImage/images/tmp\\0_3.png'
is_file_check_only = False

    def rename_file(input_dir_body_ext: str, output_dir_body_ext: str, is_file_check_only=False):
        """Move a file from input to output.
    
        Verifies that input is a file, and that the output doesn't exist. We check
        for existence of the output file after the rename, and raise a
        FileNotFoundError if it can't be found.
    
        This operation could fail if the source and destination directories aren't
        on the same file system. We check for existence of the output file after
        the rename, and raise a FileNotFoundError if it can't be found.
    
        Args:
            - is_file_check_only (bool): If True, then only check that input_dir_body_ext is a file. Otherwise, check everything.
    
        See also: copy_file(), copy_and_delete_file()
        """
        if os.path.normpath(input_dir_body_ext) == os.path.normpath(output_dir_body_ext):
            return
    
        # Check input.
        if not is_file_check_only:
            if os.path.isdir(input_dir_body_ext):
                lt.error_and_raise(
                    RuntimeError,
                    "ERROR: In rename_file(), requested input path exists and is a directory: " + str(input_dir_body_ext),
                )
        if not os.path.isfile(input_dir_body_ext):
            lt.error_and_raise(
                RuntimeError,
                "ERROR: In rename_file(), requested input file to rename does not exist: " + str(input_dir_body_ext),
            )
        if not is_file_check_only:
            if os.path.isfile(output_dir_body_ext):
                lt.error_and_raise(
                    RuntimeError,
                    "ERROR: In rename_file(), requested output file exists and is a file: " + str(output_dir_body_ext),
                )
            if os.path.isdir(output_dir_body_ext):
                lt.error_and_raise(
                    RuntimeError,
                    "ERROR: In rename_file(), requested output file exists as a directory: " + str(output_dir_body_ext),
                )
            if os.path.exists(output_dir_body_ext):
                lt.error_and_raise(
                    RuntimeError,
                    "ERROR: In rename_file(), requested output file exists as something besides a file or directory: "
                    + str(output_dir_body_ext),
                )
            if not os.path.isdir(os.path.dirname(output_dir_body_ext)):
                lt.error_and_raise(
                    RuntimeError,
                    "ERROR: In rename_file(), requested output path does not exist or is not a directory: "
                    + str(os.path.dirname(output_dir_body_ext)),
                )
        # Rename the file.
>       os.rename(input_dir_body_ext, output_dir_body_ext)
E       PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\tmpz2g6pzzq.png' -> 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\PowerpointImage/images/tmp\\0_3.png'

common\lib\tool\file_tools.py:773: PermissionError

Version

develop@9d405367fa1f4030458ca14e522e77b1f72a37c8

What OS are you seeing this on?

Windows

Relevant dependency versions

python-version: 3.10
CPython (3.10.11)
XlsxWriter-3.2.3
asttokens-3.0.0
certifi-2025.1.31
colorama-0.4.6
comm-0.2.2
contourpy-1.3.2
coverage-7.8.0
cycler-0.12.1
debugpy-1.8.14
decorator-5.2.1
et-xmlfile-2.0.0
exceptiongroup-1.2.2
executing-2.2.0
fonttools-4.57.0
h5py-3.13.0
imageio-2.37.0
iniconfig-2.1.0
ipykernel-6.29.5
ipython-8.35.0
jedi-0.19.2
jupyter-client-8.6.3
jupyter-core-5.7.2
kiwisolver-1.4.8
lxml-5.4.0
matplotlib-3.8.4
matplotlib-inline-0.1.7
mpmath-1.3.0
nest-asyncio-1.6.0
numpy-1.26.4
opencv-contrib-python-4.10.0.82
openpyxl-3.1.5
packaging-25.0
pandas-2.2.3
parso-0.8.4
pillow-11.2.1
platformdirs-4.3.7
pluggy-1.5.0
prompt_toolkit-3.0.51
psutil-7.0.0
pure-eval-0.2.3
pygments-2.19.1
pyparsing-3.2.3
pyproj-3.7.1
pypylon-4.1.0
pysolar-0.13
pytest-8.3.5
pytest-cov-6.1.1
pytest-xvfb-3.1.1
python-dateutil-2.9.0.post0
python-pptx-1.0.2
pytz-2025.2
pyvirtualdisplay-3.0
pywin32-310
pyzmq-26.4.0
rawpy-0.24.0
scipy-1.14.1
six-1.17.0
stack_data-0.6.3
sympy-1.13.3
tomli-2.2.1
tornado-6.4.2
tqdm-4.67.1
traitlets-5.14.3
typing-extensions-4.13.2
tzdata-2025.2
wcwidth-0.2.13
ffmpeg 7.1.1

python script that produces the error

set PYTHONPATH="$PWD\.."
echo "$PYTHONPATH"
$env:PYTHONPATH="$PWD\.."
pytest --color=yes -rs -vv --cov=. --cov-report term --cov-config=.coveragerc
shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    pythonLocation: C:\hostedtoolcache\windows\Python\3.10.11\x64
    PKG_CONFIG_PATH: C:\hostedtoolcache\windows\Python\3.10.11\x64/lib/pkgconfig
    Python_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.10.11\x64
    Python2_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.10.11\x64
    Python3_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.10.11\x64

Relevant console output

E       PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\tmpz2g6pzzq.png' -> 'C:\\Users\\runneradmin\\AppData\\Local\\opencsp\\scratch\\tmp\\PowerpointImage/images/tmp\\0_3.png'

Contribution Guidelines

  • I agree to follow this project's contribution guidelines

Metadata

Metadata

Assignees

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