Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 support [WIP] #184

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d4932a9
2to3-3.8 -wn setup.py docs/conf.py tests/ workflow/ extras/
mesozoic Apr 20, 2022
f31040d
Test on python3.8 instead of python2.7
mesozoic Apr 20, 2022
da1a32f
Remove dependency on pytest_httpbin
mesozoic Apr 20, 2022
85b4ecd
Tests fail, but at least they run
mesozoic Apr 20, 2022
1d0f70b
Fix test_background
mesozoic Apr 20, 2022
3ca167c
Fix test_notify
mesozoic Apr 20, 2022
d9f9429
Fix test_update
mesozoic Apr 20, 2022
bacb37b
Fix test_update_versions
mesozoic Apr 20, 2022
2b08d78
Fix test_util*
mesozoic Apr 20, 2022
3ed460e
Fix test_web*
mesozoic Apr 20, 2022
d936a38
Fix test_workflow, test_workflow3
mesozoic Apr 20, 2022
ad02b37
Fix test_workflow_encoding
mesozoic Apr 20, 2022
de407b7
Fix test_workflow_files
mesozoic Apr 20, 2022
47dd2cb
str -> bytes, unicode -> str
mesozoic Apr 20, 2022
9528288
Fix test_workflow_filter
mesozoic Apr 20, 2022
233dd85
Fix test_workflow_magic
mesozoic Apr 20, 2022
cc37aaa
Fix test_workflow_run
mesozoic Apr 20, 2022
e0f99ea
Fix test_workflow_serializers
mesozoic Apr 20, 2022
c06c229
Fix test_workflow_settings
mesozoic Apr 20, 2022
f5947c8
Fix test_workflow_update
mesozoic Apr 20, 2022
c323773
Fix test_workflow_xml
mesozoic Apr 20, 2022
0b4bf33
Fix gaps in coverage
mesozoic Apr 20, 2022
4443fc0
Remove utf8ify (unnecessary)
mesozoic Apr 20, 2022
67ca1d0
/usr/bin/python -> /usr/bin/python3
mesozoic Apr 20, 2022
ae5a1b5
Run tests on python3.{7,8,9}
mesozoic Apr 20, 2022
71312cd
Update CI/CD to use Python 3 (untested)
mesozoic Apr 20, 2022
13aceb5
Start updating docs to note switch to Python 3
mesozoic Apr 20, 2022
ba2a8ab
2.0.0
mesozoic Apr 20, 2022
a1935ec
Fix linter errors, add linter to tox
mesozoic Apr 21, 2022
a3081b7
Run GitHub workflows on 3.7, 3.8, 3.9
mesozoic Apr 21, 2022
14f5c09
Pass CODECOV_TOKEN into CI environment
mesozoic Apr 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ jobs:
run:
name: "tests & coverage"
runs-on: macos-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 2.7
python-version: ${{ matrix.python-version }}

- name: Install test dependencies
run: |
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ osx_image: xcode8.3

env:
matrix:
- VERSION=2.7.10 SOURCE=macpython
# Turn off 2.6 as it's no longer supported
# - VERSION=2.6.9 SOURCE=macports
- VERSION=3.8.9 SOURCE=macpython

before_install:
# - brew update
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A helper library in Python for authors of workflows for [Alfred 3 and 4][alfred]

<!-- [![Downloads][shield-download]][pypi] -->

Supports Alfred 3 and Alfred 4 on macOS 10.7+ (Python 2.7).
Supports Alfred 3 and Alfred 4 on macOS Catalina or later (with Python 3).

Alfred-Workflow takes the grunt work out of writing a workflow by giving you the tools to create a fast and featureful Alfred workflow from an API, application or library in minutes.

Expand Down
4 changes: 2 additions & 2 deletions README_PYPI.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

A helper library for writing `Alfred 2, 3 and 4`_ workflows.

Supports macOS 10.7+ and Python 2.7 (Alfred 3 is 10.9+/2.7 only).
Supports macOS Catalina and Python 3.7+.

Alfred-Workflow is designed to take the grunt work out of writing a workflow.

Expand Down Expand Up @@ -46,7 +46,7 @@ Here's how to show recent `Pinboard.in <https://pinboard.in/>`_ posts
in Alfred.

Create a new workflow in Alfred's preferences. Add a **Script Filter** with
Language ``/usr/bin/python`` and paste the following into the **Script**
Language ``/usr/bin/python3`` and paste the following into the **Script**
field (changing ``API_KEY``):


