-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored master branch #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,7 @@ def _python_cmd(*args): | |
# quoting arguments if windows | ||
if sys.platform == 'win32': | ||
def quote(arg): | ||
if ' ' in arg: | ||
return '"%s"' % arg | ||
return arg | ||
return '"%s"' % arg if ' ' in arg else arg | ||
args = [quote(arg) for arg in args] | ||
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 | ||
|
||
|
@@ -144,7 +142,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, | |
except ImportError: | ||
return _do_download(version, download_base, to_dir, download_delay) | ||
try: | ||
pkg_resources.require("distribute>="+version) | ||
pkg_resources.require(f"distribute>={version}") | ||
Comment on lines
-147
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return | ||
except pkg_resources.VersionConflict: | ||
e = sys.exc_info()[1] | ||
|
@@ -183,7 +181,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, | |
from urllib.request import urlopen | ||
except ImportError: | ||
from urllib2 import urlopen | ||
tgz_name = "distribute-%s.tar.gz" % version | ||
tgz_name = f"distribute-{version}.tar.gz" | ||
Comment on lines
-186
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
url = download_base + tgz_name | ||
saveto = os.path.join(to_dir, tgz_name) | ||
src = dst = None | ||
|
@@ -247,7 +245,7 @@ def violation(*args): | |
|
||
@_no_sandbox | ||
def _rename_path(path): | ||
new_name = path + '.OLD.%s' % time.time() | ||
new_name = path + f'.OLD.{time.time()}' | ||
Comment on lines
-250
to
+248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
log.warn('Renaming %s into %s', path, new_name) | ||
os.rename(path, new_name) | ||
return new_name | ||
|
@@ -296,9 +294,8 @@ def _create_fake_setuptools_pkg_info(placeholder): | |
if not placeholder or not os.path.exists(placeholder): | ||
log.warn('Could not find the install location') | ||
return | ||
pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) | ||
setuptools_file = 'setuptools-%s-py%s.egg-info' % \ | ||
(SETUPTOOLS_FAKED_VERSION, pyver) | ||
pyver = f'{sys.version_info[0]}.{sys.version_info[1]}' | ||
setuptools_file = f'setuptools-{SETUPTOOLS_FAKED_VERSION}-py{pyver}.egg-info' | ||
Comment on lines
-299
to
+298
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
pkg_info = os.path.join(placeholder, setuptools_file) | ||
if os.path.exists(pkg_info): | ||
log.warn('%s already exists', pkg_info) | ||
|
@@ -322,10 +319,11 @@ def _create_fake_setuptools_pkg_info(placeholder): | |
def _patch_egg_dir(path): | ||
# let's check if it's already patched | ||
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') | ||
if os.path.exists(pkg_info): | ||
if _same_content(pkg_info, SETUPTOOLS_PKG_INFO): | ||
log.warn('%s already patched.', pkg_info) | ||
return False | ||
if os.path.exists(pkg_info) and _same_content( | ||
pkg_info, SETUPTOOLS_PKG_INFO | ||
): | ||
log.warn('%s already patched.', pkg_info) | ||
return False | ||
Comment on lines
-325
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
_rename_path(path) | ||
os.mkdir(path) | ||
os.mkdir(os.path.join(path, 'EGG-INFO')) | ||
|
@@ -349,7 +347,7 @@ def _under_prefix(location): | |
args = sys.argv[sys.argv.index('install')+1:] | ||
for index, arg in enumerate(args): | ||
for option in ('--root', '--prefix'): | ||
if arg.startswith('%s=' % option): | ||
if arg.startswith(f'{option}='): | ||
Comment on lines
-352
to
+350
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
top_dir = arg.split('root=')[-1] | ||
return location.startswith(top_dir) | ||
elif arg == option: | ||
|
@@ -395,8 +393,6 @@ def _fake_setuptools(): | |
if not setuptools_location.endswith('.egg'): | ||
log.warn('Non-egg installation') | ||
res = _remove_flat_installation(setuptools_location) | ||
if not res: | ||
return | ||
Comment on lines
-398
to
-399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
else: | ||
log.warn('Egg installation') | ||
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') | ||
|
@@ -407,8 +403,8 @@ def _fake_setuptools(): | |
log.warn('Patching...') | ||
# let's create a fake egg replacing setuptools one | ||
res = _patch_egg_dir(setuptools_location) | ||
if not res: | ||
return | ||
if not res: | ||
return | ||
log.warn('Patched done.') | ||
_relaunch() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
"""Identify (and optionally delete) stale Delicious and Pinboard links""" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
||
__author__ = 'Jon Parise <[email protected]>' | ||
__version__ = '1.1' | ||
|
||
|
@@ -37,7 +38,7 @@ except: | |
PINBOARD_API_HOST = 'api.pinboard.in' | ||
PINBOARD_API_PATH = 'v1' | ||
PINBOARD_API_REALM = 'API' | ||
PINBOARD_API = "https://%s/%s" % (PINBOARD_API_HOST, PINBOARD_API_PATH) | ||
PINBOARD_API = f"https://{PINBOARD_API_HOST}/{PINBOARD_API_PATH}" | ||
|
||
colors = { 'normal': '', 'green': '', 'red': '' } | ||
|
||
|
@@ -70,12 +71,12 @@ def pinboard_api_request(path, params=None, user='', passwd='', throttle=True, | |
pydelicious.Waiter() | ||
|
||
if params: | ||
url = "%s/%s?%s" % (PINBOARD_API, path, urllib.urlencode(params)) | ||
url = f"{PINBOARD_API}/{path}?{urllib.urlencode(params)}" | ||
else: | ||
url = "%s/%s" % (PINBOARD_API, path) | ||
url = f"{PINBOARD_API}/{path}" | ||
|
||
if pydelicious.DEBUG: print >>sys.stderr, \ | ||
"pinboard_api_request: %s" % url | ||
if pydelicious.DEBUG: | ||
(print >>sys.stderr, f"pinboard_api_request: {url}") | ||
Comment on lines
-73
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
if not opener: | ||
opener = pinboard_api_opener(user, passwd) | ||
|
@@ -90,7 +91,7 @@ def pinboard_api_request(path, params=None, user='', passwd='', throttle=True, | |
def sanitize_url(url): | ||
hash_position = url.find('#') | ||
if hash_position != -1: | ||
return url[0:hash_position] | ||
return url[:hash_position] | ||
Comment on lines
-93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return url | ||
|
||
def setup_colors(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
_python_cmd.quote
refactored with the following changes:reintroduce-else
)assign-if-exp
)