Skip to content

Commit

Permalink
Merge pull request #1104 from flit/change/drop_py2
Browse files Browse the repository at this point in the history
Drop Python 2 support
  • Loading branch information
flit authored Mar 1, 2021
2 parents cab4069 + 955b9c5 commit 8680ee6
Show file tree
Hide file tree
Showing 26 changed files with 65 additions and 219 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,18 @@ Configuration and customization is supported through [config files](docs/configu
News
----

- Python 2 support has been dropped! Version [0.29](/pyocd/pyOCD/releases/tag/v0.29.0) is the last version to support
Python 2. If there is a critical issue on 0.29 that is a blocker for you and you cannot move to Python 2, please
raise [an issue](https://github.com/pyocd/pyOCD/issues/new/choose).

- PyOCD has moved to [its own organization](https://github.com/pyocd/) on GitHub! You will continue to see
further changes to increase communication and make pyOCD a more independent and open project.

- _**Important note**: Python 2 support is deprecated and is planned to be dropped from an upcoming release._
Existing releases of pyOCD will, of course, continue to work with Python 2. If this is a major problem for you
moving forward, please create a [new issue](https://github.com/mbedmicro/pyOCD/issues/new/choose) describing
your concerns. As of 1 January 2021, there has been no negative feedback about dropping Python 2, so this will
likely happen sooner rather than later.


Requirements
------------

- Python 3.6.0 or later. Currently Python 2.7.9 or later also works, but see note above about Python 2 support
being deprecated.
- Python 3.6.0 or later.
- macOS, Linux, or Windows 7 or newer
- A recent version of [libusb](https://libusb.info/). See [libusb installation](#libusb-installation) for details.
- Microcontroller with an Arm Cortex-M CPU
Expand Down Expand Up @@ -106,8 +103,7 @@ as follows:
$ python3 -mpip install -U pyocd
```

_Note: depending on your system, you may need to use `python` instead of `python3`. The same applies if
you are using Python 2.7 (but please see the note above about deprecation of Python 2 support in pyocd)._
_Note: depending on your system, you may need to use `python` instead of `python3`._

The latest pyOCD package is available [on PyPI](https://pypi.python.org/pypi/pyOCD/) as well as
[on GitHub](https://github.com/pyocd/pyOCD/releases).
Expand Down Expand Up @@ -244,4 +240,4 @@ License
PyOCD is licensed with the permissive Apache 2.0 license. See the [LICENSE](LICENSE) file for the
full text of the license.

Copyright © 2006-2020 Arm Ltd and others (see individual source files)
Copyright © 2006-2021 The PyOCD authors
3 changes: 1 addition & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# install pyOCD itself (and dependencies) as editable
# install pyOCD itself as editable, plus test dependencies
--editable .

pytest>=3.4
Expand All @@ -8,4 +8,3 @@ elapsedtimer
flake8
pylint
tox
mock;python_version<"3.3"
4 changes: 2 additions & 2 deletions docs/automated_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Functional tests:

## Testing with tox

pyOCD includes a configuration file for tox that enables easy testing of both Python 2.7 and 3.7.
pyOCD includes a configuration file for tox that enables easy testing of multiple Python versions.
The tox tool is included in `dev-requirements.txt`, so it will already be present in a standard
pyOCD developer virtual environment.

To run the functional tests for both Python versions, just execute `tox` from the root of the pyOCD
To run the functional tests via tox, just execute `tox` from the root of the pyOCD
repo. It will create new virtual environments for each Python version and run `automated_test.py`.

Currently only the functions tests are included in the tox configuration.
6 changes: 3 additions & 3 deletions docs/configuring_logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Configuring Logging

## Overview

pyOCD uses the standard Python [logging](https://docs.python.org/2.7/library/logging.html) package
pyOCD uses the standard Python [logging](https://docs.python.org/3.8/library/logging.html) package
for all its logging.

There are multiple log levels, in order from least to most verbose:
Expand Down Expand Up @@ -88,9 +88,9 @@ for all of pyOCD.
### Full control

The full schema for the logging configuration dictionary is documented in the
[logging.config module documentation](https://docs.python.org/2.7/library/logging.config.html#logging-config-dictschema).
[logging.config module documentation](https://docs.python.org/3.8/library/logging.config.html#logging-config-dictschema).
The logging module's
[advanced tutorial](https://docs.python.org/2.7/howto/logging.html#logging-advanced-tutorial)
[advanced tutorial](https://docs.python.org/3.8/howto/logging.html#logging-advanced-tutorial)
has a good introduction to the features and log output flow, so you can better understand the
configuration schema.

Expand Down
20 changes: 6 additions & 14 deletions docs/developers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ pyOCD Developers' Guide
=======================

PyOCD developers are recommended to setup a working environment using
[virtualenv](https://virtualenv.pypa.io/en/latest/). After cloning
the code, you can setup a virtualenv and install the pyOCD
dependencies for the current platform by following the detailed steps below.
[virtualenv](https://virtualenv.pypa.io/en/latest/). After cloning the
code, you can setup a virtualenv and install the pyOCD dependencies for
the current platform by following the detailed steps below.

## Setup

Install the necessary tools listed below. Skip any step where a compatible tool already exists.

* [Install Python](https://www.python.org/downloads/). It is recommended that you install both
Python 3.7.0 or above and Python 2.7.15 or above, in order to test under both versions. Add to
PATH.
* [Install Python](https://www.python.org/downloads/). It is recommended that you install Python 3.8.0 or above.
Add to PATH.
* Note that on Windows, the 32-bit Python 2.7 must be installed for the Python-enabled gdb to
work properly and for the `test/gdb_test.py` functional test to pass.
* [Install Git](https://git-scm.com/downloads). Add to PATH.
Expand All @@ -30,13 +29,6 @@ $ cd pyOCD
$ virtualenv venv
```

You may wish to create two virtual environments, for both Python 2.7 and 3.x.

```
$ python2 -mvirtualenv venv2
$ python3 -mvirtualenv venv3
```

**Step 2.** Activate virtual environment

Activate your virtualenv and install the pyOCD dependencies for the current platform by doing
Expand Down Expand Up @@ -86,5 +78,5 @@ $ python ./automated_test.py
Once you are satisfied with your changes and all automated tests pass, please create a
[new pull request](https://github.com/pyocd/pyOCD/pull/new/master) on GitHub to share your work.

Pull requests should be made once a changeset is [rebased onto Master](https://www.atlassian.com/git/tutorials/merging-vs-rebasing/workflow-walkthrough).
Pull requests should be made once a changeset is [rebased onto master](https://www.atlassian.com/git/tutorials/merging-vs-rebasing/workflow-walkthrough).

2 changes: 1 addition & 1 deletion pyocd/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from natsort import natsort
import textwrap
from time import sleep
from shutil import get_terminal_size

from .. import coresight
from ..core.helpers import ConnectHelper
Expand All @@ -40,7 +41,6 @@
dump_hex_data_to_str,
)
from ..utility.progress import print_progress
from ..utility.compatibility import get_terminal_size
from ..utility.columns import ColumnFormatter
from ..utility.mask import (
msb,
Expand Down
2 changes: 1 addition & 1 deletion pyocd/commands/execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import pprint
from collections import namedtuple
import subprocess
from shutil import get_terminal_size

from ..core import exceptions
from ..coresight.ap import MEM_AP
from ..utility.compatibility import get_terminal_size
from ..utility.cmdline import (
split_command_line,
UniquePrefixMatcher,
Expand Down
10 changes: 3 additions & 7 deletions pyocd/core/session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2018-2020 Arm Limited
# Copyright (c) Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,12 +21,7 @@
import yaml
import os
import weakref

# inspect.getargspec is deprecated in Python 3.
try:
from inspect import getfullargspec as getargspec
except ImportError:
from inspect import getargspec
from inspect import getfullargspec

from . import exceptions
from .options_manager import OptionsManager
Expand Down Expand Up @@ -496,7 +492,7 @@ class UserScriptFunctionProxy(object):

def __init__(self, fn):
self._fn = fn
self._spec = getargspec(fn)
self._spec = getfullargspec(fn)

def __call__(self, **kwargs):
args = {}
Expand Down
10 changes: 3 additions & 7 deletions pyocd/coresight/coresight_target.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2015-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,6 +17,7 @@

import logging
import six
from inspect import getfullargspec

from ..core.target import Target
from ..core.memory_map import MemoryType
Expand All @@ -26,12 +28,6 @@
from ..utility.sequencer import CallSequence
from ..target.pack.flash_algo import PackFlashAlgo

# inspect.getargspec is deprecated in Python 3.
try:
from inspect import getfullargspec as getargspec
except ImportError:
from inspect import getargspec

LOG = logging.getLogger(__name__)

class CoreSightTarget(SoCTarget):
Expand Down Expand Up @@ -192,7 +188,7 @@ def create_flash(self):
# need the region to have a flash algo dict to pass to it. Otherwise we assume the
# algo is built-in.
klass = region.flash_class
argspec = getargspec(klass.__init__)
argspec = getfullargspec(klass.__init__)
if 'flash_algo' in argspec.args:
if region.algo is not None:
obj = klass(self, region.algo)
Expand Down
7 changes: 3 additions & 4 deletions pyocd/debug/semihost.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from ..coresight.cortex_m import CortexM
from ..core import (exceptions, session)
from ..utility.compatibility import byte_list_to_bytes

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -476,7 +475,7 @@ def _get_args(self, args, count):
def _get_string(self, ptr, length=None):
if length is not None:
data = self.context.read_memory_block8(ptr, length)
return six.ensure_str(byte_list_to_bytes(data))
return bytes(data).decode()

target_str = ''
# TODO - use memory map to make sure we don't try to read off the end of memory
Expand All @@ -489,14 +488,14 @@ def _get_string(self, ptr, length=None):

# Found a null terminator, append data up to but not including the null
# and then exit the loop.
target_str += six.ensure_str(byte_list_to_bytes(data[:terminator]))
target_str += bytes(data[:terminator]).decode()
break
except exceptions.TransferError:
# Failed to read some or all of the string.
break
except ValueError:
# No null terminator was found. Append all of data.
target_str += six.ensure_str(byte_list_to_bytes(data))
target_str += bytes(data).decode()
ptr += 32
return target_str

Expand Down
7 changes: 2 additions & 5 deletions pyocd/debug/svd/loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2015-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,10 +21,6 @@
import zipfile

from .parser import SVDParser
from ...utility.compatibility import (
FileNotFoundError,
BadZipFile,
)

LOG = logging.getLogger(__name__)

Expand All @@ -37,7 +34,7 @@ def from_builtin(cls, svd_name):
zip_stream = pkg_resources.resource_stream("pyocd", BUILTIN_SVD_DATA_PATH)
zip = zipfile.ZipFile(zip_stream, 'r')
return SVDFile(zip.open(svd_name))
except (KeyError, FileNotFoundError, BadZipFile) as err:
except (KeyError, FileNotFoundError, zipfile.BadZipFile) as err:
from ...core.session import Session
LOG.warning("unable to open builtin SVD file: %s", err, exc_info=Session.get_current().log_tracebacks)
return None
Expand Down
1 change: 0 additions & 1 deletion pyocd/flash/file_programmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from .loader import FlashLoader
from ..core import exceptions
from ..debug.elf.elf import (ELFBinaryFile, SH_FLAGS)
from ..utility.compatibility import FileNotFoundError

LOG = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions pyocd/target/pack/cmsis_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from ...core import exceptions
from ...core.target import Target
from ...core.memory_map import (MemoryMap, MemoryType, MEMORY_TYPE_CLASS_MAP, FlashRegion)
from ...utility.compatibility import BadZipFile

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -85,7 +84,7 @@ def __init__(self, file_or_path):
else:
try:
self._pack_file = zipfile.ZipFile(file_or_path, 'r')
except BadZipFile as err:
except zipfile.BadZipFile as err:
six.raise_from(MalformedCmsisPackError("Failed to open CMSIS-Pack '{}': {}".format(
file_or_path, err)), err)

Expand Down
1 change: 0 additions & 1 deletion pyocd/target/pack/pack_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from .. import TARGET
from ...coresight.coresight_target import CoreSightTarget
from ...debug.svd.loader import SVDFile
from ...utility.compatibility import FileNotFoundError

try:
import cmsis_pack_manager
Expand Down
3 changes: 1 addition & 2 deletions pyocd/utility/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import sys
import logging

from .compatibility import get_terminal_size
from shutil import get_terminal_size

LOG = logging.getLogger(__name__)

Expand Down
Loading

0 comments on commit 8680ee6

Please sign in to comment.