rice-solar-physics / pydrad

Python tools for setting up HYDRAD runs and parsing output
https://pydrad.readthedocs.io
MIT License
4 stars 3 forks source link

get_clean_hydrad not copying local HYDRAD on Windows 10 #165

Closed jwreep closed 8 months ago

jwreep commented 8 months ago

I'm on Windows 10, with a fresh install of pydrad. Here's a simple example of trying to make a copy of the HYDRAD folder, which doesn't work.

(base) C:\Users\reep\Documents\pydrad>python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
>>> from pydrad.configure.util import get_clean_hydrad
>>> base = pathlib.Path('C:\\Users\\reep\\Desktop\\HYDRAD-master\\')
>>> copy = pathlib.Path('C:\\Users\\reep\\Desktop\\new_copy\\')
>>> get_clean_hydrad(copy, base_path=base)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\reep\Documents\pydrad\pydrad\configure\util.py", line 121, in get_clean_hydrad
    copy_tree(base_path, tmpdir)
  File "C:\Users\reep\anaconda3\Lib\site-packages\setuptools\_distutils\dir_util.py", line 151, in copy_tree
    mkpath(dst, verbose=verbose)
  File "C:\Users\reep\anaconda3\Lib\site-packages\setuptools\_distutils\dir_util.py", line 36, in mkpath
    raise DistutilsInternalError(
distutils.errors.DistutilsInternalError: mkpath: 'name' must be a string (got WindowsPath('C:/Users/reep/AppData/Local/Temp/tmpp7kv0usg'))

However, copying it from Github does work:

>>> get_clean_hydrad(copy, from_github=True)

The issue seems to boil down to distutils.dir_util.copy_tree, and it looks like it's because it's having trouble creating the new folder.

>>> from distutils.dir_util import copy_tree
>>> copy_tree(base, copy)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\reep\anaconda3\Lib\site-packages\setuptools\_distutils\dir_util.py", line 151, in copy_tree
    mkpath(dst, verbose=verbose)
  File "C:\Users\reep\anaconda3\Lib\site-packages\setuptools\_distutils\dir_util.py", line 36, in mkpath
    raise DistutilsInternalError(
distutils.errors.DistutilsInternalError: mkpath: 'name' must be a string (got WindowsPath('C:/Users/reep/Desktop/new_copy'))

The following works fine, but it just copies everything directly to the Desktop.

>>> copy_tree(base, 'C:\\Users\\reep\\Desktop\\')
wtbarnes commented 8 months ago

Oof yeah this is broken on all OSes for local copies of HYDRAD. It seems that distutils.copy_tree does not support Pathlib objects. The linked PR removes this in favor of just using shutil.copytree instead which should fix this. I've also added a test to avoid future breakages.

wtbarnes commented 8 months ago

Ok This should be fixed. Pull down the latest changes and let me know if this still persists and feel free to reopen if so!

jwreep commented 8 months ago

Looks good. Thanks, Will!

It did throw a warning, but possibly that's expected?

>>> get_clean_hydrad(copy, base_path=base)
WARNING: Cannot remove .git. Directory not found. [pydrad.configure.util]