小编cdw*_*son的帖子

@ :(符号冒号)在Makefile中的含义是什么?

Makefile中的以下内容是什么?

rule: $(deps)
    @:
Run Code Online (Sandbox Code Playgroud)

我似乎无法在制作手册中找到这个.

makefile gnu-make

141
推荐指数
2
解决办法
5万
查看次数

如何从"python setup.py test"运行unittest发现?

我正在试图找出如何python setup.py test运行等效的python -m unittest discover.我不想使用run_tests.py脚本,我不想使用任何外部测试工具(如nosepy.test).如果解决方案仅适用于python 2.7,那就没问题.

setup.py,我想我需要在配置中的test_suite和/或test_loader字段中添加一些东西,但我似乎无法找到一个正常工作的组合:

config = {
    'name': name,
    'version': version,
    'url': url,
    'test_suite': '???',
    'test_loader': '???',
}
Run Code Online (Sandbox Code Playgroud)

这可能只使用unittest内置于python 2.7?

仅供参考,我的项目结构如下:

project/
  package/
    __init__.py
    module.py
  tests/
    __init__.py
    test_module.py
  run_tests.py <- I want to delete this
  setup.py
Run Code Online (Sandbox Code Playgroud)

更新:这是可能的,unittest2但我想找到相同的东西只使用unittest

来自https://pypi.python.org/pypi/unittest2

unittest2包括一个非常基本的setuptools兼容的测试收集器.在setup.py中指定test_suite ='unittest2.collector'.这将使用包含setup.py的目录中的默认参数启动测试发现,因此它可能是最有用的示例(请参阅unittest2/collector.py).

现在,我只是使用一个名为的脚本run_tests.py,但我希望通过转向仅使用的解决方案来摆脱这个问题python setup.py test.

这是run_tests.py我希望删除的:

import unittest

if __name__ == …
Run Code Online (Sandbox Code Playgroud)

python unit-testing nose pytest unittest2

72
推荐指数
4
解决办法
5万
查看次数

如何强制virtualenv从pypi安装最新的setuptools和pip?

是否有可能强制virtualenv使用pypi提供的最新setuptools和pip?从本质上讲,我找了相反的的--never-download标志.

目前,当我创建一个新的virtualenv时,它使用与virtualenv捆绑在一起的本地(旧)版本.

$ v.mk testvenv
New python executable in testvenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ pip show setuptools
---
Name: setuptools
Version: 0.6c11
Location: /Users/cwilson/.virtualenvs/testvenv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Requires: 
$ pip search setuptools
[...]
setuptools                - Easily download, build, install, upgrade, and
                            uninstall Python packages
INSTALLED: 0.6c11
LATEST:    0.7.2
[...]
Run Code Online (Sandbox Code Playgroud)

python pip setuptools virtualenv virtualenvwrapper

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

根据python对象的属性生成python对象的唯一ID

有没有办法在python中为对象生成一个类似哈希的ID,它只基于对象的属性值?例如,

class test:
    def __init__(self, name):
        self.name = name

obj1 = test('a')
obj2 = test('a')

hash1 = magicHash(obj1)
hash2 = magicHash(obj2)
Run Code Online (Sandbox Code Playgroud)

我正在寻找的是hash1 == hash2.python中是否存在类似的内容?我知道我可以测试obj1.name == obj2.name,但我正在寻找一些我可以在任何对象上使用的通用.

python attributes object

9
推荐指数
1
解决办法
4071
查看次数

如何将git存储库添加为另一个git存储库的共享依赖项?

我需要类似于子模块的东西,但它作为依赖项存在于主存储库之外.

这是问题所在:

我正在尝试使用Git(以一种非常笨拙的方式)来管理CAD工具(Cadsoft Eagle)的设计文件,而我很难搞清楚是否有办法使用git子模块来管理每个项目的依赖于CAD工具的共享库.

我正在使用这样的文件夹结构:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
    Proj1/
        .git/
         <design files>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,将eagle.git存储库添加为每个项目的git子模块是没有意义的.

但是,我仍然需要一种方法来快照"eagle.git"存储库的当前状态,以便在将来更新库时,可以回滚它以访问当时正在使用的库文件的特定版本. Proj [x]承诺了.

理想情况下,我喜欢以下内容:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
        **eagle** <-- something that acts like a submodule  
                      but which actually points to ~/eagle/
    Proj1/
        .git/
         <design files>
         **eagle** <-- something that acts like a submodule  
                       but which …
Run Code Online (Sandbox Code Playgroud)

git cad git-submodules

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

Python对象@property

我正在尝试创建一个定义名为"坐标"的属性的点类.但是,它的表现并不像我期望的那样,我无法弄清楚原因.

