diff options
| author | Antoine Reversat <a.reversat@gmail.com> | 2010-08-05 21:49:06 -0400 |
|---|---|---|
| committer | Antoine Reversat <a.reversat@gmail.com> | 2010-08-05 21:49:06 -0400 |
| commit | b4a2d7104551bbcc443b0816438fd0d59ea8fdac (patch) | |
| tree | 372d0599e3a17cc25c1384c6d1c261f05bc54805 /src | |
| parent | 7eddff4d019fa891fe42a2b13fbbdfe268ace7af (diff) | |
| download | disutils2-b4a2d7104551bbcc443b0816438fd0d59ea8fdac.tar.gz | |
Changed some files to conform to PEP8
Diffstat (limited to 'src')
| -rw-r--r-- | src/distutils2/__init__.py | 5 | ||||
| -rw-r--r-- | src/distutils2/core.py | 2 | ||||
| -rw-r--r-- | src/distutils2/depgraph.py | 4 | ||||
| -rw-r--r-- | src/distutils2/dist.py | 25 | ||||
| -rw-r--r-- | src/distutils2/errors.py | 24 | ||||
| -rw-r--r-- | src/distutils2/extension.py | 8 | ||||
| -rw-r--r-- | src/distutils2/fancy_getopt.py | 6 | ||||
| -rw-r--r-- | src/distutils2/manifest.py | 2 | ||||
| -rw-r--r-- | src/distutils2/metadata.py | 6 | ||||
| -rwxr-xr-x | src/distutils2/mkpkg.py | 90 |
10 files changed, 108 insertions, 64 deletions
diff --git a/src/distutils2/__init__.py b/src/distutils2/__init__.py index 0514da7..f37e4ff 100644 --- a/src/distutils2/__init__.py +++ b/src/distutils2/__init__.py @@ -16,11 +16,12 @@ without causing the other modules to be imported: """ __all__ = ['__version__'] -__revision__ = "$Id: __init__.py 78020 2010-02-06 16:37:32Z benjamin.peterson $" +__revision__ = \ + "$Id: __init__.py 78020 2010-02-06 16:37:32Z benjamin.peterson $" __version__ = "1.0a2" -# when set to True, converts doctests by default too +# when set to True, converts doctests by default too run_2to3_on_doctests = True # Standard package names for fixer packages lib2to3_fixer_packages = ['lib2to3.fixes'] diff --git a/src/distutils2/core.py b/src/distutils2/core.py index e382345..b528634 100644 --- a/src/distutils2/core.py +++ b/src/distutils2/core.py @@ -33,6 +33,7 @@ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: %(script)s cmd --help """ + def gen_usage(script_name): script = os.path.basename(script_name) return USAGE % {'script': script} @@ -59,6 +60,7 @@ extension_keywords = ('name', 'sources', 'include_dirs', 'extra_objects', 'extra_compile_args', 'extra_link_args', 'swig_opts', 'export_symbols', 'depends', 'language') + def setup(**attrs): """The gateway to the Distutils: do everything your setup script needs to do, in a highly flexible and user-driven way. Briefly: create a diff --git a/src/distutils2/depgraph.py b/src/distutils2/depgraph.py index 75bc4d3..34fc1df 100644 --- a/src/distutils2/depgraph.py +++ b/src/distutils2/depgraph.py @@ -1,5 +1,5 @@ -"""Analyse the relationships between the distributions in the system and generate -a dependency graph. +"""Analyse the relationships between the distributions in the system +and generate a dependency graph. """ from distutils2.errors import DistutilsError diff --git a/src/distutils2/dist.py b/src/distutils2/dist.py index c3d547a..cc21d7a 100644 --- a/src/distutils2/dist.py +++ b/src/distutils2/dist.py @@ -6,7 +6,9 @@ being built/installed/distributed. __revision__ = "$Id: dist.py 77717 2010-01-24 00:33:32Z tarek.ziade $" -import sys, os, re +import sys +import os +import re try: import warnings @@ -26,7 +28,7 @@ from distutils2.metadata import DistributionMetadata # the same as a Python NAME -- I don't allow leading underscores. The fact # that they're very similar is no coincidence; the default naming scheme is # to look for a Python module named after the command. -command_re = re.compile (r'^[a-zA-Z]([a-zA-Z0-9_]*)$') +command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$') class Distribution(object): @@ -116,7 +118,7 @@ Common commands: (see '--help-commands' for more) ('use-2to3', None, "use 2to3 to make source python 3.x compatible"), ('convert-2to3-doctests', None, - "use 2to3 to convert doctests in seperate text files"), + "use 2to3 to convert doctests in seperate text files"), ] display_option_names = map(lambda x: translate_longopt(x[0]), display_options) @@ -124,10 +126,8 @@ Common commands: (see '--help-commands' for more) # negative options are options that exclude other options negative_opt = {'quiet': 'verbose'} - # -- Creation/initialization methods ------------------------------- - - def __init__ (self, attrs=None): + def __init__(self, attrs=None): """Construct a new Distribution instance: initialize all the attributes of a Distribution, and then use 'attrs' (a dictionary mapping attribute names to values) to assign some of those @@ -381,7 +381,7 @@ Common commands: (see '--help-commands' for more) for opt in options: if opt != '__name__': - val = parser.get(section,opt) + val = parser.get(section, opt) opt = opt.replace('-', '_') opt_dict[opt] = (filename, val) @@ -555,10 +555,10 @@ Common commands: (see '--help-commands' for more) if (hasattr(cmd_class, 'help_options') and isinstance(cmd_class.help_options, list)): - help_option_found=0 + help_option_found = 0 for (help_option, short, desc, func) in cmd_class.help_options: if hasattr(opts, parser.get_attr_name(help_option)): - help_option_found=1 + help_option_found = 1 if hasattr(func, '__call__'): func() else: @@ -584,7 +584,7 @@ Common commands: (see '--help-commands' for more) objects. """ if getattr(self, 'convert_2to3_doctests', None): - self.convert_2to3_doctests = [os.path.join(p) + self.convert_2to3_doctests = [os.path.join(p) for p in self.convert_2to3_doctests] else: self.convert_2to3_doctests = [] @@ -797,7 +797,7 @@ Common commands: (see '--help-commands' for more) class_name = command try: - __import__ (module_name) + __import__(module_name) module = sys.modules[module_name] except ImportError: continue @@ -814,7 +814,6 @@ Common commands: (see '--help-commands' for more) raise DistutilsModuleError("invalid command '%s'" % command) - def get_command_obj(self, command, create=1): """Return the command object for 'command'. Normally this object is cached on a previous call to 'get_command_obj()'; if no command @@ -955,9 +954,7 @@ Common commands: (see '--help-commands' for more) cmd_obj.run() self.have_run[command] = 1 - # -- Distribution query methods ------------------------------------ - def has_pure_modules(self): return len(self.packages or self.py_modules or []) > 0 diff --git a/src/distutils2/errors.py b/src/distutils2/errors.py index d5750f4..ef3e300 100644 --- a/src/distutils2/errors.py +++ b/src/distutils2/errors.py @@ -10,31 +10,38 @@ symbols whose names start with "Distutils" and end with "Error".""" __revision__ = "$Id: errors.py 75901 2009-10-28 06:45:18Z tarek.ziade $" + class DistutilsError(Exception): """The root of all Distutils evil.""" + class DistutilsModuleError(DistutilsError): """Unable to load an expected module, or to find an expected class within some module (in particular, command modules and classes).""" + class DistutilsClassError(DistutilsError): """Some command class (or possibly distribution class, if anyone feels a need to subclass Distribution) is found not to be holding up its end of the bargain, ie. implementing some part of the "command "interface.""" + class DistutilsGetoptError(DistutilsError): """The option table provided to 'fancy_getopt()' is bogus.""" + class DistutilsArgError(DistutilsError): """Raised by fancy_getopt in response to getopt.error -- ie. an error in the command line usage.""" + class DistutilsFileError(DistutilsError): """Any problems in the filesystem: expected file not found, etc. Typically this is for problems that we detect before IOError or OSError could be raised.""" + class DistutilsOptionError(DistutilsError): """Syntactic/semantic errors in command options, such as use of mutually conflicting options, or inconsistent options, @@ -43,60 +50,76 @@ class DistutilsOptionError(DistutilsError): files, or what-have-you -- but if we *know* something originated in the setup script, we'll raise DistutilsSetupError instead.""" + class DistutilsSetupError(DistutilsError): """For errors that can be definitely blamed on the setup script, such as invalid keyword arguments to 'setup()'.""" + class DistutilsPlatformError(DistutilsError): """We don't know how to do something on the current platform (but we do know how to do it on some platform) -- eg. trying to compile C files on a platform not supported by a CCompiler subclass.""" + class DistutilsExecError(DistutilsError): """Any problems executing an external program (such as the C compiler, when compiling C files).""" + class DistutilsInternalError(DistutilsError): """Internal inconsistencies or impossibilities (obviously, this should never be seen if the code is working!).""" + class DistutilsTemplateError(DistutilsError): """Syntax error in a file list template.""" + class DistutilsByteCompileError(DistutilsError): """Byte compile error.""" + # Exception classes used by the CCompiler implementation classes class CCompilerError(Exception): """Some compile/link operation failed.""" + class PreprocessError(CCompilerError): """Failure to preprocess one or more C/C++ files.""" + class CompileError(CCompilerError): """Failure to compile one or more C/C++ source files.""" + class LibError(CCompilerError): """Failure to create a static library from one or more C/C++ object files.""" + class LinkError(CCompilerError): """Failure to link one or more C/C++ object files into an executable or shared library file.""" + class UnknownFileError(CCompilerError): """Attempt to process an unknown file type.""" + class MetadataConflictError(DistutilsError): """Attempt to read or write metadata fields that are conflictual.""" + class MetadataUnrecognizedVersionError(DistutilsError): """Unknown metadata version number.""" + class IrrationalVersionError(Exception): """This is an irrational version.""" pass + class HugeMajorVersionNumError(IrrationalVersionError): """An irrational version because the major version number is huge (often because a year or date was used). @@ -105,4 +128,3 @@ class HugeMajorVersionNumError(IrrationalVersionError): This guard can be disabled by setting that option False. """ pass - diff --git a/src/distutils2/extension.py b/src/distutils2/extension.py index 05ccd20..f38bf60 100644 --- a/src/distutils2/extension.py +++ b/src/distutils2/extension.py @@ -17,6 +17,7 @@ import warnings # import that large-ish module (indirectly, through distutils.core) in # order to do anything. + class Extension(object): """Just a collection of attributes that describes an extension module and everything needed to build it (hopefully in a portable @@ -84,7 +85,7 @@ class Extension(object): # When adding arguments to this constructor, be sure to update # setup_keywords in core.py. - def __init__ (self, name, sources, + def __init__(self, name, sources, include_dirs=None, define_macros=None, undef_macros=None, @@ -95,11 +96,11 @@ class Extension(object): extra_compile_args=None, extra_link_args=None, export_symbols=None, - swig_opts = None, + swig_opts=None, depends=None, language=None, optional=None, - **kw # To catch unknown keywords + **kw # To catch unknown keywords ): if not isinstance(name, str): raise AssertionError("'name' must be a string") @@ -134,4 +135,3 @@ class Extension(object): options = ', '.join(sorted(options)) msg = "Unknown Extension options: %s" % options warnings.warn(msg) - diff --git a/src/distutils2/fancy_getopt.py b/src/distutils2/fancy_getopt.py index e0ac736..19cb97b 100644 --- a/src/distutils2/fancy_getopt.py +++ b/src/distutils2/fancy_getopt.py @@ -30,6 +30,7 @@ neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat)) # (for use as attributes of some object). longopt_xlate = string.maketrans('-', '_') + class FancyGetopt(object): """Wrapper around the standard 'getopt()' module that provides some handy extra functionality: @@ -42,7 +43,7 @@ class FancyGetopt(object): on the command line sets 'verbose' to false """ - def __init__ (self, option_table=None): + def __init__(self, option_table=None): # The option table is (currently) a list of tuples. The # tuples may have 3 or four values: @@ -180,7 +181,8 @@ class FancyGetopt(object): self.long_opts.append(long) if long[-1] == '=': # option takes an argument? - if short: short = short + ':' + if short: + short = short + ':' long = long[0:-1] self.takes_arg[long] = 1 else: diff --git a/src/distutils2/manifest.py b/src/distutils2/manifest.py index 87634c9..0d838ae 100644 --- a/src/distutils2/manifest.py +++ b/src/distutils2/manifest.py @@ -22,7 +22,7 @@ __all__ = ['Manifest'] # a \ followed by some spaces + EOL _COLLAPSE_PATTERN = re.compile('\\\w*\n', re.M) -_COMMENTED_LINE = re.compile('#.*?(?=\n)|^\w*\n|\n(?=$)', re.M|re.S) +_COMMENTED_LINE = re.compile('#.*?(?=\n)|^\w*\n|\n(?=$)', re.M | re.S) class Manifest(object): """A list of files built by on exploring the filesystem and filtered by diff --git a/src/distutils2/metadata.py b/src/distutils2/metadata.py index 147404d..a5a73f1 100644 --- a/src/distutils2/metadata.py +++ b/src/distutils2/metadata.py @@ -53,12 +53,12 @@ PKG_INFO_ENCODING = 'utf-8' PKG_INFO_PREFERRED_VERSION = '1.0' _LINE_PREFIX = re.compile('\n \|') -_241_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', +_241_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', 'Summary', 'Description', 'Keywords', 'Home-page', 'Author', 'Author-email', 'License') -_314_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', +_314_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', 'Supported-Platform', 'Summary', 'Description', 'Keywords', 'Home-page', 'Author', 'Author-email', 'License', 'Classifier', 'Download-URL', 'Obsoletes', @@ -66,7 +66,7 @@ _314_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', _314_MARKERS = ('Obsoletes', 'Provides', 'Requires') -_345_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', +_345_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', 'Supported-Platform', 'Summary', 'Description', 'Keywords', 'Home-page', 'Author', 'Author-email', 'Maintainer', 'Maintainer-email', 'License', diff --git a/src/distutils2/mkpkg.py b/src/distutils2/mkpkg.py index 3fe82e3..3827c32 100755 --- a/src/distutils2/mkpkg.py +++ b/src/distutils2/mkpkg.py @@ -30,11 +30,15 @@ # # Detect scripts (not sure how. #! outside of package?) -import sys, os, re, shutil, ConfigParser +import sys +import os +import re +import shutil +import ConfigParser helpText = { - 'name' : ''' + 'name': ''' The name of the program to be packaged, usually a single word composed of lower-case characters such as "python", "sqlalchemy", or "CherryPy". ''', @@ -620,28 +624,29 @@ troveList = [ 'Topic :: Utilities', ] -def askYn(question, default = None, helptext = None): +def askYn(question, default=None, helptext=None): while True: - answer = ask(question, default, helptext, required = True) + answer = ask(question, default, helptext, required=True) if answer and answer[0].lower() in 'yn': return(answer[0].lower()) print '\nERROR: You must select "Y" or "N".\n' -def ask(question, default = None, helptext = None, required = True, - lengthy = False, multiline = False): - prompt = '%s: ' % ( question, ) +def ask(question, default=None, helptext=None, required=True, + lengthy=False, multiline=False): + prompt = '%s: ' % (question,) if default: - prompt = '%s [%s]: ' % ( question, default ) + prompt = '%s [%s]: ' % (question, default) if default and len(question) + len(default) > 70: - prompt = '%s\n [%s]: ' % ( question, default ) + prompt = '%s\n [%s]: ' % (question, default) if lengthy or multiline: prompt += '\n >' - if not helptext: helptext = 'No additional help available.' - if helptext[0] == '\n': helptext = helptext[1:] - if helptext[-1] == '\n': helptext = helptext[:-1] + if not helptext: + helptext = 'No additional help available.' + + helptext = helptext.strip("\n") while True: sys.stdout.write(prompt) @@ -653,12 +658,14 @@ def ask(question, default = None, helptext = None, required = True, print helptext print '=' * 70 continue - if default and not line: return(default) + if default and not line: + return(default) if not line and required: print '*' * 70 print 'This value cannot be empty.' print '===========================' - if helptext: print helptext + if helptext: + print helptext print '*' * 70 continue return(line) @@ -669,7 +676,8 @@ def buildTroveDict(troveList): for key in troveList: subDict = dict for subkey in key.split(' :: '): - if not subkey in subDict: subDict[subkey] = {} + if not subkey in subDict: + subDict[subkey] = {} subDict = subDict[subkey] return(dict) troveDict = buildTroveDict(troveList) @@ -687,7 +695,8 @@ class SetupClass(object): def lookupOption(self, key): - if not self.config.has_option('DEFAULT', key): return(None) + if not self.config.has_option('DEFAULT', key): + return(None) return(self.config.get('DEFAULT', key)) @@ -706,7 +715,8 @@ class SetupClass(object): self.config.set('DEFAULT', compareKey, self.setupData[compareKey]) - if not valuesDifferent: return + if not valuesDifferent: + return self.config.write(open(os.path.expanduser('~/.pygiver'), 'w')) @@ -718,7 +728,7 @@ class SetupClass(object): def inspectFile(self, path): fp = open(path, 'r') try: - for line in [ fp.readline() for x in range(10) ]: + for line in [fp.readline() for x in range(10)]: m = re.match(r'^#!.*python((?P<major>\d)(\.\d+)?)?$', line) if m: if m.group('major') == '3': @@ -739,7 +749,8 @@ class SetupClass(object): for root, dirs, files in os.walk('.'): for file in files: - if root == '.' and file == 'setup.py': continue + if root == '.' and file == 'setup.py': + continue fileName = os.path.join(root, file) self.inspectFile(fileName) @@ -761,16 +772,16 @@ class SetupClass(object): self.setupData.get('version'), helpText['version']) self.setupData['description'] = ask('Package description', self.setupData.get('description'), helpText['description'], - lengthy = True) + lengthy=True) self.setupData['author'] = ask('Author name', self.setupData.get('author'), helpText['author']) self.setupData['author_email'] = ask('Author e-mail address', self.setupData.get('author_email'), helpText['author_email']) self.setupData['url'] = ask('Project URL', - self.setupData.get('url'), helpText['url'], required = False) + self.setupData.get('url'), helpText['url'], required=False) if (askYn('Do you want to set Trove classifiers?', - helptext = helpText['do_classifier']) == 'y'): + helptext=helpText['do_classifier']) == 'y'): self.setTroveClassifier() @@ -781,8 +792,10 @@ class SetupClass(object): def setTroveOther(self, classifierDict): - if askYn('Do you want to set other trove identifiers', 'n', - helpText['trove_generic']) != 'y': return + if askYn('Do you want to set other trove identifiers', + 'n', + helpText['trove_generic']) != 'y': + return self.walkTrove(classifierDict, [troveDict], '') @@ -799,7 +812,7 @@ class SetupClass(object): continue if askYn('Do you want to set items under\n "%s" (%d sub-items)' - % ( key, len(trove[key]) ), 'n', + % (key, len(trove[key])), 'n', helpText['trove_generic']) == 'y': self.walkTrove(classifierDict, trovePath + [trove[key]], desc + ' :: ' + key) @@ -808,15 +821,18 @@ class SetupClass(object): def setTroveLicense(self, classifierDict): while True: license = ask('What license do you use', - helptext = helpText['trove_license'], required = False) - if not license: return + helptext=helpText['trove_license'], + required=False) + if not license: + return licenseWords = license.lower().split(' ') foundList = [] for index in range(len(troveList)): troveItem = troveList[index] - if not troveItem.startswith('License :: '): continue + if not troveItem.startswith('License :: '): + continue troveItem = troveItem[11:].lower() allMatch = True @@ -824,17 +840,20 @@ class SetupClass(object): if not word in troveItem: allMatch = False break - if allMatch: foundList.append(index) + if allMatch: + foundList.append(index) question = 'Matching licenses:\n\n' for i in xrange(1, len(foundList) + 1): - question += ' %s) %s\n' % ( i, troveList[foundList[i - 1]] ) + question += ' %s) %s\n' % (i, troveList[foundList[i - 1]]) question += ('\nType the number of the license you wish to use or ' '? to try again:') - troveLicense = ask(question, required = False) + troveLicense = ask(question, required=False) - if troveLicense == '?': continue - if troveLicense == '': return + if troveLicense == '?': + continue + if troveLicense == '': + return foundIndex = foundList[int(troveLicense) - 1] classifierDict[troveList[foundIndex]] = 1 try: @@ -856,7 +875,7 @@ class SetupClass(object): 6 - Mature 7 - Inactive -Status''', required = False) +Status''', required=False) if devStatus: try: key = { @@ -884,7 +903,8 @@ Status''', required = False) return modified_pkgs def writeSetup(self): - if os.path.exists('setup.py'): shutil.move('setup.py', 'setup.py.old') + if os.path.exists('setup.py'): + shutil.move('setup.py', 'setup.py.old') fp = open('setup.py', 'w') try: |
