<commit_before>#!/usr/bin/env python3

import os.path
import os
import sys
from github import Github
from git import Repo, InvalidGitRepositoryError
import toml
import urllib3
import certifi
import tarfile

def auth_github():
    try:
        repo = Repo('.', search_parent_directories=True)
        config = repo.config_reader()
    except:
        print('This does not seem to be a git repository.')
        return Github()
    try:
        return Github(config.get('github', 'user'), config.get('github', 'password'))
    except configparser.NoOptionError:
        print('No username / password found in \'git config\'')
    try:
        return Github(config.get('github', 'oauthtoken'))
    except configparser.NoOptionError:
        print('No oauth token found in \'git config\'')
    return Github()

# find root of project and leanpkg.toml
cwd = os.getcwd()
while not os.path.isfile('leanpkg.toml') and os.getcwd() != '/':
    os.chdir(os.path.dirname(os.getcwd()))

# parse leanpkg.toml
try:
    leanpkg = toml.load('leanpkg.toml')
except FileNotFoundError:
    print('Error: No leanpkg.toml found')
    sys.exit(1)
<commit_msg>fix(scripts/update-mathlib): update-mathlib shouldn't need github authentication<commit_after>#!/usr/bin/env python3

import os.path
import os
import sys
from github import Github
from git import Repo, InvalidGitRepositoryError
import toml
import urllib3
import certifi
import tarfile

def auth_github():
    try:
        repo = Repo('.', search_parent_directories=True)
        config = repo.config_reader()
    except:
        print('This does not seem to be a git repository.')
        return Github()
    try:
        return Github(config.get('github', 'user'), config.get('github', 'password'))
    except configparser.NoOptionError:
        print('No username / password found in \'git config\'')
        continue
    try:
        return Github(config.get('github', 'oauthtoken'))
    except configparser.NoOptionError:
        print('No oauth token found in \'git config\'')
        continue
    return Github()

# find root of project and leanpkg.toml
cwd = os.getcwd()
while not os.path.isfile('leanpkg.toml') and os.getcwd() != '/':
    os.chdir(os.path.dirname(os.getcwd()))

# parse leanpkg.toml
try:
    leanpkg = toml.load('leanpkg.toml')
except FileNotFoundError:
    print('Error: No leanpkg.toml found')
    sys.exit(1)

{'fraction_non_alphanumeric': 0.12094395280235988, 'fraction_numerical': 0.0025284450063211127, 'mean_word_length': 3.4208566108007448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '484700', 'n_tokens_mistral': 752, 'n_tokens_neox': 745, 'n_words': 209}