-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #42: unify README and module doc
- Loading branch information
Showing
6 changed files
with
123 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,41 +15,16 @@ | |
|
||
# get distribution meta info | ||
here = os.path.abspath(os.path.dirname(__file__)) | ||
meta_fh = open(os.path.join(here, 'ppft/__init__.py')) | ||
try: | ||
meta = {} | ||
for line in meta_fh: | ||
if line.startswith('__version__'): | ||
VERSION = line.split()[-1].strip("'").strip('"') | ||
break | ||
meta['VERSION'] = VERSION | ||
for line in meta_fh: | ||
if line.startswith('__author__'): | ||
AUTHOR = line.split(' = ')[-1].strip().strip("'").strip('"') | ||
break | ||
meta['AUTHOR'] = AUTHOR | ||
LONG_DOC = "" | ||
DOC_STOP = "FAKE_STOP_12345" | ||
for line in meta_fh: | ||
if LONG_DOC: | ||
if line.startswith(DOC_STOP): | ||
LONG_DOC = LONG_DOC.strip().strip("'").strip('"').lstrip() | ||
break | ||
else: | ||
LONG_DOC += line | ||
elif line.startswith('__doc__'): | ||
DOC_STOP = line.split(' = ')[-1] | ||
LONG_DOC = "\n" | ||
meta['LONG_DOC'] = LONG_DOC | ||
finally: | ||
meta_fh.close() | ||
sys.path.append(here) | ||
from version import (__version__, __author__, __contact__ as AUTHOR_EMAIL, | ||
get_license_text, get_readme_as_rst, write_info_file) | ||
LICENSE = get_license_text(os.path.join(here, 'LICENSE')) | ||
README = get_readme_as_rst(os.path.join(here, 'README.md')) | ||
|
||
# get version numbers, long_description, etc | ||
AUTHOR = meta['AUTHOR'] | ||
VERSION = meta['VERSION'] | ||
LONG_DOC = meta['LONG_DOC'] #FIXME: near-duplicate of README.md | ||
#LICENSE = meta['LICENSE'] #FIXME: duplicate of LICENSE | ||
AUTHOR_EMAIL = '[email protected]' | ||
# write meta info file | ||
write_info_file(here, 'ppft', doc=README, license=LICENSE, | ||
version=__version__, author=__author__) | ||
del here, get_license_text, get_readme_as_rst, write_info_file | ||
|
||
# check if setuptools is available | ||
try: | ||
|
@@ -64,12 +39,12 @@ | |
# build the 'setup' call | ||
setup_kwds = dict( | ||
name='ppft', | ||
version=VERSION, | ||
version=__version__, | ||
description='distributed and parallel python', | ||
long_description = LONG_DOC, | ||
author = AUTHOR, | ||
long_description = README.strip(), | ||
author = __author__, | ||
author_email = AUTHOR_EMAIL, | ||
maintainer = AUTHOR, | ||
maintainer = __author__, | ||
maintainer_email = AUTHOR_EMAIL, | ||
license = '3-clause BSD', | ||
platforms = ['Linux', 'Windows', 'Mac'], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation) | ||
# Copyright (c) 2022 The Uncertainty Quantification Foundation. | ||
# License: 3-clause BSD. The full license text is available at: | ||
# - https://github.com/uqfoundation/ppft/blob/master/LICENSE | ||
|
||
__version__ = '1.7.6.6.dev0' | ||
__author__ = 'Mike McKerns' | ||
__contact__ = '[email protected]' | ||
|
||
|
||
def get_license_text(filepath): | ||
"open the LICENSE file and read the contents" | ||
try: | ||
LICENSE = open(filepath).read() | ||
except: | ||
LICENSE = '' | ||
return LICENSE | ||
|
||
|
||
def get_readme_as_rst(filepath): | ||
"open the README file and read the markdown as rst" | ||
try: | ||
fh = open(filepath) | ||
name, null = fh.readline().rstrip(), fh.readline() | ||
tag, null = fh.readline(), fh.readline() | ||
tag = "%s: %s" % (name, tag) | ||
split = '-'*(len(tag)-1)+'\n' | ||
README = ''.join((null,split,tag,split,'\n')) | ||
skip = False | ||
for line in fh: | ||
if line.startswith('['): | ||
continue | ||
elif skip and line.startswith(' http'): | ||
README += '\n' + line | ||
elif line.startswith('* '): | ||
README += line.replace('* ',' - ',1) | ||
elif line.startswith('-'): | ||
README += line.replace('-','=') + '\n' | ||
else: | ||
README += line | ||
skip = line.endswith(':\n') | ||
fh.close() | ||
except: | ||
README = '' | ||
return README | ||
|
||
|
||
def write_info_file(dirpath, modulename, **info): | ||
"""write the given info to 'modulename/__info__.py' | ||
info expects: | ||
doc: the module's long_description | ||
version: the module's version string | ||
author: the module's author string | ||
license: the module's license contents | ||
""" | ||
import os | ||
infofile = os.path.join(dirpath, '%s/__info__.py' % modulename) | ||
header = '''#!/usr/bin/env python | ||
# | ||
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation) | ||
# Copyright (c) 2022 The Uncertainty Quantification Foundation. | ||
# License: 3-clause BSD. The full license text is available at: | ||
# - https://github.com/uqfoundation/%s/blob/master/LICENSE | ||
''' % modulename #XXX: author and email are hardwired in the header | ||
doc = info.get('doc', None) | ||
version = info.get('version', None) | ||
author = info.get('author', None) | ||
license = info.get('license', None) | ||
with open(infofile, 'w') as fh: | ||
fh.write(header) | ||
if doc is not None: fh.write("'''%s'''\n\n" % doc) | ||
if version is not None: fh.write("__version__ = %r\n" % version) | ||
if author is not None: fh.write("__author__ = %r\n\n" % author) | ||
if license is not None: fh.write("__license__ = '''\n%s'''\n" % license) | ||
return |