从代码中删除注释的脚本。

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上设置
  1. 进入外壳。

  2. 通过[pyenv installer](https://github.com/pyenv/pyenv-installer)安装pyenv

    $ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
    
    ./docs/images/pyenv-installer.png
  3. 按照有关如何在shell启动时初始化pyenv的说明进行操作,例如:

    $ echo'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bash_profile
    $ echo'eval "$(pyenv init -)"' >> ~/.bash_profile
    $ echo'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
    
    ./docs/images/initialize-pyenv-with-shell.png
  4. 通过pyenv安装python 3.6.x,比如python3.6.2(最好是最新的微版本):

    $ pyenv install 3.6.2
    
    ./docs/images/pyenv-install-3-6-2.png
  5. 为项目创建虚拟机:

    $ pyenv virtualenv 3.6.2 comments_remover
    
    ./docs/images/pyenv-virtualenv-3.6.2-comments_remover.pngA
  6. 切换到您希望项目位于的任何目录,例如~

    $ cd ~
    
    ./docs/images/cd-~.pngA
  7. 从github克隆项目:
    • 通过ssh(首选方式):
    $ git clone git@github.com:Singapore-Tech-Entrepreneurs/comments_remover.git
    
    ./docs/images/git-clone-gitatgithub-com-singapore-tech-entrepreneurs-comments-remover-git.png
    • 或通过https:
    $ git clone https://github.com/Singapore-Tech-Entrepreneurs/comments_remover.git
    
    ./docs/images/git-clone-https-github-com-singapore-tech-entrepreneurs-comments-remover-git.png
  8. 切换到项目目录:

    $ cd comments_remover
    
    ./docs/images/cd-comments_remover.png
  9. 激活virtualenv:

    $ pyenv activate comments_remover
    
    ./docs/images/pyenv-activate-comments_remover.png
  10. 安装项目依赖项:

    $ pip install -U -r ./requirements.txt
    
    ./docs/images/pip-install-u-r-requirements-txt.png
  11. 安装测试依赖项:

    $ pip install -U -r ./requirements-test.txt
    
    ./docs/images/pip-install-u-r-requirements-test-txt.png
  12. (可选)安装[ipython](https://ipython.org/)交互式shell以加快开发速度:

    $ pip install ipython==6.1.0
    
    ./docs/images/pip-install-ipython-6-1-0.png

要运行测试,只需

$ pytest ./
./docs/images/pytest.png

要查看覆盖率报告,

pytest --cov ./
./docs/images/pytest-cov.png

你现在该走了。

部署

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

提示

如果您还没有使用[pycharm](https://www.jetbrains.com/pycharm/),请确保至少将其视为一个选项。 还可以查看[jetbrains toolbox](https://www.jetbrains.com/toolbox/),这是一个单独的工具,可以对它们进行规则化(jetbrains产品)。 要了解最新信息,请访问[pycharm blog](https://blog.jetbrains.com/pycharm/)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java testNG优先级和依赖性   java JPQL:以下WHERE子句使用继承时出现问题   java是否可以在JTable渲染器中进行查询?   java如何在javascript中向url添加变量并使用@PathVariable获取   在外部jframe中显示java控制台   java I无法连接到IBM MQ的QM错误2035 MQRC\u未授权   apache zookeeper如何解决Storm应用程序在本地集群中运行时出现的错误“java.net.ConnectException:连接被拒绝:connect”?   读取第一行的java文本文件具有键和第二行前进值   java在哪个线程池中affinityRun提交任务?如何配置线程数?   Java拆分字符串正则表达式:前导空格   如何在Java中读取Pop3服务器中的入站电子邮件   带/不带布局管理器的swing Java定位GUI组件   在Spring Webflux中使用域设置java多会话ID   http Java web将其内容刮除,但只刮除正文样式,然后不退出并永远运行   java图形绘制组件和循环故障