我正在尝试运行:
pip3 install -e .
在我的Python项目中,我有以下内容setup.py:
from setuptools import setup
setup(
name='mypackage',
install_requires=[
"anotherpackage@git+git@bitbucket.org:myorg/anotherpackage.git"
]
)
Run Code Online (Sandbox Code Playgroud)
但是它失败了:
error in mypackage setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid URL given
Run Code Online (Sandbox Code Playgroud)
我猜想我的URL格式是正确的,因为PEP 508不允许为ssh克隆URL指定git用户名。
带有git + ssh协议的PEP 508 URL与install_requires私有git存储库(在本例中为BitBucket托管)相关的正确语法是什么?指定特定分支,标记或sha的语法是什么?
我有一个内部Python项目,该项目依赖于多个内部开发的Python包。我想避免在组织中托管自己的PIP存储库的必要,因此,我尝试直接使用git URL。我需要对git URL使用ssh协议,因为所有用户都已配置了他们的ssh密钥,要求所有用户在BitBuckets中配置其应用密码会很麻烦(我需要2FA,并且常规用户密码无效) 。
我已经尝试使用:
dependency_linkssetup(
name='mypackage',
install_requires=[
"anotherpackage==0.0.1"
],
dependency_links=[
"git+git@bitbucket.org:myorg/anotherpackage.git@0.0.1#egg=anotherpackage-0.0.1"
]
)
Run Code Online (Sandbox Code Playgroud)
但是它们已被弃用,并且被忽略pip3 install -e .。根据我发现的文档,应该改用PEP 508 URL。
requirements.txt与项文件从重复的install_requires条目 …这是情况:我正在尝试单元测试函数A调用函数B.函数B在弹弓try +块中调用,在某些情况下它可以使用弹弓投掷+.我想在midje测试中模拟函数B,以便返回try + block中的catch实际捕获的内容.我似乎无法创造出正确的东西.这是代码和测试的大致缩略图:
(defn function-A
[param]
(try+
(function-B param)
(catch [:type :user-not-found]
(do-something))))
(defn function-B
[param]
(throw+ [:type :user-not-found]))
(fact "do-something is called"
(function-A "param") => (whatever is the result of calling do-something)
(provided
(function-B "param") =throws=> (clojure.lang.ExceptionInfo. "throw+: {:type :user-not-found}"
{:object {:type :user-not-found}, :environment {}}
nil)))
Run Code Online (Sandbox Code Playgroud)
我正在抛出的ExceptionInfo似乎是正确的.当我的应用程序通过大量的prn语句运行时,我可以看到这一点.但是,无论我尝试什么,我都无法让测试工作.
我还在repl中尝试了下面的代码,看看我是否能理解这个问题.然而,虽然两段代码似乎都涉及相同的异常,但只有一个(纯粹的弹弓)设法捕获并打印"抓住它".我想如果我能理解为什么一个有效而另一个无法有效,我就可以通过单元测试解决问题.
(try+
(try
(throw+ {:type :user-not-found})
(catch Exception e
(prn "Caught: " e)
(prn "Class: " (.getClass e))
(prn "Message: " (.getMessage e))
(prn "Cause: " (.getCause e))
(prn "Data: " …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
(defn compile-report [id]
(let [a (gen-first-part id)
b (gen-second-part id)
c (gen-third-part id)
d (gen-fourth-part id)]
(conj a b c d)))
Run Code Online (Sandbox Code Playgroud)
每个'gen-x-part'函数都是cpu密集型的.据我了解,let表单将在单个线程上串行运行这些计算.如果我有一个核心机器,那么在它自己的线程上运行它们就没有意义,因为它们都是cpu绑定的.但是,我有一台4芯机器.如何利用每个核心并将这些功能分配到自己的核心?谢谢.
我有一个Clojure程序,它返回even下面的一个懒惰的斐波纳契数列的总和n:
(defn sum-of-even-fibonaccis-below-1 [n]
(defn fib [a b] (lazy-seq (cons a (fib b (+ b a)))))
(reduce + (take-while (partial >= n) (take-nth 3 (fib 0 1)))))
(time (dotimes [n 1000] (sum-of-even-fibonaccis-below-1 4000000))) ;; => "Elapsed time: 98.764msecs"
Run Code Online (Sandbox Code Playgroud)
效率不高.但是,如果我不减少序列并简单地返回值列表,(0 2 8 34 144...)它可以更快地完成其工作20倍:
(defn sum-of-even-fibonaccis-below-2 [n]
(defn fib [a b] (lazy-seq (cons a (fib b (+ b a)))))
(take-while (partial >= n) (take-nth 3 (fib 0 1))))
(time (dotimes [n 1000] (sum-of-even-fibonaccis-below-2 4000000))) ;; …Run Code Online (Sandbox Code Playgroud) (defn get-vector []
(let [rs (atom [])]
(map (fn [x] (swap! rs conj x)) [1 2 3 4])
@rs))
(get-vector)
Run Code Online (Sandbox Code Playgroud)
我认为这个功能应该回归[1 2 3 4]; 但是,它只返回一个空向量[].
(deftask test1 "first test task" [] (print "1") identity)
(deftask test2 "second test task" [] (print "2") identity)
(boot (comp (test1) (test2)))
=> 12nil
(boot (comp (fn [x] (print "1") identity) (fn [x] (print "2") identity)))
=> 21nil
Run Code Online (Sandbox Code Playgroud)
如果我使用comp任务,执行顺序是从左到右.如果我使用comp匿名函数,则执行顺序是从右到左.这种不一致性如何合理?
我如何使用类似于recur尾部位置的东西?
看看我的代码:
(defn -main [& args]
(println "Hi! Type a file name...")
(defn readFile[])
(let [fileName(read-line)]
(let [rdr (reader fileName)]
(if-not (.exists rdr)
((println "Sorry, this file doesn't exists. Type a valid file name...")
(recur)))
(defn list '())
(doseq [line (line-seq rdr)]
(if-not (= "" line)
(concat list '(line)))
(list))))
(defn fileLinesList (readFile))
...
...)
Run Code Online (Sandbox Code Playgroud)
我知道我不能recur在这里使用......但我不知道如何在clojure中实现它.
我是Clojure的新手,我来自OOP环境.所以...
在这种情况下有没有办法使用递归? 什么是另类?
lisp recursion functional-programming tail-recursion clojure