Skip to content

Commit

Permalink
Merge pull request #17 from Lukasa/windows
Browse files Browse the repository at this point in the history
Correctly install script on Windows
  • Loading branch information
sigmavirus24 committed Apr 17, 2013
2 parents 8fb0304 + df181c7 commit c9df6d1
Showing 1 changed file with 100 additions and 45 deletions.
145 changes: 100 additions & 45 deletions setup.py
@@ -1,45 +1,100 @@
try: try:
from setuptools import setup from setuptools import setup
except ImportError: except ImportError:
from distutils.core import setup # NOQA from distutils.core import setup # NOQA


# patch distutils if it can't cope with the "classifiers" or "download_url" # patch distutils if it can't cope with the "classifiers" or "download_url"
# keywords (prior to python 2.3.0). # keywords (prior to python 2.3.0).
from distutils.dist import DistributionMetadata from distutils.dist import DistributionMetadata
if not hasattr(DistributionMetadata, 'classifiers'): if not hasattr(DistributionMetadata, 'classifiers'):
DistributionMetadata.classifiers = None DistributionMetadata.classifiers = None
if not hasattr(DistributionMetadata, 'download_url'): if not hasattr(DistributionMetadata, 'download_url'):
DistributionMetadata.download_url = None DistributionMetadata.download_url = None


package = ['charade'] # When installing the charade script, we want to make it executable on Windows.
script = ['bin/charade'] # There are many ways to do this, but this seems to be the best. 'Borrowed'

# from: http://matthew-brett.github.io/pydagogue/installing_scripts.html
from charade import __version__ import os.path


setup( try:
name='charade', from distutils.command.install_scripts import install_scripts
version=__version__,
description='Universal encoding detector for python 2 and 3', BAT_FILE_TEMPLATE = r"""@echo off
long_description='\n\n'.join([open('README.rst').read(), set mypath=%~dp0
open('HISTORY.rst').read()]), set pyscript="%mypath%{FNAME}"
author='Mark Pilgrim', set /p line1=<%pyscript%
author_email='mark@diveintomark.org', if "%line1:~0,2%" == "#!" (goto :goodstart)
maintainer='Ian Cordasco', echo First line of %pyscript% does not start with "#!"
maintainer_email='graffatcolmingov@gmail.com', exit /b 1
url='https://github.com/sigmavirus24/charade', :goodstart
license="LGPL", set py_exe=%line1:~2%
keywords=['encoding', 'i18n', 'xml'], call %py_exe% %pyscript% %*
classifiers=[ """
"Development Status :: 4 - Beta",
"Environment :: Other Environment", class WindowsScriptCompat(install_scripts):
"Intended Audience :: Developers", """
"License :: OSI Approved :: GNU Library or Lesser General Public" A class that ensures that executable scripts correctly install on
" License (LGPL)", Windows.
"Operating System :: OS Independent", """
"Programming Language :: Python", def run(self):
"Topic :: Software Development :: Libraries :: Python Modules", install_scripts.run(self) # Ugh, old-style classes.
"Topic :: Text Processing :: Linguistic",
], if os.name == "nt":
scripts=script, for filepath in self.get_outputs():
packages=package, # If we can find an executable in the shebang of a script
) # file, make a batch file wrapper for it.
with open(filepath, 'rt') as f:
first_line = f.readline()

if not (first_line.startswith('#!') and
'python' in first_line.lower()):
continue

path, name = os.path.split(filepath)
froot, extension = os.path.splitext(name)
bat_file = os.path.join(path, froot + '.bat')
bat_contents = BAT_FILE_TEMPLATE.replace('{FNAME}', name)

if not self.dry_run:
with open(bat_file, 'wt') as out:
out.write(bat_contents)

return

except ImportError:
# Uh...let's just hope the user isn't on Windows!
pass

package = ['charade']
script = ['bin/charade']

from charade import __version__

setup(
name='charade',
version=__version__,
description='Universal encoding detector for python 2 and 3',
long_description='\n\n'.join([open('README.rst').read(),
open('HISTORY.rst').read()]),
author='Mark Pilgrim',
author_email='mark@diveintomark.org',
maintainer='Ian Cordasco',
maintainer_email='graffatcolmingov@gmail.com',
url='https://github.com/sigmavirus24/charade',
license="LGPL",
keywords=['encoding', 'i18n', 'xml'],
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Other Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Library or Lesser General Public"
" License (LGPL)",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Linguistic",
],
scripts=script,
packages=package,
cmdclass={'install_scripts': WindowsScriptCompat},
)

0 comments on commit c9df6d1

Please sign in to comment.