Expand Down
2 changes: 1 addition & 1 deletion bin/publish-cheeseshop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rootdir=$(cd $(dirname $0)/../; pwd)
cd "${rootdir}"
version=$( cat workflow/version )

/usr/bin/python setup.py sdist
/usr/bin/python3 setup.py sdist
twine upload dist/Alfred-Workflow-$version.tar.gz

cd -
2 changes: 0 additions & 2 deletions docs/api/util.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Text encoding and formatting.

.. autofunction:: unicodify

.. autofunction:: utf8ify

.. autofunction:: applescriptify


Expand Down
21 changes: 0 additions & 21 deletions docs/api/web.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@ modelled on the excellent `requests`_ library.
The purpose of :mod:`workflow.web` is to cover trivial cases at just 0.5% of
the size of `requests`_.

.. danger::

As :mod:`workflow.web` is based on Python 2's standard HTTP libraries,
there are two important problems with SSL connections.

Python versions older than 2.7.9 (i.e. pre-Yosemite) **do not**
verify SSL certificates when establishing HTTPS connections.

As a result, you **must not** use this module for sensitive
connections unless you're certain it will only run on 2.7.9/Yosemite
and later. If your workflow is Alfred 3-only, this requirement is met.

Secondly, versions of macOS older than High Sierra (10.13) have an
extremely outdated version of OpenSSL, which is incompatible with
many servers' SSL configuration.

Consequently, :mod:`workflow.web` cannot connect to such servers.
As this includes GitHub's SSL configuration, the
:ref:`update mechanism <guide-updates>` only works on High Sierra
and later.


.. autofunction:: get
.. autofunction:: post
Expand Down
3 changes: 0 additions & 3 deletions docs/api/workflow.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ The default manager (which supports JSON, pickle and cPickle) is at
.. autoclass:: JSONSerializer
:members:

.. autoclass:: CPickleSerializer
:members:

.. autoclass:: PickleSerializer
:members:

Expand Down
26 changes: 13 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
'sphinxcontrib.napoleon',
]

intersphinx_mapping = {'python': ('https://docs.python.org/2.7', None)}
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand All @@ -59,8 +59,8 @@
master_doc = 'index'

