Package cheesecake :: Module cheesecake_index
[show private | hide private]
[frames | no frames]

Module cheesecake.cheesecake_index

Cheesecake: How tasty is your code?

The idea of the Cheesecake project is to rank Python packages based on various empirical "kwalitee" factors, such as:


Classes
Cheesecake Computes 'goodness' of Python packages.
CheesecakeIndex  
FilesIndex  
Index Class describing one index.
IndexCodeKwalitee  
IndexDocstrings Compute how many objects have relevant docstrings.
IndexDocumentation  
IndexFormattedDocstrings Compute how many of existing docstrings include any formatting, like epytext or reST.
IndexGeneratedFiles Lower score for automatically generated files that should not be present in a package.
IndexInstall Check if package can be installed via "python setup.py" command.
IndexInstallability  
IndexPEP8 Compute PEP8 index for the modules in the package.
IndexPyLint Compute pylint index of the whole package.
IndexPyPIDownload Check if package was successfully downloaded from PyPI and how far from it actual package was.
IndexRequiredFiles Check for existence of important files, like README or INSTALL.
IndexSetupPy Reward packages that have setup.py file.
IndexUnitTested Check if the package has unit tests which can be easily found by any of known test frameworks.
IndexUnitTests Compute unittest index as percentage of methods/functions that are exercised in unit tests.
IndexUnpack Give points for successful unpacking of a package archive.
IndexUnpackDir Check if package unpack directory resembles package archive name.
IndexUrlDownload Give points for successful downloading of a package.
NameSetter  
OneOf  
Step Single step during computation of package score.
StepByVariable Step which is always run if given Cheesecake instance variable is true.

Exceptions
CheesecakeError Custom exception class for Cheesecake-specific errors.

Function Summary
  camel2underscore(name)
Convert name from CamelCase to underscore_name.
  discover_file_type(filename)
Discover type of a file according to its name and its parent directory.
  Doc(name)
  generate_arguments(arguments, max_length)
Pass list of strings in chunks of size not greater than max_length.
  get_attributes(obj, names)
Return attributes dictionary with keys from names.
  get_files_dirs_list(root)
Return list of all files and directories below root.
  get_files_of_type(file_list, file_type)
Return files from file_list that match given file_type.
  get_method_arguments(method)
Return tuple of arguments for given method, excluding self.
  get_package_name_and_type(package, known_extensions)
Return package name and type.
  get_package_name_from_path(path)
Get package name as file portion of path.
  get_package_name_from_url(url)
Use urlparse to obtain package name from URL.
  has_extension(filename, ext)
Check if filename has given extension.
  index_class_to_name(clsname)
Covert index class name to index name.
  is_empty(path)
Returns True if file or directory pointed by path is empty.
  isiterable(obj)
Check whether object is iterable.
  length(L)
Overall length of all strings in list.
  main()
Display Cheesecake index for package specified via command-line options.
  make_indices_dict(indices)
  process_cmdline_args()
Parse command-line options.
  sorted(L)
  strip_dir_part(path, root)
Strip root part from path.
  WithOptionalExt(name, extensions)
Handy way of writing Cheese rules for files with extensions.

Variable Summary
str __revision__ = '176'

Function Details

camel2underscore(name)

Convert name from CamelCase to underscore_name.

>>> camel2underscore('CamelCase')
'camel_case'
>>> camel2underscore('already_underscore_name')
'already_underscore_name'
>>> camel2underscore('BigHTMLClass')
'big_html_class'
>>> camel2underscore('')
''

discover_file_type(filename)

Discover type of a file according to its name and its parent directory.

Currently supported file types:
  • pyc
  • pyo
  • module: .py files of an application
  • demo: .py files for documentation/demonstration purposes
  • test: .py files used for testing
  • special: .py file for special purposes
>>> discover_file_type('module.py')
'module'
>>> discover_file_type('./setup.py')
'special'
>>> discover_file_type('some/directory/junk.pyc')
'pyc'
>>> discover_file_type('examples/readme.txt')
>>> discover_file_type('examples/runthis.py')
'demo'
>>> discover_file_type('optimized.pyo')
'pyo'
>>> test_files = ['ut/test_this_and_that.py',
...               'another_test.py',
...               'TEST_MY_MODULE.PY']
>>> for filename in test_files:
...     assert discover_file_type(filename) == 'test', filename
>>> discover_file_type('this_is_not_a_test_really.py')
'module'

Note:

This function only checks file's name, and doesn't touch the filesystem. If you have to, check if file exists by yourself.

generate_arguments(arguments, max_length)

Pass list of strings in chunks of size not greater than max_length.

