Skip to content

Commit

Permalink
Merge branch 'cathy/setup_repo'
Browse files Browse the repository at this point in the history
  • Loading branch information
cathyatdriver committed Nov 13, 2017
2 parents 5021f5c + eb1b4e0 commit 9a284c0
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 0 deletions.
92 changes: 92 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
*~
118 changes: 118 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
Empty file added beliefs/__init__.py
Empty file.
35 changes: 35 additions & 0 deletions beliefs/models/DirectedGraph.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file added beliefs/models/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions conda-build/.package_install_steps.py
Original file line number Diff line number Diff line change
@@ -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()
31 changes: 31 additions & 0 deletions conda-build/meta.yaml
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 9a284c0

Please sign in to comment.