Python包用户常见任务(例如复制示例、获取数据等)
项目描述
pyct
一个实用包,包括
-
pyct.cmd:为其他包提供各种命令。 (目前没有复杂的插件系统,只是在其他包中尝试导入/异常。)相同的命令也可以从Python内部访问。可以为现有的基于argparse的命令添加新子命令(如果模块中已存在命令),也可以创建整个命令(如果模块中没有现有命令)。目前,有复制示例和获取数据的命令。参见
-
pyct.build:提供各种命令以帮助打包,主要作为项目维护者的便利。
pyct.cmd
要安装带有pyct.cmd所需依赖项的pyct: pip install pyct[cmd]
或 conda install -c pyviz pyct
。
在项目中使用示例的例子:https://github.com/holoviz/geoviews/blob/main/geoviews/__main__.py
一旦添加,用户可以使用examples
命令复制软件包的示例并下载所需的数据
$ datashader examples --help
usage: datashader examples [-h] [--path PATH] [-v] [--force] [--use-test-data]
optional arguments:
-h, --help show this help message and exit
--path PATH location to place examples and data
-v, --verbose
--force if PATH already exists, force overwrite existing examples
if older than source examples. ALSO force any existing data
files to be replaced
--use-test-data Use data's test files, if any, instead of fetching full
data. If test file not in '.data_stubs', fall back to
fetching full data.
要复制例如datashader的示例而不下载数据,有一个copy-examples
命令
usage: datashader copy-examples [-h] [--path PATH] [-v] [--force]
optional arguments:
-h, --help show this help message and exit
--path PATH where to copy examples
-v, --verbose
--force if PATH already exists, force overwrite existing files if
older than source files
只下载数据,使用fetch-data
命令
usage: datashader fetch-data [-h] [--path PATH] [--datasets DATASETS] [-v]
[--force] [--use-test-data]
optional arguments:
-h, --help show this help message and exit
--path PATH where to put data
--datasets DATASETS *name* of datasets file; must exist either in path
specified by --path or in package/examples/
-v, --verbose
--force Force any existing data files to be replaced
--use-test-data Use data's test files, if any, instead of fetching full
data. If test file not in '.data_stubs', fall back to
fetching full data.
可以指定不同的'datasets'文件
$ cat earthsim-examples/test.yml
---
data:
- url: http://s3.amazonaws.com/datashader-data/Chesapeake_and_Delaware_Bays.zip
title: 'Depth data for the Chesapeake and Delaware Bay region of the USA'
files:
- Chesapeake_and_Delaware_Bays.3dm
$ earthsim fetch-data --path earthsim-examples --datasets-filename test.yml
Downloading data defined in /tmp/earthsim-examples/test.yml to /tmp/earthsim-examples/data
Skipping Depth data for the Chesapeake and Delaware Bay region of the USA
可以使用较小的文件而不是较大的文件,通过使用--use-test-data
标志并在examples/data/.data_stubs
中放置一个同名的较小文件来实现
$ tree examples/data -a
examples/data
├── .data_stubs
│ └── nyc_taxi_wide.parq
└── diamonds.csv
$ cat examples/dataset.yml
data:
- url: http://s3.amazonaws.com/datashader-data/nyc_taxi_wide.parq
title: 'NYC Taxi Data'
files:
- nyc_taxi_wide.parq
- url: http://s3.amazonaws.com/datashader-data/maccdc2012_graph.zip
title: 'National CyberWatch Mid-Atlantic Collegiate Cyber Defense Competition'
files:
- maccdc2012_nodes.parq
- maccdc2012_edges.parq
- maccdc2012_full_nodes.parq
- maccdc2012_full_edges.parq
$ pyviz fetch-data --path=examples --use-test-data
Fetching data defined in /tmp/pyviz/examples/datasets.yml and placing in /tmp/pyviz/examples/data
Copying test data file '/tmp/pyviz/examples/data/.data_stubs/nyc_taxi_wide.parq' to '/tmp/pyviz/examples/data/nyc_taxi_wide.parq'
No test file found for: /tmp/pyviz/examples/data/.data_stubs/maccdc2012_nodes.parq. Using regular file instead
Downloading National CyberWatch Mid-Atlantic Collegiate Cyber Defense Competition 1 of 1
[################################] 59/59 - 00:00:00
要清理任何伪装成真实数据的潜在测试文件,请使用clean-data
usage: pyviz clean-data [-h] [--path PATH]
optional arguments:
-h, --help show this help message and exit
--path PATH where to clean data
pyct.build
目前提供了一种方法,通过在每次运行setup.py时将示例文件夹复制到包目录中来将示例与项目打包。这种工作方式可能在未来发生变化,但提供此作为统一/简化多个pyviz项目维护的第一步。
pyct报告
提供了一种使用方法来检查当前环境中的包版本
- 控制台脚本(入口点):
pyct report [packages]
,或者 - Python函数:
import pyct; pyct.report(packages)
Python函数对于例如jupyter notebook用户特别有用,因为我们通常关心的是当前内核中的包(而不是从jupyter notebook服务器/实验室启动的环境中的包)。
注意,上面的packages
可以包括任何Python包的名称(返回__version__
),以及特殊情况python
或conda
(返回命令行工具的版本)或system
(返回操作系统版本)。
项目详情
下载文件
下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。