This article is for Circuit Python developers that use PIP and CircuitPython-Stubs in a Windows environment.
Stubs are helpers for code completion hints with IDE's such as PyCharm, VSCode, and others.
Unfortunately PIP & CircuitPython-Stubs do not automatically stay updated. These are things you must manually update when a new version of Circuit Python is released or whenever your heart dictates you want to update it. This is a problem because I never remember to keep them updated and recently found out my version of stubs was last updated in Circuit Python 7.3.3 (we're now at Circuit Python 9.0.1).
This is assuming you already have PIP and CircuitPython stubs installed.
The manual way to update them is:
python -m pip install --upgrade pip
pip install circuitpython-stubs --upgrade
These are the types of things I do not want to be required to remember to update. I consider these things minutia that should automatically stay updated.
Windows Task Scheduler can automate the process of keeping both PIP and circuitpython-stubs up to date every time you log into Windows. First we need to create a batch script and put it in a directory/folder that will always be available to Windows.
I chose to put it in the following folder:
\Downloads\CircuitPython-Stubs_Updater
You can name the script whatever you'd like. You can edit a .bat file as easly as a .txt file, you don't need a special IDE to do it, Notepad works fine for it.
I named my batch file:
circuitpython-stubs.bat
It resides inside of the CircuitPython-Stubs_Updater folder and includes the following code in the .bat file.
@echo off set mydate=%date:~10,4%-%date:~4,2%-%date:~7,2% echo -------------------------------------- echo Date: %mydate% echo Windows PIP and Circuit Python Stubs Updater echo Use this batch file with Windows Task Manager for automation. echo This window will automatically close when done echo -------------------------------------- echo. echo. echo Upgrading PIP... timeout /T 5 start "" python -m pip install --upgrade pip echo. echo. echo Updating Circuit Python Stubs... timeout /T 5 start "" py -m pip install --upgrade circuitpython-stubs echo. echo. echo Finished Updating echo This window will automatically close in 10 seconds. timeout /T 10 echo. exit
Next you must go into Task Scheduler and create a task that will automatically launch the batch file on a regular schedule. There are many options in how/when to choose to launch the task. On the right side of Task Scheduler click on Create Task.
Give your task a name and description. You can choose to specify the version of Windows but leaving at default configuration for your OS is fine for this purpose. Other configurations are available if you want to run something in compatibility mode.
In the Triggers tab you can customize it to run at a specific time, day of the week, a specific user, etc.. You can setup multiple triggers too. The most general purpose Trigger is to run the script At log on
Next we'll setup Actions. This is where you'll specify the file you want executed for the task.
Windows will automatically replace %USERNAME% here with the current logged in user. You want to paste this literally into the path and don't replace %USERNAME% with your actual username.. unless you want to. This is much easier to copy and paste as it will apply to any Windows user logged in.
Fill in the Program/script: field with the filename
circuitpython-stubs.bat
Fill in Start in (optional): field with the path to the file.
C:\Users\%USERNAME%\Downloads\CircuitPython-Stubs_Updater\
The tabs for Conditions | Settings | History can all be left at defaults. There isn't any necessary configuration to do in those tabs for something like this. Click OK and your task should be all setup and ready to go!
You can test your task by right-clicking on it in task manager and choosing Run.
When the task runs it will pop up a command prompt and show the batch script running.
A common question for scheduled tasks is "How can I prevent the command prompt from popping up every single time?
You can suppress/hide the command prompt by choosing the logged in Windows user you want it to run as and enter your login credentials.
Simply check the "Hidden" checkbox and it will run invisibly as a Windows background task staying updated forever without ever having to worry about remembering to manually update these things again.
PIP and CircuitPython-Stubs will now automatically update every time you log into Windows.