从代码中删除注释的脚本。
XComment的Python项目详细描述
目录
安装
$ pip install XComment
用法
使用项目的cli与脚本交互。
处理文件
例如,您正在使用文件/tests/sources/html/index.html。
先决条件:virtualenv被激活(当然)。
要删除注释(不带注释的输出代码到输出文件),请调用
`shell $ comments_remover ./tests/sources/HTML/input.html HTML ./ ` 这需要/tests/sources/html/input.html,指定为html文件,并将前者的副本(显然删除了特定于html的注释)放到/中,命名为rc.input.html。后者是原始文件的名称,默认情况下前缀为rc.。
要突出显示注释(仅将注释输出到输出文件),请调用
$ comments_remover ./tests/sources/HTML/input.html HTML -p ./
处理目录
如果在开始时指定了目录路径,则脚本将使用指定语言递归地处理包含源的所有子目录。
档案
对于处理存档源,请使用选项-a
示例:
$ # remove comments $ comments_remover ./tmp/test.zip -a Python $ # highlight comments $ comments_remover ./tmp/test.zip -a -p Python
记录
-l选项启用日志记录(默认情况下在stdout中)
-f<;path>;指定日志文件的路径
示例:
$ comments_remover ./tmp/test.py -l -f ./remove.log Python
获取支持的语言列表
对于get list支持的语言,请使用-i选项。 结果列表将以json格式返回
$ comments_remover -i ["PHP", "Python", "CSS", "HTML", "JavaScript", "ActionScript", "Ruby", "Assembly", "AppleScript", "Bash", "CSharp", "VB", "XML", "SQL", "C"]
要查看完整的cli规范,请运行
$ comments_remover
开发
在本地启动和运行
使用以下配置进行测试:
- ubuntu 16.04/17
- Python3.6。
注意:下面出现的`./`引用项目根目录,除非另有明确说明。
在ubuntu上设置
进入外壳。
通过[pyenv installer](https://github.com/pyenv/pyenv-installer)安装pyenv
$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
按照有关如何在shell启动时初始化pyenv的说明进行操作,例如:
$ echo'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bash_profile
$ echo'eval "$(pyenv init -)"' >> ~/.bash_profile
$ echo'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
通过pyenv安装python 3.6.x,比如python3.6.2(最好是最新的微版本):
$ pyenv install 3.6.2
为项目创建虚拟机:
$ pyenv virtualenv 3.6.2 comments_remover
切换到您希望项目位于的任何目录,例如~:
$ cd ~
- 从github克隆项目:
- 通过ssh(首选方式):
$ git clone git@github.com:Singapore-Tech-Entrepreneurs/comments_remover.git
- 或通过https:
$ git clone https://github.com/Singapore-Tech-Entrepreneurs/comments_remover.git
切换到项目目录:
$ cd comments_remover
激活virtualenv:
$ pyenv activate comments_remover
安装项目依赖项:
$ pip install -U -r ./requirements.txt
安装测试依赖项:
$ pip install -U -r ./requirements-test.txt
(可选)安装[ipython](https://ipython.org/)交互式shell以加快开发速度:
$ pip install ipython==6.1.0
进入外壳。
通过[pyenv installer](https://github.com/pyenv/pyenv-installer)安装pyenv
$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
按照有关如何在shell启动时初始化pyenv的说明进行操作,例如:
$ echo'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bash_profile $ echo'eval "$(pyenv init -)"' >> ~/.bash_profile $ echo'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
通过pyenv安装python 3.6.x,比如python3.6.2(最好是最新的微版本):
$ pyenv install 3.6.2
为项目创建虚拟机:
$ pyenv virtualenv 3.6.2 comments_remover
切换到您希望项目位于的任何目录,例如~:
$ cd ~
- 从github克隆项目:
- 通过ssh(首选方式):
$ git clone git@github.com:Singapore-Tech-Entrepreneurs/comments_remover.git
- 或通过https:
$ git clone https://github.com/Singapore-Tech-Entrepreneurs/comments_remover.git
切换到项目目录:
$ cd comments_remover
激活virtualenv:
$ pyenv activate comments_remover
安装项目依赖项:
$ pip install -U -r ./requirements.txt
安装测试依赖项:
$ pip install -U -r ./requirements-test.txt
(可选)安装[ipython](https://ipython.org/)交互式shell以加快开发速度:
$ pip install ipython==6.1.0
要运行测试,只需
$ pytest ./
要查看覆盖率报告,
pytest --cov ./
你现在该走了。
部署
pip注册表
安装依赖项
$ python install -r requirements-deploy.txt
设置PYPI凭据
$ exportTWINE_USERNAME=<pypi username>
$ exportTWINE_PASSWORD=<pypi password>
创建分布
$ python setup.py sdist bdist_wheel
上传
$ twine upload dist/XComment-x.y.z.tar.gz
$ python install -r requirements-deploy.txt
设置PYPI凭据
$ exportTWINE_USERNAME=<pypi username> $ exportTWINE_PASSWORD=<pypi password>
创建分布
$ python setup.py sdist bdist_wheel
上传
$ twine upload dist/XComment-x.y.z.tar.gz
提示
如果您还没有使用[pycharm](https://www.jetbrains.com/pycharm/),请确保至少将其视为一个选项。 还可以查看[jetbrains toolbox](https://www.jetbrains.com/toolbox/),这是一个单独的工具,可以对它们进行规则化(jetbrains产品)。 要了解最新信息,请访问[pycharm blog](https://blog.jetbrains.com/pycharm/)。