Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Assure powrap is compatible with Windows #105

Merged
merged 2 commits into from
Mar 30, 2023
Merged

Conversation

egeakman
Copy link
Contributor

@egeakman egeakman commented Feb 16, 2023

Hopefully closes #104

All tests are passing. I additionally tested it with different files and conditions.

Can you check if everything is okay @JulienPalard?

Comment on lines +32 to +34
delete = os.name == "posix" and sys.platform != "cygwin"

with NamedTemporaryFile("w+", delete=delete, encoding="utf-8") as tmpfile:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Workaround for https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile:

Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows). If delete is true (the default), the file is deleted as soon as it is closed.

We simply don't delete the file after it is created, making it possible to write into it while it is still open. (For non-Posix systems)

Comment on lines +56 to +57
if not delete:
os.remove(tmpfile.name)
Copy link
Contributor Author

@egeakman egeakman Feb 16, 2023

Choose a reason for hiding this comment

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

We manually delete the temp file after every iteration.

powrap/powrap.py Outdated Show resolved Hide resolved
@jeanas
Copy link

jeanas commented Feb 19, 2023

#106 should obviate this.

@egeakman
Copy link
Contributor Author

Released a tag on egeakman/powrap:v1.0.1 for temporary use in python-docs-tr

@egeakman
Copy link
Contributor Author

Ping @JulienPalard

@JulienPalard
Copy link
Collaborator

I'm lagging behind! oO

@JulienPalard JulienPalard merged commit b5c70a7 into AFPy:main Mar 30, 2023
@JulienPalard
Copy link
Collaborator

Release v1.0.1 on PyPI.

@egeakman egeakman deleted the windows branch March 31, 2023 12:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

powrap doesn't accept files containing undecodable characters
3 participants