Skip to content

Commit

Permalink
Make code black
Browse files Browse the repository at this point in the history
Preparation for #17
  • Loading branch information
ale-rt committed Apr 10, 2020
1 parent 05ae66e commit 06607af
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 183 deletions.
146 changes: 83 additions & 63 deletions bootstrap-buildout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

from optparse import OptionParser

__version__ = '2015-07-01'
__version__ = "2015-07-01"
# See zc.buildout's changelog if this version is up to date.

tmpeggs = tempfile.mkdtemp(prefix='bootstrap-')
tmpeggs = tempfile.mkdtemp(prefix="bootstrap-")

usage = '''\
usage = """\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
Bootstraps a buildout-based project.
Expand All @@ -40,36 +40,50 @@
Note that by using --find-links to point to local resources, you can keep
this script from going over the network.
'''
"""

parser = OptionParser(usage=usage)
parser.add_option("--version",
action="store_true", default=False,
help=("Return bootstrap.py version."))
parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
help=("Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", "--config-file",
help=("Specify the path to the buildout configuration "
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--buildout-version",
help="Use a specific zc.buildout version")
parser.add_option("--setuptools-version",
help="Use a specific setuptools version")
parser.add_option("--setuptools-to-dir",
help=("Allow for re-use of existing directory of "
"setuptools versions"))
parser.add_option(
"--version",
action="store_true",
default=False,
help=("Return bootstrap.py version."),
)
parser.add_option(
"-t",
"--accept-buildout-test-releases",
dest="accept_buildout_test_releases",
action="store_true",
default=False,
help=(
"Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."
),
)
parser.add_option(
"-c",
"--config-file",
help=("Specify the path to the buildout configuration " "file to be used."),
)
parser.add_option(
"-f", "--find-links", help=("Specify a URL to search for buildout releases")
)
parser.add_option(
"--allow-site-packages",
action="store_true",
default=False,
help=("Let bootstrap.py use existing site packages"),
)
parser.add_option("--buildout-version", help="Use a specific zc.buildout version")
parser.add_option("--setuptools-version", help="Use a specific setuptools version")
parser.add_option(
"--setuptools-to-dir",
help=("Allow for re-use of existing directory of " "setuptools versions"),
)

options, args = parser.parse_args()
if options.version:
Expand All @@ -86,35 +100,35 @@
from urllib2 import urlopen

ez = {}
if os.path.exists('ez_setup.py'):
exec(open('ez_setup.py').read(), ez)
if os.path.exists("ez_setup.py"):
exec(open("ez_setup.py").read(), ez)
else:
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
exec(urlopen("https://bootstrap.pypa.io/ez_setup.py").read(), ez)

if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site

# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
if hasattr(site, "getsitepackages"):
for sitepackage_path in site.getsitepackages():
# Strip all site-packages directories from sys.path that
# are not sys.prefix; this is because on Windows
# sys.prefix is a site-package directory.
if sitepackage_path != sys.prefix:
sys.path[:] = [x for x in sys.path
if sitepackage_path not in x]
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]

setup_args = dict(to_dir=tmpeggs, download_delay=0)

if options.setuptools_version is not None:
setup_args['version'] = options.setuptools_version
setup_args["version"] = options.setuptools_version
if options.setuptools_to_dir is not None:
setup_args['to_dir'] = options.setuptools_to_dir
setup_args["to_dir"] = options.setuptools_to_dir

ez['use_setuptools'](**setup_args)
ez["use_setuptools"](**setup_args)
import setuptools
import pkg_resources

Expand All @@ -129,43 +143,49 @@

ws = pkg_resources.working_set

setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location
setuptools_path = ws.find(pkg_resources.Requirement.parse("setuptools")).location

# Fix sys.path here as easy_install.pth added before PYTHONPATH
cmd = [sys.executable, '-c',
'import sys; sys.path[0:0] = [%r]; ' % setuptools_path +
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', tmpeggs]
cmd = [
sys.executable,
"-c",
"import sys; sys.path[0:0] = [%r]; " % setuptools_path
+ "from setuptools.command.easy_install import main; main()",
"-mZqNxd",
tmpeggs,
]

find_links = os.environ.get(
'bootstrap-testing-find-links',
options.find_links or
('http://downloads.buildout.org/'
if options.accept_buildout_test_releases else None)
)
"bootstrap-testing-find-links",
options.find_links
or (
"http://downloads.buildout.org/"
if options.accept_buildout_test_releases
else None
),
)
if find_links:
cmd.extend(['-f', find_links])
cmd.extend(["-f", find_links])

requirement = 'zc.buildout'
requirement = "zc.buildout"
version = options.buildout_version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index
_final_parts = '*final-', '*final'

_final_parts = "*final-", "*final"

def _final_version(parsed_version):
try:
return not parsed_version.is_prerelease
except AttributeError:
# Older setuptools
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
if (part[:1] == "*") and (part not in _final_parts):
return False
return True

index = setuptools.package_index.PackageIndex(
search_path=[setuptools_path])
index = setuptools.package_index.PackageIndex(search_path=[setuptools_path])
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
Expand All @@ -184,13 +204,13 @@ def _final_version(parsed_version):
best.sort()
version = best[-1].version
if version:
requirement = '=='.join((requirement, version))
requirement = "==".join((requirement, version))
cmd.append(requirement)

import subprocess

if subprocess.call(cmd) != 0:
raise Exception(
"Failed to execute command:\n%s" % repr(cmd)[1:-1])
raise Exception("Failed to execute command:\n%s" % repr(cmd)[1:-1])

######################################################################
# Import and run buildout
Expand All @@ -199,12 +219,12 @@ def _final_version(parsed_version):
ws.require(requirement)
import zc.buildout.buildout

if not [a for a in args if '=' not in a]:
args.append('bootstrap')
if not [a for a in args if "=" not in a]:
args.append("bootstrap")

# if -c was provided, we push it back into args for buildout' main function
if options.config_file is not None:
args[0:0] = ['-c', options.config_file]
args[0:0] = ["-c", options.config_file]

zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)
1 change: 1 addition & 0 deletions news/17.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make code black [ale-rt]
2 changes: 1 addition & 1 deletion plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
2 changes: 1 addition & 1 deletion plone/memoize/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def xhtml_compress(string):

@implementer(IXHTMLCompressor)
class XHTMLSlimmer(object):

def compress(self, string):
if SLIMMER:
return xhtml_slimmer(string)
return string


xhtmlslimmer = XHTMLSlimmer()
9 changes: 6 additions & 3 deletions plone/memoize/forever.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@


def memoize(fun):

def get_key(fun, *args, **kwargs):
return (args, frozenset(kwargs.items()), )
return (
args,
frozenset(kwargs.items()),
)

def get_cache(fun, *args, **kwargs):
return _memos

return volatile.cache(get_key, get_cache)(fun)

__all__ = (memoize, )

__all__ = (memoize,)
9 changes: 5 additions & 4 deletions plone/memoize/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@


class Memojito(object):
propname = '_memojito_'
propname = "_memojito_"

def clear(self, inst):
if hasattr(inst, self.propname):
delattr(inst, self.propname)

def clearbefore(self, func):

def clear(*args, **kwargs):
inst = args[0]
self.clear(inst)
return func(*args, **kwargs)

return clear

def clearafter(self, func):

def clear(*args, **kwargs):
inst = args[0]
val = func(*args, **kwargs)
self.clear(inst)
return val

return clear

def memoize(self, func):

@wraps(func)
def memogetter(*args, **kwargs):
inst = args[0]
Expand All @@ -54,6 +53,7 @@ def memogetter(*args, **kwargs):
cache[key] = val
setattr(inst, self.propname, cache)
return val

return memogetter


Expand All @@ -66,4 +66,5 @@ def memogetter(*args, **kwargs):
def memoizedproperty(func):
return property(_m.memoize(func))


__all__ = (memoize, memoizedproperty, clearbefore, clearafter)
2 changes: 0 additions & 2 deletions plone/memoize/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class ICacheChooser(Interface):

def __call__(fun_name):
"""Return a cache with a dict interface based on a dotted
function name `fun_name`.
Expand All @@ -13,7 +12,6 @@ def __call__(fun_name):


class IXHTMLCompressor(Interface):

def compress(string):
"""Expects a valid XHTML Unicode string as input and returns a valid
XHTML Unicode string.
Expand Down
Loading

0 comments on commit 06607af

Please sign in to comment.