为了在我们的公司内部分python项目,我需要进行可安装的分发.
这应该包括:
是否有一个简单的插件,(例如bdist_wheel的替代品)不仅会编译一个轮子而且还会编译该项目的组件?
显然我可以编写脚本,但我希望可能有一个快捷方式,可以用更少的步骤构建软件包+依赖项.
这需要在Windows + Linux上使用Python 2.7.
这是我的Jenkins 2.x管道:
node ('master'){
stage 'Checkout'
checkout scm
stage "Build Pex"
sh('build.sh')
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个管道时,checkout会按预期将代码放入工作区,但不是期望在workspace /(它确实存在!)中找到脚本,而是查找一个不相关的目录:workspace @ tmp/durable-d812f509.
Entering stage Build Pex
Proceeding
[Pipeline] sh
[workspace] Running shell script
+ build.sh
/home/conmonsysdev/deployments/jenkins_ci_2016_interns/jenkins_home/jobs/pex/branches/master/workspace@tmp/durable-d812f509/script.sh: line 2: build.sh: command not found
Run Code Online (Sandbox Code Playgroud)
如何修改这个Jenkins文件,以便在我检查项目源代码的完全相同的目录中执行build.sh?
当我运行 mypy 时,它抱怨找不到模块:
sal@ahfang:~/workspace/ecs/cx-project-skeleton-repo/src/cx-example-function$ pipenv run python -m mypy .
example_lambda.py:3: error: Cannot find module named 'aws_xray_sdk.core'
Run Code Online (Sandbox Code Playgroud)
但是当尝试使用完全相同的 Python 解释器导入完全相同的模块时,似乎该模块确实存在并且是可导入的。
python
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import aws_xray_sdk.core
>>>
Run Code Online (Sandbox Code Playgroud)
除了强制忽略 mypy.ini 文件中的导入之外,我还应该做些什么来帮助 mypy 查看确实存在的可导入模块?
Is there a way to ignore all of the errors in certain packages within my project?
Some of the code in my project is compiled Protocol Buffers code which doesn't pass a MyPy check. It all lives within a directory /myproj/generated/proto.
Here's what I have in my mypy config file:
[mypy-myproject.generated]
ignore_missing_imports = True
ignore_errors = True
Run Code Online (Sandbox Code Playgroud)
What can I add to this to make it ignore all error messages generated from an analysis of anything that's inside of myproject.generated? …
我想创建一个 Pydantic 模型,其中有一个列表字段,未初始化的默认值为空列表。有没有一种惯用的方法来做到这一点?
对于 Python 的内置数据类对象,您可以使用field(default_factory=list)
,但是在我自己的实验中,这似乎可以防止我的 Pydantic 模型被腌制。一个天真的实现可能是这样的:
from pydantic import BaseModel
class Foo(BaseModel):
defaulted_list_field: Sequence[str] = [] # Bad!
Run Code Online (Sandbox Code Playgroud)
但是我们都知道不要使用像空列表文字这样的可变值作为默认值。
那么给 Pydantic 列表字段一个默认值的正确方法是什么?
我正试图在公司防火墙后面运行SBT.另一个团队配置了Artifactory代理.这个代理可以正常启用匿名访问,但是当我们让它需要密码时,认为开始出错了.
当我在工作站上运行SBT时,出现以下错误:
[error] Unable to find credentials for [Artifactory Realm @ coderepo.xxx.amrs.bigco.com]
Run Code Online (Sandbox Code Playgroud)
结果是我无法引导sbt:
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-lang#scala-library;2.10.6: not found
[warn] :: org.scala-sbt#sbt;0.13.12: not found
[warn] :: org.scala-lang#scala-compiler;2.10.6: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Run Code Online (Sandbox Code Playgroud)
我已经尝试在./ .sbt和〜/ .ivy2中放置一个.credentials文件:我一直在测试以下内容的变体,所有这些都不起作用:
realm=Artifactory Realm @ coderepo.xxx.amrs.bigco.com
host=coderepo.xxx.amrs.bigco.com
user=<username>
password=<pwd>
Run Code Online (Sandbox Code Playgroud)
我猜这个错误意味着它无法找到与领域匹配的凭据定义,所以我在两个位置尝试了第一行的多个版本:
realm=Artifactory Realm
realm=[Artifactory Realm @ coderepo.xxx.amrs.bigco.com]
realm=coderepo.xxx.amrs.bigco.com
Run Code Online (Sandbox Code Playgroud)
这些似乎都没有任何影响.
那么,允许SBT使用用户名和密码对受密码保护的Artifactory存储库进行身份验证的正确方法是什么?
UPDATE0:根据常春藤文档,最可能的领域名称只是"Artifactory Realm".根据SBT文档,凭证文件的正确默认位置应为%USERPROFILE%/.sbt/.credentials(是的,我使用的是Windows).即使在删除.ivy2目录中的.credentials文件后,它仍然无效.
更新1:相关但实际上并没有帮助:
UPDATE2:我开始怀疑这是sbt中的一个错误 - 我在这里添加了一个问题:https://github.com/sbt/sbt/issues/2817
这个问题解释了如何制作pip下载和保存包.如果我遵循这个公式,Pip将下载wheel(.whl)文件(如果可用).
(venv) [user@host glances]$ pip download -d wheelhouse -r build_requirements.txt
Collecting wheel (from -r build_requirements.txt (line 1))
File was already downloaded /usr_data/tmp/glances/wheelhouse/wheel-0.29.0-py2.py3-none-any.whl
Collecting pex (from -r build_requirements.txt (line 2))
File was already downloaded /usr_data/tmp/glances/wheelhouse/pex-1.1.18-py2.py3-none-any.whl
Collecting requests (from -r build_requirements.txt (line 3))
File was already downloaded /usr_data/tmp/glances/wheelhouse/requests-2.12.4-py2.py3-none-any.whl
Collecting pip (from -r build_requirements.txt (line 4))
File was already downloaded /usr_data/tmp/glances/wheelhouse/pip-9.0.1-py2.py3-none-any.whl
Collecting setuptools (from -r build_requirements.txt (line 5))
File was already downloaded /usr_data/tmp/glances/wheelhouse/setuptools-32.3.1-py2.py3-none-any.whl
Successfully downloaded wheel pex requests pip setuptools
Run Code Online (Sandbox Code Playgroud)
它下载的每个文件都是一个Wheel …
我想要一个可以计算我拥有的对象数量的类 - 听起来收集所有对象然后对它们进行分组会更有效.
Python在collections.Counter中有一个理想的结构,Java或Scala有类似的类型吗?
我有一个像这样结构的项目:
/
/ Jenkinsfile
/ build_tools /
/ pipeline.groovy # Functions which define the pipeline
/ reporting.groovy # Other misc build reporting stuff
/ dostuff.sh # A shell script used by the pipeline
/ domorestuff.sh # Another pipeline supporting shell-script
Run Code Online (Sandbox Code Playgroud)
是否可以在/ build_tools中导入groovy文件,以便我可以在Jenkinsfile中使用这两个文件中的函数?
理想情况下,我想要一个看起来像这样的(Jenocode)Jenkins文件:
from build_tools.pipeline import build_pipeline
build_pipeline(project_name="my project", reporting_id=12345)
Run Code Online (Sandbox Code Playgroud)
我坚持的一点是你如何在我的伪代码的#1行上编写一个等效的伪装导入语句.
PS.为什么我这样做:build_tools文件夹实际上是许多项目共享的git子模块.我试图让每个项目访问一组通用的构建工具,以阻止每个项目维护者重新发明这个轮子.
我有一个相当难以管理的 Windows 闭源 Windows GUI 应用程序。它很乱(到处都是文件)并且安装过程很复杂。
有人建议我们将应用程序容器化,但这能做到吗?
对于 UNIX 应用程序,有一个简单的模式 - 只需让应用程序访问 X11 服务器的端口,并允许应用程序写入该端口,但是否有 Windows 等效项?有什么方法可以容器化 Windows 应用程序,但允许它在主机操作系统的桌面上生成窗口?
如果可能的话,是否有任何方便的食谱可以开始使用?