<commit_before>
import sys, os
import datetime


pippath = __file__
pippath_folder, filename = os.path.split(pippath)


try:
    import setuptools
except ImportError:
    print("Installing setuptools...")
    # install setuptools
    setuptools_path = '"%s"' %os.path.join(pippath_folder, "ez_setup.py")
    python_folder = os.path.split(sys.executable)[0]
    python_exe = os.path.join(python_folder, "python")
    os.system(" ".join([python_exe, setuptools_path]) )
    # update systempath to look inside setuptools.egg, so don't have to restart python
    sitepackfolder = os.path.join(os.path.split(sys.executable)[0], "Lib", "site-packages")
    for filename in os.listdir(sitepackfolder):
        if filename.startswith("setuptools") and filename.endswith(".egg"):
            sys.path.append(os.path.join(sitepackfolder, filename))
            break

# add current precompiled pip folder to path for later import
sys.path.insert(0, pippath_folder)

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

def install(package, *options):
    """
    Install a package from within the IDLE, same way as using the commandline
    and typing "pip install ..." Any number of additional string arguments
    specify the install options that typically come after, such as "-U"
    for update. See pip-documentation for valid option strings. 
    """
    # (works on Windows, but needs to be tested on other OS)
    import pip
    from pip import main
    # call on pip
    python_folder = os.path.split(sys.executable)[0]
    python_exe = os.path.join(python_folder, "python") # use the executable named "python" instead of "pythonw"
    pip_path = os.path.abspath(os.path.split(pip.__file__)[0]) # get entire pip folder path, not the __init__.py file
    call_on_pip = [python_exe, '"%s"'%pip_path]
    # pip args
    args = ["install", package]
    args.extend(options)
    # pause after
    pause_after = ["&", "pause"]
    # send to commandline
    os.system(" ".join(call_on_pip + args + pause_after) ) #os.system('"%s" "%s" '%(python_exe,pip_path) + " ".join(args) + " & pause")

def login(username, password):
    """
    Creates the .pypirc file with login info (required in order to upload).
    The login (i.e. the file) persists until you call the logout function. 
    
    Note: Assumes same login info for both the testsite
    and the live site, so if different must login for each switch.
    """
    pypircstring = ""
    pypircstring += "[distutils]" + "\n"
    pypircstring += "index-servers = " + "\n"
    pypircstring += "\t" + "pypi" + "\n"
    pypircstring += "\t" + "pypitest" + "\n"
    pypircstring += "\n"
    pypircstring += "[pypi]" + "\n"
    pypircstring += "repository: https://pypi.python.org/pypi" + "\n"
    pypircstring += "username: " + username + "\n"
    pypircstring += "password: " + password + "\n"
    pypircstring += "\n"
    pypircstring += "[pypitest]" + "\n"
    pypircstring += "repository: https://testpypi.python.org/pypi" + "\n"
    pypircstring += "username: " + username + "\n"
    pypircstring += "password: " + password + "\n"
    # create the file
    home = os.path.expanduser("~")
    path = os.path.join(home, ".pypirc")
    writer = open(path, "w")<commit_msg>Support for local setup.py install. Also new uninstall, and C/C++ build test functions.<commit_after>
import sys, os
import datetime


pippath = __file__
pippath_folder, filename = os.path.split(pippath)


try:
    import setuptools
except ImportError:
    print("Installing setuptools...")
    # install setuptools
    setuptools_path = '"%s"' %os.path.join(pippath_folder, "ez_setup.py")
    python_folder = os.path.split(sys.executable)[0]
    python_exe = os.path.join(python_folder, "python")
    os.system(" ".join([python_exe, setuptools_path]) )
    # update systempath to look inside setuptools.egg, so don't have to restart python
    sitepackfolder = os.path.join(os.path.split(sys.executable)[0], "Lib", "site-packages")
    for filename in os.listdir(sitepackfolder):
        if filename.startswith("setuptools") and filename.endswith(".egg"):
            sys.path.append(os.path.join(sitepackfolder, filename))
            break

# add current precompiled pip folder to path for later import
sys.path.insert(0, pippath_folder)

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

def _commandline_call(action, package, *options):
    # (works on Windows, but needs to be tested on other OS)
    import pip
    from pip import main
    # find the main python executable
    python_folder = os.path.split(sys.executable)[0]
    python_exe = os.path.join(python_folder, "python") # use the executable named "python" instead of "pythonw"
    args = [python_exe]
    # direct to local setup.py or call on pip
    if package.endswith("setup.py"):
        # "python setup.py install"
        os.chdir(os.path.split(package)[0]) # changes working directory to setup.py folder
        args.append("setup.py")
        args.append("install")
    else:
        # equivalent to "pip install packageorfile"
        if action == "build":
            raise Exception("Build can only be done on a local 'setup.py' filepath, not on '%s'" % package)
        pip_path = os.path.abspath(os.path.split(pip.__file__)[0]) # get entire pip folder path, not the __init__.py file
        args.append('"%s"'%pip_path)
        args.append(action)
        args.append(package)
    # options
    args.extend(options)
    # pause after
    args.append("& pause")
    # send to commandline
    os.system(" ".join(args) ) #os.system('"%s" "%s" '%(python_exe,pip_path) + " ".join(args) + " & pause")

def install(package, *options):
    """
    Install a package from within the IDLE, same way as using the commandline
    and typing "pip install ..." Any number of additional string arguments
    specify the install options that typically come after, such as "-U"
    for update. See pip-documentation for valid option strings. 
    """
    _commandline_call("install", package, *options)

def build(package, *options):
    """
    Test if a local C/C++ package will build (aka compile)
    successfully without actually installing it (ie placing it in
    site-packages), from within the IDLE. Same way as using the commandline
    and typing "pip build ..." Any number of additional string arguments
    specify the build options that typically come after.
    See pip-documentation for valid option strings. 
    """
    _commandline_call("build", package, *options)

def uninstall(package, *options):
    """
    Uninstall a package from within the IDLE, same way as using the commandline
    and typing "pip uninstall ..." Any number of additional string arguments
    specify the uninstall options that typically come after.
    See pip-documentation for valid option strings. 
    """
    _commandline_call("uninstall", package, *options)
    
def login(username, password):
    """
    Creates the .pypirc file with login info (required in order to upload).
    The login (i.e. the file) persists until you call the logout function. 
    
    Note: Assumes same login info for both the testsite
    and the live site, so if different must login for each switch.
    """
    pypircstring = ""
    pypircstring += "[distutils]" + "\n"
    pypircstring += "index-servers = " + "\n"
    pypircstring += "\t" + "pypi" + "\n"
    pypircstring += "\t" + "pypitest" + "\n"
    pypircstring += "\n"
    pypircstring += "[pypi]" + "\n"
    pypircstring += "repository: https://pypi.python.org/pypi" + "\n"
    pypircstring += "username: " + username + "\n"
    pypircstring += "password: " + password + "\n"
    pypircstring += "\n"
    pypircstring += "[pypitest]" + "\n"
    pypircstring += "repository: https://testpypi.python.org/pypi" + "\n"
    pypircstring += "username: " + username + "\n"
    pypircstring += "password: " + password + "\n"
    # create the file
    home = os.path.expanduser("~")
    path = os.path.join(home, ".pypirc")
    writer = open(path, "w")
{'fraction_non_alphanumeric': 0.13727959697732997, 'fraction_numerical': 0.0013853904282115869, 'mean_word_length': 3.2739504843918192, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2520401', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2460, 'n_words': 751}