@@ -77,19 +77,19 @@ def find_root(
7777
7878def set_root (
7979 path : Union [str , Path ],
80- pythonpath : bool = True ,
81- cwd : bool = True ,
8280 project_root_env_var : bool = True ,
8381 dotenv : bool = True ,
82+ pythonpath : bool = True ,
83+ cwd : bool = True ,
8484) -> None :
8585 """Set given path as a project root.
8686
8787 Args:
8888 path (Union[str, Path]): project root path.
89- pythonpath (bool, optional): whether to add project root to pythonpath.
90- cwd (bool, optional): whether to set current working directory to project root.
9189 project_root_env_var (bool, optional): whether to set PROJECT_ROOT environment variable to project root.
9290 dotenv (bool, optional): whether to load .env file from project root.
91+ pythonpath (bool, optional): whether to add project root to pythonpath.
92+ cwd (bool, optional): whether to set current working directory to project root.
9393
9494 Raises:
9595 FileNotFoundError: if root path does not exist.
@@ -102,18 +102,18 @@ def set_root(
102102 if not os .path .exists (path ):
103103 raise FileNotFoundError (f"Project root path does not exist: { path } " )
104104
105- if pythonpath :
106- sys .path .insert (0 , path )
107-
108- if cwd :
109- os .chdir (path )
110-
111105 if project_root_env_var :
112106 os .environ ["PROJECT_ROOT" ] = path
113107
114108 if dotenv :
115109 load_dotenv (os .path .join (path , ".env" ))
116110
111+ if pythonpath :
112+ sys .path .insert (0 , path )
113+
114+ if cwd :
115+ os .chdir (path )
116+
117117
118118def setup_root (
119119 search_from : Union [str , Path ],
@@ -124,24 +124,30 @@ def setup_root(
124124 ".git" ,
125125 "pyproject.toml" ,
126126 ),
127- pythonpath : bool = True ,
128- cwd : bool = True ,
129127 project_root_env_var : bool = True ,
130128 dotenv : bool = True ,
129+ pythonpath : bool = True ,
130+ cwd : bool = True ,
131131) -> Path :
132132 """Combines `get_root()` and `set_root()` into one method.
133133
134134 Args:
135135 search_from (str): path to folder to start search from.
136136 indicator (Union[str, Iterable[str]], optional): Project root indicator(s). Defaults to ".project-root".
137- pythonpath (bool, optional): whether to add project root to pythonpath.
138- cwd (bool, optional): whether to set current working directory to project root.
139137 project_root_env_var (bool, optional): whether to set PROJECT_ROOT environment variable to project root.
140138 dotenv (bool, optional): whether to load .env file from project root.
139+ pythonpath (bool, optional): whether to add project root to pythonpath.
140+ cwd (bool, optional): whether to set current working directory to project root.
141141
142142 Returns:
143143 Path: path to project root.
144144 """
145145 path = find_root (search_from , indicator )
146- set_root (path , pythonpath , cwd , project_root_env_var , dotenv )
146+ set_root (
147+ path = path ,
148+ project_root_env_var = project_root_env_var ,
149+ dotenv = dotenv ,
150+ pythonpath = pythonpath ,
151+ cwd = cwd ,
152+ )
147153 return path
0 commit comments