コード例 #1
0
def run(mode, argument):

    logging.info('-'*30)
    logging.info('Checking ' + argument)

    if mode == 'directory':
        data = projectdata.get_data(os.path.abspath(argument))
        logging.info('Found ' + data.get('name', 'nothing'))
    elif mode == 'file':
        data = distributiondata.get_data(os.path.abspath(argument))
        logging.info('Found ' + data.get('name', 'nothing'))
    else:
        # It's probably a package name
        data = pypidata.get_data(argument)
        logging.info('Found ' + data.get('name', 'nothing'))

    rating = ratings.rate(data)

    logging.info('-'*30)
    for problem in rating[1]:
        # XXX It would be nice with a * pointlist instead, but that requires
        # that we know how wide the terminal is and nice word-breaks, so that's
        # for later.
        logging.info(problem)
    if rating[1]:
        logging.info('-'*30)
    logging.info('Final rating: ' + str(rating[0]) + '/10')
    logging.info(ratings.LEVELS[rating[0]])
    logging.info('-'*30)

    return rating[0]
コード例 #2
0
ファイル: __init__.py プロジェクト: pennyarcade/py_pov
def run(mode, argument):

    logging.info('-'*30)
    logging.info('Checking ' + argument)

    if mode == 'directory':
        data = projectdata.get_data(os.path.abspath(argument))
        logging.info('Found ' + data.get('name', 'nothing'))
    elif mode == 'file':
        data = distributiondata.get_data(os.path.abspath(argument))
        logging.info('Found ' + data.get('name', 'nothing'))
    else:
        # It's probably a package name
        data = pypidata.get_data(argument)
        logging.info('Found ' + data.get('name', 'nothing'))

    rating = ratings.rate(data)

    logging.info('-'*30)
    for problem in rating[1]:
        # XXX It would be nice with a * pointlist instead, but that requires
        # that we know how wide the terminal is and nice word-breaks, so that's
        # for later.
        logging.info(problem)
    if rating[1]:
        logging.info('-'*30)
    logging.info('Final rating: ' + str(rating[0]) + '/10')
    logging.info(ratings.LEVELS[rating[0]])
    logging.info('-'*30)

    return rating[0]
コード例 #3
0
def run(mode, argument):

    logging.info("-" * 30)
    logging.info("Checking " + argument)

    if mode == "directory":
        data = projectdata.get_data(os.path.abspath(argument))
        logging.info("Found " + data.get("name", "nothing"))
    elif mode == "file":
        data = distributiondata.get_data(os.path.abspath(argument))
        logging.info("Found " + data.get("name", "nothing"))
    else:
        # It's probably a package name
        data = pypidata.get_data(argument)
        logging.info("Found " + data.get("name", "nothing"))

    rating = ratings.rate(data)

    logging.info("-" * 30)
    for problem in rating[1]:
        # XXX It would be nice with a * pointlist instead, but that requires
        # that we know how wide the terminal is and nice word-breaks, so that's
        # for later.
        logging.info(problem)
    if rating[1]:
        logging.info("-" * 30)
    logging.info("Final rating: " + str(rating[0]) + "/10")
    logging.info(ratings.LEVELS[rating[0]])
    logging.info("-" * 30)

    return rating[0]
コード例 #4
0
def get_data(path):
    filename = os.path.split(path)[-1]
    basename, ext = os.path.splitext(filename)
    if basename.endswith('.tar'):
        basename, ignored = os.path.splitext(basename)

    try:
        tempdir = tempfile.mkdtemp()

        if ext in ('.bz2', '.tbz', 'tb2', '.gz', '.tgz', '.tar'):
            tarfile.open(name=path, mode='r:*').extractall(tempdir)

        elif ext in ('.zip', '.egg'):
            zipfile.ZipFile(path, mode='r').extractall(tempdir)

        else:
            raise ValueError('Unknown file type: ' + ext)

        projectpath = os.path.join(tempdir, basename)
        data = projectdata.get_data(projectpath)

    finally:
        shutil.rmtree(tempdir)

    return data
コード例 #5
0
def get_data(path):
    filename = os.path.split(path)[-1]
    basename, ext = os.path.splitext(filename)
    if basename.endswith(".tar"):
        basename, ignored = os.path.splitext(basename)

    try:
        tempdir = tempfile.mkdtemp()

        if ext in (".bz2", ".tbz", "tb2", ".gz", ".tgz", ".tar"):
            tarfile.open(name=path, mode="r:*").extractall(tempdir)

        elif ext in (".zip", ".egg"):
            zipfile.ZipFile(path, mode="r").extractall(tempdir)

        else:
            raise ValueError("Unknown file type: " + ext)

        projectpath = os.path.join(tempdir, basename)
        data = projectdata.get_data(projectpath)

    finally:
        shutil.rmtree(tempdir)

    return data
