Skip to content

Commit

Permalink
Add version and author to C header, have setup.py grab those values f…
Browse files Browse the repository at this point in the history
…rom the header file.
  • Loading branch information
kenrobbins committed Sep 21, 2015
1 parent 6014d6c commit 4dbffb9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions python-rapidjson/rapidjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/error/en.h"

#include "docstrings.h"
#include "version.h"

using namespace rapidjson;

Expand Down Expand Up @@ -877,5 +879,11 @@ PyInit_rapidjson()
PyModule_AddIntConstant(module, "DATETIME_MODE_ISO8601", DATETIME_MODE_ISO8601);
PyModule_AddIntConstant(module, "DATETIME_MODE_ISO8601_IGNORE_TZ", DATETIME_MODE_ISO8601_IGNORE_TZ);

PyModule_AddStringConstant(module, "__version__", PYTHON_RAPIDJSON_VERSION);
PyModule_AddStringConstant(
module,
"__author__",
PYTHON_RAPIDJSON_AUTHOR " <" PYTHON_RAPIDJSON_AUTHOR_EMAIL ">");

return module;
}
3 changes: 3 additions & 0 deletions python-rapidjson/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define PYTHON_RAPIDJSON_VERSION "0.0.6"
#define PYTHON_RAPIDJSON_AUTHOR "Ken Robbins"
#define PYTHON_RAPIDJSON_AUTHOR_EMAIL "ken@kenrobbins.com"
26 changes: 23 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import os.path
import re

try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension

ROOT_PATH = os.path.abspath(os.path.dirname(__file__))

def find_version():
with open(os.path.join(ROOT_PATH, 'python-rapidjson/version.h')) as f:
data = f.read()

v = re.search(r'PYTHON_RAPIDJSON_VERSION\s+(\S+)', data).group(1)
return v.replace('"', '')

def find_author():
with open(os.path.join(ROOT_PATH, 'python-rapidjson/version.h')) as f:
data = f.read()

author = re.search(r'PYTHON_RAPIDJSON_AUTHOR\s+(\S+)', data).group(1)
email = re.search(r'PYTHON_RAPIDJSON_AUTHOR_EMAIL\s+(\S+)', data).group(1)
return (author.replace('"', ''), email.replace('"', ''))

with open('README.rst') as f:
long_description = f.read()

Expand All @@ -14,13 +34,13 @@

setup(
name='python-rapidjson',
version='0.0.6',
version=find_version(),
description='Python wrapper around rapidjson',
long_description=long_description,
license='MIT License',
keywords='json rapidjson',
author='Ken Robbins',
author_email='ken@kenrobbins.com',
author=find_author()[0],
author_email=find_author()[1],
url='https://github.com/kenrobbins/python-rapidjson',
download_url='https://github.com/kenrobbins/python-rapidjson',
classifiers=[
Expand Down

0 comments on commit 4dbffb9

Please sign in to comment.