Skip to content

Commit

Permalink
Merge branch 'pip' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerkin committed Mar 6, 2018
2 parents 2d0a3ae + 3e4cc5f commit 263e686
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ install:
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
- pip install . --process-dependency-links
- pip install .
- pip install coveralls
######################################################
script:
Expand Down
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cypy>=0.2
quantities==0.12.1
pandas>=0.18
ipython
matplotlib
bs4
lxml
nbconvert
ipykernel
nbformat
gitpython
50 changes: 40 additions & 10 deletions sciunit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pkgutil
import importlib
import json
import re
from io import TextIOWrapper,StringIO
from datetime import datetime

Expand Down Expand Up @@ -153,7 +154,7 @@ def convert_notebook(self, name):
file_path = self.get_path("%s.ipynb"%name)
code = exporter.from_filename(file_path)[0]
self.write_code(name, code)
self.clean_code(name, ['get_ipython'])
self.clean_code(name, [])#'get_ipython'])

def convert_and_execute_notebook(self, name):
"""Converts a notebook into a python file and then runs it."""
Expand All @@ -179,7 +180,7 @@ def write_code(self, name, code):
f.write(code)

def clean_code(self, name, forbidden):
"""Remove lines containing items in forbidden from the code.
"""Remove lines containing items in 'forbidden' from the code.
Helpful for executing converted notebooks that still retain IPython
magic commands.
"""
Expand All @@ -188,11 +189,29 @@ def clean_code(self, name, forbidden):
code = code.split('\n')
new_code = []
for line in code:
if not [bad for bad in forbidden if bad in line]:
if [bad for bad in forbidden if bad in line]:
pass
else:
allowed = ['time','timeit'] # Magics where we want to keep the command
line = self.strip_line_magic(line,allowed)
new_code.append(line)
new_code = '\n'.join(new_code)
self.write_code(name, new_code)

def strip_line_magic(self,line,magics_allowed):
matches = re.findall("run_line_magic\(([^]]+)", line)
if matches and matches[0]: # This line contains the pattern
match = matches[0]
if match[-1] == ')':
match = match[:-1] # Just because the re way is hard
magic_kind,stripped = eval(match)
if magic_kind not in magics_allowed:
stripped = "" # If the part after the magic won't work, just get rid of it
else:
printd("No line magic pattern match in '%s'" % line)
stripped = line
return stripped

def do_notebook(self, name):
"""Runs a notebook file after optionally
converting it to a python file."""
Expand Down Expand Up @@ -227,20 +246,31 @@ def write(self, s):
super(MockDevice,self).write(s)


def import_all_modules(package,verbose=False):
def import_all_modules(package, skip=None, verbose=False, prefix="", depth=0):
"""Recursively imports all subpackages, modules, and submodules of a
given package.
'package' should be an imported package, not a string.
'skip' is a list of modules or subpackages not to import.
"""

for _, modname, ispkg in pkgutil.walk_packages(path=package.__path__,
onerror=lambda x: None):
skip = [] if skip is None else skip

for ff, modname, ispkg in pkgutil.walk_packages(path=package.__path__,
prefix=prefix,
onerror=lambda x: None):
if ff.path not in package.__path__[0]: # Solves weird bug
continue
if verbose:
print(modname,ispkg)
print('\t'*depth,modname)
if modname in skip:
if verbose:
print('\t'*depth,'*Skipping*')
continue
module = '%s.%s' % (package.__name__,modname)
subpackage = importlib.import_module(module)
if ispkg:
module = '%s.%s' % (package.__name__,modname)
subpackage = importlib.import_module(module)
import_all_modules(subpackage,verbose=verbose)
import_all_modules(subpackage, skip=skip,
verbose=verbose,depth=depth+1)


def import_module_from_path(module_path, name=None):
Expand Down
25 changes: 12 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Setup file for SciUnit"""

import sys
import os

from pip.req import parse_requirements
from pip.download import PipSession

try:
from setuptools import setup
Expand All @@ -12,6 +16,13 @@
ipython = "ipython>=5.1,<6.0"
else:
ipython = "ipython>=5.1"

def read_requirements():
'''parses requirements from requirements.txt'''
reqs_path = os.path.join('.', 'requirements.txt')
install_reqs = parse_requirements(reqs_path, session=PipSession())
reqs = [str(ir.req) for ir in install_reqs]
return reqs

setup(
name='sciunit',
Expand All @@ -26,19 +37,7 @@
description='A test-driven framework for formally validating scientific models against data.',
long_description="",
test_suite="sciunit.unit_test.core_tests",
install_requires=['cypy>=0.2',
'quantities==0.12.1',
#'quantities==999',
'pandas>=0.18',
ipython,
'matplotlib',
'bs4',
'lxml',
'nbconvert',
'ipykernel',
'nbformat',
'gitpython'],
#dependency_links = ['git+https://github.com/python-quantities/python-quantities.git@master#egg=quantities-999'],
install_requires=read_requirements(),
entry_points={
'console_scripts': [
'sciunit = sciunit.__main__:main'
Expand Down

0 comments on commit 263e686

Please sign in to comment.