Created
January 21, 2016 11:05
-
-
Save takluyver/0a45729a356e002d22e3 to your computer and use it in GitHub Desktop.
Flituptools
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
from pathlib import Path | |
import re | |
# This is a code smell all by itself | |
import setuptools | |
from flit import common, inifile | |
fields_same_name = [ | |
'name', | |
'version', | |
'author', | |
'author_email', | |
'description', | |
'classifiers', | |
] | |
fields_diff_name = { | |
'description': 'summary', | |
'url': 'home_page', | |
} | |
def setuptools_requirement_format(req): | |
m = re.match(r'(?P<name>[\w\-.]+)\s*(\((?P<vers>.*?)\))?(;(?P<env>.*))?', req) | |
# TODO: doesn't handle environment markers | |
name, vers = m.group('name', 'vers') | |
if vers: | |
return name + ' ' + vers | |
else: | |
return name | |
def setup(ini_path=Path('flit.ini'), package_data=None): | |
ini_info = inifile.read_pkg_ini(ini_path) | |
module = common.Module(ini_info['module'], ini_path.parent) | |
metadata = common.make_metadata(module, ini_info) | |
kwargs = {} | |
for field in fields_same_name: | |
val = getattr(metadata, field, None) | |
if val: | |
kwargs[field] = val | |
for st_field, metadata_field in fields_diff_name.items(): | |
val = getattr(metadata, metadata_field, None) | |
if val: | |
kwargs[st_field] = val | |
if module.is_package: | |
kwargs['packages'] = setuptools.find_packages(include=[module.name+'*']) | |
else: | |
kwargs['py_modules'] = [module.name] | |
if metadata.requires_dist: | |
kwargs['install_requires'] = [setuptools_requirement_format(req) | |
for req in metadata.requires_dist] | |
print(kwargs['install_requires']) | |
if ini_info['scripts']: | |
kwargs['entry_points'] = {'console_scipts': | |
['{} = {}:{}'.format(k, mod, func) | |
for k, (mod, func) in ini_info['scripts'].items()] | |
} | |
if package_data is not None: | |
kwargs['package_data'] = package_data | |
# You're on your own from here | |
setuptools.setup(**kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Carreau @jhamrick @ellisonbg : If you really want to have a
setup.py
alongside flit metadata, you can use this, and the setup.py will look like:I don't recommend doing this, and I don't intend to support it or use it myself, but it's simple enough and it works. Feel free to improve on it.