Documentation build failing in Windows
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What happened?
When using pixi run doc to create documentation in Windows, time-coding.rst is aborting with a failure because the file tries to delete test-datetimes1.nc while windows thinks it is open. We tried using gc.collect() to force garbage collection and del _, and a using a sleep timer to ensure that the processes were complete, but none of those worked.
Switching from xr.open_dataset() to xr.load_dataset() prevents the problem, but may not be appropriate in this situation.
What did you expect to happen?
Ideally the docs should build in any environment; however, expecting users Windows users to use WSL or another method when developing may be acceptable, if covered in the contributing guide.
Minimal Complete Verifiable Example
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "xarray[complete]@git+https://github.com/pydata/xarray.git@main",
# ]
# ///
#
# This script automatically imports the development branch of xarray to check for issues.
# Please delete this header if you have _not_ tested this script with `uv run`!
import xarray as xr
xr.show_versions()
# your reproducer code ...
Steps to reproduce
No response
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
sphinx.errors.ExtensionError: Cell raised uncaught exception:
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:701, in _rmtree_unsafe(path, dir_fd, onexc)
700 try:
--> 701 os.unlink(fullname)
702 except FileNotFoundError:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'
During handling of the above exception, another exception occurred:
PermissionError Traceback (most recent call last)
Cell In[49], line 2
1 # Cleanup
----> 2 tempdir.cleanup()
File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:975, in TemporaryDirectory.cleanup(self)
973 def cleanup(self):
974 if self._finalizer.detach() or _os.path.exists(self.name):
--> 975 self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:955, in TemporaryDirectory._rmtree(cls, name, ignore_errors, repeated)
952 if not ignore_errors:
953 raise
--> 955 _shutil.rmtree(name, onexc=onexc)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:852, in rmtree(path, ignore_errors, onerror, onexc, dir_fd)
849 exc_info = type(exc), exc, exc.__traceback__
850 return onerror(func, path, exc_info)
--> 852 _rmtree_impl(path, dir_fd, onexc)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:705, in _rmtree_unsafe(path, dir_fd, onexc)
703 continue
704 except OSError as err:
--> 705 onexc(os.unlink, fullname, err)
706 try:
707 os.rmdir(path)
File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:930, in TemporaryDirectory._rmtree.<locals>.onexc(func, path, exc)
927 _resetperms(path)
929 try:
--> 930 _os.unlink(path)
931 except IsADirectoryError:
932 cls._rmtree(path, ignore_errors=ignore_errors)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'
Extension error:
Cell raised uncaught exception:
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:701, in _rmtree_unsafe(path, dir_fd, onexc)
700 try:
--> 701 os.unlink(fullname)
702 except FileNotFoundError:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'
During handling of the above exception, another exception occurred:
PermissionError Traceback (most recent call last)
Cell In[49], line 2
1 # Cleanup
----> 2 tempdir.cleanup()
File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:975, in TemporaryDirectory.cleanup(self)
973 def cleanup(self):
974 if self._finalizer.detach() or _os.path.exists(self.name):
--> 975 self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:955, in TemporaryDirectory._rmtree(cls, name, ignore_errors, repeated)
952 if not ignore_errors:
953 raise
--> 955 _shutil.rmtree(name, onexc=onexc)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:852, in rmtree(path, ignore_errors, onerror, onexc, dir_fd)
849 exc_info = type(exc), exc, exc.__traceback__
850 return onerror(func, path, exc_info)
--> 852 _rmtree_impl(path, dir_fd, onexc)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:705, in _rmtree_unsafe(path, dir_fd, onexc)
703 continue
704 except OSError as err:
--> 705 onexc(os.unlink, fullname, err)
706 try:
707 os.rmdir(path)
File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:930, in TemporaryDirectory._rmtree.<locals>.onexc(func, path, exc)
927 _resetperms(path)
929 try:
--> 930 _os.unlink(path)
931 except IsADirectoryError:
932 cls._rmtree(path, ignore_errors=ignore_errors)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'
Anything else we need to know?
No response
Environment
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with doc/time-coding.rst and reproduce the failure using pixi run doc on Windows. Trace the cleanup of the temporary test-datetimes1.nc file and compare the xr.open_dataset() and xr.load_dataset() paths. Done means the documentation build completes on Windows without the WinError 32 cleanup failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100