Skip to content

Commit

Permalink
Merge pull request #194 from Cal-CS-61A-Staff/pip-fix
Browse files Browse the repository at this point in the history
Fixes pip
  • Loading branch information
soumyabasu committed Sep 21, 2014
2 parents 0651462 + 4d6264e commit 2031f1f
Show file tree
Hide file tree
Showing 33 changed files with 112 additions and 102 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ install:

script:
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then FLASK_CONF=TEST python $CMD; fi
- if [[ $TRAVIS_PYTHON_VERSION == "3.3" ]]; then cd client; fi
- if [[ $TRAVIS_PYTHON_VERSION == "3.3" ]]; then nosetests; fi

before_script:
Expand Down
Empty file added client/__init__.py
Empty file.
6 changes: 4 additions & 2 deletions client/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ok
import os
import sys
sys.path.append('.')
sys.path.append(os.getcwd())

from client import ok

def main():
ok.ok_main(ok.parse_input())
Expand Down
8 changes: 4 additions & 4 deletions client/models/concept_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
ConceptTestCases simply display the answer if already unlocked.
"""

from models import serialize
from protocols import grading
from protocols import unlock
from utils import formatting
from client.models import serialize
from client.protocols import grading
from client.protocols import unlock
from client.utils import formatting

class ConceptCase(grading.GradedTestCase, unlock.UnlockTestCase):
"""TestCase for conceptual questions."""
Expand Down
4 changes: 2 additions & 2 deletions client/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
concrete subclasses of TestCase should be located in client/models/.
"""

from models import serialize
import exceptions
from client.models import serialize
from client import exceptions

class Assignment(serialize.Serializable):
"""A representation of an assignment."""
Expand Down
12 changes: 6 additions & 6 deletions client/models/doctest_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
mimic a Python interpreter.
"""

from models import serialize
from protocols import grading
from protocols import unlock
from utils import formatting
from utils import timer
from client import exceptions
from client.models import serialize
from client.protocols import grading
from client.protocols import unlock
from client.utils import formatting
from client.utils import timer
import code
import exceptions
import re
import traceback

Expand Down
2 changes: 1 addition & 1 deletion client/models/serialize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import exceptions
from client import exceptions

class Serializable(object):
"""An abstract class for serializable objects."""
Expand Down
12 changes: 6 additions & 6 deletions client/ok.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
communications should be limited to the body of an on_interact method.
"""

from models import *
from protocols import *
from client import config
from client.models import *
from client.protocols import *
from client.utils import auth
from client.utils import loading
from client.utils import output
from urllib import request, error
from utils import auth
from utils import loading
from utils import output
import argparse
import base64
import config
import json
import multiprocessing
import sys
Expand Down
2 changes: 1 addition & 1 deletion client/protocols/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
for the ok grading session.
"""

from protocols import protocol
from client.protocols import protocol
from datetime import datetime

class AnalyticsProtocol(protocol.Protocol):
Expand Down
2 changes: 1 addition & 1 deletion client/protocols/file_contents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from protocols import protocol
from client.protocols import protocol
import os


Expand Down
6 changes: 3 additions & 3 deletions client/protocols/grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
are compatible with the GradingProtocol.
"""

from models import core
from protocols import protocol
from utils import formatting
from client.models import core
from client.protocols import protocol
from client.utils import formatting

#####################
# Testing Mechanism #
Expand Down
2 changes: 1 addition & 1 deletion client/protocols/protocol.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import exceptions
from client import exceptions

class Protocol(object):
"""A Protocol encapsulates a single aspect of ok.py functionality."""
Expand Down
8 changes: 4 additions & 4 deletions client/protocols/unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
compatible with the UnlockProtocol.
"""

from models import core
from models import serialize
from protocols import protocol
from utils import formatting
from client.models import core
from client.models import serialize
from client.protocols import protocol
from client.utils import formatting
import hmac
import random
import string
Expand Down
48 changes: 29 additions & 19 deletions client/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
and then make a zipfile called "ok" that can be distributed to students.
"""

