eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.65k stars 553 forks source link

Brownie init doesn't work when you specify a path with unmade parent folder #1148

Open cjidboon94 opened 3 years ago

cjidboon94 commented 3 years ago

Environment information

What was wrong?

Please include information like: When running brownie init ~/parent-folder-doesn't-exist/child, brownie init will fail because of the default behaviour of Path.mkdir. (e.g. see this stackoverflow question)

C:\WINDOWS\system32>brownie init C:\Users\Chris\Documents\Brownie
INFO: Could not find files for the given pattern(s).
Brownie v1.14.6 - Python development framework for Ethereum

  File "c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\brownie\_cli\__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\brownie\_cli\init.py", line 31, in main
    path = project.new(args["<path>"] or ".", args["--force"], args["--force"])
  File "c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\brownie\project\main.py", line 583, in new
    _create_folders(project_path)
  File "c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\brownie\project\main.py", line 920, in _create_folders
    project_path.joinpath(path).mkdir(exist_ok=True)
  File "c:\users\chris\appdata\local\programs\python\python39\lib\pathlib.py", line 1313, in mkdir
    self._accessor.mkdir(self, mode)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\Chris\\Documents\\Brownie\\build'

How can it be fixed?

This can be fixed by changing line 920 in brownie/project/main.py from: project_path.joinpath(path).mkdir(exist_ok=True) to: project_path.joinpath(path).mkdir(exist_ok=True, parents=True)

iamdefinitelyahuman commented 3 years ago

Happy to receive a PR for this :)