从sublime text外部在sublime text中运行python

sublime_harness的Python项目详细描述


升华线束

Build Status

从Sublime Text之外的Sublime Text中运行Python

sublime-harness的构建允许在Sublime Text的上下文中执行任意python。它也是Sublime plugin tests框架的一部分。

Currently, only Linux is supported but OSX and Windows support are planned.

折旧通知

我们决定不赞成sublime-harness,而赞成randy3k/UnitTesting

它有更大的平台支持,并且为本地开发设计的脆弱性更小。

https://github.com/randy3k/UnitTesting

开始

使用pip install sublime_harness

安装模块
importos,timefromsublime_harnessimportHarnessharness=Harness()script="""
import sublime

# Harness will run the `run` function
def run():
    with open('/tmp/hi', 'w') as f:
        f.write('Hello World!')
    sublime.run_command('exit')"""harness.run(script)# Wait for our file to exist (Sublime Text is forked and not synchronous)output_file='/tmp/hi'while(notos.path.exists(output_file)oros.stat(output_file).st_size==0):time.sleep(0.1)# Read our datawithopen(output_file)asf:printf.read()# Hello World!

文件

sublime_harness为您的所有引导需要提供Harness类。

Sublime Text将通过sublime-info解析,这允许通过环境变量重写。

线束。
Harness()"""Generate a new Harness for Sublime Text

When initialized, `Harness` allocates a directory (currently,
same for all harnesses) for your script.
"""

harness.目录
harness.directory"""Directory where `run` will be execute

If you would like to load relative modules, they should be copied to this directory."""

线束。运行
harness.run(script)"""Python to execute within the context of Sublime Text

**YOU MUST CLEAN UP AFTER RUNNING THIS METHOD VIA `close`**

You can only run one harness at a time due to the lack of namespacing.

:param script: Python to execute within Sublime Text
:type script: str
"""

线束。关闭
harness.close()"""Cleans up harness files"""

示例

Harness.dictionary中所述,可以相对于脚本加载外部文件。这是一个如何设置和使用它们的示例。

# Set up a new harnessimportos,timefromsublime_harnessimportHarnessharness=Harness()# Copy over a local file to the directorydest_hello_path=harness.directory+'/hello.py'withopen(dest_hello_path,'w')asf:f.write('hello = "World!"')# Generate and run our temporary taskscript="""
import os
import sublime

try :
    from hello import hello  # ST 2 compatible
except:
    from .hello import hello  # ST 3 compatible

def run():
    with open('/tmp/hi-directory', 'w') as f:
        f.write(hello)
    sublime.run_command('exit')
"""harness.run(script)output_file='/tmp/hi-directory'while(notos.path.exists(output_file)oros.stat(output_file).st_size==0):time.sleep(0.1)# Grab the file outputwithopen(output_file)asf:printf.read()# 'World!'# Remove the plugin and our fileharness.close()os.unlink(dest_hello_path)

贡献

代替正式的形式指南,注意保持现有的编码风格。为任何新的或更改的功能添加单元测试。通过nosetests进行测试。

捐赠

支持此项目并通过gittip支持others by twolfson

Support via Gittip

无证

截至2013年10月16日,Todd Wolfson已将此存储库及其内容发布到公共域。

它已在UNLICENSE下发布。

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

推荐PyPI第三方库


热门话题
java将Scanner对象作为构造函数参数传递给UserInterface类   spring未能启动bean“subtocolWebSocketHandler”;嵌套的例外是java。lang.IllegalArgumentException:没有处理程序   Java EE应用程序中后台服务的多线程Java线程(设置守护进程和优先级)?   java Pull to refresh返回列表的第一个位置   无法将comparator类转换为java。可比的   java将json从servlet传递到dojo   JavaHibernate:将子类实例转换为超类实例   java警告调用servlet类时非法反射访问   java静态变量值   java@Entity和@embeddeble之间有什么区别   java将作业配置导入公共作业配置类(注释配置)   sql公共表表达式(以values语句开头)在java中给出错误   java在ImageJ中使用ImageProcessor   java PostgreSQL executeBatch()会随着时间的推移而变慢   java在安卓中以表格形式排列sqllite表数据?   java中SVG的swing定制呈现   java删除与另一个实体映射的实体   java何时/如何添加ListView适配器,使用back按钮恢复它?(片段)   java为什么IBinder和Binder之间的类型转换不是非法的?   java在方法参数列表中使用ArrayList或List