小编Kji*_*jir的帖子

如何在没有setup.py的项目中运行tox?

我想用tox两个virtualenvs运行我的单元测试,因为我的应用程序必须支持2个不同的Python版本.

我的问题是tox需要a setup.py,但我没有,因为我的应用程序不是模块并且有自己的安装程序.现在我不想经历自动化安装过程的麻烦setup.py,我只想运行我的单元测试而不必写一个setup.py.

那可能吗?或者我怎么能写一个"空"的setup.py,什么都不做?你能指点我一些关于这个主题的distutils文档(文档解释了如何写一个有意义的setup.py,而不是空的)?

python unit-testing distutils tox

60
推荐指数
2
解决办法
9422
查看次数

如何在LaTeX中创建像\ title这样的命令?

我正在为LaTeX编写一个文档类,我希望它是通用的.在这个文档类中,我重新定义了\maketitle显示自定义标题页面的命令,在这里我想显示一些信息,如标题,作者等,还有一些其他信息.这是我显示标题的方式:

{\LARGE{\bf \@title}}\\
Run Code Online (Sandbox Code Playgroud)

我想创建一个与之类似的新命令,\title或者\author我该怎么做?

latex

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

简化/优化for循环链

我有一系列for循环,它们在原始的字符串列表上工作,然后逐渐过滤列表,例如:

import re

# Regex to check that a cap exist in string.
pattern1 = re.compile(r'\d.*?[A-Z].*?[a-z]')
vocab = ['dog', 'lazy', 'the', 'fly'] # Imagine it's a longer list.

def check_no_caps(s):
    return None if re.match(pattern1, s) else s

def check_nomorethan_five(s):
    return s if len(s) <= 5 else None

def check_in_vocab_plus_x(s,x):
    # s and x are both str.
    return None if s not in vocab else s+x

