-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RF: more of common logistics into setup_support #3600
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
92ea5d2
RF: move more common functionality from setup.py to setup_support.py
yarikoptic a849e23
RF: move common handling around setup() into setup_support.datalad_se…
yarikoptic 40dac18
DOC: fixed up docstring for get_version to match reality
yarikoptic 652cd4d
BF: provide appname (hardcoded to datalad) within BuildManPage to get…
yarikoptic 9d72921
ENH: do not bother converting README.md with recent setuptools
yarikoptic b79be71
ENH: provide .handle_method for BuildManPage so we could have proper …
yarikoptic 85a67fa
RF: use "datalad.extensions" instead of coincidentally consistently n…
yarikoptic 5ec34f2
RF: a "more correct" comparison for setuptools"s version
yarikoptic d86461a
RF: move all build support modules under datalad_build_support package
yarikoptic 9e7e125
BF: use dirname instead of join with pardir so could be used when sym…
yarikoptic e0bd962
BF: man -- do not double quote name_version in the title
yarikoptic 6f700cb
BF(py2): datalad_build_support: Add __init__.py
kyleam b10b873
MV: Prefix datalad_build_support/ with an underscore
kyleam 65eb761
ENH: added forgotten __init__ in _datalad_build_support with __version__
yarikoptic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,45 +7,18 @@ | |
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## | ||
|
||
from os.path import ( | ||
dirname, | ||
join as opj, | ||
sep as pathsep, | ||
splitext, | ||
) | ||
|
||
from setuptools import ( | ||
findall, | ||
find_packages, | ||
setup, | ||
) | ||
|
||
from setup_support import ( | ||
BuildConfigInfo, | ||
BuildManPage, | ||
BuildRSTExamplesFromScripts, | ||
BuildSchema, | ||
get_version, | ||
setup_entry_points, | ||
) | ||
|
||
|
||
def findsome(subdir, extensions): | ||
"""Find files under subdir having specified extensions | ||
findsome, | ||
datalad_setup) | ||
|
||
Leading directory (datalad) gets stripped | ||
""" | ||
return [ | ||
f.split(pathsep, 1)[1] for f in findall(opj('datalad', subdir)) | ||
if splitext(f)[-1].lstrip('.') in extensions | ||
] | ||
|
||
# datalad version to be installed | ||
version = get_version() | ||
|
||
# Only recentish versions of find_packages support include | ||
# datalad_pkgs = find_packages('.', include=['datalad*']) | ||
# so we will filter manually for maximal compatibility | ||
datalad_pkgs = [pkg for pkg in find_packages('.') if pkg.startswith('datalad')] | ||
|
||
requires = { | ||
'core': [ | ||
|
@@ -153,22 +126,6 @@ def findsome(subdir, extensions): | |
# 'build_py': DataladBuild | ||
} | ||
|
||
# PyPI doesn't render markdown yet. Workaround for a sane appearance | ||
# https://github.com/pypa/pypi-legacy/issues/148#issuecomment-227757822 | ||
README = opj(dirname(__file__), 'README.md') | ||
try: | ||
import pypandoc | ||
long_description = pypandoc.convert(README, 'rst') | ||
except (ImportError, OSError) as exc: | ||
# attempting to install pandoc via brew on OSX currently hangs and | ||
# pypandoc imports but throws OSError demanding pandoc | ||
print( | ||
"WARNING: pypandoc failed to import or thrown an error while converting" | ||
" README.md to RST: %r .md version will be used as is" % exc | ||
) | ||
long_description = open(README).read() | ||
|
||
|
||
# | ||
# Avoid using entry_points due to their hefty overhead | ||
# | ||
|
@@ -196,25 +153,21 @@ def findsome(subdir, extensions): | |
]}) | ||
setup_kwargs['entry_points'] = entry_points | ||
|
||
setup( | ||
name="datalad", | ||
author="The DataLad Team and Contributors", | ||
author_email="[email protected]", | ||
version=version, | ||
datalad_setup( | ||
'datalad', | ||
description="data distribution geared toward scientific datasets", | ||
long_description=long_description, | ||
packages=datalad_pkgs, | ||
install_requires= | ||
requires['core'] + requires['downloaders'] + | ||
requires['publish'] + requires['metadata'], | ||
extras_require=requires, | ||
cmdclass=cmdclass, | ||
package_data={ | ||
'datalad': | ||
findsome('resources', {'sh', 'html', 'js', 'css', 'png', 'svg', 'txt', 'py'}) + | ||
findsome('resources', | ||
{'sh', 'html', 'js', 'css', 'png', 'svg', 'txt', 'py'}) + | ||
findsome(opj('downloaders', 'configs'), {'cfg'}) + | ||
findsome(opj('distribution', 'tests'), {'yaml'}) + | ||
findsome(opj('metadata', 'tests', 'data'), {'mp3', 'jpg', 'pdf'}) | ||
}, | ||
**setup_kwargs | ||
) | ||
) |
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 |
---|---|---|
|
@@ -11,24 +11,27 @@ | |
import sys | ||
from genericpath import exists | ||
from os import linesep, makedirs | ||
from os.path import dirname, join as opj | ||
from os.path import dirname, join as opj, sep as pathsep, splitext | ||
|
||
from distutils.core import Command | ||
from distutils.errors import DistutilsOptionError | ||
import datetime | ||
|
||
from setuptools import findall, find_packages, setup | ||
|
||
import formatters as fmt | ||
|
||
|
||
def _path_rel2file(p): | ||
return opj(dirname(__file__), p) | ||
|
||
|
||
def get_version(): | ||
def get_version(name): | ||
"""Load version of datalad from version.py without entailing any imports | ||
""" | ||
# This might entail lots of imports which might not yet be available | ||
# so let's do ad-hoc parsing of the version.py | ||
with open(opj(dirname(__file__), 'datalad', 'version.py')) as f: | ||
with open(opj(dirname(__file__), name, 'version.py')) as f: | ||
version_lines = list(filter(lambda x: x.startswith('__version__'), f)) | ||
assert (len(version_lines) == 1) | ||
return version_lines[0].split('=')[1].strip(" '\"\t\n") | ||
|
@@ -361,3 +364,78 @@ def _provide_lean_script_contents( | |
setup_kwargs['scripts'] = scripts | ||
|
||
return setup_kwargs | ||
|
||
|
||
def get_long_description_from_README(): | ||
"""Read README.md, convert to .rst using pypandoc | ||
|
||
If pypandoc is not available or fails - just output original .md | ||
""" | ||
# PyPI doesn't render markdown yet. Workaround for a sane appearance | ||
# https://github.com/pypa/pypi-legacy/issues/148#issuecomment-227757822 | ||
yarikoptic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
README = opj(dirname(__file__), 'README.md') | ||
try: | ||
import pypandoc | ||
return pypandoc.convert(README, 'rst') | ||
except (ImportError, OSError) as exc: | ||
# attempting to install pandoc via brew on OSX currently hangs and | ||
# pypandoc imports but throws OSError demanding pandoc | ||
print( | ||
"WARNING: pypandoc failed to import or thrown an error while " | ||
"converting" | ||
" README.md to RST: %r .md version will be used as is" % exc | ||
) | ||
return open(README).read() | ||
|
||
|
||
def findsome(subdir, extensions): | ||
"""Find files under subdir having specified extensions | ||
|
||
Leading directory (datalad) gets stripped | ||
""" | ||
return [ | ||
f.split(pathsep, 1)[1] for f in findall(opj('datalad', subdir)) | ||
if splitext(f)[-1].lstrip('.') in extensions | ||
] | ||
|
||
|
||
def datalad_setup(name, **kwargs): | ||
"""A helper for a typical invocation of setuptools.setup. | ||
|
||
If not provided in kwargs, following fields will be autoset to the defaults | ||
or obtained from the present on the file system files: | ||
|
||
- author | ||
- author_email | ||
- packages -- all found packages which start with `name` | ||
- long_description -- converted to .rst using pypandoc README.md | ||
- version -- parsed `__version__` within `name/version.py` | ||
|
||
Parameters | ||
---------- | ||
name: str | ||
Name of the Python package | ||
**kwargs: | ||
The rest of the keyword arguments passed to setuptools.setup as is | ||
""" | ||
# Simple defaults | ||
for k, v in { | ||
'author': "The DataLad Team and Contributors", | ||
'author_email': "[email protected]" | ||
}.items(): | ||
if kwargs.get(k) is None: | ||
kwargs[k] = v | ||
|
||
# More complex, requiring some function call | ||
|
||
# Only recentish versions of find_packages support include | ||
# packages = find_packages('.', include=['datalad*']) | ||
# so we will filter manually for maximal compatibility | ||
if kwargs.get('packages') is None: | ||
kwargs['packages'] = [pkg for pkg in find_packages('.') if pkg.startswith(name)] | ||
if kwargs.get('long_description') is None: | ||
kwargs['long_description'] = get_long_description_from_README() | ||
if kwargs.get('version') is None: | ||
kwargs['version'] = get_version(name) | ||
|
||
return setup(name=name, **kwargs) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring should be updated to drop hard-coded "datalad".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted and pushed