Skip to content

Commit 207253a

Browse files
committed
Rebased python3 branch with some changes from tuna-f1sh/Arduino-Makefile@87d5241
1 parent 6f786a9 commit 207253a

File tree

11 files changed

+76
-48
lines changed

11 files changed

+76
-48
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
@@ -32,6 +32,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
3232
- New: Updated Arch instructions. (https://github.com/Akram-Chehaima)
3333
- New: Add support for Robotis OpenCR 1.0 boards.
3434
- New: Build the ArduinoCore API
35+
- New: Support for Python 3 and multi-os Python installation using new PYTHON_CMD variable.
3536

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

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,38 +83,34 @@ installer or download the distribution zip file and extract it.
8383
The Makefile also delegates resetting the board to a short Python program.
8484
You'll need to install [`pySerial`](https://pypi.python.org/pypi/pyserial) to use it though.
8585

86-
On most systems you should be able to install it using either `pip` or `easy_install`.
86+
On most systems you should be able to install it using either `pip3` or `easy_install3`.
8787

8888
```sh
89-
pip install pyserial
89+
pip3 install pyserial
9090

9191
# or if you prefer easy_install
9292

93-
easy_install -U pyserial
93+
easy_install3 -U pyserial
9494
```
9595

9696
If you prefer to install it as a package, then you can do that as well.
9797

9898
On Debian or Ubuntu:
9999

100100
```sh
101-
apt-get install python-serial
101+
apt-get install python3-serial
102102
```
103103

104104
On Fedora:
105105

106106
```sh
107-
yum install pyserial
108-
109-
# or on Fedora 22+
110-
111-
dnf install pyserial
107+
dnf install python3-pyserial
112108
```
113109

114110
On openSUSE:
115111

116112
```sh
117-
zypper install python-serial
113+
zypper install python3-serial
118114
```
119115

120116
On Arch:
@@ -123,15 +119,16 @@ On Arch:
123119
sudo pacman -S python-pyserial
124120
```
125121

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

128124
```sh
129-
sudo port install py27-serial
125+
brew install python
126+
pip3 install pyserial
130127
```
131128

132129
On Windows:
133130

134-
You need to install Cygwin and its packages for Make, Perl, Python2 and the following Serial library.
131+
You need to install Cygwin and its packages for Make, Perl, Python3 and the following Serial library.
135132

136133
Assuming you included Python in your Cygwin installation:
137134

@@ -141,15 +138,15 @@ Assuming you included Python in your Cygwin installation:
141138
4. build and install Python module:
142139

143140
```
144-
python setup.py build
145-
python setup.py install
141+
python3 setup.py build
142+
python3 setup.py install
146143
```
147144

148145
Alternatively, if you have setup Cygwin to use a Windows Python installation,
149146
simply install using pip:
150147

151148
```
152-
pip install pyserial
149+
pip3 install pyserial
153150
```
154151

155152
Arduino-Makefile should automatically detect the Python installation type and

arduino-mk-vars.md

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

116116
----
117117

118+
### PYTHON_CMD
119+
120+
**Description:**
121+
122+
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.
123+
124+
**Example:**
125+
126+
```Makefile
127+
PYTHON_CMD = /usr/bin/python3
128+
```
129+
130+
**Requirement:** *Optional*
131+
132+
----
133+
118134
## Arduino IDE variables
119135

120136
### ARDUINO_DIR

bin/ard-reset-arduino

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43
import serial
54
import serial.tools.list_ports
65
import os.path
76
import argparse
87
from time import sleep
98

10-
pyserial_version = None
11-
try:
12-
pyserial_version = int(serial.VERSION[0])
13-
except:
14-
pyserial_version = 2 # less than 2.3
15-
169
parser = argparse.ArgumentParser(description='Reset an Arduino')
1710
parser.add_argument('--zero', action='store_true', help='Reset Arduino Zero or similar Native USB to enter bootloader')
1811
parser.add_argument('--caterina', action='store_true', help='Reset a Leonardo, Micro, Robot or LilyPadUSB.')
@@ -65,11 +58,7 @@ if args.zero:
6558

6659
ser = serial.Serial(args.port[0], 57600)
6760
ser.close()
68-
69-
if pyserial_version < 3:
70-
ser.setBaudrate(1200)
71-
else:
72-
ser.baudrate = 1200
61+
ser.baudrate = 1200
7362

7463
# do the open/close at 1200 BAUD
7564
ser.open()

bin/ardmk-init

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
23
"""
34
Arduino-mk Makefile and project initialiser
45
@@ -17,7 +18,6 @@ Example:
1718
See `armk-init --help` for CLI arguments
1819
"""
1920

20-
from __future__ import print_function
2121
import os
2222
import argparse
2323

@@ -54,7 +54,7 @@ PARSER.add_argument('--cli', action='store_true', help='run with user prompts (r
5454
PARSER.add_argument('-P', '--project', action='store_true',
5555
help='create boilerplate project with src, lib and bin folder structure')
5656
PARSER.add_argument('-t', '--template', action='store_true',
57-
help='create bare minimum Arduino source file')
57+
help='create bare minimum Arduino source file')
5858
PARSER.add_argument('-V', '--version', action='version', version='%(prog)s '+ VERSION)
5959
ARGS = PARSER.parse_args()
6060

bin/robotis-loader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
# This script sends a program on a robotis board (OpenCM9.04 or CM900)
44
# using the robotis bootloader (used in OpenCM IDE)
5-
#
5+
#
66
# Usage:
77
# python robotis-loader.py <serial port> <binary>
88
#

packaging/fedora/arduino-mk.spec

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: arduino-mk
22
Version: 1.6.0
3-
Release: 1%{dist}
3+
Release: 2%{dist}
44
Summary: Program your Arduino from the command line
55
Packager: Simon John <[email protected]>
66
URL: https://github.com/sudar/Arduino-Makefile
@@ -9,8 +9,7 @@ Group: Development/Tools
99
License: LGPLv2+
1010
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
1111
BuildArch: noarch
12-
Requires: arduino-core pyserial
13-
BuildRequires: arduino-core
12+
Requires: arduino-core python3-pyserial
1413

1514
%description
1615
Arduino is an open-source electronics prototyping platform based on
@@ -29,6 +28,7 @@ mkdir -p %{buildroot}/%{_datadir}/arduino
2928
mkdir -p %{buildroot}/%{_bindir}
3029
mkdir -p %{buildroot}/%{_mandir}/man1
3130
mkdir -p %{buildroot}/%{_docdir}/%{name}/examples
31+
sed -i 's/^#!\/usr\/bin\/env python/#!\/usr\/bin\/python3/' bin/*
3232
install -m 755 -d %{buildroot}/%{_docdir}/%{name}
3333
install -m 755 -d %{buildroot}/%{_docdir}/%{name}/examples
3434
for dir in `find examples -type d` ; do install -m 755 -d %{buildroot}/%{_docdir}/%{name}/$dir ; done
@@ -60,6 +60,10 @@ rm -rf %{buildroot}
6060
%{_docdir}/%{name}/examples
6161

6262
%changelog
63+
* Wed Jan 22 2020 Simon John <[email protected]>
64+
- Added sed for shebang
65+
* Thu Oct 24 2019 Simon John <[email protected]>
66+
- Removed BuildRequires
6367
* Thu Oct 05 2017 Simon John <[email protected]>
6468
- Added ardmk-init binary and manpage
6569
* Tue Jul 11 2017 Karl Semich <[email protected]>

tests/script/bootstrap/common.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,22 @@ if [ -z $COMMON_SOURCED ]; then
160160
fi
161161
fi
162162

163-
if ! command -v python >/dev/null 2>&1; then
163+
if ! command -v python3 >/dev/null 2>&1; then
164164
echo "Installing Python..."
165-
_install "python"
165+
_install "python3"
166166
fi
167167

168-
if ! command -v pip >/dev/null 2>&1; then
168+
if ! command -v pip3 >/dev/null 2>&1; then
169169
echo "Installing Pip..."
170-
if ! command -v easy_install >/dev/null 2>&1; then
171-
_install "python-setuptools"
170+
if ! command -v easy_install3 >/dev/null 2>&1; then
171+
_install "python3-setuptools"
172172
fi
173173

174-
if ! command -v easy_install >/dev/null 2>&1; then
175-
die "easy_install not available, can't install pip"
174+
if ! command -v easy_install3 >/dev/null 2>&1; then
175+
die "easy_install3 not available, can't install pip3"
176176
fi
177177

178-
$SUDO_CMD easy_install pip
178+
$SUDO_CMD easy_install3 pip3
179179
fi
180180

181181
PIP_SUDO_CMD=
@@ -184,7 +184,7 @@ if [ -z $COMMON_SOURCED ]; then
184184
PIP_SUDO_CMD=$SUDO_CMD
185185
fi
186186

187-
$PIP_SUDO_CMD pip install --src dependencies --pre -Ur $BOOTSTRAP_DIR/pip-requirements.txt
187+
$PIP_SUDO_CMD pip3 install --src dependencies --pre -Ur $BOOTSTRAP_DIR/pip-requirements.txt
188188

189189
COMMON_SOURCED=1
190190
fi
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pyserial==2.7
1+
pyserial==3.4

0 commit comments

Comments
 (0)