def setUp(self):
     self.d = TemporaryDirectory()
     fname = os.path.join(self.d.name, 'pubspec.yaml')
     with open(fname, 'wt') as f:
         f.write(VALID_PUBSPEC_CONTENT)
     self.pubspec = PubspecFile.from_path(fname)
     self.pub_package = PubPackage(self.pubspec)
 def testCanFailToRetrievePubspecLock(self):
     with TemporaryDirectory() as d:
         fname = os.path.join(d, 'pubspec.yaml')
         with open(fname, 'wt') as f:
             f.write(VALID_PUBSPEC_CONTENT)
         p = PubspecFile.from_path(fname)
         self.assertEqual(None, p.get_pubspec_lock())
 def testCanFindParent(self):
     with TemporaryDirectory() as d:
         fname = os.path.join(d, 'pubspec.yaml')
         with open(fname, 'wt') as f:
             f.write(VALID_PUBSPEC_CONTENT)
         p = PubspecFile.from_path(fname)
         self.assertEqual(d, p.parent)
    def run(self):
        analyzer_path = os.path.join(self.dartsdk_path, 'bin', 'dartanalyzer')
        # Clear all regions
        self.clear_all()
        if is_windows():
            analyzer_path += '.bat'
        options = '--machine'
        startupinfo = supress_window()

        pubspec = PubspecFile.from_path(self.fileName)
        if not pubspec:
            _logger.error('no pubspec found for %s', self.fileName)
            print('Dart: No pubspec found for {}'.format(self.fileName))
            return

        proc = subprocess.Popen(
            [analyzer_path, options, self.fileName],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            startupinfo=startupinfo,
            cwd=pubspec.parent,
        )
        try:
            outs, errs = proc.communicate(timeout=15)
        except TimeoutExpired as e:
            _logger.debug("error running DartLintThread: %s", e)
            proc.kill()
            outs, errs = proc.communicate()

        pattern = (r'^(?P<severity>\w+)\|(?P<type>\w+)\|(?P<code>\w+)\|' +
                   r'(?P<file_name>.+)\|(?P<line>\d+)\|(?P<col>\d+)\|' +
                   r'(?P<err_length>\d+)\|(?P<message>.+)')
        msg_pattern_machine = re.compile(pattern)

        # Don't show any panel if there are no errors.
        if not errs.decode('utf-8').strip():
            print('No errors.')
            self.view.set_status('dartlint', 'Dartlint: No errors')
            return

        # Don't bother if the buffer hasn't changed since the last analysis.
        with g_edits_lock:
            if ((not self.force)
                    and DartLint.edits[self.view.buffer_id()] == 0):
                return

        # We've got a new linter result.
        with g_tokens_lock:
            now = datetime.now()
            g_result_tokens[self.view.buffer_id()] = (now.minute * 60 +
                                                      now.second)
            lines = errs.decode('utf-8').split(os.linesep)
            g_linter_results.put((g_result_tokens[self.view.buffer_id()],
                                  self.view.buffer_id(), lines))
    def run(self):
        analyzer_path = os.path.join(self.dartsdk_path, 'bin', 'dartanalyzer')
        # Clear all regions
        self.clear_all()
        if is_windows():
            analyzer_path += '.bat'
        options = '--machine'
        startupinfo = supress_window()

        pubspec = PubspecFile.from_path(self.fileName)
        if not pubspec:
            _logger.error('no pubspec found for %s', self.fileName)
            print('Dart: No pubspec found for {}'.format(self.fileName))
            return

        proc = subprocess.Popen([analyzer_path, options, self.fileName],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                startupinfo=startupinfo,
                                cwd=pubspec.parent,
                                )
        try:
            outs, errs = proc.communicate(timeout=15)
        except TimeoutExpired as e:
            _logger.debug("error running DartLintThread: %s", e)
            proc.kill()
            outs, errs = proc.communicate()

        pattern = (r'^(?P<severity>\w+)\|(?P<type>\w+)\|(?P<code>\w+)\|' +
            r'(?P<file_name>.+)\|(?P<line>\d+)\|(?P<col>\d+)\|' +
            r'(?P<err_length>\d+)\|(?P<message>.+)')
        msg_pattern_machine = re.compile(pattern)

        # Don't show any panel if there are no errors.
        if not errs.decode('utf-8').strip():
            print('No errors.')
            self.view.set_status('dartlint', 'Dartlint: No errors')
            return

        # Don't bother if the buffer hasn't changed since the last analysis.
        with g_edits_lock:
            if ((not self.force) and
                DartLint.edits[self.view.buffer_id()] == 0):
                    return

        # We've got a new linter result.
        with g_tokens_lock:
            now = datetime.now()
            g_result_tokens[self.view.buffer_id()] = (now.minute * 60 + now.second)
            lines = errs.decode('utf-8').split(os.linesep)
            g_linter_results.put((g_result_tokens[self.view.buffer_id()],
                             self.view.buffer_id(), lines))
示例#6
0
    def run(self):
        sdk = SDK()
        previous_view = self.window.active_view()
        report = self.window.new_file()
        report.set_name('Dart - Configuration Report')
        report.set_scratch(True)

        self.append(report, 'Sublime Text Information\n')
        self.append(report, '=' * 80)
        self.add_newline(report)
        self.append(report, 'version: ')
        self.append(report, sublime.version())
        self.append(report, ' (')
        self.append(report, sublime.channel())
        self.append(report, ' channel)')
        self.add_newline(report)
        self.append(report, 'platform: ')
        self.append(report, sublime.platform())
        self.add_newline(report)
        self.append(report, 'architecture: ')
        self.append(report, sublime.arch())
        self.add_newline(report)
        self.add_newline(report)

        self.append(report, 'Dart SDK Information\n')
        self.append(report, '=' * 80)
        self.add_newline(report)

        self.append(report, 'version: ')
        dart_version = sdk.check_version()
        self.append(report, dart_version)
        self.add_newline(report)

        self.append(report, 'Dart Package Settings\n')
        self.append(report, '=' * 80)
        self.add_newline(report)
        self.append(report, 'dart_sdk_path: ')
        self.append(report, sdk.path)
        self.add_newline(report)
        self.append(report, 'dart_dartium_path: ')
        self.append(report, sdk.path_to_dartium)
        self.add_newline(report)
        self.append(report, 'dart_user_browsers: ')
        self.add_newline(report)
        self.append(report, pprint.pformat(sdk.user_browsers))
        self.add_newline(report)
        self.add_newline(report)

        self.append(report, 'Project Information\n')
        self.append(report, '=' * 80)
        self.add_newline(report)
        if previous_view:
            try:
                self.append(
                    report,
                    str(PubspecFile.from_path(
                                            previous_view.file_name()).path)
                    )
            except Exception as e:
                self.append(report, 'No pubspec found\n')

        self.add_newline(report)
 def testInitCanFail(self):
     p = PubspecFile.from_path('???')
     self.assertEqual(p, None)