# General information about the project.
project = u'Alfred-Workflow'
copyright = u' 2013–{} Dean Jackson'.format(date.today().year)
project = 'Alfred-Workflow'
copyright = ' 2013–{} Dean Jackson'.format(date.today().year)

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -246,8 +246,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'Alfred-Workflow.tex', u'Alfred-Workflow Documentation',
u'Dean Jackson <deanishe@deanishe.net>', 'manual'),
('index', 'Alfred-Workflow.tex', 'Alfred-Workflow Documentation',
'Dean Jackson <deanishe@deanishe.net>', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -276,8 +276,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'alfred-workflow', u'Alfred-Workflow Documentation',
[u'Dean Jackson <deanishe@deanishe.net>'], 1)
('index', 'alfred-workflow', 'Alfred-Workflow Documentation',
['Dean Jackson <deanishe@deanishe.net>'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -290,8 +290,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Alfred-Workflow', u'Alfred-Workflow Documentation',
u'Dean Jackson <deanishe@deanishe.net>',
('index', 'Alfred-Workflow', 'Alfred-Workflow Documentation',
'Dean Jackson <deanishe@deanishe.net>',
'Alfred-Workflow',
'Python helper library for Alfred Workflows',
'Miscellaneous'),
Expand All @@ -313,10 +313,10 @@
# -- Options for Epub output ----------------------------------------------

# Bibliographic Dublin Core info.
epub_title = u'Alfred-Workflow'
epub_author = u'Dean Jackson <deanishe@deanishe.net>'
epub_publisher = u'Dean Jackson <deanishe@deanishe.net>'
epub_copyright = u'2014, Dean Jackson <deanishe@deanishe.net>'
epub_title = 'Alfred-Workflow'
epub_author = 'Dean Jackson <deanishe@deanishe.net>'
epub_publisher = 'Dean Jackson <deanishe@deanishe.net>'
epub_copyright = '2014, Dean Jackson <deanishe@deanishe.net>'

# The basename for the epub file. It defaults to the project name.
# epub_basename = u'Alfred-Workflow'
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/background.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ background). What we're doing is:
# Is cache over 1 hour old or non-existent?
if not wf.cached_data_fresh('exchange-rates', 3600):
run_in_background('update',
['/usr/bin/python',
['/usr/bin/python3',
wf.workflowfile('update_exchange_rates.py')])

if is_running('update'):
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/magic-arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The magic arguments are defined in the :attr:`Workflow.magic_arguments <workflow
The dictionary keys are the keywords for the arguments (without the
prefix) and the values are functions that should be called when the magic
argument is entered. You can show a message in Alfred by returning a
``unicode`` string from the function.
``str`` string from the function.

To add a new magic argument that opens the workflow's settings file, you
could do:
Expand Down
7 changes: 2 additions & 5 deletions docs/guide/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ Built-in serializers

There are 3 built-in, pre-configured serializers:

- :class:`cpickle <workflow.workflow.CPickleSerializer>` — the default serializer
for both cached and stored data, with very good support for native Python
data types;
- :class:`pickle <workflow.workflow.PickleSerializer>` — a more flexible, but
much slower alternative to ``cpickle``; and
- :class:`cpickle <workflow.workflow.PickleSerializer>` — the default serializer
for both cached and stored data, with support for native Python data types;
- :class:`json <workflow.workflow.JSONSerializer>` — a very common data format,
but with limited support for native Python data types.

Expand Down
8 changes: 4 additions & 4 deletions docs/guide/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ following (and only the following) **Escaping** options:

The **Script** field should contain the following::

/usr/bin/python yourscript.py "{query}"
/usr/bin/python3 yourscript.py "{query}"


where ``yourscript.py`` is the name of your script [#]_.
Expand All @@ -31,7 +31,7 @@ to capture any errors thrown by your scripts:
.. code-block:: python
:linenos:

#!/usr/bin/python
#!/usr/bin/python3
# encoding: utf-8

import sys
Expand Down Expand Up @@ -68,6 +68,6 @@ to capture any errors thrown by your scripts:
sys.exit(wf.run(main))


.. [#] It's better to specify ``/usr/bin/python`` over just ``python``. This
.. [#] It's better to specify ``/usr/bin/python3`` over just ``python``. This
ensures that the script will always be run with the system default
Python regardless of what ``PATH`` might be.
Python regardless of what ``PATH`` might be.
4 changes: 2 additions & 2 deletions docs/guide/text-encoding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ than a concrete implementation), while encoded strings are binary data that are
encoded according to some scheme that maps characters to a specific binary
representation (e.g. UTF-8 or ASCII).

In Python, these have the types ``unicode`` and ``str`` respectively.
In Python, these have the types ``str`` and ``bytes`` respectively.

As noted, Unicode strings only exist within a running program. Any text stored
on disk, passed into or out of a program or transmitted over a network *must*
Expand Down Expand Up @@ -351,7 +351,7 @@ an empty environment. This tells Python (and other POSIX software) by omission
that encoding is ASCII.

Although this won't affect Python 2's auto-promotion of encoded strings
(``str`` objects) to Unicode (it always uses ASCII), it *does*
(``bytes`` objects) to Unicode (it always uses ASCII), it *does*
affect the printing of Unicode strings, so using :func:`print` may work
perfectly in your shell where the environmental encoding is UTF-8 but not in
Alfred 2, where encoding is ASCII by default.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ read:

.. code-block:: bash

/usr/bin/python myscript.py pages
/usr/bin/python3 myscript.py pages


The other options (``--view``, ``--edit``, ``--share``) are set via the
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ elsewhere, filter them and display results to the user. Alfred-Workflow takes
care of a lot of the details for you, allowing you to concentrate your efforts
on your workflow's functionality.

Alfred-Workflow supports macOS 10.7+ (Python 2.7).
Alfred-Workflow supports macOS Catalina or later.


Features
Expand Down Expand Up @@ -58,7 +58,7 @@ Quick example
Here's how to show recent `Pinboard.in <https://pinboard.in/>`_ posts in Alfred.

Create a new workflow in Alfred's preferences. Add a **Script Filter** with
Language ``/usr/bin/python`` and paste the following into the **Script**
Language ``/usr/bin/python3`` and paste the following into the **Script**
box (changing ``API_KEY``):

.. code-block:: python
Expand Down
39 changes: 3 additions & 36 deletions docs/supported-versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Supported versions
==================

Alfred-Workflow supports all versions of Alfred 2–4. It works with
Python 2.6 and 2.7, but *not yet* Python 3.
Alfred-Workflow supports all versions of Alfred 2–4. It works with Python 3.8
and does not support Python 2 any longer.

Some features are not available on older versions of macOS.

Expand Down Expand Up @@ -51,48 +51,15 @@ Alfred-Workflow supports the same macOS versions as Alfred, namely 10.6 (Snow Le
Python versions
===============

Alfred-Workflow only officially supports the system Pythons that come with macOS (i.e. ``/usr/bin/python``), which is 2.6 on 10.6/Snow Leopard and 2.7 on later versions.
Alfred-Workflow only officially supports the system Pythons that come with macOS (i.e. ``/usr/bin/python3``).

.. important::

Other Pythons (e.g. Homebrew, conda, pyenv etc.) are *not* supported.

This is a deliberate design choice, so please do not submit feature requests for support of, or bug reports concerning issues with any non-system Pythons.

**This includes Python 3**.

Python 3 support will be added in a new major version of the library when Catalina is more popular.


Here is the `full list of new features in Python 2.7`_, but the most important things if you want your workflow to run on Snow Leopard/Python 2.6 are:

- :mod:`argparse` is not available in 2.6. Use :mod:`getopt` or
`include argparse in your workflow`_. Personally, I'm a big fan of
`docopt`_ for parsing command-line arguments, but :mod:`argparse`
is better for certain use cases.
- You must specify field numbers for :meth:`str.format`, i.e.
``'{0}.{1}'.format(first, second)`` not just
``'{}.{}'.format(first, second)``.
- No :class:`~collections.Counter` or
:class:`~collections.OrderedDict` in :mod:`collections`.
- No dictionary views in 2.6.
- No set literals.
- No dictionary or set comprehensions.

Python 2.6 is still included in later versions of macOS (up to and including El Capitan), so run your Python scripts with ``/usr/bin/python2.6`` in addition to ``/usr/bin/python`` (2.7) to make sure they will run on Snow Leopard.


Why no Python 3 support?
------------------------

Alfred-Workflow is targeted at the system Python on macOS. Its goal is to enable developers to build workflows that will "just work" for users on any vanilla installation of macOS since Snow Leopard.

As such, it :ref:`strongly discourages developers <thirdparty>` from requiring users of their workflows to bugger about with their OS in order to get a workflow to work. This naturally includes requiring the installation of some non-default Python.

Version 2 of Alfred-Workflow, which will be a complete rewrite, will support Python 3 and Alfred 4+ only.


.. _full list of new features in Python 2.7: https://docs.python.org/3/whatsnew/2.7.html
.. _include argparse in your workflow: https://pypi.python.org/pypi/argparse
.. _docopt: http://docopt.org/
.. _Powerpack: https://buy.alfredapp.com/
4 changes: 2 additions & 2 deletions docs/tutorial_1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ argument.

.. note::

You *can* choose ``/usr/bin/python`` as the **Language** and paste
You *can* choose ``/usr/bin/python3`` as the **Language** and paste
your Python code into the **Script** box, but this isn't the best idea.

If you do this, you can't run the script from the Terminal (which can be
Expand Down Expand Up @@ -615,4 +615,4 @@ To learn more about coding in Python, try these resources:
`TextMate <https://github.com/textmate/textmate/releases>`_ is an
excellent and free editor.
`TextWrangler <http://www.barebones.com/products/textwrangler/>`_ is
another good, free editor for macOS (supports 10.6).
another good, free editor for macOS (supports 10.6).
4 changes: 2 additions & 2 deletions docs/tutorial_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ update itself:

# Start update script if cached data are too old (or doesn't exist)
if not wf.cached_data_fresh('posts', max_age=600):
cmd = ['/usr/bin/python', wf.workflowfile('update.py')]
cmd = ['/usr/bin/python3', wf.workflowfile('update.py')]
run_in_background('update', cmd)

# Notify the user if the cache is being updated
Expand Down Expand Up @@ -1062,4 +1062,4 @@ enable your workflow to update itself from GitHub.
.. _GitHub releases: https://help.github.com/articles/about-releases

.. [#] :mod:`argparse` isn't available in Python 2.6, so this workflow won't
run on Snow Leopard (10.6).
run on Snow Leopard (10.6).
Loading