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

python(bugfix): fix tempfile issues on windows #163

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

marcsiftstack
Copy link
Contributor

Use custom NamedTemporaryFile that is windows compatible.

Before:

marc@marc-windows MINGW64 ~/code/sift/python/examples/data_import/tdms (python/fix-windows-imports)
$ python  main.py
Traceback (most recent call last):
  File "C:\Users\marc\code\sift\python\examples\data_import\tdms\main.py", line 29, in <module>
    import_service = tdms_upload_service.upload(
        "sample_data.tdms", asset_name, group_into_components=True
    )
  File "C:\Users\marc\code\sift\python\lib\sift_py\data_import\tdms.py", line 81, in upload
    valid_channels = self._convert_to_csv(path, temp_file.name, ignore_errors)
  File "C:\Users\marc\code\sift\python\lib\sift_py\data_import\tdms.py", line 140, in _convert_to_csv
    with TdmsWriter(f.name) as tdms_writer:
         ~~~~~~~~~~^^^^^^^^
  File "C:\Users\marc\venvs\venv\Lib\site-packages\nptdms\writer.py", line 161, in __enter__
    self.open()
    ~~~~~~~~~^^
  File "C:\Users\marc\venvs\venv\Lib\site-packages\nptdms\writer.py", line 110, in open
    self._file = open(self._file_path, self._file_mode + 'b')
                 ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\marc\\AppData\\Local\\Temp\\tmp59mb6wjj'

After:

$ python  main.py
...
Upload example complete!

@marcsiftstack marcsiftstack requested a review from niliayu January 14, 2025 21:22
@marcsiftstack marcsiftstack force-pushed the python/fix-windows-imports branch from 39a9475 to 639813d Compare January 14, 2025 21:29
Copy link
Collaborator

@niliayu niliayu left a comment

Choose a reason for hiding this comment

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

lgtm, one nit!

python/lib/sift_py/data_import/tempfile.py Show resolved Hide resolved
@marcsiftstack marcsiftstack merged commit fa7467c into main Jan 14, 2025
7 checks passed
@marcsiftstack marcsiftstack deleted the python/fix-windows-imports branch January 14, 2025 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants