This repository was archived by the owner on Mar 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
109 lines (82 loc) · 2.74 KB
/
setup.py
File metadata and controls
109 lines (82 loc) · 2.74 KB
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
# -*- coding: utf-8 -*-
#pylint: disable=missing-docstring,wrong-import-order
import os
import sys
from distutils.cmd import Command
import yaml
from setuptools import setup
from setuptools.command.test import test as TestCommand
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
#import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
class CleanPyc(Command):
description = 'clean *.pyc'
user_options = []
exclude_list = ['.egg', '.git', '.idea', '__pycache__']
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print "start cleanup pyc files."
for pyc_path in self.pickup_pyc():
print "remove pyc: {0}".format(pyc_path)
os.remove(pyc_path)
print "the end."
def pickup_pyc(self):
for root, _, files in os.walk(os.getcwd()):
for fname in files:
if self.is_exclude(root):
continue
if not self.is_pyc(fname):
continue
yield os.path.join(root, fname)
@classmethod
def is_exclude(cls, path):
for item in CleanPyc.exclude_list:
if path.find(item) != -1:
return True
return False
@classmethod
def is_pyc(cls, path):
return path.endswith('.pyc')
def read_yaml(rel_path):
with open(rel_path, 'r') as stream:
data_loaded = yaml.safe_load(stream)
return data_loaded
def get_appveyor_version():
data = read_yaml("appveyor.yml")
if "version" not in data:
raise RuntimeError("Unable to find version string.")
appveyor_version = data["version"]
last_dot_idx = appveyor_version.rindex(".")
return appveyor_version[:last_dot_idx]
setup(name='polite',
version=get_appveyor_version(),
description='Easy functions for paths, logging and configuration files',
author='Mathew Toppper',
author_email='mathew.topper@dataonlygreater.com',
license="MIT",
packages=['polite'],
package_data={'polite': ['config/*.yaml']},
install_requires=[
'configobj',
'pyyaml',
'setuptools'
],
tests_require=['pytest'],
cmdclass={'test': PyTest,
'cleanpyc': CleanPyc,
},
)