Rebased python3 branch with some changes from tuna-f1sh@87d5241

This commit is contained in:
Simon John 2020-08-04 23:19:49 +01:00
parent 6f786a96b0
commit 207253abc6
11 changed files with 76 additions and 48 deletions

View file

@ -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)

View file

@ -98,3 +98,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

View file

@ -32,6 +32,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)

View file

@ -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

View file

@ -115,6 +115,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

View file

@ -1,18 +1,11 @@
#!/usr/bin/env python
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()

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
"""
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()

View file

@ -1,8 +1,8 @@
#!/usr/bin/python
#!/usr/bin/env python
# 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>
#

View file

@ -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
@ -29,6 +28,7 @@ mkdir -p %{buildroot}/%{_datadir}/arduino
mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}/%{_mandir}/man1
mkdir -p %{buildroot}/%{_docdir}/%{name}/examples
sed -i 's/^#!\/usr\/bin\/env python/#!\/usr\/bin\/python3/' bin/*
install -m 755 -d %{buildroot}/%{_docdir}/%{name}
install -m 755 -d %{buildroot}/%{_docdir}/%{name}/examples
for dir in `find examples -type d` ; do install -m 755 -d %{buildroot}/%{_docdir}/%{name}/$dir ; done
@ -60,6 +60,10 @@ rm -rf %{buildroot}
%{_docdir}/%{name}/examples
%changelog
* Wed Jan 22 2020 Simon John <git@the-jedi.co.uk>
- Added sed for shebang
* 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>

View file

@ -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

View file

@ -1 +1 @@
pyserial==2.7
pyserial==3.4