Fix project lookup on windows.
This commit is contained in:
		
							parent
							
								
									d0ad38b714
								
							
						
					
					
						commit
						9572c6a3df
					
				
					 1 changed files with 10 additions and 8 deletions
				
			
		| 
						 | 
					@ -1,13 +1,14 @@
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
from typing import Optional
 | 
					
 | 
				
			||||||
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def root() -> Optional[str]:
 | 
					def root() -> str | None:
 | 
				
			||||||
    cwd = os.getcwd()
 | 
					    cwd = Path.cwd()
 | 
				
			||||||
    while cwd != "/":
 | 
					    while cwd != Path.root:
 | 
				
			||||||
        if os.path.isfile(os.path.join(cwd, "project.json")):
 | 
					        if (cwd / "project.json").is_file():
 | 
				
			||||||
            return cwd
 | 
					            return str(cwd)
 | 
				
			||||||
        cwd = os.path.dirname(cwd)
 | 
					        cwd = cwd.parent
 | 
				
			||||||
    return None
 | 
					    return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +16,7 @@ def chdir() -> None:
 | 
				
			||||||
    projectRoot = root()
 | 
					    projectRoot = root()
 | 
				
			||||||
    if projectRoot is None:
 | 
					    if projectRoot is None:
 | 
				
			||||||
        raise RuntimeError(
 | 
					        raise RuntimeError(
 | 
				
			||||||
            "No project.json found in this directory or any parent directory")
 | 
					            "No project.json found in this directory or any parent directory"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    os.chdir(projectRoot)
 | 
					    os.chdir(projectRoot)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue