Skip to content

Commit

Permalink
Merge pull request #224 from twisted/8491-rodrigc-console
Browse files Browse the repository at this point in the history
Author: rodrigc
Reviewer: alex, adiroiban
Fixes: #8491

Convert scripts in bin to console_scripts
  • Loading branch information
rodrigc committed Jul 16, 2016
2 parents 2dd6d50 + a001904 commit c5a4c63
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 204 deletions.
7 changes: 2 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ include NEWS README.rst INSTALL.rst CONTRIBUTING LICENSE code_of_conduct.md

# Exclude admin scripts and things only useful when running from a source checkout
exclude codecov.yml
exclude bin/_preamble.py
exclude admin
exclude bin/admin
recursive-exclude admin *
recursive-exclude bin/admin *
prune bin
prune admin

# Include test-running utilities for downstream packagers
include tox.ini .coveragerc
Expand Down
15 changes: 0 additions & 15 deletions bin/cftp

This file was deleted.

15 changes: 0 additions & 15 deletions bin/ckeygen

This file was deleted.

15 changes: 0 additions & 15 deletions bin/conch

This file was deleted.

20 changes: 0 additions & 20 deletions bin/mailmail

This file was deleted.

12 changes: 0 additions & 12 deletions bin/pyhtmlizer

This file was deleted.

15 changes: 0 additions & 15 deletions bin/tkconch

This file was deleted.

18 changes: 0 additions & 18 deletions bin/twistd

This file was deleted.

6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def main(args):
requirements = ["zope.interface >= 3.6.0"]

from twisted.python.dist import (
STATIC_PACKAGE_METADATA, getExtensions, getScripts,
STATIC_PACKAGE_METADATA, getExtensions, getConsoleScripts,
setup, _EXTRAS_REQUIRE)

setup_args = STATIC_PACKAGE_METADATA.copy()
Expand All @@ -43,7 +43,9 @@ def main(args):
packages=setuptools.find_packages(),
install_requires=requirements,
conditionalExtensions=getExtensions(),
scripts=getScripts(),
entry_points={
'console_scripts': getConsoleScripts()
},
include_package_data=True,
zip_safe=False,
extras_require=_EXTRAS_REQUIRE,
Expand Down
19 changes: 4 additions & 15 deletions setup3.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,26 @@ def find_package_modules(self, package, package_dir):



class PickyBuildScripts(build_scripts):
"""
A version of build_scripts which doesn't install the scripts that aren't
yet ported to Python 3.
"""
def copy_scripts(self):
from twisted.python.dist3 import portedScripts
self.scripts = portedScripts
return super(PickyBuildScripts, self).copy_scripts()



def main():
# Make sure the to-be-installed version of Twisted is used, if available,
# since we're importing from it:
if os.path.exists('twisted'):
sys.path.insert(0, '.')

from twisted.python.dist import (STATIC_PACKAGE_METADATA, _EXTRAS_REQUIRE,
getExtensions, getScripts, setup)
getConsoleScripts, getExtensions, setup)

args = STATIC_PACKAGE_METADATA.copy()
args.update(dict(
cmdclass={
'build_py': PickyBuildPy,
'build_scripts': PickyBuildScripts,
},
packages=find_packages(),
install_requires=["zope.interface >= 4.0.2"],
conditionalExtensions=getExtensions(),
scripts=getScripts(),
entry_points={
'console_scripts': getConsoleScripts()
},
include_package_data=True,
zip_safe=False,
extras_require=_EXTRAS_REQUIRE,
Expand Down
28 changes: 14 additions & 14 deletions twisted/python/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,23 @@ def getExtensions():



def getScripts(basedir=''):
def getConsoleScripts():
"""
Returns a list of scripts for Twisted.
"""
scriptdir = os.path.join(basedir, 'bin')
if not os.path.isdir(scriptdir):
# Probably a project-specific tarball, in which case only this
# project's bins are included in 'bin'
scriptdir = os.path.join(basedir, 'bin')
if not os.path.isdir(scriptdir):
return []
thingies = os.listdir(scriptdir)
for specialExclusion in ['_preamble.py', '_preamble.pyc']:
if specialExclusion in thingies:
thingies.remove(specialExclusion)
return list(filter(os.path.isfile,
[os.path.join(scriptdir, x) for x in thingies]))
scripts = [ "cftp = twisted.conch.scripts.cftp:run",
"ckeygen = twisted.conch.scripts.ckeygen:run",
"conch = twisted.conch.scripts.conch:run",
"mailmail = twisted.mail.scripts.mailmail:run",
"pyhtmlizer = twisted.scripts.htmlizer:run",
"tkconch = twisted.conch.scripts.tkconch:run"
]
portedToPython3Scripts = [ "trial = twisted.scripts.trial:run",
"twistd = twisted.scripts.twistd:run" ]
if _PY3:
return portedToPython3Scripts
else:
return scripts + portedToPython3Scripts


## Helpers and distutil tweaks
Expand Down
2 changes: 0 additions & 2 deletions twisted/python/dist3.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,5 +597,3 @@
]

modulesToInstall = modules + testModules + almostModules

portedScripts = ["bin/trial", "bin/twistd"]
56 changes: 0 additions & 56 deletions twisted/python/test/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,62 +253,6 @@ def test_getVersionCore(self):



class GetScriptsTests(TestCase):
"""
Tests for L{dist.getScripts} which returns the scripts which should be
included in the distribution of a project.
"""

def test_excludedPreamble(self):
"""
L{dist.getScripts} includes neither C{"_preamble.py"} nor
C{"_preamble.pyc"}.
"""
basedir = FilePath(self.mktemp())
bin = basedir.child('bin')
bin.makedirs()
bin.child('_preamble.py').setContent(b'some preamble code\n')
bin.child('_preamble.pyc').setContent(b'some preamble byte code\n')
bin.child('program').setContent(b'good program code\n')
scripts = dist.getScripts(basedir=basedir.path)
self.assertEqual(scripts, [bin.child('program').path])


def test_scriptsInRelease(self):
"""
getScripts should return the scripts associated with a project
in the context of a released subproject tarball.
"""
basedir = self.mktemp()
os.mkdir(basedir)
os.mkdir(os.path.join(basedir, 'bin'))
with open(os.path.join(basedir, 'bin', 'exy'), 'w') as f:
f.write('yay')
scripts = dist.getScripts(basedir=basedir)
self.assertEqual(len(scripts), 1)
self.assertEqual(os.path.basename(scripts[0]), 'exy')


def test_getScriptsTopLevel(self):
"""
getScripts returns scripts that are (only) in the top level bin
directory.
"""
basedir = FilePath(self.mktemp())
basedir.createDirectory()
bindir = basedir.child("bin")
bindir.createDirectory()
included = bindir.child("included")
included.setContent(b"yay included")
subdir = bindir.child("subdir")
subdir.createDirectory()
subdir.child("not-included").setContent(b"not included")

scripts = dist.getScripts(basedir=basedir.path)
self.assertEqual(scripts, [included.path])



class DummyCommand:
"""
A fake Command.
Expand Down
2 changes: 2 additions & 0 deletions twisted/topfiles/8491.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Scripts such as cftp, ckeygen, conch, mailmail, pyhtmlizer, tkconch, twistd and trial have been updated to be setuptools console scripts.

0 comments on commit c5a4c63

Please sign in to comment.