slist = ['the', 'dog', 'jumps', 'over', 'the', 'fly']
# filter with check_no_caps
slist = [check_no_caps(s) …
Run Code Online (Sandbox Code Playgroud)

python reduce dictionary filter nested-loops

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

如何在运行时删除LD_LIBRARY_PATH?

我正在构建一个使用Intel的IPP库的C++应用程序.默认情况下,此库安装在/ opt中,并且要求您设置LD_LIBRARY_PATH编译和运行软件(如果选择共享库链接,我会这样做).我已经修改了我configure.ac/ Makefile.am我在编译时不需要设置该变量,但是我仍然无法在运行时找到共享库; 我怎么做?

我正在使用-Wl, -R/path/to/libdir标志进行编译g++

更新1:实际上我的二进制程序有一些正确链接的IPP库,但只有一个不是:

$ ldd myprogram
linux-vdso.so.1 =>  (0x00007fffa93ff000)
libippacem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippacem64t.so.6.0 (0x00007f22c2fa3000)
libippsem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippsem64t.so.6.0 (0x00007f22c2d20000)
libippcoreem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippcoreem64t.so.6.0 (0x00007f22c2c14000)
[...]
libiomp5.so => not found
libiomp5.so => not found
libiomp5.so => not found
Run Code Online (Sandbox Code Playgroud)

当然图书馆在那里:

$ locate libiomp5.so
/opt/intel/ipp/6.0.2.076/em64t/sharedlib/libiomp5.so
Run Code Online (Sandbox Code Playgroud)

c++ g++ autotools shared-libraries intel-ipp

10
推荐指数
2
解决办法
9068
查看次数

boost :: asio只能接收完整的UDP数据报吗?

我正在使用boost :: asio构建的UDP服务器,我从教程中开始定制我的需求.当我调用socket.receive_from(boost::asio::buffer(buf), remote, 0, error);它时,用数据包中的数据填充我的缓冲区,但是,如果我的理解是正确的,它会丢弃任何不适合缓冲区的数据.对receive_from的后续调用将接收下一个可用的数据报,因此在我看来,即使没有通知,也会有一些数据丢失.我理解这是错误的方式吗?

我试着一遍又一遍地阅读boost :: asio文档,但我没有设法找到关于我应该以正确的方式做到这一点的线索.我想做的是读取一定数量的数据,以便我可以处理它; 如果读取整个数据报是唯一的方法,我可以管理它,但是我怎么能确保不丢失我收到的数据?我应该使用什么缓冲区大小来确定?有什么方法可以告诉我我的缓冲区太小而且我丢失了信息吗?

我不得不假设我可能会收到大量的数据报.

c++ sockets udp network-programming boost-asio

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

为什么autoconf没有正确检测到增强?

我使用autoconf检测boost库,在autoconf-archive宏的支持下,它们可以与系统范围的boost库一起使用,但是如果我在我的主目录中手动编译boost,则会失败:

sb@stephane:~/devel/spectra2$ ./configure --with-boost=/home/sb/local/
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for style of include used by make... GNU
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... …
Run Code Online (Sandbox Code Playgroud)

c++ autoconf boost boost-filesystem

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

是否可以通过JPA和CriteriaBuilder的组合键进行排序

我想使用JPA CriteriaBuilder创建一个查询,我想添加一个ORDER BY子句.这是我的实体:

@Entity
@Table(name = "brands")
public class Brand implements Serializable {

    public enum OwnModeType {
        OWNER, LICENCED
    }

    @EmbeddedId
    private IdBrand id;
    private String code;
    //bunch of other properties
}
Run Code Online (Sandbox Code Playgroud)

嵌入式课程是:

@Embeddable
public class IdBrand implements Serializable {

    @ManyToOne
    private Edition edition;
    private String name;
}
Run Code Online (Sandbox Code Playgroud)

我构建查询的方式是这样的:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Brand> q = cb.createQuery(Brand.class).distinct(true);
Root<Brand> root = q.from(Brand.class);
if (f != null) {
    f.addCriteria(cb, q, root);
    f.addOrder(cb, q, root, sortCol, ascending);
}
return em.createQuery(q).getResultList();
Run Code Online (Sandbox Code Playgroud)

这里有一些函数: …

java jpa criteria-api

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

如何在Sphinx文档中显示类的继承成员?

我想记录一些类,这些类都是从具有一些公共属性的相同基类派生的,我想重复子类中每个属性的文档,以便我可以在一个地方看到类的所有属性.

所以例如我有这个代码:

class Base(object):

    """Base class."""

    #: First attribute
    a = int
    #: Second attribute
    b = str

class FirstChild(Base):

    """First Child of Base."""

    #: Child attribute
    c = float

class SecondChild(Base):

    """Second Child of Base."""

    pass
Run Code Online (Sandbox Code Playgroud)

我有这个第一个:

.. automodule:: example
   :members:
   :show-inheritance:
Run Code Online (Sandbox Code Playgroud)

输出将如下所示:

class class example.Base

   Bases: "object"

   Base class.

   a
      First attribute
      alias of "int"

   b
      Second attribute
      alias of "str"

class class example.FirstChild

   Bases: "example.Base"

   First Child of Base.

   c
      Child attribute
      alias of "float"

class class …
Run Code Online (Sandbox Code Playgroud)

python-sphinx autodoc

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

是否可以将成员初始化推迟到构造函数体?

我有一个类,对象作为成员,没有默认的构造函数.我想在构造函数中初始化这个成员,但似乎在C++中我不能这样做.这是班级:

#include <boost/asio.hpp>
#include <boost/array.hpp>

using boost::asio::ip::udp;

template<class T>
class udp_sock
{
    public:
        udp_sock(std::string host, unsigned short port);
    private:
        boost::asio::io_service _io_service;
        udp::socket _sock;
        boost::array<T,256> _buf;
};

template<class T>
udp_sock<T>::udp_sock(std::string host = "localhost",
  unsigned short port = 50000)
{
    udp::resolver res(_io_service);
    udp::resolver::query query(udp::v4(), host, "spec");
    udp::endpoint ep = *res.resolve(query);
    ep.port(port);
    _sock(_io_service, ep);
}
Run Code Online (Sandbox Code Playgroud)

编译器基本上告诉我它找不到udp :: socket的默认构造函数,根据我的研究,我理解C++在调用构造函数之前隐式初始化每个成员.有没有办法以我想要的方式去做,或者它是否"面向Java"并且在C++中不可行?

我通过像这样定义我的构造函数解决了这个问题:

template<class T>
udp_sock<T>::udp_sock(std::string host = "localhost",
  unsigned short port = 50000) : _sock(_io_service)
{
    udp::resolver res(_io_service);
    udp::resolver::query query(udp::v4(), host, "spec");
    udp::endpoint ep = *res.resolve(query); …
Run Code Online (Sandbox Code Playgroud)

c++ oop constructor boost initialization

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

以编程方式关闭下拉按钮

我正在使用这个zurb-foundation下拉按钮 - http://foundation.zurb.com/sites/docs/v/5.5.3/components/dropdown_buttons.html

但是,当用户在下拉按钮本身外部单击或用户单击下拉列表中的项目时,我还需要关闭下拉列表,因此我需要一种方法以编程方式关闭打开的下拉列表事件.

我需要以编程方式关闭打开的下拉列表来进行什么javascript调用?

javascript zurb-foundation

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