Browse Source

add package setup

Read the README.md to use himport
Philippe Le Brouster 7 years ago
parent
commit
eba290dff1
8 changed files with 134 additions and 65 deletions
  1. 10 5
      README.md
  2. 12 8
      bin/himport
  3. 1 1
      himports/dolibarrAlchemyHledger.py
  4. 111 0
      setup.py
  5. 0 6
      utils/pyenv-exec
  6. 0 8
      utils/pyenv-himport
  7. 0 23
      utils/pyenv-init
  8. 0 14
      utils/scripts.cfg

+ 10 - 5
README.md

@@ -1,18 +1,19 @@
-# himports
 
-## Usage from repository
+# Usage from repository
 
 **Installation**
 
     git clone https://code.ffdn.org/plb/himport.git
     cd himport
-    ./utils/pyenv-init
+
+    virtualenv venv
+    ./venv/bin pip install -e .
 
 **Utilisation**
 
-    ./utils/pyenv-himport
+    ./venv/bin/himport
 
-## Configuration
+# Configuration
 
 **General**
 
@@ -26,3 +27,7 @@ You can copy the configuration file from ``himport.conf.template``
 
 This file is used to store SQL information to connect to the dolibarr database
 
+
+# Authors
+
+Philippe Le Brouster <plb@nebkha.net>

+ 12 - 8
bin/himport

@@ -9,9 +9,9 @@ import sys
 import codecs
 import getpass
 
-from himports import settings
-from himports.dolibarrWriter import Writer
-from himports.dolibarrAlchemyHledger import HledgerDolibarrSQLAlchemy
+from himport import settings
+from himport.dolibarrWriter import Writer
+from himport.dolibarrAlchemyHledger import HledgerDolibarrSQLAlchemy
 
 logging.basicConfig(level=logging.INFO)
 logger = logging.getLogger('hreport')
@@ -19,7 +19,7 @@ logger = logging.getLogger('hreport')
 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
 
 
-def process_args(argv):
+def process_args():
     options = {}
     usage = u'''Usage: himport -v -y <YEAR> [ -y <YEAR> ] ...
         options:
@@ -28,7 +28,7 @@ def process_args(argv):
     '''
     try:
         opts, args = getopt.getopt(
-            argv, "hvy:",
+            sys.argv[1:], "hvy:",
             ["mysql-password=", "mysql-port", "year="]
         )
     except getopt.GetoptError:
@@ -94,12 +94,16 @@ def do_sqlalchemy(options):
     dolibarr.disconnect()
 
 
-def main(argv):
+def main():
     locale.setlocale(locale.LC_ALL, b'fr_FR.utf-8')
-    options = process_args(argv)
+    options = process_args()
 
     do_sqlalchemy(options)
 
 
 if __name__ == "__main__":
-    main(sys.argv[1:])
+    try:
+        main(sys.argv[1:])
+    except Exception as e:
+        print e.message
+        sys.exit(1)

+ 1 - 1
himports/dolibarrAlchemyHledger.py

@@ -4,7 +4,7 @@ from __future__ import unicode_literals
 import settings
 import datetime
 
-from himports.dolibarrAlchemy import DolibarrSQLAlchemy
+from himport.dolibarrAlchemy import DolibarrSQLAlchemy
 
 
 #

+ 111 - 0
setup.py

