小编Dun*_*eod的帖子

如何链接到sphinx toctree中的页面部分

我有一个.. toctreesphinx页面的一部分,其中包含rst我的包中其他文件的相对链接.如何包含指向给定页面的子部分的链接,而不是整页本身?

我捅了一下

.. toctree::

   page#section
Run Code Online (Sandbox Code Playgroud)

但那没用.任何帮助都很棒.

python-sphinx

16
推荐指数
1
解决办法
1863
查看次数

如何在没有超时的情况下在Travis CI上安装东西?

我正在尝试在travis-ci.org上测试一个包构建,但是我遇到了pip install scipy的超时:

Installing collected packages: scipy
  Running setup.py install for scipy
    Running command /home/travis/virtualenv/python2.6.9/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-Fn2gmJ/scipy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hWDx9L-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/travis/virtualenv/python2.6.9/include/site/python2.6


No output has been received in the last 10 minutes, this potentially indicates a stalled build or something wrong with the build itself.

The build has been terminated
Run Code Online (Sandbox Code Playgroud)

(从最近的构建日志中提取).

如何在没有超时的情况下在Travis上构建scipy> = 0.11?

continuous-integration scipy travis-ci

16
推荐指数
2
解决办法
3485
查看次数

如何判断numpy布尔数组是否只包含一个"True`s"块?

如果我有一个包含布尔值的numpy数组,比如一些数学比较的输出,那么确定该数组是否只包含一个连续的Trues 块的最佳方法是什么,例如

array([False, False, False, True, True, True, False, False, False], dtype=bool)
Run Code Online (Sandbox Code Playgroud)

即序列...,True, False, ..., True...从未发生的地方?

python numpy

7
推荐指数
1
解决办法
1709
查看次数

查找一个数组中哪些元素与另一个元素中的任何元素接近的最有效方法是什么?

我有两个1维numpy.ndarray对象,并想知道第一个数组中的哪些元素在第二个数组中dx任何元素内.

我现在拥有的是什么

# setup
numpy.random.seed(1)
a = numpy.random.random(1000)  # create one array
numpy.random.seed(2)
b = numpy.random.random(1000)  # create second array
dx = 1e-4  # close-ness parameter

# function I want to optimise
def find_all_close(a, b):
    # compare one number to all elements of b
    def _is_coincident(t):
        return (numpy.abs(b - t) <= dx).any()
    # vectorize and loop over a
    is_coincident = numpy.vectorize(_is_coincident)
    return is_coincident(a).nonzero()[0]
Run Code Online (Sandbox Code Playgroud)

返回timeit结果如下

10 loops, best of 3: 16.5 msec per …
Run Code Online (Sandbox Code Playgroud)

python arrays algorithm numpy

6
推荐指数
1
解决办法
140
查看次数

如何创建一个空的 python 包?

我想使用诗歌工具创建一个空(元)包,主要是为了简化将依赖项列表组合在一起的过程。如果我按如下方式创建 project.toml:

[build-system]
requires = ["poetry"]

[tool.poetry]
name = "metapackage"
version = "1.0.0"
description = "My empty metapackage"
authors = ["Me"]
license = "MIT"

[tool.poetry.dependencies]
numpy = "*"
Run Code Online (Sandbox Code Playgroud)

然后执行poetry build,出现错误:

$ mkdir -p metapackage
$ python -m poetry build --no-interaction --format wheel -vvvUsing virtualenv: /Users/duncan/opt/miniconda3/envs/py37
Building metapackage (1.0.0)

[ValueError]
metapackage is not a package.

Traceback (most recent call last):
  File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, …
Run Code Online (Sandbox Code Playgroud)

python python-packaging python-poetry

5
推荐指数
1
解决办法
2630
查看次数

如何在python中伪造缺少单元测试的依赖项?

我写了一个python模块,它依赖于我的CI测试机上没有的第三方软件包,因此我无法远程测试我的模块,因为我无法通过该import dependency语句.

如果我们假设我无法在CI主机上手动安装依赖项(看起来很痛苦),那么伪造/模拟/删除任何缺少的第三方软件包的最简单方法是什么,以便我可以测试我的代码?

我只使用依赖项提供的单个类,所以我很乐意只是模拟该对象,如果有办法那样做,而不是整个模块.

python python-mock python-unittest

2
推荐指数
1
解决办法
392
查看次数