1 Star 0 Fork 0

Walter Wu/pymodbus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
setup_commands.py 5.44 KB
一键复制 编辑 原始数据 按行查看 历史
dhoomakethu 提交于 2018-01-03 12:45 . Release 1.4.0 (#253)
from distutils.core import Command
import sys, os, shutil
# --------------------------------------------------------------------------- #
# Extra Commands
# --------------------------------------------------------------------------- #
class BuildApiDocsCommand(Command):
""" Helper command to build the available api documents
This scans all the subdirectories under api and runs the
build.py script underneath trying to build the api
documentation for the given format.
"""
description = "build all the projects api documents"
user_options = []
def initialize_options(self):
""" options setup """
if not os.path.exists('./build'):
os.mkdir('./build')
def finalize_options(self):
""" options teardown """
pass
def run(self):
""" command runner """
old_cwd = os.getcwd()
directories = (d for d in os.listdir('./doc/api') if not d.startswith('.'))
for entry in directories:
os.chdir('./doc/api/%s' % entry)
os.system('python build.py')
os.chdir(old_cwd)
class DeepCleanCommand(Command):
"""
Helper command to return the directory to a completely
clean state.
"""
description = "clean everything that we don't want"
user_options = []
trash = ['build', 'dist', 'pymodbus.egg-info',
os.path.join(os.path.join('doc', 'sphinx'), 'build'),
]
def initialize_options(self):
""" options setup """
pass
def finalize_options(self):
pass
def run(self):
""" command runner """
self._delete_pyc_files()
self._delete_trash_dirs()
def _delete_trash_dirs(self):
""" remove all directories created in building """
self._delete_pyc_files()
for directory in self.trash:
if os.path.exists(directory):
shutil.rmtree(directory)
@staticmethod
def _delete_pyc_files():
""" remove all python cache files """
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.pyc'):
os.remove(os.path.join(root,file))
class LintCommand(Command):
"""
Helper command to perform a lint scan of the
sourcecode and return the results.
"""
description = "perform a lint scan of the code"
user_options = []
def initialize_options(self):
""" options setup """
if not os.path.exists('./build'):
os.mkdir('./build')
def finalize_options(self):
pass
def run(self):
""" command runner """
scanners = [s for s in dir(self) if s.find('__try') >= 0]
for scanner in scanners:
if getattr(self, scanner)():
break
def _try_pyflakes(self):
try:
from pyflakes.scripts.pyflakes import main
sys.argv = """pyflakes pymodbus""".split()
main()
return True
except Exception:
return False
def _try_pychecker(self):
try:
import pychecker
sys.argv = """pychecker pymodbus/*.py""".split()
main()
return True
except: return False
def _try_pylint(self):
try:
import pylint
sys.argv = """pylint pymodbus/*.py""".split()
main()
return True
except: return False
class Python3Command(Command):
""" Helper command to scan for potential python 3
errors.
./setup.py scan_2to3 > build/diffs_2to3 build/report_2to3
"""
description = "perform 2to3 scan of the code"
user_options = []
directories = ['pymodbus', 'test', 'examples']
def initialize_options(self):
""" options setup """
if not os.path.exists('./build'):
os.mkdir('./build')
def finalize_options(self):
pass
def run(self):
""" command runner """
self._run_python3()
def _run_python3(self):
try:
from lib2to3.main import main
sys.argv = ['2to3'] + self.directories
main("lib2to3.fixes")
return True
except: return False
class Pep8Command(Command):
"""
Helper command to scan for potential pep8 violations
"""
description = "perform pep8 scan of the code"
user_options = []
directories = ['pymodbus']
def initialize_options(self):
""" options setup """
if not os.path.exists('./build'):
os.mkdir('./build')
def finalize_options(self):
pass
def run(self):
""" command runner """
self._run_pep8()
def _run_pep8(self):
try:
from pep8 import _main as main
sys.argv = """pep8 --repeat --count --statistics
""".split() + self.directories
main()
return True
except Exception:
return False
# --------------------------------------------------------------------------- #
# Command Configuration
# --------------------------------------------------------------------------- #
command_classes = {
'deep_clean': DeepCleanCommand,
'build_apidocs': BuildApiDocsCommand,
'lint': LintCommand,
'scan_2to3': Python3Command,
'pep8': Pep8Command,
}
# --------------------------------------------------------------------------- #
# Export command list
# --------------------------------------------------------------------------- #
__all__ = ['command_classes']
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wu-mingqi/pymodbus.git
git@gitee.com:wu-mingqi/pymodbus.git
wu-mingqi
pymodbus
pymodbus
master

搜索帮助