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
模块的测试用例。
- test_autotime.py: 针对
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