Skip to content

Commit 87d5241

Browse files
committed
Support for multi-os Python install
`/usr/bin/env` being used in scripts at the moment is not acceptable in certain distributions. macOS system Python is generally not used by developers in favour of Homebrew Python - this installs to `/usr/bin/local`. One cannot support both install locations `/usr/bin` and `/usr/bin/local` without using `/usr/bin/env` in the shebang. To remedy this, the Makefile resolves the shell `python` (3 first, then any) executable to `PYTHON_CMD` and calls the scripts with this binary.
1 parent 5076bf4 commit 87d5241

File tree

8 files changed

+47
-8
lines changed

8 files changed

+47
-8
lines changed

Arduino.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,15 @@ endif
853853
# Reset
854854

855855
ifndef RESET_CMD
856-
ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
856+
ARD_RESET_ARDUINO := $(PYTHON_CMD) $(shell which ard-reset-arduino 2> /dev/null)
857857
ifndef ARD_RESET_ARDUINO
858858
# same level as *.mk in bin directory when checked out from git
859859
# or in $PATH when packaged
860-
ARD_RESET_ARDUINO = $(ARDMK_DIR)/bin/ard-reset-arduino
860+
ARD_RESET_ARDUINO = $(PYTHON_CMD) $(ARDMK_DIR)/bin/ard-reset-arduino
861861
endif
862862
ifneq (,$(findstring CYGWIN,$(shell uname -s)))
863863
# confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
864-
ifeq ($(shell which python),/usr/bin/python)
864+
ifeq ($(PYTHON_CMD),/usr/bin/python)
865865
RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(DEVICE_PATH)
866866
else
867867
RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)

Common.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,24 @@ ifeq ($(CURRENT_OS),WINDOWS)
9898
echo $(error On Windows, ARDUINO_DIR and other defines must use forward slash and not contain spaces, special characters or be cygdrive relative)
9999
endif
100100
endif
101+
102+
########################################################################
103+
# System Python
104+
105+
ifndef PYTHON_CMD
106+
# try for Python 3 first
107+
PYTHON_CMD := $(shell which python3 2> /dev/null)
108+
ifdef PYTHON_CMD
109+
$(call show_config_variable,PYTHON_CMD,[AUTODETECTED])
110+
else
111+
# fall-back to any Python
112+
PYTHON_CMD := $(shell which python 2> /dev/null)
113+
ifdef PYTHON_CMD
114+
$(call show_config_variable,PYTHON_CMD,[AUTODETECTED])
115+
else
116+
echo $(error "Unable to find system Python! Utility scipts won't work. Override this error by defining PYTHON_CMD")
117+
endif
118+
endif
119+
else
120+
$(call show_config_variable,PYTHON_CMD,[USER])
121+
endif

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
3333
- New: Updated Arch instructions. (https://github.com/Akram-Chehaima)
3434
- New: Add support for Robotis OpenCR 1.0 boards.
3535
- New: Build the ArduinoCore API
36+
- New: Support for Python 3 and multi-os Python installation using new PYTHON_CMD variable.
3637

3738
### 1.6.0 (2017-07-11)
3839
- Fix: Allowed for SparkFun's weird usb pid/vid submenu shenanigans (issue #499). (https://github.com/sej7278)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ On Arch:
123123
sudo pacman -S python-pyserial
124124
```
125125

126-
On Mac using MacPorts:
126+
On macOS using Homebrew (one can install to System Python but this is not recommend or good practice):
127127

128128
```sh
129-
sudo port install py27-serial
129+
brew install python
130+
pip3 install pyserial
130131
```
131132

132133
On Windows:

arduino-mk-vars.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ RESET_CMD = $(HOME)/gertduino/reset
134134

135135
----
136136

137+
### PYTHON_CMD
138+
139+
**Description:**
140+
141+
Path to Python binary. Requires pyserial module installed. Makefile will error if unable to auto-find as utility scripts will not work. To override this, give it an empty define.
142+
143+
**Example:**
144+
145+
```Makefile
146+
PYTHON_CMD = /usr/bin/python3
147+
```
148+
149+
**Requirement:** *Optional*
150+
151+
----
152+
137153
## Arduino IDE variables
138154

139155
### ARDUINO_DIR

bin/ard-reset-arduino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/python3
22

33
from __future__ import print_function
44
import serial

bin/ardmk-init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/python3
22
"""
33
Arduino-mk Makefile and project initialiser
44

bin/robotis-loader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22

33
# This script sends a program on a robotis board (OpenCM9.04 or CM900)
44
# using the robotis bootloader (used in OpenCM IDE)

0 commit comments

Comments
 (0)