Skip to content

Commit

Permalink
python.distutils plugin: setup.py keywords
Browse files Browse the repository at this point in the history
fixes #422, connected to #422
  • Loading branch information
arcivanov committed Nov 23, 2016
1 parent a02dca9 commit c3ee349
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def run(self):
dependency_links = ['https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz'],
zip_safe=True,
cmdclass={'install': install},
keywords='',
)
""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def run(self):
dependency_links = ['https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz'],
zip_safe=True,
cmdclass={'install': install},
keywords='',
)
""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def run(self):
dependency_links = ['https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz'],
zip_safe=True,
cmdclass={'install': install},
keywords='',
)
""")

Expand Down
17 changes: 17 additions & 0 deletions src/main/python/pybuilder/plugins/python/distutils_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def run(self):
dependency_links = $dependency_links,
zip_safe=True,
cmdclass={'install': install},
keywords=$setup_keywords,
)
""")

Expand Down Expand Up @@ -124,6 +125,10 @@ def initialize_distutils_plugin(project):
project.set_property_if_unset("distutils_readme_file", "README.md")
project.set_property_if_unset("distutils_description_overwrite", False)

project.set_property_if_unset("distutils_console_scripts", None)
project.set_property_if_unset("distutils_entry_points", None)
project.set_property_if_unset("distutils_setup_keywords", None)


@after("prepare")
def set_description(project, logger):
Expand Down Expand Up @@ -176,6 +181,7 @@ def render_setup_script(project):
else ""),
"preinstall_script": _normalize_setup_post_pre_script(project.setup_preinstall_script or "pass"),
"postinstall_script": _normalize_setup_post_pre_script(project.setup_postinstall_script or "pass"),
"setup_keywords": build_setup_keywords(project)
}

return SETUP_TEMPLATE.substitute(template_values)
Expand Down Expand Up @@ -473,6 +479,17 @@ def build_entry_points_string(project):
return result


def build_setup_keywords(project):
setup_keywords = project.get_property("distutils_setup_keywords")
if not setup_keywords or not len(setup_keywords):
return repr("")

if isinstance(setup_keywords, (list, tuple)):
return repr(" ".join(setup_keywords))

return repr(setup_keywords)


def build_classifiers_string(project):
classifiers = project.get_property('distutils_classifiers', [])
return build_string_from_array(classifiers, indent=12)
Expand Down
16 changes: 16 additions & 0 deletions src/unittest/python/plugins/python/distutils_plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
_normalize_setup_post_pre_script,
build_string_from_array,
_run_process_and_wait,
build_setup_keywords,
)
from test_utils import (PyBuilderTestCase,
patch,
Expand Down Expand Up @@ -443,6 +444,7 @@ def run(self):
dependency_links = ['https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz'],
zip_safe=True,
cmdclass={'install': install},
keywords='',
)
""", actual_setup_script)

Expand Down Expand Up @@ -510,6 +512,7 @@ def run(self):
dependency_links = ['https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz'],
zip_safe=True,
cmdclass={'install': install},
keywords='',
)
""", actual_setup_script)

Expand Down Expand Up @@ -548,6 +551,19 @@ def test_should_render_entry_points_when_property_is_set(self):
" ]\n"
" }", actual_setup_script)

def test_should_render_setup_keywords_when_property_is_set(self):
self.project.set_property("distutils_setup_keywords", "a b c")
actual_setup_script = build_setup_keywords(self.project)
self.assertEquals("'a b c'", actual_setup_script)

self.project.set_property("distutils_setup_keywords", ["a"])
actual_setup_script = build_setup_keywords(self.project)
self.assertEquals("'a'", actual_setup_script)

self.project.set_property("distutils_setup_keywords", ("a b"))
actual_setup_script = build_setup_keywords(self.project)
self.assertEquals("'a b'", actual_setup_script)

def test_should_render_single_entry_pointproperty_is_set(self):
self.project.set_property("distutils_entry_points", {'foo_entry': "release = zest.releaser.release:main"})

Expand Down

0 comments on commit c3ee349

Please sign in to comment.