CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/smc_pyutil/setup.py
Views: 687
1
# -*- coding: utf-8 -*-
2
3
# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
4
# License: MS-RSL – see LICENSE.md for details
5
6
###
7
# To do development on this, install it locally:
8
# pip install --user --upgrade smc_pyutil/
9
###
10
11
from __future__ import absolute_import
12
import os
13
from os.path import join
14
from setuptools import findall
15
16
path = os.path.dirname(os.path.realpath(__file__))
17
18
TEMPLATES = join("smc_pyutil", "templates")
19
# CRITICAL: I don't know any other way to ensure the permissions are
20
# right on the templates than this.
21
os.system("chmod a+r -R %s" % join(path, TEMPLATES))
22
# Next, some of the templates don't get copied over during pip install
23
# unless we explicitly set the data_files (as suggested by chatgpt):
24
template_files = findall(TEMPLATES)
25
template_data = [(f.split(TEMPLATES)[1], [f]) for f in template_files]
26
27
28
def readme():
29
with open('README.md') as f:
30
return f.read()
31
32
33
# from https://github.com/ninjaaron/fast-entry_points/ issue https://github.com/sagemathinc/cocalc/issues/2259
34
import fastentrypoints
35
from setuptools import setup, find_packages
36
37
# This checks, if setup.py is run with 'install --user'
38
# in that case we assume it is installed for development and do NOT change the python executable.
39
# Therefore we want to load the local library via the site.py mechanism.
40
# (this mimics http://svn.python.org/projects/python/trunk/Lib/distutils/dist.py, called in setup behind the scenes)
41
from distutils.core import Distribution
42
43
d = Distribution()
44
d.parse_command_line()
45
46
# CRITICAL!
47
# Uses a wrapped python executable to not load the user's "site" packages in ~/.local.
48
# Otherwise, setuptool's startup scripts do not work, if there is a conflicting
49
# setuptools version in .local/lib/python-packages (or, any other locally installed python lib)
50
# setting sys.executable changes the she-bang #!... at the top of these scripts
51
# credits to http://stackoverflow.com/a/17329493
52
# NOTE: the logic below does not work right now, because the nosite variant is not available
53
# during the build process. however, maybe there is a way to use the included
54
# cocalc-python3-clean script at some point in the future ...
55
python3_nosite = '/usr/local/bin/python3-nosite'
56
# don't overwrite for local smc-in-smc development
57
if 'user' not in list(d.command_options.get("install", {}).keys()):
58
# check, if python3_nosite exists and is executable
59
if os.path.isfile(python3_nosite) and os.access(python3_nosite, os.X_OK):
60
import sys
61
sys.executable = python3_nosite
62
63
# names for console scripts
64
# history: "smc" was based on the old name "SageMathCloud".
65
# Then, we switched to "cc" as a shortcut for CoCalc, but it's similar to the C compiler.
66
# Using "cocalc-*" is easier to discover and remember.
67
68
cs = [
69
'open = smc_pyutil.smc_open:main',
70
'close = smc_pyutil.smc_close:main',
71
]
72
73
for prefix in ['smc', 'cc', 'cocalc']:
74
add = cs.append
75
add('%s-sagews2pdf = smc_pyutil.sagews2pdf:main' % prefix)
76
add('%s-sws2sagews = smc_pyutil.sws2sagews:main' % prefix)
77
add('%s-open = smc_pyutil.smc_open:main' % prefix)
78
add('%s-new-file = smc_pyutil.new_file:main' % prefix)
79
add('%s-status = smc_pyutil.status:main' % prefix)
80
add('%s-jupyter-no-output= smc_pyutil.jupyter_delete_output:main' % prefix)
81
add('%s-ipynb2sagews = smc_pyutil.ipynb2sagews:main' % prefix)
82
add('%s-start = smc_pyutil.start_smc:main' % prefix)
83
add('%s-stop = smc_pyutil.stop_smc:main' % prefix)
84
add('%s-html2sagews = smc_pyutil.html2sagews:main' % prefix)
85
add('%s-sagews2ipynb = smc_pyutil.sagews2ipynb:main' % prefix)
86
87
# only cc and cocalc prefixes
88
if prefix != 'smc':
89
add('%s-first-steps = smc_pyutil.first_steps:main' % prefix)
90
add('%s-ipynb-to-pdf = smc_pyutil.ipynb_to_pdf:main' % prefix)
91
add('%s-close = smc_pyutil.smc_close:main' % prefix)
92
add('%s-jupyter-classic-open = smc_pyutil.jupyter_notebook:prepare_file_for_open'
93
% prefix)
94
95
setup(
96
name='smc_pyutil',
97
version='1.2',
98
description='CoCalc Python Utilities',
99
long_description=readme(),
100
url='https://github.com/sagemathinc/cocalc',
101
author='SageMath, Inc.',
102
author_email='[email protected]',
103
license='GPLv3+',
104
packages=find_packages(),
105
install_requires=['markdown2', 'psutil', 'PyYAML', 'ansi2html'],
106
zip_safe=False,
107
classifiers=[
108
'License :: OSI Approved :: GPLv3',
109
'Programming Language :: Python :: 2.7',
110
'Programming Language :: Python :: 3.5',
111
'Topic :: Mathematics :: Server',
112
],
113
keywords='server mathematics cloud',
114
scripts=[
115
'smc_pyutil/bin/smc-sage-server', 'smc_pyutil/bin/cocalc-python3-clean'
116
],
117
entry_points={'console_scripts': cs},
118
include_package_data=True,
119
package_data={'smc_pyutil': ['smc_pyutil/templates/*']},
120
data_files=template_data,
121
)
122
123