Last active
January 2, 2022 11:53
-
-
Save SegFaultAX/2c010063939a4d0712e6 to your computer and use it in GitHub Desktop.
Install any package to coderpad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
# Application code goes here! | |
pass | |
PACKAGES = ("praw", ) | |
### IGNORE BELOW THIS LINE ### | |
def run(cmd, shell=False, silent=False): | |
import subprocess, shlex, os | |
args = shlex.split(cmd) | |
if silent: | |
with open(os.devnull) as DEVNULL: | |
return subprocess.call(args, stdout=DEVNULL, stderr=subprocess.STDOUT) | |
else: | |
subprocess.call(args, shell=shell) | |
def do_packages(package, *packages): | |
import sys, os | |
all_packages = (package,) + packages | |
print "Installing packages: {}".format(", ".join(all_packages)) | |
user = os.environ.get("HOME") | |
site_packages = os.path.join(user, ".local/lib/python2.7/site-packages") | |
sys.path.append(site_packages) | |
run("pip install --user {}".format(" ".join((package,) + packages)), silent=True) | |
def go(args=""): | |
if PACKAGES: | |
do_packages(*PACKAGES) | |
print "Setup complete... Running main.\n\n\n" | |
run("python /home/coderpad/solution.py GOGO {}".format(args)) | |
import sys | |
if len(sys.argv) > 1 and sys.argv[1] == "GOGO": | |
sys.argv.pop(0) | |
main() | |
else: | |
print "Run go() in the REPL to run your program!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand how to use this. For example, how does this help if I want to install the matplotlib library in CoderPad?