Suggest improvement in .bat script

I have an offer for the suggestion box. I modified the odrivetool.bat file slightly.

@echo off
::  %~dp0  produces the full path to the directory containing this (executing) script.
SET _ipython="%~dp0\ipython.exe"
%_ipython% "%~dp0\odrivetool" -- %*

The file as downloaded simply called 'ipython “%~dp0\odrivetool” – %* '. This relies upon the shell’s search path (PATH environment variable) to find the iPython interpreter. In my experience, relying upon environment variables is asking for reliability/support/usability problems.

The odrivetool install placed it in the /Scripts sub-folder of the Python directory, for the python version whose ‘pip install odrive’ i called. This is the same directory as the ipython.exe. My offered change relies upon that property (same folder) rather than upon the PATH variable. I coded it with a local variable just to make it easy to modify if someone moves one of them to break that relationship (the tool and its interpreter would still be linked, just no longer co-located).

It is not uncommon with Python, to have multiple versions installed at once (i now have 3). In such cases the PATH variable can get pretty ugly to manage. I noticed a problem when i upgraded firmware from v0.5.1 to v0.5.3. After upgrading the firmware, i encountered a few odrivetool problems (tool did not recognizes firmware enums). So i upgraded odrivetool to match. But when i invoked it, version 0.5.1 was still being run. I eventually found that my PATH had a different version of Python listed first, so a different Python/Scripts/odrivetool was being called, even though i was explicitly calling c:\path_to_odrive\odrivetool.bat from the shell. My edit above fixed that.

1 Like

I like it. Can you submit this as a pull request against the fw-v0.5.4 branch on github? GitHub - odriverobotics/ODrive: High performance motor control

Well i tried. But i don’t really know what i’m doing. Used a handfull of version control systems in my day, but Git is not one of them. I created an account, but instructions to create a branch were off point (“select create branch” from what menu ?). So what would make sense to me - diff between my ‘fix’ branch and the ‘develop’ branch - was not possible. Anyway, i’m sure i screwed it up. Hopefully the remnants i left were useful to you.

Hehe yeah, that didn’t work :stuck_out_tongue: but that’s ok.

Typically what you have to do is:

  • In Github, create an account and then “Fork” the repository
  • Download Git for your PC
  • Clone your fork from GitHub to your PC by using Git
  • Create a new branch locally, based on the fw-0.5.4 branch
  • Make a commit with the changes
  • Push the changes back up to the “remote” (your fork on Github)
  • Create a pull request on github from the new branch on your fork to the fw-0.5.4 branch on the “upstream” repository.

I just tried your change here and it doesn’t work on my PC though :thinking:

Ah, the problem is that us developers execute ./odrivetool from the tools\ folder, not the python script folder. We expect to see ipython on PATH instead…

Is there a way to have it check for ipython.exe in the local folder FIRST and then if it fails, check PATH?

Thanks for the step-by-step on Git pull request. I’ll try to gain that skill.

I’m strongly against relying upon environment variables - guaranteed repeatability problems. So i would prefer an install process that explicitly specifies the tool/versions it relies upon. It is best if those dependencies are collected and captured in a single file, so a reader can easily find them (and change them when future moves dictate). But that may be too radical an alternative, given where things are now. So in keeping with your request…

I’m not a windows scripting guru. But according to the docs, the IF ELSE statement could do what you ask. I’ve tested it works as my original offering. Have not tested it from \tools directory.

@echo off
::  %~dp0  produces the full path to the directory containing this (executing) script.
::  If this script is local to a Python/Scripts directory, use that version of iPython.
::  Otherwise, rely upon the PATH to find ipython.
IF EXIST "%~dp0\ipython.exe". (
    SET _ipython="%~dp0\ipython.exe"
) ELSE (
    SET _ipython="ipython"
%_ipython% "%~dp0\odrivetool" -- %*