Using Powershell terminal, to activate environment resulted in error: venv\Scripts\activate : File C:\Users\jjd1c23\Documents\MELDB\concepts-processing\venv\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system.
To Enable execution policy run Set-ExecutionPolicy RemoteSigned in PS with admin privileges.
Now can activate venv within powershell.
Running hatch run pytest command still resulted in error: PermissionError: [WinError 5] Access is denied: 'C:\\Users\\jjd1c23\\Documents\\MELDB\\concepts-processing\\tests\\tmp\\phen\\.git\\objects\\b3\\cb7928d503b6fb0bb489780d7215a937814da6'
New temporary folders are created and tests are seem to run successfully.
However shutil.rmtree() deletes whole repo after each test, which is denied permission when deleting "./git" folder.
Similar Issue on Stackoverfow#76546956, however changing file permissions of all files in temp_dir has not work.
Errors can be ignored with shutil.rmtree(temp_dir, ignore_errors=True) to allow tests to pass, however as the files: .git/objects/b3, .git/objects/bf, .git/objects/e6 are not deleted, may result in unexpected behaviour. Phen.py makes use of the same function, making this not a viable solution.
@jjd1c23 This is a Windows python environment problem. When I've developed on Windows I've done so through Anaconda, created a shell and then launched jupyter-lab from the working directory. So essentialy it's the same type of environment that we use on linux.
I would suggest switching to jupyter-lab on the windows if it was only a test problem but as we are using the shutil.rmtree function bin phen.py we are probably going to need to solve it.
We could add the function to util.py to do a depth first deletion using os. I've not tested this but it's an option...
import osimport statdef delete_directory(directory): """Recursively deletes a directory and all its contents using os.walk() depth first.""" if os.path.exists(directory): # Walk the directory tree bottom-up (depth-first) for root, dirs, files in os.walk(directory, topdown=False): # Delete all files for file in files: file_path = os.path.join(root, file) try: os.chmod(file_path, stat.S_IWRITE) # Ensure writable os.remove(file_path) except Exception as e: _logger.error(f"Failed to delete file {file_path}: {e}") # Delete all directories for dir in dirs: dir_path = os.path.join(root, dir) try: os.rmdir(dir_path) except Exception as e: _logger.error(f"Failed to delete directory {dir_path}: {e}") # Remove the root directory itself try: os.rmdir(directory) _logger.debug(f"Deleted: {directory}") except Exception as e: _logger.error(f"Failed to delete {directory}: {e}") else: print(f"Directory not found: {directory}")
I have tried setting up Anaconda and running JupyterLab, however this seems to just run a standard PS resulting in the same error.
The DFS delete function above as well as the exception handler below, both catch the Win Error 5 and all files in .git folder can be deleted.
def handleRemoveReadonly(func, path, exc): if not os.access(path, os.W_OK): print("HANDLING ERROR", path) os.chmod(path, stat.S_IWUSR) func(path) else: print("NOT HANDLING ERROR", path) raise
However the when trying to delete the empty \phen itself an new error is thrown: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process
SOLUTION: install wsl and Ubuntu 22.04.5 LTS environment.
Python and Python-venv need to be installed with sudo apt install, before running instructions from contributing.md. @mjbonifa