コード例 #6
0
ファイル: tests.py プロジェクト: pennyarcade/py_pov
    def test_complete(self):
        directory = resource_filename(__name__,
                                      os.path.join('testdata', 'complete'))
        data = projectdata.get_data(directory)
        rating = rate(data)

        # Should have a perfect score
        self.assertEqual(rating, (10, []))
コード例 #7
0
    def execute(self, finder):
        issues = []

        for filepath in finder.files(self.config['filters']):
            dirname, _ = os.path.split(filepath)

            with warnings.catch_warnings():
                warnings.simplefilter('ignore')
                with SysOutCapture() as capture:
                    try:
                        data = projectdata.get_data(dirname)
                    except RuntimeError:
                        err = capture.get_stderr()
                        if err:
                            issues.append(PyromaIssue(
                                TIDYPY_ISSUES['SCRIPT_FAIL'][0],
                                TIDYPY_ISSUES['SCRIPT_FAIL'][1] % (err,),
                                filepath,
                            ))
                        else:
                            issues.append(PyromaIssue(
                                TIDYPY_ISSUES['NOT_CALLED'][0],
                                TIDYPY_ISSUES['NOT_CALLED'][1],
                                filepath,
                            ))
                        continue

                    for test in ratings.ALL_TESTS:
                        name = test.__class__.__name__
                        if name in self.disabled:
                            continue

                        if test.test(data) is False:
                            issues.append(PyromaIssue(
                                name,
                                test.message(),
                                filepath,
                            ))

                    err = capture.get_stderr()
                    if err:
                        if err.startswith('<string>:'):
                            issues.append(PyromaIssue(
                                TIDYPY_ISSUES['RST_ERROR'][0],
                                TIDYPY_ISSUES['RST_ERROR'][1] % (err,),
                                filepath,
                            ))
                        else:
                            issues.append(ToolIssue(
                                err,
                                filepath,
                            ))

        return [
            issue
            for issue in issues
            if issue.code not in self.disabled
        ]
コード例 #8
0
def _run_pyroma(setup_file):
    """Run pyroma."""
    from pyroma import projectdata, ratings
    from prospector.message import Message, Location

    return_dict = dict()

    data = projectdata.get_data(os.getcwd())
    all_tests = ratings.ALL_TESTS
    for test in [mod() for mod in [t.__class__ for t in all_tests]]:
        if test.test(data) is False:
            class_name = test.__class__.__name__
            key = _Key(setup_file, 0, class_name)
            loc = Location(setup_file, None, None, 0, 0)
            msg = test.message()
            return_dict[key] = Message("pyroma", class_name, loc, msg)

    return return_dict
コード例 #9
0
def _run_pyroma(setup_file, show_lint_files):
    """Run pyroma."""
    from pyroma import projectdata, ratings
    from prospector.message import Message, Location

    _debug_linter_status("pyroma", setup_file, show_lint_files)

    return_dict = dict()

    data = projectdata.get_data(os.getcwd())
    all_tests = ratings.ALL_TESTS
    for test in [mod() for mod in [t.__class__ for t in all_tests]]:
        if test.test(data) is False:
            class_name = test.__class__.__name__
            key = _Key(setup_file, 0, class_name)
            loc = Location(setup_file, None, None, 0, 0)
            msg = test.message()
            return_dict[key] = Message("pyroma", class_name, loc, msg)

    return return_dict
コード例 #10
0
    def test_lacking(self):
        directory = resource_filename(__name__,
                                      os.path.join('testdata', 'lacking'))
        data = projectdata.get_data(directory)
        rating = rate(data)

        self.assertEqual(rating, (0, [
            "The package had no description!",
            "The package's long_description is quite short.",
            "Your package does not have classifiers data.",
            "You should specify what Python versions you support.",
            "Your package does not have keywords data.",
            "Your package does not have author data.",
            "Your package does not have author_email data.",
            "Your package does not have url data.",
            "Your package does not have license data.",
            "You are using Setuptools or Distribute but do not specify if "
            "this package is zip_safe or not. You should specify it, as it "
            "defaults to True, which you probably do not want.",
        ]))