>>> for x in generate_arguments(['abc', 'def'], 4):
...     print x
['abc']
['def']
>>> for x in generate_arguments(['a', 'bc', 'd', 'e', 'f'], 2):
...     print x
['a']
['bc']
['d', 'e']
['f']
If a single argument is larger than max_length, ValueError is raised.
>>> L = []
>>> for x in generate_arguments(['abc', 'de', 'fghijk', 'l'], 4):
...     L.append(x)
Traceback (most recent call last):
  ...
ValueError: Argument 'fghijk' larger than 4.
>>> L
[['abc'], ['de']]

get_attributes(obj, names)

Return attributes dictionary with keys from names.

Object is queried for each attribute name, if it doesn't have this attribute, default value None will be returned.

>>> class Class:
...     pass
>>> obj = Class()
>>> obj.attr = True
>>> obj.value = 13
>>> obj.string = "Hello"
>>> d = get_attributes(obj, ['attr', 'string', 'other'])
>>> d == {'attr': True, 'string': "Hello", 'other': None}
True

get_files_dirs_list(root)

Return list of all files and directories below root.

Root directory is excluded from files/directories paths.

get_files_of_type(file_list, file_type)

Return files from file_list that match given file_type.

>>> file_list = ['test/test_foo.py', 'setup.py', 'README', 'test/test_bar.py']
>>> get_files_of_type(file_list, 'test')
['test/test_foo.py', 'test/test_bar.py']

get_method_arguments(method)

Return tuple of arguments for given method, excluding self.

>>> class Class:
...     def method(s, arg1, arg2, other_arg):
...         pass
>>> get_method_arguments(Class.method)
('arg1', 'arg2', 'other_arg')

get_package_name_and_type(package, known_extensions)

Return package name and type.

Package type must exists in known_extensions list. Otherwise None is returned.

>>> extensions = ['tar.gz', 'zip']
>>> get_package_name_and_type('underscored_name.zip', extensions)
('underscored_name', 'zip')
>>> get_package_name_and_type('unknown.extension.txt', extensions)

get_package_name_from_path(path)

Get package name as file portion of path.

>>> get_package_name_from_path('/some/random/path/package.tar.gz')
'package.tar.gz'
>>> get_package_name_from_path('/path/underscored_name.zip')
'underscored_name.zip'
>>> get_package_name_from_path('/path/unknown.extension.txt')
'unknown.extension.txt'

get_package_name_from_url(url)

Use urlparse to obtain package name from URL.

>>> get_package_name_from_url('http://www.example.com/file.tar.bz2')
'file.tar.bz2'
>>> get_package_name_from_url('https://www.example.com/some/dir/file.txt')
'file.txt'

has_extension(filename, ext)

Check if filename has given extension.

>>> has_extension("foobar.py", ".py")
True
>>> has_extension("foo.bar.py", ".py")
True
>>> has_extension("foobar.pyc", ".py")
False
This function is case insensitive.
>>> has_extension("FOOBAR.PY", ".py")
True

index_class_to_name(clsname)

Covert index class name to index name.

>>> index_class_to_name("IndexDownload")
'download'
>>> index_class_to_name("IndexUnitTests")
'unit_tests'
>>> index_class_to_name("IndexPyPIDownload")
'py_pi_download'

is_empty(path)

Returns True if file or directory pointed by path is empty.

isiterable(obj)

Check whether object is iterable.

>>> isiterable([1,2,3])
True
>>> isiterable("string")
True
>>> isiterable(object)
False

length(L)

Overall length of all strings in list.

>>> length(['a', 'bc', 'd', '', 'efg'])
7

main()

Display Cheesecake index for package specified via command-line options.

process_cmdline_args()

Parse command-line options.

strip_dir_part(path, root)

Strip root part from path.

>>> strip_dir_part('/home/ruby/file', '/home')
'ruby/file'
>>> strip_dir_part('/home/ruby/file', '/home/')
'ruby/file'
>>> strip_dir_part('/home/ruby/', '/home')
'ruby/'
>>> strip_dir_part('/home/ruby/', '/home/')
'ruby/'

WithOptionalExt(name, extensions)

Handy way of writing Cheese rules for files with extensions.

Instead of writing:
>>> one_of = OneOf('readme', 'readme.html', 'readme.txt')
Write this:
>>> opt_ext = WithOptionalExt('readme', ['html', 'txt'])
It means the same! (representation has a meaning)
>>> str(one_of) == str(opt_ext)
True

Variable Details

__revision__

Type:
str
Value:
'176'                                                                  

Generated by Epydoc 2.1 on Fri Feb 9 02:15:13 2007 http://epydoc.sf.net