# CRITICAL: I don't know any other way to ensure the permissions are
# right on the templates than this
import os
from os.path import join
path = os.path.dirname(os.path.realpath(__file__))
os.system("chmod a+r -R %s"%join(path, "smc_pyutil", "templates"))

def readme():
    with open('README.md') as f:
        return f.read()

from setuptools import setup

# CRITICAL!
# -s tells python to not load the user's "site" packages in ~/.local
# otherwise, setuptool's startup scripts do not work, if there is a conflicting
# setuptools version in .local/lib/python-packages (or, any other locally installed python lib)
# setting sys.executable changes the she-bang #!... at the top of these scripts
# credits to http://stackoverflow.com/a/17329493
import sys
# MANUALLY disable when doing development!, where we do `pip install --user --upgrade smc_pyutil/`
sys.executable = '/usr/bin/python -s'

setup(
    name             = 'smc_pyutil',
    version          = '1.1',
    description      = 'SageMathCloud Python Utilities',
    long_description = readme(),
    url              = 'https://github.com/sagemathinc/smc',
    author           = 'SageMath, Inc.',
    author_email     = 'office@sagemath.com',
    license          = 'GPLv3+',
    packages         = ['smc_pyutil'],
    install_requires = ['markdown2', 'psutil'],
    zip_safe        = False,
    classifiers     = [
        'License :: OSI Approved :: GPLv3',
        'Programming Language :: Python :: 2.7',
        'Topic :: Mathematics :: Server',
    ],
    keywords        = 'server mathematics cloud',
    scripts         = ['smc_pyutil/bin/smc-sage-server'],
    entry_points    = {
        'console_scripts': [
            'open                 = smc_pyutil.smc_open:main',
            'smc-sagews2pdf       = smc_pyutil.sagews2pdf:main',
            'smc-sws2sagews       = smc_pyutil.sws2sagews:main',
            'smc-docx2txt         = smc_pyutil.docx2txt:main',
            'smc-open             = smc_pyutil.smc_open:main',
            'smc-new-file         = smc_pyutil.new_file:main',
            'smc-status           = smc_pyutil.status:main',
            'smc-jupyter          = smc_pyutil.jupyter_notebook:main',
            'smc-ls               = smc_pyutil.git_ls:main',
            'smc-compute          = smc_pyutil.smc_compute:main',
            'smc-start            = smc_pyutil.start_smc:main',
            'smc-stop             = smc_pyutil.stop_smc:main',
            'smc-update-snapshots = smc_pyutil.update_snapshots:update_snapshots',
            'smc-top              = smc_pyutil.smc_top:main',
        ]
    },
    include_package_data = True
)

@@ -1,16 +1,119 @@
+###%0A# To do development on this, install it locally:%0A#   pip install --user --upgrade smc_pyutil/%0A###%0A%0A
 # CRITICAL: I do
@@ -165,16 +165,16 @@
 ons are%0A
-
 # right 
@@ -456,16 +456,508 @@
  setup%0A%0A
+# This checks, if setup.py is run with 'install --user'%0A# in that case we assume it is installed for development and do NOT change the python executable.%0A# Therefore we want to load the local library via the site.py mechanism.%0A# (this mimics http://svn.python.org/projects/python/trunk/Lib/distutils/dist.py, called in setup behind the scenes)%0Afrom distutils.core import Distribution%0Ad = Distribution()%0Ad.parse_command_line()%0Aif 'user' not in d.command_options.get(%22install%22, %7B%7D).keys():%0A    
 # CRITIC
@@ -960,16 +960,20 @@
 ITICAL!%0A
+    
 # -s tel
@@ -1033,16 +1033,20 @@
 /.local%0A
+    
 # otherw
@@ -1117,16 +1117,20 @@
 licting%0A
+    
 # setupt
@@ -1217,16 +1217,20 @@
 on lib)%0A
+    
 # settin
@@ -1301,16 +1301,20 @@
 scripts%0A
+    
 # credit
@@ -1354,16 +1354,20 @@
 7329493%0A
+    
 import s
@@ -1373,107 +1373,12 @@
 sys%0A
-# MANUALLY disable when doing development!, where we do %60pip install --user --upgrade smc_pyutil/%60%0A
+    
 sys.

make it possible to use smc_pyutil locally for dev purposes