aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Whittington <git@jbrengineering.co.uk>2020-08-05 18:22:29 +0200
committerJohn Whittington <git@jbrengineering.co.uk>2020-08-05 18:22:29 +0200
commit517fe4a632b57a6c4ee2754bbb06470055427a5e (patch)
tree982ca56447615221c9a66de551cb2f79e4fc973d
parent26e34cd6f2471f04ba097001a215caed12a8574a (diff)
parent88dc641c8d582f28243141052517fe03e92e6687 (diff)
Merge remote-tracking branch 'sej7278/python3'
-rw-r--r--Arduino.mk6
-rw-r--r--Common.mk21
-rw-r--r--HISTORY.md1
-rw-r--r--README.md29
-rw-r--r--arduino-mk-vars.md16
-rwxr-xr-xbin/ard-reset-arduino17
-rwxr-xr-xbin/ardmk-init6
-rwxr-xr-xbin/robotis-loader4
-rw-r--r--packaging/fedora/arduino-mk.spec7
-rw-r--r--tests/script/bootstrap/common.sh18
-rw-r--r--tests/script/bootstrap/pip-requirements.txt2
11 files changed, 76 insertions, 51 deletions
diff --git a/Arduino.mk b/Arduino.mk
index 010f5e6..30bf36b 100644
--- a/Arduino.mk
+++ b/Arduino.mk
@@ -853,15 +853,15 @@ endif
# Reset
ifndef RESET_CMD
- ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
+ ARD_RESET_ARDUINO := $(PYTHON_CMD) $(shell which ard-reset-arduino 2> /dev/null)
ifndef ARD_RESET_ARDUINO
# same level as *.mk in bin directory when checked out from git
# or in $PATH when packaged
- ARD_RESET_ARDUINO = $(ARDMK_DIR)/bin/ard-reset-arduino
+ ARD_RESET_ARDUINO = $(PYTHON_CMD) $(ARDMK_DIR)/bin/ard-reset-arduino
endif
ifneq (,$(findstring CYGWIN,$(shell uname -s)))
# confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
- ifeq ($(shell which python),/usr/bin/python)
+ ifeq ($(PYTHON_CMD),/usr/bin/python)
RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(DEVICE_PATH)
else
RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
diff --git a/Common.mk b/Common.mk
index 27d2135..5421b96 100644
--- a/Common.mk
+++ b/Common.mk
@@ -107,3 +107,24 @@ ifeq ($(CURRENT_OS),WINDOWS)
echo $(error On Windows, ARDUINO_DIR and other defines must use forward slash and not contain spaces, special characters or be cygdrive relative)
endif
endif
+
+########################################################################
+# System Python
+
+ifndef PYTHON_CMD
+ # try for Python 3 first
+ PYTHON_CMD := $(shell which python3 2> /dev/null)
+ ifdef PYTHON_CMD
+ $(call show_config_variable,PYTHON_CMD,[AUTODETECTED])
+ else
+ # fall-back to any Python
+ PYTHON_CMD := $(shell which python 2> /dev/null)
+ ifdef PYTHON_CMD
+ $(call show_config_variable,PYTHON_CMD,[AUTODETECTED])
+ else
+ echo $(error "Unable to find system Python! Utility scipts won't work. Override this error by defining PYTHON_CMD")
+ endif
+ endif
+else
+ $(call show_config_variable,PYTHON_CMD,[USER])
+endif
diff --git a/HISTORY.md b/HISTORY.md
index a2aeaef..8950c7e 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -33,6 +33,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
- New: Updated Arch instructions. (https://github.com/Akram-Chehaima)
- New: Add support for Robotis OpenCR 1.0 boards.
- New: Build the ArduinoCore API
+- New: Support for Python 3 and multi-os Python installation using new PYTHON_CMD variable.
### 1.6.0 (2017-07-11)
- Fix: Allowed for SparkFun's weird usb pid/vid submenu shenanigans (issue #499). (https://github.com/sej7278)
diff --git a/README.md b/README.md
index cab5d19..68a4ae3 100644
--- a/README.md
+++ b/README.md
@@ -83,14 +83,14 @@ installer or download the distribution zip file and extract it.
The Makefile also delegates resetting the board to a short Python program.
You'll need to install [`pySerial`](https://pypi.python.org/pypi/pyserial) to use it though.
-On most systems you should be able to install it using either `pip` or `easy_install`.
+On most systems you should be able to install it using either `pip3` or `easy_install3`.
```sh
-pip install pyserial
+pip3 install pyserial
# or if you prefer easy_install
-easy_install -U pyserial
+easy_install3 -U pyserial
```
If you prefer to install it as a package, then you can do that as well.
@@ -98,23 +98,19 @@ If you prefer to install it as a package, then you can do that as well.
On Debian or Ubuntu:
```sh
-apt-get install python-serial
+apt-get install python3-serial
```
On Fedora:
```sh
-yum install pyserial
-
-# or on Fedora 22+
-
-dnf install pyserial
+dnf install python3-pyserial
```
On openSUSE:
```sh
-zypper install python-serial
+zypper install python3-serial
```
On Arch:
@@ -123,15 +119,16 @@ On Arch:
sudo pacman -S python-pyserial
```
-On Mac using MacPorts:
+On macOS using Homebrew (one can install to System Python but this is not recommend or good practice):
```sh
-sudo port install py27-serial
+brew install python
+pip3 install pyserial
```
On Windows:
-You need to install Cygwin and its packages for Make, Perl, Python2 and the following Serial library.
+You need to install Cygwin and its packages for Make, Perl, Python3 and the following Serial library.
Assuming you included Python in your Cygwin installation:
@@ -141,15 +138,15 @@ Assuming you included Python in your Cygwin installation:
4. build and install Python module:
```
-python setup.py build
-python setup.py install
+python3 setup.py build
+python3 setup.py install
```
Alternatively, if you have setup Cygwin to use a Windows Python installation,
simply install using pip:
```
-pip install pyserial
+pip3 install pyserial
```
Arduino-Makefile should automatically detect the Python installation type and
diff --git a/arduino-mk-vars.md b/arduino-mk-vars.md
index cd70a9f..e0b8618 100644
--- a/arduino-mk-vars.md
+++ b/arduino-mk-vars.md
@@ -134,6 +134,22 @@ RESET_CMD = $(HOME)/gertduino/reset
----
+### PYTHON_CMD
+
+**Description:**
+
+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.
+
+**Example:**
+
+```Makefile
+PYTHON_CMD = /usr/bin/python3
+```
+
+**Requirement:** *Optional*
+
+----
+
## Arduino IDE variables
### ARDUINO_DIR
diff --git a/bin/ard-reset-arduino b/bin/ard-reset-arduino
index d6f974f..69a442e 100755
--- a/bin/ard-reset-arduino
+++ b/bin/ard-reset-arduino
@@ -1,18 +1,11 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
-from __future__ import print_function
import serial
import serial.tools.list_ports
import os.path
import argparse
from time import sleep
-pyserial_version = None
-try:
- pyserial_version = int(serial.VERSION[0])
-except:
- pyserial_version = 2 # less than 2.3
-
parser = argparse.ArgumentParser(description='Reset an Arduino')
parser.add_argument('--zero', action='store_true', help='Reset Arduino Zero or similar Native USB to enter bootloader')
parser.add_argument('--caterina', action='store_true', help='Reset a Leonardo, Micro, Robot or LilyPadUSB.')
@@ -65,11 +58,7 @@ if args.zero:
ser = serial.Serial(args.port[0], 57600)
ser.close()
-
- if pyserial_version < 3:
- ser.setBaudrate(1200)
- else:
- ser.baudrate = 1200
+ ser.baudrate = 1200
# do the open/close at 1200 BAUD
ser.open()
@@ -100,7 +89,7 @@ if args.zero:
# check if a new port has attached and return the index if it has
port_index = new_port(initial_ports, reset_ports)
# return the new port if detected, otherwise return passed port
- if port_index is -1:
+ if port_index == -1:
bootloader_port = args.port[0]
else:
bootloader_port = reset_ports[port_index]
diff --git a/bin/ardmk-init b/bin/ardmk-init
index 51b12f0..11d1126 100755
--- a/bin/ardmk-init
+++ b/bin/ardmk-init
@@ -1,4 +1,5 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
+
"""
Arduino-mk Makefile and project initialiser
@@ -17,7 +18,6 @@ Example:
See `armk-init --help` for CLI arguments
"""
-from __future__ import print_function
import os
import argparse
@@ -54,7 +54,7 @@ PARSER.add_argument('--cli', action='store_true', help='run with user prompts (r
PARSER.add_argument('-P', '--project', action='store_true',
help='create boilerplate project with src, lib and bin folder structure')
PARSER.add_argument('-t', '--template', action='store_true',
- help='create bare minimum Arduino source file')
+ help='create bare minimum Arduino source file')
PARSER.add_argument('-V', '--version', action='version', version='%(prog)s '+ VERSION)
ARGS = PARSER.parse_args()
diff --git a/bin/robotis-loader b/bin/robotis-loader
index 95d4e71..3f3c21b 100755
--- a/bin/robotis-loader
+++ b/bin/robotis-loader
@@ -1,8 +1,8 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# This script sends a program on a robotis board (OpenCM9.04 or CM900)
# using the robotis bootloader (used in OpenCM IDE)
-#
+#
# Usage:
# python robotis-loader.py <serial port> <binary>
#
diff --git a/packaging/fedora/arduino-mk.spec b/packaging/fedora/arduino-mk.spec
index b1f07f1..559e229 100644
--- a/packaging/fedora/arduino-mk.spec
+++ b/packaging/fedora/arduino-mk.spec
@@ -1,6 +1,6 @@
Name: arduino-mk
Version: 1.6.0
-Release: 1%{dist}
+Release: 2%{dist}
Summary: Program your Arduino from the command line
Packager: Simon John <git@the-jedi.co.uk>
URL: https://github.com/sudar/Arduino-Makefile
@@ -9,8 +9,7 @@ Group: Development/Tools
License: LGPLv2+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
-Requires: arduino-core pyserial
-BuildRequires: arduino-core
+Requires: arduino-core python3-pyserial
%description
Arduino is an open-source electronics prototyping platform based on
@@ -60,6 +59,8 @@ rm -rf %{buildroot}
%{_docdir}/%{name}/examples
%changelog
+* Thu Oct 24 2019 Simon John <git@the-jedi.co.uk>
+- Removed BuildRequires
* Thu Oct 05 2017 Simon John <git@the-jedi.co.uk>
- Added ardmk-init binary and manpage
* Tue Jul 11 2017 Karl Semich <fuzzyTew@gmail.com>
diff --git a/tests/script/bootstrap/common.sh b/tests/script/bootstrap/common.sh
index c3cd90e..20c1037 100644
--- a/tests/script/bootstrap/common.sh
+++ b/tests/script/bootstrap/common.sh
@@ -160,22 +160,22 @@ if [ -z $COMMON_SOURCED ]; then
fi
fi
- if ! command -v python >/dev/null 2>&1; then
+ if ! command -v python3 >/dev/null 2>&1; then
echo "Installing Python..."
- _install "python"
+ _install "python3"
fi
- if ! command -v pip >/dev/null 2>&1; then
+ if ! command -v pip3 >/dev/null 2>&1; then
echo "Installing Pip..."
- if ! command -v easy_install >/dev/null 2>&1; then
- _install "python-setuptools"
+ if ! command -v easy_install3 >/dev/null 2>&1; then
+ _install "python3-setuptools"
fi
- if ! command -v easy_install >/dev/null 2>&1; then
- die "easy_install not available, can't install pip"
+ if ! command -v easy_install3 >/dev/null 2>&1; then
+ die "easy_install3 not available, can't install pip3"
fi
- $SUDO_CMD easy_install pip
+ $SUDO_CMD easy_install3 pip3
fi
PIP_SUDO_CMD=
@@ -184,7 +184,7 @@ if [ -z $COMMON_SOURCED ]; then
PIP_SUDO_CMD=$SUDO_CMD
fi
- $PIP_SUDO_CMD pip install --src dependencies --pre -Ur $BOOTSTRAP_DIR/pip-requirements.txt
+ $PIP_SUDO_CMD pip3 install --src dependencies --pre -Ur $BOOTSTRAP_DIR/pip-requirements.txt
COMMON_SOURCED=1
fi
diff --git a/tests/script/bootstrap/pip-requirements.txt b/tests/script/bootstrap/pip-requirements.txt
index 8313187..205196f 100644
--- a/tests/script/bootstrap/pip-requirements.txt
+++ b/tests/script/bootstrap/pip-requirements.txt
@@ -1 +1 @@
-pyserial==2.7
+pyserial==3.4