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

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 14 additions & 18 deletions distribute_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

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:

args = [quote(arg) for arg in args]
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function use_setuptools refactored with the following changes:

return
except pkg_resources.VersionConflict:
e = sys.exc_info()[1]
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function download_setuptools refactored with the following changes:

url = download_base + tgz_name
saveto = os.path.join(to_dir, tgz_name)
src = dst = None
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _rename_path refactored with the following changes:

log.warn('Renaming %s into %s', path, new_name)
os.rename(path, new_name)
return new_name
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _create_fake_setuptools_pkg_info refactored with the following changes:

pkg_info = os.path.join(placeholder, setuptools_file)
if os.path.exists(pkg_info):
log.warn('%s already exists', pkg_info)
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _patch_egg_dir refactored with the following changes:

_rename_path(path)
os.mkdir(path)
os.mkdir(os.path.join(path, 'EGG-INFO'))
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _under_prefix refactored with the following changes:

top_dir = arg.split('root=')[-1]
return location.startswith(top_dir)
elif arg == option:
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _fake_setuptools refactored with the following changes:

else:
log.warn('Egg installation')
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
Expand All @@ -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()

Expand Down
13 changes: 7 additions & 6 deletions stale
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

"""Identify (and optionally delete) stale Delicious and Pinboard links"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 40-40 refactored with the following changes:


__author__ = 'Jon Parise <[email protected]>'
__version__ = '1.1'

Expand All @@ -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': '' }

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pinboard_api_request refactored with the following changes:


if not opener:
opener = pinboard_api_opener(user, passwd)
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sanitize_url refactored with the following changes:

return url

def setup_colors():
Expand Down