Skip to content

Commit

Permalink
Merge pull request #27 from openvstorage/setup_packaging
Browse files Browse the repository at this point in the history
Setup packaging
  • Loading branch information
JeffreyDevloo authored May 28, 2019
2 parents 78d9c11 + 2b2089a commit 7777c95
Show file tree
Hide file tree
Showing 17 changed files with 650 additions and 5 deletions.
File renamed without changes.
8 changes: 8 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Pyrakoon
An alternative Python client for Arakoon

## Installation
- Download or clone this repository.
- Run `python setup.py install` on the directory where you cloned it.
- Import the client with `from pyrakoon import *`

1 change: 1 addition & 0 deletions packaging/debian/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
11 changes: 11 additions & 0 deletions packaging/debian/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Source: pyrakoon
Maintainer: OpenvStorage <support@openvstorage.com>
Standards-Version: 3.9.4
Section: python
Priority: optional
Build-Depends: python (>= 2.7.2), debhelper (>= 9)

Package: pyrakoon
Architecture: amd64
Pre-Depends: python (>= 2.7.2)
Description: An alternative Python client for Arakoon
429 changes: 429 additions & 0 deletions packaging/debian/debian/copyright

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packaging/debian/debian/pyrakoon.dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/lib/python2.7/dist-packages/pyrakoon
1 change: 1 addition & 0 deletions packaging/debian/debian/pyrakoon.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyrakoon/* usr/lib/python2.7/dist-packages/pyrakoon
4 changes: 4 additions & 0 deletions packaging/debian/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/make -f

%:
dh $@
1 change: 1 addition & 0 deletions packaging/debian/debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
10 changes: 10 additions & 0 deletions packaging/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package_name": "pyrakoon",
"product_name": "Pyrakoon",
"tags": ["enterprise"],
"source_contents": "--transform 's,^,{0}-{1}/,' pyrakoon CHANGELOG.txt LICENSE.txt",
"version": {
"major": 0,
"minor": 1
}
}
4 changes: 4 additions & 0 deletions pyrakoon/__author__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) iNuron - info@openvstorage.com
# This file is part of Open vStorage. For license information, see <LICENSE.txt>

__author__ = u'OpenvStorage'
5 changes: 5 additions & 0 deletions pyrakoon/__hash__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) iNuron - info@openvstorage.com
# This file is part of Open vStorage. For license information, see <LICENSE.txt>

# Modified during build step. Using 'None' to make the regex easier
__hash__ = 'None'
8 changes: 3 additions & 5 deletions pyrakoon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@

import logging
from .constants.logging import PYRAKOON_LOGGER
from .__version__ import __version__, __version_tuple__
from .__author__ import __author__
from .__license__ import __license__

"""
pyrakoon, an Arakoon_ client for Python
.. _Arakoon: http://www.arakoon.org
"""

__version_info__ = 0, 0, 1
__version__ = '.'.join(str(i) for i in __version_info__)
__author__ = u'OpenvStorage'
__license__ = u'LGPL2'

__docformat__ = 'restructuredtext en'

# Setup NullHandler
Expand Down
4 changes: 4 additions & 0 deletions pyrakoon/__license__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) iNuron - info@openvstorage.com
# This file is part of Open vStorage. For license information, see <LICENSE.txt>

__license__ = u'LGPL2'
10 changes: 10 additions & 0 deletions pyrakoon/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (C) iNuron - info@openvstorage.com
# This file is part of Open vStorage. For license information, see <LICENSE.txt>

from .__hash__ import __hash__

# Used by setup.py to compute the version
__version_info__ = 0, 1, 0
# Version with the added hash
__version_tuple__ = __version_info__ + (__hash__,)
__version__ = '.'.join(str(i) for i in __version_tuple__)
Empty file added requirements.txt
Empty file.
158 changes: 158 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) iNuron - info@openvstorage.com
# This file is part of Open vStorage. For license information, see <LICENSE.txt>

import io
import os
import re
from subprocess import check_output
from setuptools import find_packages, setup
from setuptools.command.install import install


class Container(object):
"""
Houses some variables
"""
def __init__(self):
self.commit_hash = None
self.init_pys = {}


class PyrakoonInstall(install):
def run(self):
# Setup the hash
set_hash(PACKAGE_NAME)
# Run the setuptools install
install.run(self)


CONTAINER = Container()
HASH_REGEX = "(__hash__ = .*['\"])(.*)(['\"])"


def read_init(package):
init_py = CONTAINER.init_pys.get(package)
if init_py is not None:
return init_py
with open(os.path.join(package, '__init__.py'), 'r') as init_file:
file_contents = init_file.read()
CONTAINER.init_pys[package] = file_contents
return file_contents


def get_hash(package):
"""
Retrieve the hash of the package
"""
_ = package
try:
CONTAINER.commit_hash = check_output(['git', 'rev-parse', 'HEAD']).strip()
except:
CONTAINER.commit_hash = ''
print 'Unable to get the hash'
return CONTAINER.commit_hash


def set_hash(package):
"""
Write the hash out the __hash__.py. Done during setup
"""
package_hash = get_hash(package)
if package_hash is not None:
try:
hash_file_path = os.path.join(package, '__hash__.py')
with open(hash_file_path, 'r') as hash_f:
contents = hash_f.read()
new_contents = re.sub(HASH_REGEX, '\g<1>{}\g<3>'.format(package_hash), contents)
with open(hash_file_path, 'w') as hash_f:
hash_f.write(new_contents)
print 'Written out the hash to __hash__.py'
except:
print 'Unable to write the hash'


def get_version(package):
"""
Return package version as listed in `__version__.py`
"""
with open(os.path.join(package, '__version__.py'), 'r') as version_f:
contents = version_f.read()
with open(os.path.join(package, '__hash__.py'), 'r') as hash_f:
hash_contents = hash_f.read()
# Unable to use __version__ as it is computed. Compute it again
version_numbers = re.search("__version_info__ = ([0-9]+(?:, ?[0-9]+)*)", contents).group(1)
hash_content = re.search(HASH_REGEX, hash_contents).group(2)
if hash_content == 'None':
hash_content = str(get_hash(package))
return '{0}+{1}'.format('.'.join(n.strip() for n in version_numbers.split(',')), hash_content)


def get_author(package):
"""
Return package author as listed in `__author__.py`
"""
with open(os.path.join(package, '__author__.py'), 'r') as author_f:
contents = author_f.read()
return re.search("__author__ = .*['\"](.*)['\"]", contents).group(1)


def get_license(package):
"""
Return package license as listed in `__license__.py`
"""
with open(os.path.join(package, '__license__.py'), 'r') as license_f:
contents = license_f.read()
return re.search("__license__ = .*['\"](.*)['\"]", contents).group(1)


# Package meta-data.
PACKAGE_NAME = 'pyrakoon'
NAME = 'Pyrakoon'
DESCRIPTION = 'An alternative Python client for Arakoon'
URL = 'https://github.com/openvstorage/pyrakoon'
EMAIL = 'support@openvstorage.com'
AUTHOR = get_author(PACKAGE_NAME)
REQUIRES_PYTHON = '>=2.7, <3.0'
VERSION = get_version(PACKAGE_NAME)
LICENSE = get_license(PACKAGE_NAME)

# Packages
REQUIRED = []
EXTRAS = {}

# Import the README and use it as the long-description.
try:
with io.open('README.MD', encoding='utf-8') as f:
long_description = '\n' + f.read()
except IOError:
long_description = DESCRIPTION

setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=long_description,
long_description_content_type='text/markdown',
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
packages=find_packages(exclude=('test', 'demo')),
install_requires=REQUIRED,
extras_require=EXTRAS,
include_package_data=True,
license=LICENSE,
classifiers=[
# Trove classifiers
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: Implementation :: CPython',
],
cmdclass={
'install': PyrakoonInstall,
},
)

0 comments on commit 7777c95

Please sign in to comment.