diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b10bf4e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: python + +python: + - '2.7' + - '3.5' + - '3.6' + +matrix: + include: + - python: '3.7' # temp solution until python 3.7 is more cleanly supported + dist: xenial + sudo: true + allow_failures: + - python: '3.7' # dependencies are blocking installation + fast_finish: true + +install: + - pip install git+git://github.com/udst/choicemodels.git + - pip install . + - pip install -r requirements-full.txt + - pip install -r requirements-dev.txt + - pip list + - pip show urbansim_templates + +script: + - cd urbansim_templates/tests + - coverage run --source urbansim_templates --module pytest --verbose + +after_success: + - coverage report --show-missing + - coveralls \ No newline at end of file diff --git a/README.md b/README.md index dbfea42..fb34192 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Build Status](https://travis-ci.org/UDST/urbansim_templates.svg?branch=master)](https://travis-ci.org/UDST/urbansim_templates) +[![Coverage Status](https://coveralls.io/repos/github/UDST/urbansim_templates/badge.svg?branch=master)](https://coveralls.io/github/UDST/urbansim_templates?branch=master) + # UrbanSim Templates UrbanSim Templates defines a common structure for new model steps and provides a core set of flexible templates and related tools. The goal is to enable smoother model setup, easier code reuse, and improvements to task orchestration. @@ -9,9 +12,24 @@ UrbanSim Templates is currently in pre-release. API documentation is in the Pyth ## Installation -You can follow the setup instructions in [UAL/urbansim_parcel_bayarea](https://github.com/ual/urbansim_parcel_bayarea) to create a conda environment with everything you need for working in the UrbanSim Templates ecosystem. +It can be helpful to set up a dedicated Python environment for working on UrbanSim projects, for reproducibility and to avoid conflicts with other projects. MORE INFO TK. + +### Production releases + +Coming soon to pip and conda. -If you already have most of it installed, this should be sufficient: +### Development releases + +The latest development release can be installed using the Github URL. These currently require having a development release of ChoiceModels as well, which you should install first. + +``` +pip install git+git://github.com/udst/choicemodels.git +pip install git+git://github.com/udst/urbansim_templates.git +``` + +### Cloning the repository + +If you will be editing the library code or frequently updating to newer development versions, you can clone the repository and link it to your Python environment: ``` git clone https://github.com/udst/urbansim_templates.git @@ -19,7 +37,6 @@ cd urbansim_templates python setup.py develop ``` - ## Bug reports Open an issue, or contact Sam (maurer@urbansim.com). @@ -104,3 +121,5 @@ ModelManager works directly with the current versions of [UrbanSim](https://gith - Shared template functionality is in `utils.py`. There's also a `TemplateStep` parent class in `shared.py`, but this hasn't worked very well; see [issue #38](https://github.com/UDST/urbansim_templates/issues/38). - We don't have design patterns yet for templates whose final output is to _generate_ DataFrames or Series, rather than modifying existing ones, but we're working on it. + +- To avoid dependency bloat, the default installation only includes the external libraries required for core model management and the most commonly used templates. Templates using additional libraries should check whether they're installed before fitting or running a model step, and provide helpful error messages if not. diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..cb8cecb --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,5 @@ +# requirements for development and testing + +coverage +coveralls +pytest diff --git a/requirements-full.txt b/requirements-full.txt new file mode 100644 index 0000000..b339d94 --- /dev/null +++ b/requirements-full.txt @@ -0,0 +1,3 @@ +# additional requirements for less-used templates + +pylogit >= 0.2 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..286508c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +# minimal requirements for model management and core templates + +choicemodels >= 0.2.dev4 +numpy >= 1.14 +orca >= 1.4 +pandas >= 0.22 +patsy >= 0.4 +statsmodels >= 0.8 +urbansim >= 3.1 diff --git a/setup.py b/setup.py index 5d84b64..37164f0 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,9 @@ from setuptools import setup, find_packages +with open('requirements.txt') as f: + requirements = f.readlines() +requirements = [item.strip() for item in requirements] + setup( name='urbansim_templates', version='0.1.dev17', @@ -13,14 +17,8 @@ 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'License :: OSI Approved :: BSD License' ], packages=find_packages(exclude=['*.tests']), - install_requires=[ - 'numpy >= 1.14', - 'orca >= 1.4', - 'pandana >= 0.3', - 'pandas >= 0.22', - 'statsmodels >= 0.8', - 'urbansim >= 3.1.1' - ] -) + install_requires=requirements +) \ No newline at end of file diff --git a/urbansim_templates/__init__.py b/urbansim_templates/__init__.py index 238774e..09d0223 100644 --- a/urbansim_templates/__init__.py +++ b/urbansim_templates/__init__.py @@ -1 +1 @@ -version = __version__ = '0.1.dev17' \ No newline at end of file +version = __version__ = '0.1.dev17' diff --git a/urbansim_templates/models/large_multinomial_logit.py b/urbansim_templates/models/large_multinomial_logit.py index f0fedb1..85282c3 100644 --- a/urbansim_templates/models/large_multinomial_logit.py +++ b/urbansim_templates/models/large_multinomial_logit.py @@ -1,16 +1,10 @@ from __future__ import print_function -import numpy as np -import pandas as pd -import patsy - import orca -from choicemodels import mnl -from choicemodels import MultinomialLogit, MultinomialLogitResults -from choicemodels.tools import (MergedChoiceTable, monte_carlo_choices, - iterative_lottery_choices) +# choicemodels imports are in the fit() and run() methods from .. import modelmanager +from ..utils import version_greater_or_equal from .shared import TemplateStep @@ -412,6 +406,15 @@ def fit(self, mct=None): None """ + try: + from choicemodels import __version__, MultinomialLogit + from choicemodels.tools import MergedChoiceTable + assert version_greater_or_equal(__version__, '0.2.dev4') + except: + raise ImportError("LargeMultinomialLogitStep estimation requires " + "choicemodels 0.2.dev4 or later. For installation instructions, see " + "https://github.com/udst/choicemodels.") + if (mct is not None): data = mct @@ -476,6 +479,16 @@ def run(self, chooser_batch_size=None, interaction_terms=None): None """ + try: + from choicemodels import __version__, MultinomialLogitResults + from choicemodels.tools import (MergedChoiceTable, monte_carlo_choices, + iterative_lottery_choices) + assert version_greater_or_equal(__version__, '0.2.dev4') + except: + raise ImportError("LargeMultinomialLogitStep simulation requires " + "choicemodels 0.2.dev4 or later. For installation instructions, see " + "https://github.com/udst/choicemodels.") + obs = self._get_df(tables=self.out_choosers, fallback_tables=self.choosers, filters=self.out_chooser_filters) diff --git a/urbansim_templates/tests/.gitignore b/urbansim_templates/tests/.gitignore index 763624e..068415c 100644 --- a/urbansim_templates/tests/.gitignore +++ b/urbansim_templates/tests/.gitignore @@ -1 +1,2 @@ +.coverage __pycache__/* \ No newline at end of file