コード例 #11
0
    def test_custom_test(self):
        directory = resource_filename(__name__,
                                      os.path.join('testdata', 'custom_test'))
        data = projectdata.get_data(directory)
        rating = rate(data)

        self.assertEqual(rating, (2, [
            "The package's version number does not comply with PEP-386 or PEP-440.",
            "The package's description should be longer than 10 characters.",
            "The package's long_description is quite short.",
            "Your package does not have classifiers data.",
            "You should specify what Python versions you support.",
            "Your package does not have keywords data.",
            "Your package does not have author data.",
            "Your package does not have author_email data.",
            "Your package should have a 'url' field with a link to the project home page, or a 'project_urls' field, with a dictionary of links, or both.",
            "Your package does neither have a license field nor any license classifiers.",
            "Specifying a development status in the classifiers gives users " \
            "a hint of how stable your software is.",
        ]))
コード例 #12
0
    def test_custom_test(self):
        directory = resource_filename(__name__,
                                      os.path.join('testdata', 'custom_test'))
        data = projectdata.get_data(directory)
        rating = rate(data)

        self.assertEqual(rating, (2, [
            "The package's version number does not comply with PEP-386 or PEP-440.",
            "The package's description should be longer than 10 characters.",
            "The package's long_description is quite short.",
            "Your package does not have classifiers data.",
            "You should specify what Python versions you support.",
            "Your package does not have keywords data.",
            "Your package does not have author data.",
            "Your package does not have author_email data.",
            "Your package does not have url data.",
            "Your package does not have license data.",
            "You are using Setuptools or Distribute but do not specify if "
            "this package is zip_safe or not. You should specify it, as it "
            "defaults to True, which you probably do not want.",
        ]))
コード例 #13
0
    def test_lacking(self):
        directory = resource_filename(__name__,
                                      os.path.join('testdata', 'lacking'))
        data = projectdata.get_data(directory)
        rating = rate(data)

        self.assertEqual(rating, (0, [
            "The package had no description!",
            "The package's long_description is quite short.",
            "Your package does not have classifiers data.",
            "You should specify what Python versions you support.",
            "Your package does not have keywords data.",
            "Your package does not have author data.",
            "Your package does not have author_email data.",
            "Your package should have a 'url' field with a link to the project home page, or a 'project_urls' field, with a dictionary of links, or both.",
            "Your package does neither have a license field nor any license classifiers.",
            'Your long_description is not valid ReST: \n<string>:1: (WARNING/2) Inline literal start-string without end-string.',
            "Specifying a development status in the classifiers gives users " \
            "a hint of how stable your software is.",

        ]))
コード例 #14
0
    def run(self, found_files):
        messages = []
        for module in found_files.iter_module_paths(include_ignored=True):
            dirname, filename = os.path.split(module)
            if filename != 'setup.py':
                continue

            data = projectdata.get_data(dirname)

            all_tests = [m() for m in PYROMA_TEST_CLASSES]
            for test in all_tests:
                code = PYROMA_CODES.get(test.__class__, 'PYRUNKNOWN')

                if code in self.ignore_codes:
                    continue

                passed = test.test(data)
                if passed is False:  # passed can be True, False or None...
                    loc = Location(module, 'setup', None, -1, -1)
                    msg = Message('pyroma', code, loc, test.message())
                    messages.append(msg)

        return messages
コード例 #15
0
ファイル: __init__.py プロジェクト: assad2012/prospector
    def run(self):
        messages = []
        for module in self._files.iter_module_paths(include_ignored=True):
            dirname, filename = os.path.split(module)
            if filename != 'setup.py':
                continue

            data = projectdata.get_data(dirname)

            all_tests = [m() for m in PYROMA_TEST_CLASSES]
            for test in all_tests:
                code = PYROMA_CODES[test.__class__]

                if code in self.ignore_codes:
                    continue

                passed = test.test(data)
                if passed is False:  # passed can be True, False or None...
                    loc = Location(module, 'setup', None, -1, -1)
                    msg = Message('pyroma', code, loc, test.message())
                    messages.append(msg)

        return messages
コード例 #16
0
ファイル: tests.py プロジェクト: pennyarcade/py_pov
    def test_complete(self):
        directory = resource_filename(__name__,
                                      os.path.join('testdata', 'complete'))

        data = projectdata.get_data(directory)
        self.assertEqual(data, COMPLETE)
コード例 #17
0
 def _get_file_rating(self, dirname):
     directory = resource_filename(__name__,
                                   os.path.join("testdata", dirname))
     data = projectdata.get_data(directory)
     return rate(data)