ipython-autotime 项目教程

ipython-autotime 项目教程

ipython-autotimeTime everything in IPython项目地址:https://gitcode.com/gh_mirrors/ip/ipython-autotime

1. 项目的目录结构及介绍

ipython-autotime/
├── LICENSE
├── MANIFEST.in
├── README.md
├── autotime/
│   ├── __init__.py
│   └── autotime.py
├── setup.py
└── tests/
    └── test_autotime.py
  • LICENSE: 项目的许可证文件,采用 Apache 2.0 许可证。
  • MANIFEST.in: 包含需要包含在发布包中的文件列表。
  • README.md: 项目说明文档,包含安装和使用说明。
  • autotime/: 核心代码目录,包含扩展的主要实现。
    • __init__.py: 模块初始化文件。
    • autotime.py: 扩展的主要实现文件。
  • setup.py: 用于安装和发布项目的配置文件。
  • tests/: 测试代码目录,包含测试用例。
    • test_autotime.py: 针对 autotime 模块的测试用例。

2. 项目的启动文件介绍

项目的启动文件是 autotime/autotime.py。这个文件包含了 IPython 扩展的主要实现,负责在每个代码块执行时记录和显示执行时间。

# autotime/autotime.py
from IPython.core.magic import Magics, magics_class, line_cell_magic
import time

@magics_class
class Autotime(Magics):
    def __init__(self, shell):
        super(Autotime, self).__init__(shell)
        self.start_time = None

    @line_cell_magic
    def time(self, line, cell=None):
        start_time = time.time()
        if cell:
            self.shell.run_cell(cell)
        else:
            self.shell.run_line(line)
        end_time = time.time()
        print(f"Time: {end_time - start_time:.3f}s")

def load_ipython_extension(ipython):
    ipython.register_magics(Autotime)

3. 项目的配置文件介绍

项目的配置文件是 setup.py。这个文件用于配置项目的安装和发布信息。

# setup.py
from setuptools import setup, find_packages

setup(
    name='ipython-autotime',
    version='0.3.2',
    packages=find_packages(),
    install_requires=[
        'ipython',
    ],
    license='Apache Software License',
    author='Phillip Cloud',
    author_email='cpcloud@gmail.com',
    description='Time everything in IPython',
    long_description=open('README.md').read(),
    long_description_content_type='text/markdown',
    url='https://github.com/cpcloud/ipython-autotime',
    classifiers=[
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
    ],
)

这个文件定义了项目的名称、版本、依赖、许可证、作者等信息,并提供了安装和发布所需的配置。

ipython-autotimeTime everything in IPython项目地址:https://gitcode.com/gh_mirrors/ip/ipython-autotime

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郁虹宝Lucille

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值