sys.

Here are the examples of the python api sys. taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

3 View Source File : test_expressions.py
License : MIT License
Project Creator : DHI-GRAS

def test_valid_expression(case):
    from terracotta.expressions import evaluate_expression
    # make sure we have enough recursion depth for long expression
    sys.setrecursionlimit(10_000)

    expr, result = case

    np.testing.assert_array_equal(
        evaluate_expression(expr, OPERANDS),
        result
    )


@pytest.mark.parametrize('case', INVALID_EXPR)

3 View Source File : pihole_stat_rainbow_hat.py
License : MIT License
Project Creator : Elycin

    def set_server(self, server):
        if self.__running:
            print("Please stop the script before running.")
        else:
            try:
                self.__pihole_interface = pihole.PiHole(server)
                print("Instantiated new instance of Pi-hole API.")
            except:
                sys.stderr.print("There was a problem while attempting to connect to the specified Pi-hole server.")

    # Set the administration password for the PiHole Interface so this script can use it.
    def set_password(self, password):

3 View Source File : pihole_stat_rainbow_hat.py
License : MIT License
Project Creator : Elycin

    def set_password(self, password):
        if self.__running:
            print("Please stop the script before running.")
        else:
            try:
                self.__pihole_interface.authenticate(password)
                print("Authentication succeeded.")
            except:
                sys.stderr.print("Invalid password while attempting to authenticate with Pi-hole API.")

    # Set the frequency in seconds of when the display should be updated.
    def set_update_frequency(self, frequency_in_seconds):

3 View Source File : main.py
License : GNU General Public License v3.0
Project Creator : jabbalaci

def main(argv) -> None:
    check_api_keys()
    #
    App = QApplication(argv)
    window = MainWindow(argv)
    window.show()
    sys.exit(App.exec())

##############################################################################

if __name__ == "__main__":

2 View Source File : CLI.py
License : MIT License
Project Creator : chanzuckerberg

def main(args=None):
    sys.setrecursionlimit(1_000_000)  # permit as much call stack depth as OS can give us

    parser = create_arg_parser()
    argcomplete.autocomplete(parser)

    replace_COLUMNS = os.environ.get("COLUMNS", None)
    os.environ["COLUMNS"] = "100"  # make help descriptions wider
    args = parser.parse_args(args if args is not None else sys.argv[1:])
    if replace_COLUMNS is not None:
        os.environ["COLUMNS"] = replace_COLUMNS
    else:
        del os.environ["COLUMNS"]

    try:
        if args.command == "check":
            check(**vars(args))
        elif args.command == "run":
            runner(**vars(args))
        elif args.command == "run_self_test":
            run_self_test(**vars(args))
        elif args.command == "localize":
            localize(**vars(args))
        elif args.command == "configure":
            configure(**vars(args))
        elif args.command == "eval":
            eval_expr(**vars(args))
        elif args.command == "zip":
            zip_wdl(**vars(args))
        else:
            assert False
    except (
        Error.SyntaxError,
        Error.ImportError,
        Error.ValidationError,
        Error.MultipleValidationErrors,
    ) as exn:
        global quant_warning
        print_error(exn)
        if args.check_quant and quant_warning:
            print(
                "* Hint: for compatibility with older existing WDL code, try setting --no-quant-check to relax "
                "quantifier validation rules.",
                file=sys.stderr,
            )
        if args.debug:
            raise exn
        sys.exit(2)
    sys.exit(0)


def create_arg_parser():

2 View Source File : __main__.py
License : MIT License
Project Creator : koebi

