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

[Py3] Support relative and package imports #45

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions workflow/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import subprocess
import pickle

from workflow import Workflow

__all__ = ['is_running', 'run_in_background']

_wf = None
Expand All @@ -27,6 +25,7 @@
def wf():
global _wf
if _wf is None:
from workflow import Workflow
_wf = Workflow()
return _wf

Expand Down
12 changes: 9 additions & 3 deletions workflow/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
import subprocess

import workflow
import web

try:
from .web import get as web_get
except (ImportError, ValueError):
# ValueError is thrown is py2
# ImportError is thrown is py3
from web import get as web_get

# __all__ = []

Expand Down Expand Up @@ -212,7 +218,7 @@ def download_workflow(url):
wf().logger.debug(
'Downloading updated workflow from `%s` to `%s` ...', url, local_path)

response = web.get(url)
response = web_get(url)

with open(local_path, 'wb') as output:
output.write(response.content)
Expand Down Expand Up @@ -311,7 +317,7 @@ def get_valid_releases(github_slug, prereleases=False):
def retrieve_releases():
wf().logger.info(
'Retrieving releases for `%s` ...', github_slug)
return web.get(api_url).json()
return web_get(api_url).json()

slug = github_slug.replace('/', '-')
for release in wf().cached_data('gh-releases-{0}'.format(slug),
Expand Down
39 changes: 23 additions & 16 deletions workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import atexit
import binascii
from contextlib import contextmanager
import cPickle
from copy import deepcopy
import errno
import json
Expand All @@ -47,6 +46,21 @@
except ImportError: # pragma: no cover
import xml.etree.ElementTree as ET

try:
from .background import run_in_background
from .update import check_update, Version
except (ValueError, ImportError):
# ValueError is thrown is py2
# ImportError is thrown is py3
from background import _process_exists, run_in_background
from update import check_update, Version

SUPPORTS_CPICKLE = True
try:
import cPickle
except ImportError:
cPickle = None
SUPPORTS_CPICKLE = False

#: Sentinel for properties that haven't been set yet (that might
#: correctly have the value ``None``)
Expand Down Expand Up @@ -698,7 +712,8 @@ def dump(cls, obj, file_obj):

# Set up default manager and register built-in serializers
manager = SerializerManager()
manager.register('cpickle', CPickleSerializer)
if SUPPORTS_CPICKLE:
manager.register('cpickle', CPickleSerializer)
manager.register('pickle', PickleSerializer)
manager.register('json', JSONSerializer)

Expand Down Expand Up @@ -863,7 +878,6 @@ def _validate_lockfile(self):
except ValueError:
return self.release()

from background import _process_exists
if not _process_exists(pid):
self.release()

Expand Down Expand Up @@ -1120,8 +1134,11 @@ def __init__(self, default_settings=None, update_settings=None,
self._bundleid = None
self._debugging = None
self._name = None
self._cache_serializer = 'cpickle'
self._data_serializer = 'cpickle'
self._cache_serializer = 'pickle'
self._data_serializer = 'pickle'
if SUPPORTS_CPICKLE:
self._cache_serializer = 'cpickle'
self._data_serializer = 'cpickle'
self._info = None
self._info_loaded = False
self._logger = None
Expand Down Expand Up @@ -1162,7 +1179,6 @@ def __init__(self, default_settings=None, update_settings=None,
@property
def alfred_version(self):
"""Alfred version as :class:`~workflow.update.Version` object."""
from update import Version
return Version(self.alfred_env.get('version'))

@property
Expand Down Expand Up @@ -1343,7 +1359,6 @@ def version(self):
version = self.info.get('version')

if version:
from update import Version
version = Version(version)

self._version = version
Expand Down Expand Up @@ -2385,7 +2400,6 @@ def last_version_run(self):

version = self.settings.get('__workflow_last_version')
if version:
from update import Version
version = Version(version)

self._last_version_run = version
Expand Down Expand Up @@ -2415,7 +2429,6 @@ def set_last_version(self, version=None):
version = self.version

if isinstance(version, basestring):
from update import Version
version = Version(version)

self.settings['__workflow_last_version'] = str(version)
Expand Down Expand Up @@ -2494,8 +2507,6 @@ def check_update(self, force=False):
# version = self._update_settings['version']
version = str(self.version)

from background import run_in_background

# update.py is adjacent to this file
update_script = os.path.join(os.path.dirname(__file__),
b'update.py')
Expand Down Expand Up @@ -2525,17 +2536,13 @@ def start_update(self):
installed, else ``False``

"""
import update

github_slug = self._update_settings['github_slug']
# version = self._update_settings['version']
version = str(self.version)

if not update.check_update(github_slug, version, self.prereleases):
if not check_update(github_slug, version, self.prereleases):
return False

from background import run_in_background

# update.py is adjacent to this file
update_script = os.path.join(os.path.dirname(__file__),
b'update.py')
Expand Down