小编Nic*_*eld的帖子

使用setuptools/distribute创建python包时,是否需要*.egg-info目录?

我有一个像这样的"标准"python包布局:

  • setup.py - 使用setuptools
  • 自述
  • SRC/moduleA
  • 测试/

但是,当我执行setup.py时,它决定创建目录src/moduleA.egg-info.

问题是,我是否需要担心此目录的内容并使用我的其余代码检查它,或者我应该依靠setuptools/distribute来重新生成它?似乎.egg-info目录中的所有信息都来自setup.py中的配置.

python packaging setuptools

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

配置autofac以忽略标记为过时的构造函数

是否可以轻松配置autofac,以便只使用非过时的构造函数来解决?

例如,对于具有非DI代码的辅助构造函数的类,

public class Example {

    public Example(MyService service) {
        // ...
    }

    [Obsolete]
    public Example() {
        service = GetFromServiceLocator<MyService>();
        // ...
    }
}

// ....

var builder = new ContainerBuilder();
builder.RegisterType<Example>();
// no MyService defined.
var container = builder.Build();

// this should throw an exception
var example = container.Resolve<Example>();
Run Code Online (Sandbox Code Playgroud)

如果我们没有注册MyService,请求autofac解析示例,应该失败.

.net c# autofac obsolete

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

C中的短路错误处理

我想知道是否有一种更好的方法来处理C中的情况,只要在一系列表达式中遇到错误就要退出函数.(在这种情况下,它是一个在出错时返回NULL的函数)

例如,在某些C代码中,他们试图通过将一系列语句与AND(&&)组合来实现短路错误处理.

return doSomething() && 
     doSomething2() && 
     doSomething3() && ... ;
Run Code Online (Sandbox Code Playgroud)

这让我感到恼火,因为我们在一个声明中一行填写了这么多内容.但我想替代方案是

if (!(value = doSomething()))
    return NULL;
if (!(value = doSomething2()))
    return NULL;
etc
return value;
Run Code Online (Sandbox Code Playgroud)

但是我在perl和bash脚本中看到的短路错误评估呢?

int die(int retvalue) {
    exit(retvalue);
}
.....
(value = doSomething()) || die(1);
(value = doSomething2()) || die(2);
(value = doSomething3()) || die(3);
return value;
Run Code Online (Sandbox Code Playgroud)

这个问题的主要问题是RHS必须是一个表达式,所以你不能真正转到函数或从函数返回.有人会发现这个有价值的还是有限的?

编辑:我想我应该在第一个例子中包含换行符.问题是如果你决定在中间添加另一个表达式,你需要小心.

c error-handling short-circuiting

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

串行编程:测量字符之间的时间

我正在 Linux 中通过串行线路发送/接收数据,我想找到字符之间的延迟。

Modbus 使用 3.5 个字符的延迟来检测消息帧边界。如果超过 1.5 个字符的延迟,则消息帧被声明为不完整的。

我正在用 C 编写一个快速程序,它基本上是

fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
// setup newtio
....
tcsetattr(fd, TCSANOW, &newtio);
for(;;) {
    res = read(fs, buf, 1);
    if (res > 0) {
        // store time in milliseconds?
        //do stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以测量这里的时间吗?或者我是否需要以不同的方式查看从串行线路中检索数据?

我还尝试连接到 SIGIO 以在有数据时获取信号,但我似乎一次获取 8 个字节的数据。

(是的,我知道存在一些 modbus 库,但我想在其他应用程序中使用它)

c serial-port modbus timing

3
推荐指数
2
解决办法
3599
查看次数

autofac/c#:特定基类的通用工厂?

autofac是否可以创建只能解析特定基类类型的通用工厂?

我现在看到改造一个'brownfield'c#项目使用autofac是多么可行.该项目需要创建一个不同类型但具有相同基类的组件树.这些组件需要身份验证和数据库服务(以及其他内容),因此很难只拥有空构造函数.

因此,工厂可以创建导出基类的对象,使用autofac扫描这些类,并为它们提供工厂.我认为如果你不必为每个类提供工厂,它可能会更容易构建组件对象树.

除此之外,还是这是一个糟糕设计的标志?组件和树应该尽可能少地执行,我们将此树传递给其他服务以提供处理和呈现吗?

像(哪里?是神秘工厂)的东西

public MyBase { 
    public Add(MyBase x) {..}
}

public DerivedA: MyBase {}

public DerivedB : MyBase {}

public DerivedC : DerivedA {}

public SomethingElse
{
     private ? _myBaseFact;

     public SomethingElse(? myBaseFact) { 
            _myBaseFact = myBaseFact;
     }

     public BuildComponentTree() {
        DerivedA a = _myBaseFact<DerivedA>();
        DerivedB b = _myBaseFact<DerivedB>();
        DerivedC c = _myBaseFact<DerivedC>();
        a.Add(b);
        b.Add(c);
     }
}
Run Code Online (Sandbox Code Playgroud)

编辑:我被要求一个更具体的例子,这是公平的:)有框架组件,我想允许开发人员创建自己的组件,而无需注册autofac.拥有工厂类意味着开发人员必须将自定义组件添加到此工厂吗?请原谅这个例子,这与我遇到它时框架的工作原理类似.

FwComponent {
    public FwComponent (DataProvider, AuthManager, OtherModule)
    public Add(FwComponent x);
    public Setup();
    public Process();
    public Render();
}

Page : …
Run Code Online (Sandbox Code Playgroud)

c# factory dependency-injection autofac

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

在Jenkins Pipeline DSL中迭代一个groovy列表

我的Pipeline中有一个简单的groovy列表,它添加了一些地图:

def componentList = []

def componentMapEntry1 = [:]
componentMapEntry1['componentName']="Dashboard_Core"
componentList << componentMapEntry1

def componentMapEntry2 = [:]
componentMapEntry2['componentName']="Dashboard_Equities"
componentList << componentMapEntry2

def cme3 = [:]
cme3["componentName"] = "home"
componentList << cme3
Run Code Online (Sandbox Code Playgroud)

执行作业时,我验证大小

echo "size of list "+componentList.size()
Run Code Online (Sandbox Code Playgroud)

...

[Pipeline] echo
size of list 3
Run Code Online (Sandbox Code Playgroud)

我可以把它打印出来

println componentList
Run Code Online (Sandbox Code Playgroud)

...

[Pipeline] echo
[{componentName=Dashboard_Core}, {componentName=Dashboard_Equities}, {componentName=home}]
Run Code Online (Sandbox Code Playgroud)

我可以做一个for循环并迭代列表

for (i = 0; i <componentList.size(); i++) {
    println componentList[i]
}
Run Code Online (Sandbox Code Playgroud)

...

[Pipeline] echo
{componentName=Dashboard_Core}
[Pipeline] echo
{componentName=Dashboard_Equities}
[Pipeline] echo
{componentName=home}
Run Code Online (Sandbox Code Playgroud)

到目前为止一切都很好.

当我尝试使用标准groovy迭代器时出现问题:

componentList.each {
    println …
Run Code Online (Sandbox Code Playgroud)

groovy jenkins-workflow jenkins-pipeline

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

从Ada的受保护对象访问私有类型

我正在尝试用受保护对象包装散列映射,以便可以通过多个任务访问它.我希望受保护类型的过程可用,但将哈希映射和元素记录定义移动到包私有部分会很好.

这里的示例代码:

package Thing_Protected is

   type Thing_Info is record
      Key : Ada.Strings.Unbounded.Unbounded_String;
      Counter_Value : Natural := 0;
   end record;

   package Thing_Info_Maps is new Ada.Containers.Hashed_Maps
      (Key_Type => Ada.Strings.Unbounded.Unbounded_String,
      Element_Type => Thing_Info,
      Hash => Ada.Strings.Unbounded.Hash,
      Equivalent_Keys => Ada.Strings.Unbounded."=");

   protected type Thing is
      procedure Increment (Key : String);
      procedure Another_Thing (Key : String);
   private
      Thing_Map : Thing_Info_Maps.Map;
   end Thing;

private

   -- move Thing_Info, Thing_info_maps into here.

end Thing_Protected;
Run Code Online (Sandbox Code Playgroud)

我已经尝试将Thing_Info定义为私有类型..但我不确定如何将Thing_Info_Maps包定义为私有但仍然从受保护对象类型访问它.

所以我真的不想找到一种方法来获得这样的东西:

package Thing_Protected is

   type Thing_Info is private;
   package Thing_Info_Maps is private;

   protected type …
Run Code Online (Sandbox Code Playgroud)

multithreading ada

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