def main():
    config = configparser.ConfigParser()
    config.read(['setup.cfg', 'tox.ini'])
    conf = config['potypo']

    if 'locales_dir' not in conf:
        print("No locales_dir specified. Aborting."
        sys.exit(1)

    if 'default_language' not in conf:
        print("No default_language specified. Aborting."
        sys.exit(1)

    chunker_list = load_classes(chunkers, conf.get('chunkers', ''))
    filter_list = load_classes(filters, conf.get('filters', ''))

    if 'phrases' in conf:
        phrases = conf['phrases'].strip().split('\n')
        chunker_list.append(chunkers.make_PhraseChunker(phrases))

    if 'edgecase_words' in conf:
        words = conf['edgecase_words'].strip().split('\n')
        filter_list.append(filters.make_EdgecaseFilter(words))

    def errmsg(path, linenum, word):
        print("ERROR: {}:{}: {}".format(path, linenum, word))

    wl_dir = conf.get('wl_dir', None)

    # checks contains one Check-Object for every po-file
    checks = []

    for root, dirs, files in os.walk(conf['locales_dir']):
        for f in files:
            if f.endswith(".po"):
                try:
                    checks.append(Check(os.path.join(root, f), wl_dir, chunker_list, filter_list))
                except errors.DictNotFoundError as err:
                    print(err, "Potypo will not check for spelling errors in this language.")

    en_wordlist = Check.get_wordlist(conf['default_language'], wl_dir, conf['locales_dir'])
    en_dict = DictWithPWL(conf['default_language'], pwl=en_wordlist)
    en_ckr = SpellChecker(en_dict, chunkers=chunker_list, filters=filter_list)

    fail = False # used for tracking whether failing errors occurred
    for c in checks:
        print("Checking Errors in file", c.popath, "for lang", c.lang)
        for entry in c.po:
            if entry.obsolete:
                continue

            en_ckr.set_text(entry.msgid)
            for err in en_ckr:
                fail = True
                path = os.path.relpath(c.popath, start=config['potypo']['locales_dir'])
                errmsg(path, entry.linenum, err.word)

            c.checker.set_text(entry.msgstr)
            for err in c.checker:
                if c.lang not in conf.get('no_fail', []):
                    fail = True
                path = os.path.relpath(c.popath, start=config['potypo']['locales_dir'])
                errmsg(path, entry.linenum, err.word)

    print("Spell-checking done.")

    if fail:
        sys.exit(1)
    sys.exit(0)

if __name__ == "__main__":
    main()

0 View Source File : showDepartsAndArrivalsPerEdge.py
License : GNU General Public License v3.0
Project Creator : DayuanTan

def main():
    options = parse_args()
    departCounts = defaultdict(lambda: 0)
    arrivalCounts = defaultdict(lambda: 0)

    for route in parse_fast(options.routefile, 'route', ['edges']):
        edges = route.edges.split()
        if options.subpart is not None and not hasSubpart(edges, options.subpart):
            continue
        departCounts[edges[0]] += 1
        arrivalCounts[edges[-1]] += 1
    for walk in parse_fast(options.routefile, 'walk', ['edges']):
        edges = walk.edges.split()
        if options.subpart is not None and not hasSubpart(edges, options.subpart):
            continue
        departCounts[edges[0]] += 1
        arrivalCounts[edges[-1]] += 1

    # warn about potentially missing edges
    for trip in parse_fast(options.routefile, 'trip', ['id', 'fromTaz', 'toTaz']):
        if options.subpart is not None:
            sys.stderr.print("Warning: Ignoring trips when using --subpart")
            break
        departCounts[trip.fromTaz] += 1
        arrivalCounts[trip.toTaz] += 1
    for walk in parse_fast(options.routefile, 'walk', ['from', 'to']):
        if options.subpart is not None:
            sys.stderr.print("Warning: Ignoring trips when using --subpart")
            break
        departCounts[walk.attr_from] += 1
        arrivalCounts[walk.to] += 1

    departStats = Statistics("departEdges")
    arrivalStats = Statistics("arrivalEdges")
    for e in sorted(departCounts.keys()):
        departStats.add(departCounts[e], e)
    for e in sorted(arrivalCounts.keys()):
        arrivalStats.add(arrivalCounts[e], e)
    print(departStats)
    print(arrivalStats)

    with open(options.outfile, 'w') as outf:
        outf.write("  <  edgedata>\n")
        outf.write('    < interval begin="0" end="10000" id="routeStats">\n')
        allEdges = set(departCounts.keys())
        allEdges.update(arrivalCounts.keys())
        for e in sorted(allEdges):
            outf.write('       < edge id="%s" departed="%s" arrived="%s" delta="%s"/>\n' %
                       (e, departCounts[e], arrivalCounts[e], arrivalCounts[e] - departCounts[e]))
        outf.write("    < /interval>\n")
        outf.write(" < /edgedata>\n")


if __name__ == "__main__":