aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCathy Yeh <cathy@driver.xyz>2017-11-13 13:23:40 -0800
committerCathy Yeh <cathy@driver.xyz>2017-11-13 13:23:40 -0800
commit9a284c0ff5339d6fb4802327bcd52278c0424630 (patch)
tree9d3ddc2ad513a7ba5712e53a3ffd58268ff91182
parent5021f5ca1e8069b34f7c932363eec746d01013a0 (diff)
parenteb1b4e06bbee479ff0937cc9920dd26a9f725f37 (diff)
downloadbeliefs-9a284c0ff5339d6fb4802327bcd52278c0424630.tar.gz
beliefs-9a284c0ff5339d6fb4802327bcd52278c0424630.tar.bz2
beliefs-9a284c0ff5339d6fb4802327bcd52278c0424630.zip
Merge branch 'cathy/setup_repo'v0.0.1
-rw-r--r--.gitignore92
-rw-r--r--Makefile118
-rw-r--r--VERSION1
-rw-r--r--beliefs/__init__.py0
-rw-r--r--beliefs/models/DirectedGraph.py35
-rw-r--r--beliefs/models/__init__.py0
-rw-r--r--conda-build/.package_install_steps.py29
-rw-r--r--conda-build/meta.yaml31
8 files changed, 306 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..410246f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,92 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+.hypothesis/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# IPython Notebook
+.ipynb_checkpoints
+
+# pyenv
+.python-version
+
+# celery beat schedule file
+celerybeat-schedule
+
+# dotenv
+.env
+
+# virtualenv
+venv/
+ENV/
+
+# Spyder project settings
+.spyderproject
+
+# Rope project settings
+.ropeproject
+
+# emacs autosave
+*~
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..805f519
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,118 @@
+SHELL := /bin/bash
+
+# see git describe documentation for a descption
+# the version as set in meta.yaml
+RELEASE_VERSION = $(shell cat VERSION)
+PROJECT_NAME = $(shell grep -Eo "name: .*" conda-build/meta.yaml | cut -f 2 -d ' ')
+
+GIT_URL = $(shell git config --get remote.origin.url)
+GIT_REV = $(shell git rev-parse --short HEAD)
+DEV_VERSION = $(RELEASE_VERSION)_dev$(GIT_REV)
+
+# conda-build 2.1.12 started breaking our builds.
+# 2.1.10 was the last version we know works so let's lock to this and more carefully update.
+CONDA_BUILD_VERSION = 2.1.10
+
+CONDA_OUTPUT_FOLDER ?= /opt/releases/driver/
+# where to put the build objects. We can't use the default because
+# there is a known bug by which conda can't build on encrypted drives
+CONDA_BUILD_FOLDER = /tmp/$(PROJECT_NAME)_$(DEV_VERSION)_$(shell whoami)
+# EXPORT_ALL_VARIABLES: will cause conflict with conda specific ENV variables.
+# this is required to satisfy our dependencies
+PYTHON_VERSION = 3.5
+
+DRIVER_CONDA_CHANNELS = -c conda -c driver
+
+export GIT_LFS_SKIP_SMUDGE=1
+
+.EXPORT_ALL_VARIABLES:
+
+####################################################################################################
+# Development commands
+#
+
+develop: install-deps-in-current-env
+ VERSION=$(DEV_VERSION) DRIVER_BUILD_GIT_URL=$(GIT_URL) DRIVER_BUILD_GIT_REV=$(GIT_REV) \
+ python .package_install_steps.py develop
+
+# builds a conda package from the meta.yaml file and places it into the local repo
+build-in-current-env: verify-conda-build-installed
+ -mkdir -p $(CONDA_OUTPUT_FOLDER) && test -w $(CONDA_OUTPUT_FOLDER)
+ conda config --set anaconda_upload no
+ VERSION=$(DEV_VERSION) DRIVER_BUILD_GIT_URL=$(GIT_URL) DRIVER_BUILD_GIT_REV=$(GIT_REV) \
+ conda-build conda-build/meta.yaml \
+ $(DRIVER_CONDA_CHANNELS) \
+ --croot $(CONDA_BUILD_FOLDER) \
+ --output-folder $(CONDA_OUTPUT_FOLDER) \
+ --python $(PYTHON_VERSION)
+
+# Install package into the current environment
+install-in-current-env: build-in-current-env
+ conda install --yes $(DRIVER_CONDA_CHANNELS) -c file://$(CONDA_OUTPUT_FOLDER) $(PROJECT_NAME)=$(DEV_VERSION)
+
+uninstall-from-current-env: # develop uninstall # install uninstall
+ -conda uninstall --yes $(PROJECT_NAME) || pip uninstall --yes $(PROJECT_NAME)
+
+install-deps-in-current-env: install-in-current-env uninstall-from-current-env
+
+####################################################################################################
+# Conda environment commands
+#
+
+# run the test scripts in a clean conda environment
+setup-clean-env:
+ -conda create --yes --name test_env_$(PROJECT_NAME)_$(DEV_VERSION) python=$(PYTHON_VERSION)
+
+teardown-clean-env:
+ conda remove --name test_env_$(PROJECT_NAME)_$(DEV_VERSION) --all --yes
+
+####################################################################################################
+# Release commands
+#
+
+git-tag:
+ git pull --tags
+ git tag -a v$(RELEASE_VERSION) -m "v$(RELEASE_VERSION)"
+ git push origin v$(RELEASE_VERSION)
+
+build-release-and-upload: verify-conda-build-installed
+ conda config --set anaconda_upload yes
+ # Create the package if it does not already exist and set the permission to
+ # private (to driver).
+ -anaconda package driver/$(PROJECT_NAME) --create --private
+ VERSION=$(RELEASE_VERSION) DRIVER_BUILD_GIT_URL=$(GIT_URL) DRIVER_BUILD_GIT_REV=$(GIT_REV) \
+ conda-build conda-build/meta.yaml \
+ $(DRIVER_CONDA_CHANNELS) \
+ --croot $(CONDA_BUILD_FOLDER) \
+ --python $(PYTHON_VERSION) \
+ --channel driver
+
+release: test-in-clean-env git-tag build-release-and-upload
+
+####################################################################################################
+# test commands
+#
+
+test-in-clean-env: verify-conda-build-installed
+ $(MAKE) setup-clean-env
+ source activate test_env_$(PROJECT_NAME)_$(DEV_VERSION) && \
+ $(MAKE) install-in-current-env && \
+ $(MAKE) test-in-current-env && \
+ source deactivate test_env_$(PROJECT_NAME)_$(DEV_VERSION)
+ $(MAKE) teardown-clean-env
+
+# run tests in the current environment
+test-in-current-env:
+ git lfs fetch
+ echo TEST
+
+####################################################################################################
+# helper commands
+#
+
+# make sure that we don't have uncommited changes, we'll want to check for un-added files in the future
+verify-changes-commited:
+ git diff-index --quiet HEAD --
+
+verify-conda-build-installed:
+ -source deactivate && conda install conda-build=$(CONDA_BUILD_VERSION) --yes
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..8acdd82
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.0.1
diff --git a/beliefs/__init__.py b/beliefs/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/beliefs/__init__.py
diff --git a/beliefs/models/DirectedGraph.py b/beliefs/models/DirectedGraph.py
new file mode 100644
index 0000000..8dfb9bd
--- /dev/null
+++ b/beliefs/models/DirectedGraph.py
@@ -0,0 +1,35 @@
+import networkx as nx
+
+
+class DirectedGraph(nx.DiGraph):
+ """
+ Base class for all directed graphical models.
+ """
+ def __init__(self, edges, node_labels):
+ """
+ Input:
+ edges: an edge list, e.g. [(parent1, child1), (parent1, child2)]
+ node_labels: a list of strings of node labels
+ """
+ super().__init__()
+ if edges is not None:
+ self.add_edges_from(edges)
+ if node_labels is not None:
+ self.add_nodes_from(node_labels)
+
+ def get_leaves(self):
+ """
+ Returns a list of leaves of the graph.
+ """
+ return [node for node, out_degree in self.out_degree_iter() if
+ out_degree == 0]
+
+ def get_roots(self):
+ """
+ Returns a list of roots of the graph.
+ """
+ return [node for node, in_degree in self.in_degree().items() if
+ in_degree == 0]
+
+ def get_topologically_sorted_nodes(self, reverse=False):
+ return nx.topological_sort(self, reverse=reverse)
diff --git a/beliefs/models/__init__.py b/beliefs/models/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/beliefs/models/__init__.py
diff --git a/conda-build/.package_install_steps.py b/conda-build/.package_install_steps.py
new file mode 100644
index 0000000..4e22bb8
--- /dev/null
+++ b/conda-build/.package_install_steps.py
@@ -0,0 +1,29 @@
+import os
+from setuptools import setup, find_packages
+from yaml import load
+import jinja2
+
+
+def load_meta_data(fname):
+ with open(fname) as input_fp:
+ # note that EDITABLE_FLAG is not required because we getting it from environ
+ template = jinja2.Template(input_fp.read(), undefined=jinja2.StrictUndefined)
+ return load(template.render(**os.environ))
+
+
+def main():
+ meta_data = load_meta_data('conda-build/meta.yaml')
+ setup(
+ name=meta_data['package']['name'],
+ version=meta_data['package']['version'],
+ include_package_data=True,
+ zip_safe=False,
+ entry_points={
+ 'console_scripts': meta_data['build'].get('entry_points', [])
+ },
+ packages=find_packages()
+ )
+
+
+if __name__ == '__main__':
+ main()
diff --git a/conda-build/meta.yaml b/conda-build/meta.yaml
new file mode 100644
index 0000000..b7d065b
--- /dev/null
+++ b/conda-build/meta.yaml
@@ -0,0 +1,31 @@
+package:
+ name: beliefs
+ version: {{ VERSION }}
+
+source:
+ git_url: ..
+
+build:
+ script: python .package_install_steps.py install
+ script_env:
+ - VERSION
+
+requirements:
+ build:
+ - python
+ - setuptools
+ - jinja2
+ - pyyaml
+
+ run:
+ - python
+ - jinja2
+ - pyyaml
+ - pytest
+ - numpy
+ - networkx >=1.11
+
+anaconda_upload: True
+
+about:
+ home: https://github.com/drivergroup/beliefs/