class Point:
    def __init__(self, coord=None):
        self.x = coord[0]
        self.y = coord[1]

    @property
    def coordinate(self):
        return (self.x, self.y)

    @coordinate.setter
    def coordinate(self, value):
        self.x = value[0]
        self.y = value[1]

p = Point((0,0))
p.coordinate = (1,2)

>>> p.x
0
>>> p.y
0
>>> p.coordinate
(1, 2)
Run Code Online (Sandbox Code Playgroud)

似乎px和py由于某种原因没有设置,即使setter"应该"设置这些值.谁知道为什么会这样?

python new-style-class

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

为什么将现有的repo添加为子模块会修改.git/config?

如果我添加一个当前不存在的子模块,则不会添加任何子模块信息.git/config.

$ mkdir testing
$ cd testing
$ git init
$ git submodule add git@git.server:submodule.git
$ cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
Run Code Online (Sandbox Code Playgroud)

但是,如果我添加一个当前作为子模块存在的仓库,则该URL将添加到.git/config:

$ mkdir testing
$ cd testing
$ git init
$ git clone git@git.server:submodule.git
$ git submodule add git@git.server:submodule.git
$ cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
[submodule "submodule"]
    url = …
Run Code Online (Sandbox Code Playgroud)

git add git-submodules

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

如何在Sphinx文档中将成员注释为抽象?

以下两个属性定义在Sphinx autodoc html输出中显示完全相同:

@property
def concrete(self):
    """This is the concrete docstring"""
    pass

@abstractproperty
def abstract(self):
    """This is the abstract docstring"""
    pass
Run Code Online (Sandbox Code Playgroud)

Sphinx是否有办法用某种标识符注释抽象方法?我希望在我的文档中可以明显看出我的ABC成员需要实现哪些,以及一旦定义了所需的,就会获得mixin免费赠品.

python documentation abc python-sphinx

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

为什么 Sequence 是 mypy 中 + 不支持的操作数类型?

mypy给出的错误Sequence[str]不是该运算符支持的操作数类型+

# test.py

from typing import Sequence


def test(x: Sequence[str], y: Sequence[str]) -> Sequence[str]:
    return x + y

Run Code Online (Sandbox Code Playgroud)
$ mypy test.py
test.py:5: error: Unsupported left operand type for + ("Sequence[str]")
Found 1 error in 1 file (checked 1 source file)
Run Code Online (Sandbox Code Playgroud)

pytype 给出了类似的错误:

$ pytype test.py 

[...]

  No attribute '__add__' on Sequence[str] or '__radd__' on Sequence[str]

[...]
Run Code Online (Sandbox Code Playgroud)

为什么 是Sequence[str]不受支持的操作数类型+

python typing mypy

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

为什么在父类__init __()中调用super()会改变子类__init __()的行为?

我一直试图理解super()多重继承的上下文中的行为.我很困惑为什么super()在test2.py的父类中调用会导致__init__()为父母双方调用?

test1.py

#!/usr/bin/env python

class A(object):

    def __init__(self):
        self.A = "A"
        print self.A

class B(object):

    def __init__(self):
        self.B = "B"
        print self.B

class C(A, B):

    def __init__(self):
        self.C = "C"
        print self.C
        super(C, self).__init__()

if __name__ == '__main__':
    print "Without super() in parent __init__():"
    c = C()
    print c.__dict__
    print C.__mro__
Run Code Online (Sandbox Code Playgroud)

生产:

$ ./test.py 
Without super() in parent __init__():
C
A
{'A': 'A', 'C': 'C'}
(<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <type 'object'>)
Run Code Online (Sandbox Code Playgroud)

test2.py …

python multiple-inheritance super superclass method-resolution-order

4
推荐指数
1
解决办法
2164
查看次数

在OSX上隐藏Tkinter应用程序的控制台

我在启动基于GUI Tkinter的应用程序时试图隐藏终端,但是当我双击OSX上的app.py文件时,会出现终端窗口.我已经尝试将扩展名更改为.pyw并尝试使用/ usr/bin/pythonw启动它,但无论如何,终端窗口仍会出现.

我甚至尝试添加下面的try/except,但是当我运行它时,我收到错误:出现在终端窗口中的'无效命令名称"console"'.

from Tkinter import *

class MainWindow(Tk):
    def __init__(self):
        Tk.__init__(self)
        try:
            self.tk.call('console', 'hide')
        except TclError, err:
           print err

win = MainWindow()
win.mainloop()
Run Code Online (Sandbox Code Playgroud)

我无法找到任何方法来隐藏终端窗口出现.有人有任何想法吗?

python macos tk-toolkit tkinter

3
推荐指数
1
解决办法
3915
查看次数