electro-smith / DaisyExamples

Examples for the Daisy Platform
https://github.com/electro-smith/DaisyWiki/wiki
MIT License
372 stars 193 forks source link

Fix project create script: Remove file path string concat #212

Closed rafkhan closed 2 years ago

rafkhan commented 3 years ago

I ran into an issue when trying to create a sample project:

python ./helper.py create ../lowstepper/lowstepper_daisy_firmware --board seed
creating new project: ../lowstepper/lowstepper_daisy_firmware for platform: seed
copying /utils/Template to new project: ../lowstepper/lowstepper_daisy_firmware
source directory is not valid.
done

I noticed that the line above (L151 file_path = pathlib.Path(__file__).as_posix().replace('helper.py', '')) is returning an empty string, I'm not a python programmer and not sure if that is the expected result. However, this can serve as a temporary fix while the above is investigated. It was sufficient to make the documentation here work.

stephenhensley commented 3 years ago

Hi @rafkhan thanks for opening an issue, and providing a workaround.

Your fix looks like a better way to join the path anyway, but I'm just curious did swapping that make your "source directory" valid, or did you have to create the folders manually? The error looks like a typical error for trying to create a new directory or file in a directory that doesn't exist yet.

rafkhan commented 3 years ago

My apologies @stephenhensley - I forgot to comment both scenarios without the fix, but I did actually test that :) Here they are. There was no need to manually create any directories.

(FWIW I'm running 3.8.7 in pyenv on MacOS 10.14.6)

With existing directory and no fix

➜  DaisyExamples git:(master) ✗ ./helper.py create ../THIS_DIRECTORY_EXISTS --board seed
creating new project: ../THIS_DIRECTORY_EXISTS for platform: seed
copying /utils/Template to new project: ../THIS_DIRECTORY_EXISTS
source directory is not valid.
done

➜  DaisyExamples git:(master) ✗ ls -la ../THIS_DIRECTORY_EXISTS
total 8
drwxr-xr-x   3 rafy  staff    96  7 Sep 22:58 .
drwxr-xr-x  33 rafy  staff  1056  7 Sep 22:58 ..
-rw-r--r--   1 rafy  staff   387  7 Sep 22:58 THIS_DIRECTORY_EXISTS.cpp

Both the source and destination are invalid (no fix)

➜  DaisyExamples git:(master) ✗ ./helper.py create ../THIS_DIRECTORY_DOES_NOT_EXIST --board seed
creating new project: ../THIS_DIRECTORY_DOES_NOT_EXIST for platform: seed
copying /utils/Template to new project: ../THIS_DIRECTORY_DOES_NOT_EXIST
source directory is not valid.
Traceback (most recent call last):
  File "./helper.py", line 290, in <module>
    run()
  File "./helper.py", line 258, in run
    create_from_template(dest, brd, libs)
  File "./helper.py", line 190, in create_from_template
    with open(src_file, 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: '../THIS_DIRECTORY_DOES_NOT_EXIST/THIS_DIRECTORY_DOES_NOT_EXIST.cpp'

With the fix applied, and with a pre-existing directory:

➜  DaisyExamples git:(helper_script_template_src_path_fix) ✗ ./helper.py create ../THIS_DIRECTORY_EXISTS --board seed
creating new project: ../THIS_DIRECTORY_EXISTS for platform: seed
copying utils/Template to new project: ../THIS_DIRECTORY_EXISTS
done
➜  DaisyExamples git:(helper_script_template_src_path_fix) ✗ ls -la ../THIS_DIRECTORY_EXISTS
total 32
drwxr-xr-x   8 rafy  staff   256  7 Sep 23:02 .
drwxr-xr-x  33 rafy  staff  1056  7 Sep 23:02 ..
drwxr-xr-x   8 rafy  staff   256  7 Sep 23:02 .vscode
-rw-r--r--   1 rafy  staff   317  7 Sep 23:02 Makefile
-rw-r--r--   1 rafy  staff   120  7 Sep 23:02 README.md
-rw-r--r--   1 rafy  staff   387  7 Sep 23:02 THIS_DIRECTORY_EXISTS.cpp
-rw-r--r--   1 rafy  staff  2164  7 Sep 23:02 THIS_DIRECTORY_EXISTS.sln
drwxr-xr-x   8 rafy  staff   256  7 Sep 23:02 vs

With the fix applied, and with no pre-existing directory

➜  DaisyExamples git:(helper_script_template_src_path_fix) ✗ rm -rf ../THIS_DIRECTORY_DOES_NOT_EXIST
➜  DaisyExamples git:(helper_script_template_src_path_fix) ✗ ./helper.py create ../THIS_DIRECTORY_DOES_NOT_EXIST --board seed
creating new project: ../THIS_DIRECTORY_DOES_NOT_EXIST for platform: seed
copying utils/Template to new project: ../THIS_DIRECTORY_DOES_NOT_EXIST
done
➜  DaisyExamples git:(helper_script_template_src_path_fix) ✗ ls -la ../THIS_DIRECTORY_DOES_NOT_EXIST
total 32
drwxr-xr-x   8 rafy  staff   256  7 Sep 23:11 .
drwxr-xr-x  34 rafy  staff  1088  7 Sep 23:11 ..
drwxr-xr-x   8 rafy  staff   256  7 Sep 23:11 .vscode
-rw-r--r--   1 rafy  staff   333  7 Sep 23:11 Makefile
-rw-r--r--   1 rafy  staff   128  7 Sep 23:11 README.md
-rw-r--r--   1 rafy  staff   387  7 Sep 23:11 THIS_DIRECTORY_DOES_NOT_EXIST.cpp
-rw-r--r--   1 rafy  staff  2180  7 Sep 23:11 THIS_DIRECTORY_DOES_NOT_EXIST.sln
drwxr-xr-x   8 rafy  staff   256  7 Sep 23:11 vs
stephenhensley commented 2 years ago

Ah, good to know.

Thank you for the thorough report. Could be something specific to Mac OS since I haven't seen it be an issue on my windows machine.

Thanks for the fix!