Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Oct 11, 2018
1 parent e4abb0b commit 3396d27
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 1 deletion.
107 changes: 107 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# 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/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# IDEA
.idea
1 change: 0 additions & 1 deletion README.md

This file was deleted.

3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pybel-git
=========
Git and continuous integration tools for PyBEL.
49 changes: 49 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
##########################
# Setup.py Configuration #
##########################
# Configuring setup()
[metadata]
name = pybel_git
version = 0.0.1-dev
author = Charles Tapley Hoyt
author_email = [email protected]
maintainer = Charles Tapley Hoyt
maintainer_email = [email protected]
classifiers =
Development Status :: 1 - Planning
Intended Audience :: Developers
Programming Language :: Python
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3 :: Only
License :: OSI Approved :: MIT License
license = MIT
license_file = LICENSE
description = PyBEL Git utilities
long_description = file: README.rst
keywords =
Biological Expression Language
Protein Protein Interaction Networks

[options]
install_requires =
pybel
click
easy-config
gitpython
python_requires = >=3.6
packages = find:
package_dir =
= src
zip-safe = false

[options.entry_points]
console_scripts =
pybel-git = pybel_git.cli:main

[options.packages.find]
where = src

# configuring bdist_wheel
[bdist_wheel]
python-tag = py36
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-

"""Setup module for PyBEL-Git."""

import setuptools

if __name__ == '__main__':
setuptools.setup()
1 change: 1 addition & 0 deletions src/pybel_git/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
6 changes: 6 additions & 0 deletions src/pybel_git/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-

from .cli import main

if __name__ == '__main__':
main()
49 changes: 49 additions & 0 deletions src/pybel_git/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""Command line interface for PyBEL-Git."""

import os
import sys

import click
from git import Repo

from pybel import Manager, from_path
from pybel.cli import connection_option
from .commands import get_changed

EMOJI = '🔔'


@click.group()
def main():
"""PyBEL Git utilities."""


# TODO download pre-built cache?

@main.command()
@click.option('-d', '--directory', default=os.getcwd(), type=click.Path(file_okay=False, dir_okay=True),
help='Directory of git repository')
@connection_option
def ci(directory: str, connection: str):
"""Run in continuous integration setting."""
click.echo(f'{EMOJI} checking directory: {directory}')

repo = Repo(directory)
head_commit = repo.git.rev_parse('HEAD')
click.echo(f'{EMOJI} head commit: {head_commit}')

file_names = get_changed(repo)
if not file_names:
sys.exit(0)

manager = Manager(connection=connection)
failures = []
for file_name in file_names:
click.echo(f'{EMOJI} file changed: {file_name}')
graph = from_path(file_name, manager=manager)
if graph.warnings:
failures.append(graph)

sys.exit(1 if failures else 0)
18 changes: 18 additions & 0 deletions src/pybel_git/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-


from typing import List

from git import Repo


def get_changed(repo: Repo) -> List[str]:
"""Get a list of files that have changed in the last commit."""
head_commit = repo.git.rev_parse('HEAD')
output = repo.git.diff_tree('--no-commit-id', '--name-only', '-r', head_commit)

return [
name
for name in output.split('\n')
if name.endswith('.bel')
]
19 changes: 19 additions & 0 deletions src/pybel_git/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-

"""Configuration for PyBEL-Git."""

import logging

from easy_config import EasyConfig

log = logging.getLogger(__name__)


class PyBELGitConfig(EasyConfig):
"""Configuration for PyBEL-Git."""
NAME = 'pybel_git'
FILES = []


pybel_git_config = PyBELGitConfig.load()
log.info('loaded pybel-git configuration: %s', pybel_git_config)

0 comments on commit 3396d27

Please sign in to comment.