Skip to content

Commit

Permalink
setuptools now works fine. 'pip install .'
Browse files Browse the repository at this point in the history
Deliberately did not include database, configs and 'externals' in the package for now.
  • Loading branch information
kavvkon committed Dec 26, 2017
1 parent 170c98e commit 2c2ed0d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 18 deletions.
60 changes: 60 additions & 0 deletions DispaSET/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import sys
import logging
import click

from .preprocessing.data_handler import load_config_excel,load_config_yaml
from .preprocessing.preprocessing import build_simulation
from .solve import solve_GAMS, solve_pyomo
from ._version import __version__

@click.group(chain=True)
@click.option('-c','--config', prompt='Specify the path to the config file', type=click.Path(exists=True),
default='./ConfigFiles/ConfigTest.xlsx', help='Path to the config file (eg ConfigFiles/Config.xlsx)')
@click.option('-g','--gams', 'engine',
flag_value='gams', default=True, help='Use GAMS version (default)') #Interface to use for solving. Gams or pyomo')
@click.option('-p','--pyomo', 'engine',
flag_value='pyomo', help='Use pyomo version')
@click.version_option(prog_name='DispaSET', version=__version__)
@click.pass_context
def cli(ctx, config, engine):
"""Build and run the Dispaset model according to a config file.
E.g. ./dispaset.py -c ./ConfigFiles/ConfigTest.xlsx build simulate
"""
ctx.obj = {}
if config.endswith(('.xlsx','.xls')):
ctx.obj['conf'] = load_config_excel(config)
elif config.endswith(('.yml','.yaml')):
ctx.obj['conf'] = load_config_yaml(config)
else:
logging.error('Unrecognized file format')
sys.exit(1)

ctx.obj['engine'] = engine


@cli.command()
@click.pass_context
def build(ctx):
"""Build simulation files"""
conf = ctx.obj['conf']
engine = ctx.obj['engine']
if engine == 'gams' and conf['WriteGDX']:
logging.warning('The config specifies that a gdx file should be written, although PYOMO is selected as engine. This a properly installed version of GAMS. Desactivate the option if it is not the case')
SimData = build_simulation(ctx.obj['conf'] )


@cli.command()
@click.pass_context
def simulate(ctx):
"""Run GAMS or pyomo for simulation"""
conf = ctx.obj['conf']
engine = ctx.obj['engine']

if engine == 'pyomo':
r = solve_pyomo(conf['SimulationDirectory'])

if engine == 'gams':
r = solve_GAMS(conf['SimulationDirectory'], conf['GAMS_folder'])

#if __name__ == '__main__':
# cli(obj={},standalone_mode=False)
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include *.md LICENSE
graft DispaSET
global-exclude *.py[co]
37 changes: 19 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
#!/usr/bin/env python

from setuptools import setup, find_packages
import codecs
import os
HERE = os.path.abspath(os.path.dirname(__file__))

def read(*parts):
"""
Build an absolute path from *parts* and and return the contents of the
resulting file. Assume UTF-8 encoding.
"""
with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f:
return f.read()

# Sets the __version__ variable
__version__ = None
exec(open('DispaSET/_version.py').read())

def recursive_listdir(folder):
'''
Generates a list of all files in a a specified directory
'''
return [(dp,[os.path.join(dp, f)]) for dp, dn, fn in os.walk(os.path.expanduser(folder)) for f in fn]

def define_data_files():
list_files = []
for folder in ['ConfigFile','Database','Externals']:
list_files += recursive_listdir(folder)
return list_files


setup(
name='Dispa-SET',
name='dispaset',
version=__version__,
author='Sylvain Quoilin, Konstantinos Kavvadias',
author_email='squoilin@uliege.be',
Expand All @@ -31,14 +27,19 @@ def define_data_files():
url='http://www.dispaset.eu',
download_url='http://www.dispaset.eu/en/latest/releases.html',
packages=find_packages(),
package_data={'DispaSET': ['config/*.yaml','GAMS/*']},
data_files=define_data_files(),
long_description=read('README.md'),
include_package_data=True,
install_requires=[
"click >= 3.3",
"numpy >= 1.12",
"pandas >= 0.19"
"pandas >= 0.19",
"xlrd >= 0.9",
"matplotlib >= 1.5.1"
],
scripts=['dispaset'],
entry_points={
'console_scripts': [
'dispaset = DispaSET.cli:cli'
]},
classifiers=[
'Intended Audience :: Science/Research',
'License :: OSI Approved :: EUPL Software License',
Expand Down

0 comments on commit 2c2ed0d

Please sign in to comment.