@@ -0,0 +1,111 @@
+"""A setuptools based setup module.
+
+See:
+https://packaging.python.org/en/latest/distributing.html
+https://github.com/pypa/sampleproject
+"""
+
+# Always prefer setuptools over distutils
+from setuptools import setup, find_packages
+# To use a consistent encoding
+from codecs import open
+from os import path
+
+here = path.abspath(path.dirname(__file__))
+
+# Get the long description from the README file
+with open(path.join(here, 'README.md'), encoding='utf-8') as f:
+    long_description = f.read()
+
+setup(
+    name='himport',
+
+    # Versions should comply with PEP440.  For a discussion on single-sourcing
+    # the version across setup.py and the project code, see
+    # https://packaging.python.org/en/latest/single_source_version.html
+    version='0.1',
+
+    description='Himport project',
+    long_description=long_description,
+
+    # The project's main homepage.
+    url='',
+
+    # Author details
+    author='Philippe Le Brouster',
+    author_email='plb@nebkha.net',
+
+    # Choose your license
+    license='',
+
+    # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
+    classifiers=[
+        # How mature is this project? Common values are
+        #   3 - Alpha
+        #   4 - Beta
+        #   5 - Production/Stable
+        'Development Status :: 4 - Beta',
+
+        # Indicate who your project is intended for
+        'Intended Audience :: Developers',
+        'Topic :: Software Development :: Build Tools',
+        'Office/Business :: Financial :: Accounting',
+
+        # Specify the Python versions you support here. In particular, ensure
+        # that you indicate whether you support Python 2, Python 3 or both.
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
+    ],
+
+    # What does your project relate to?
+    keywords='himport',
+
+    # You can just specify the packages manually here if your project is
+    # simple. Or you can use find_packages().
+    packages=find_packages(exclude=['contrib', 'doc', 'tests']),
+
+    # Alternatively, if you want to distribute just a my_module.py, uncomment
+    # this:
+    #   py_modules=["my_module"],
+
+    # List run-time dependencies here.  These will be installed by pip when
+    # your project is installed. For an analysis of "install_requires" vs pip's
+    # requirements files see:
+    # https://packaging.python.org/en/latest/requirements.html
+    install_requires=['MySQL-python', 'sqlalchemy', 'future'],
+
+    # List additional groups of dependencies here (e.g. development
+    # dependencies). You can install these using the following syntax,
+    # for example:
+    # $ pip install -e .[dev,test]
+    extras_require={
+    #    'dev': ['check-manifest'],
+    #    'test': ['coverage'],
+    },
+
+    # If there are data files included in your packages that need to be
+    # installed, specify them here.  If using Python 2.6 or less, then these
+    # have to be included in MANIFEST.in as well.
+    package_data={
+        'himport': [],
+    },
+
+    # Although 'package_data' is the preferred approach, in some case you may
+    # need to place data files outside of your packages. See:
+    # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
+    # In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
+    #data_files=[('my_data', ['data/data_file'])],
+
+    # To provide executable scripts, use entry points in preference to the
+    # "scripts" keyword. Entry points provide cross-platform support and allow
+    # pip to create the appropriate form of executable for the target platform.
+    entry_points={
+        'console_scripts': [
+            'himport=himport.cli:main',
+        ],
+    },
+)

+ 0 - 6
utils/pyenv-exec

@@ -1,6 +0,0 @@
-#! /bin/sh
-
-# this script aim to initialise the environement.
-. $(dirname $0)/scripts.cfg
-
-"$@"

+ 0 - 8
utils/pyenv-himport

@@ -1,8 +0,0 @@
-#! /usr/bin/env bash
-
-UTILS_DIR=$(dirname "${BASH_SOURCE[0]}")
-
-# this script aim to initialise the environement.
-. $UTILS_DIR/scripts.cfg
-
-$UTILS_DIR/../bin/himport $@

+ 0 - 23
utils/pyenv-init

@@ -1,23 +0,0 @@
-#! /bin/bash
-
-set -e
-
-# this script aim to initialise the environement.
-. $(dirname $0)/scripts.cfg
-
-# create python virtualenv
-if ! which virtualenv >/dev/null; then
-    echo "Please install python-virtualenv"
-    exit 1
-fi
-
-if [ ! -d "$PYTHONENV_DIR" ]; then 
-    if ! virtualenv $PYTHONENV_DIR --system-site-packages; then
-        virtualenv $PYTHONENV_DIR
-    fi
-fi
-
-. $PYTHONENV_DIR/bin/activate
-
-pip install -r $BASE_DIR/requirements.pip
-

+ 0 - 14
utils/scripts.cfg

@@ -1,14 +0,0 @@
-#! /bin/sh
-
-DIR=$(dirname $0)
-BASE_DIR=$(readlink -f $DIR/..)
-UTILS_DIR=$BASE_DIR/utils
-PYTHONENV_DIR=${BASE_DIR}/python-env
-
-# use the virtual python environnement in $VAR_DIR/python-env
-[ ! -e "$PYTHONENV_DIR/bin/activate" ] || . $PYTHONENV_DIR/bin/activate
-
-# Include the project python path
-export PYTHONPATH="$BASE_DIR:$PYTHONPATH"
-
-