-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
137 lines (109 loc) · 4.06 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# coding: utf-8
import os
from setuptools import setup, find_packages
import importlib
import re
# Vars to set:
description = ""
author = "hayj"
author_email = "[email protected]"
version = "0.0.1" # replaced by the version in the main init file if exists
# Current dir:
thelibFolder = os.path.dirname(os.path.realpath(__file__))
# We take all requirements from the file or you can set it here :
requirementPath = thelibFolder + '/requirements.txt'
install_requires = [] # Example : ["gunicorn", "docutils >= 0.3", "lxml==0.5a7"]
dependency_links = []
if os.path.isfile(requirementPath):
with open(requirementPath) as f:
dependency_links = []
install_requires = []
required = f.read().splitlines()
for current in required:
if 'git' in current:
if "https" not in current:
current = current.replace("-e git", "https")
current = current.replace(".git#egg", "/zipball/master#egg")
dependency_links.append(current)
else:
install_requires.append(current)
# dependency_links is deprecated, see https://serverfault.com/questions/608192/pip-install-seems-to-be-ignoring-dependency-links
dependency_links = []
# We search a folder containing "__init__.py":
def walklevel(some_dir, level=1):
some_dir = some_dir.rstrip(os.path.sep)
assert os.path.isdir(some_dir)
num_sep = some_dir.count(os.path.sep)
for root, dirs, files in os.walk(some_dir):
yield root, dirs, files
num_sep_this = root.count(os.path.sep)
if num_sep + level <= num_sep_this:
del dirs[:]
mainPackageName = thelibFolder.lower().split('/')[-1]
for dirname, dirnames, filenames in walklevel(thelibFolder):
if "__init__.py" in filenames:
mainPackageName = dirname.split("/")[-1]
packagePath = thelibFolder + '/' + mainPackageName
# Get the version of the lib in the __init__.py:
initFilePath = packagePath + '/' + "__init__.py"
if os.path.isdir(packagePath):
with open(initFilePath, 'r') as f:
text = f.read()
result = re.search('^__version__\s*=\s*["\'](.*)["\']', text, flags=re.MULTILINE)
if result is not None:
version = result.group(1)
# To import the lib, use:
# thelib = importlib.import_module(mainPackageName)
# Readme content:
readme = None
readmePath = thelibFolder + '/README.md'
if os.path.isfile(readmePath):
try:
import pypandoc
readme = pypandoc.convert(readmePath, 'rst')
except(IOError, ImportError):
readme = open(readmePath).read()
packageName = thelibFolder.lower().split('/')[-1]
if packageName.startswith("pip-"):
packageName = mainPackageName.lower()
# The whole setup:
setup(
# The name for PyPi:
name=packageName,
# The version of the code which is located in the main __init__.py:
version=version,
# All packages to add:
packages=find_packages(),
# About the author:
author=author,
author_email=author_email,
# A short desc:
description=description,
# A long desc with the readme:
long_description=readme,
# Dependencies:
install_requires=install_requires,
dependency_links=dependency_links,
# For handle the MANIFEST.in:
include_package_data=True,
# The url to the official repo:
# url='https://',
# You can choose what you want here : https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Programming Language :: Python",
"Development Status :: 1 - Planning",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2.7",
"Topic :: Utilities",
],
# If you want a command line like "do-something", on a specific funct of the package :
# entry_points = {
# 'console_scripts': [
# 'wm-setup = workspacemanager.setup:generateSetup',
# 'wm-pew = workspacemanager.venv:generateVenv',
# 'wm-deps = workspacemanager.deps:installDeps',
# ],
# },
)