from models import *
from protocols import *
import argparse
import os
import sys
OK_ROOT = os.path.dirname(os.path.relpath(__file__))

from client.models import *
from client.protocols import *
import argparse
import shutil
import zipfile
import importlib
import sys

STAGING_DIR = os.path.join(os.getcwd(), 'staging')
OK_NAME = 'ok'
CONFIG_NAME = 'config.py'

REQUIRED_FILES = [
'__main__',
'__init__',
'exceptions',
'ok',
]
Expand All @@ -32,12 +34,14 @@
def populate_staging(staging_dir, config_path):
"""Populates the staging directory with files for ok.py."""
for filename in REQUIRED_FILES:
fullname = filename + '.py'
shutil.copyfile(fullname, os.path.join(staging_dir, fullname))
filename += '.py'
fullname = os.path.join(OK_ROOT, filename)
shutil.copyfile(fullname, os.path.join(staging_dir, filename))
shutil.copyfile(config_path, os.path.join(staging_dir, CONFIG_NAME))

for folder in REQUIRED_FOLDERS:
shutil.copytree(folder, os.path.join(staging_dir, folder))
shutil.copytree(os.path.join(OK_ROOT, folder),
os.path.join(staging_dir, folder))

config = load_config(config_path)
populate_protocols(staging_dir, config)
Expand All @@ -60,19 +64,21 @@ def populate_protocols(staging_dir, config):
relevant protocols.
"""
os.mkdir(os.path.join(staging_dir, 'protocols'))
shutil.copyfile(os.path.join('protocols', 'protocol.py'),
shutil.copyfile(os.path.join(OK_ROOT, 'protocols', 'protocol.py'),
os.path.join(staging_dir, 'protocols', 'protocol.py'))

protocol_modules = ['protocol']
for proto in protocol.get_protocols(config.protocols):
# Split the module along pacakge delimiters, the '.'
path_components = proto.__module__.split('.')
# Remove 'client' from path, since it's already part of OK_ROOT.
path_components.pop(0)
# Add the module to the list of imports in protocols/__init__
protocol_modules.append(path_components[-1])
# Convert to filesystem path.
protocol_src = os.path.join(*path_components) + '.py'
protocol_src = os.path.join(OK_ROOT, *path_components) + '.py'
protocol_dest = os.path.join(staging_dir, *path_components) + '.py'

protocol_dest = os.path.join(staging_dir, protocol_src)
if os.path.isfile(protocol_src):
shutil.copyfile(protocol_src, protocol_dest)
else:
Expand All @@ -86,21 +92,23 @@ def populate_models(staging_dir, config):
relevant test cases.
"""
os.mkdir(os.path.join(staging_dir, 'models'))
shutil.copyfile(os.path.join('models', 'core.py'),
shutil.copyfile(os.path.join(OK_ROOT, 'models', 'core.py'),
os.path.join(staging_dir, 'models', 'core.py'))
shutil.copyfile(os.path.join('models', 'serialize.py'),
shutil.copyfile(os.path.join(OK_ROOT, 'models', 'serialize.py'),
os.path.join(staging_dir, 'models', 'serialize.py'))

case_modules = ['core', 'serialize']
for case in core.get_testcases(config.cases):
# Split the module along pacakge delimiters, the '.'
path_components = case.__module__.split('.')
# Remove 'client' from path, since it's already part of OK_ROOT.
path_components.pop(0)
# Add the module to the list of imports in models/__init__
case_modules.append(path_components[-1])
# Convert to filesystem path.
case_src = os.path.join(*path_components) + '.py'
case_src = os.path.join(OK_ROOT, *path_components) + '.py'
case_dest = os.path.join(staging_dir, *path_components) + '.py'

case_dest = os.path.join(staging_dir, case_src)
if os.path.isfile(case_src):
shutil.copyfile(case_src, case_dest)
else:
Expand All @@ -115,23 +123,25 @@ def create_zip(staging_dir, destination):

dest = os.path.join(destination, OK_NAME)
zipf = zipfile.ZipFile(dest, 'w')
zipf.write(os.path.join(OK_ROOT, '__main__.py'), './__main__.py')
for root, _, files in os.walk(staging_dir):
if '__pycache__' in root:
continue
for filename in files:
if filename.endswith('.pyc'):
continue
fullname = os.path.join(root, filename)
# Replace 'staging' with '.' in the zip archive.
arcname = fullname.replace(staging_dir, '.')
# Replace 'staging' with './client' in the zip archive.
arcname = fullname.replace(staging_dir, './client')
zipf.write(fullname, arcname=arcname)
zipf.close()

def parse_args():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-c', '--config', type=str, default=CONFIG_NAME,
parser.add_argument('-c', '--config', type=str,
default=os.path.join(OK_ROOT, CONFIG_NAME),
help='Publish with a specificed config file.')
parser.add_argument('-d', '--destination', type=str, default='',
parser.add_argument('-d', '--destination', type=str, default='.',
help='Publish to the specified directory.')

return parser.parse_args()
Expand Down
6 changes: 3 additions & 3 deletions client/tests/models/core_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests the PythonTestCase model."""

from models import core
from models import serialize
from client import exceptions
from client.models import core
from client.models import serialize
from unittest import mock
import exceptions
import sys
import unittest

Expand Down
14 changes: 7 additions & 7 deletions client/tests/models/doctest_case_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Tests the DoctestCase model."""

from models import core
from models import doctest_case
from protocols import unlock
from client import exceptions
from client import ok
from client.models import core
from client.models import doctest_case
from client.protocols import unlock
from client.utils import formatting
from client.utils import output
from unittest import mock
from utils import formatting
from utils import output
import exceptions
import ok
import sys
import unittest

Expand Down
4 changes: 2 additions & 2 deletions client/tests/models/serialize_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from models import serialize
from client import exceptions
from client.models import serialize
from unittest import mock
import exceptions
import unittest

class MockSerializable(serialize.Serializable):
Expand Down
2 changes: 1 addition & 1 deletion client/tests/ok_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ok
from client import ok
import sys
import unittest

Expand Down
4 changes: 2 additions & 2 deletions client/tests/protocols/file_contents_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from protocols import file_contents
from client.protocols import file_contents
from unittest import mock
import os
import unittest

DEMO = 'demo_assignments'
DEMO = 'client/demo_assignments'
INVALID = os.path.join(DEMO, 'invalid')
VALID = os.path.join(DEMO, 'valid')
TMP = os.path.join(DEMO, 'tmp')
Expand Down
6 changes: 3 additions & 3 deletions client/tests/protocols/grading_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests the GradingProtocol."""

from models import core
from protocols import grading
from client.models import core
from client.protocols import grading
from client.utils import output
from unittest import mock
from utils import output
import unittest

class GradeTest(unittest.TestCase):
Expand Down
7 changes: 3 additions & 4 deletions client/tests/protocols/protocol_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Tests the GradingProtocol."""
"""Tests Protocol."""

from protocols import protocol
from client import exceptions
from client.protocols import protocol
from unittest import mock
import unittest
import utils
import exceptions

class GetProtocolTest(unittest.TestCase):
def calls_get_protocols(self, names, expected_classes):
Expand Down
6 changes: 3 additions & 3 deletions client/tests/protocols/unlock_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests the UnlockProtocol."""

from models import core
from protocols import unlock
from client.models import core
from client.protocols import unlock
from client.utils import output
from unittest import mock
from utils import output
import unittest

class InteractTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion client/tests/utils/formatting_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from utils import formatting
from client.utils import formatting
import unittest

class PrettyJsonTest(unittest.TestCase):
Expand Down
Loading

0 comments on commit 2031f1f

Please sign in to comment.