Skip to content

Commit

Permalink
Merge c26d06a into 3052d84
Browse files Browse the repository at this point in the history
  • Loading branch information
mriehl committed Jul 28, 2014
2 parents 3052d84 + c26d06a commit fc37c0a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
10 changes: 6 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
use_plugin("python.integrationtest")
use_plugin("python.flake8")
use_plugin("python.frosted")
use_plugin("python.jedi_linter")


if not sys.version_info[0:2] == (3, 2):
use_plugin("python.cram")
Expand Down Expand Up @@ -88,10 +90,6 @@ def initialize(project):
project.get_property("coverage_exceptions").append("pybuilder.cli")
project.get_property("coverage_exceptions").append("pybuilder.plugins.core_plugin")

project.set_property("copy_resources_target", "$dir_dist")
project.get_property("copy_resources_glob").append("LICENSE")
project.get_property("filter_resources_glob").append("**/pybuilder/__init__.py")

project.set_property('flake8_break_build', True)
project.set_property('flake8_include_test_sources', True)
project.set_property('flake8_include_scripts', True)
Expand All @@ -100,6 +98,10 @@ def initialize(project):
project.set_property('frosted_include_test_sources', True)
project.set_property('frosted_include_scripts', True)

project.set_property("copy_resources_target", "$dir_dist")
project.get_property("copy_resources_glob").append("LICENSE")
project.get_property("filter_resources_glob").append("**/pybuilder/__init__.py")

project.get_property("source_dist_ignore_patterns").append(".project")
project.get_property("source_dist_ignore_patterns").append(".pydevproject")
project.get_property("source_dist_ignore_patterns").append(".settings")
Expand Down
81 changes: 81 additions & 0 deletions src/main/python/pybuilder/plugins/python/jedi_linter_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
#
# This file is part of PyBuilder
#
# Copyright 2011-2014 PyBuilder Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Plugin for Jedi linting support.
https://jedi.jedidjah.ch/
"""

__author__ = 'Maximilien Riehl'

try:
import jedi
except ImportError:
jedi = None

from pybuilder.core import after, task, init, use_plugin, depends
from pybuilder.errors import BuildFailedException, MissingPrerequisiteException, InternalException
from pybuilder.utils import discover_files_matching


use_plugin("python.core")


@init
def initialize_jedi_linter_plugin(project, logger):
project.build_depends_on("jedi")
project.set_property_if_unset("jedi_linter_break_build", False)
project.set_property_if_unset("jedi_linter_verbose", False)

logger.warn("The jedi plugin is unstable since the linter API will probably change.")


@after("prepare")
def assert_jedi_is_installed(logger):
if not jedi:
raise MissingPrerequisiteException("Missing build dependency `jedi`, please install_dependencies first.")
if "_analysis" not in dir(jedi.Script):
raise InternalException("The jedi linter API changed, please contact the authors")


@task
@depends("prepare")
def analyze(project, logger):
source_modules = discover_files_matching(project.get_property("dir_source_main_python"),
"*.py")
errors = []

logger.info("Executing jedi linter on project sources.")

try:
for path in source_modules:
for error in jedi.Script(path=path)._analysis():
errors.append(error)
except Exception as e:
logger.error("Jedi crashed: {0}".format(e))

number_of_errors = len(errors)
output = logger.info if number_of_errors == 0 else logger.warn
output("Jedi linter found {0} errors.".format(number_of_errors))
if project.get_property("jedi_linter_verbose") or project.get_property("verbose"):
for error in errors:
logger.warn(error)

if project.get_property("jedi_linter_break_build") and number_of_errors > 0:
raise BuildFailedException("Jedi linter found errors")

0 comments on commit fc37c0a

Please sign in to comment.