给定这样的文件夹结构:
dags/
  **/
    code.py
tests/
  dags/
    **/
      test_code.py
  conftest.py
Run Code Online (Sandbox Code Playgroud)
其中 dags 作为 src 文件的根,“dags/a/b/c.py”导入为“abc”。
我想在code.py中测试以下函数:
dags/
  **/
    code.py
tests/
  dags/
    **/
      test_code.py
  conftest.py
Run Code Online (Sandbox Code Playgroud)
但我面临的问题是我无法找到修补get_connfrom的方法dag_common.connections。我尝试了以下操作:
import os
import sys
# adds dags to sys.path for tests/*.py files to be able to import them
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "dags"))
{{fixtures}}
Run Code Online (Sandbox Code Playgroud)
我测试了以下替代品{{fixtures}}:
(1.a) - 默认
from dag_common.connections import get_conn
from utils.database import dbtypes
def select_records(
    conn_id: str,
    sql: str,
    bindings,
):
    conn: dbtypes.Connection = get_conn(conn_id)
    with conn.cursor() …Run Code Online (Sandbox Code Playgroud) 在Chrome控制台中列出对象的属性时,我偶然发现了以前从未见过的符号.实际上,一些属性被概述了<angle-brackets-properties>和[[double-square-brackets-properties]]符号.任何人都可以了解一下:
在尝试调试Dockerfile中的RUN语句时,我尝试将输出重定向到绑定卷(./mongo/log)中的文件.
令我惊讶的是,我无法通过RUN命令创建文件,或者使用重定向/附加(>,>>)运算符将另一个命令的输出传递给文件.然而,我能够通过登录正在运行的容器docker exec -ti mycontainer /bin/sh并从那里发出命令来执行所述任务.
为什么会发生这种情况?如何将Dockerfile/redirect输出中的文件触摸到文件或运行Dockerfile的控制台?
这是我的Dockerfile:
FROM mongo:3.4
#Installing NodeJS
  RUN apt-get update && \
    apt-get install -y curl && \
    curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
    apt-get install -y nodejs
#Setting Up Mongo
  WORKDIR /var/www/smq
  COPY ./mongo-setup.js mongo-setup.js
  ##for testing
  RUN touch /var/log/node.log && /
      node --help 2>&1 > /var/log/node.log
  ##this was the command to debug
  #RUN node mongo-setup.js > /var/log/mongo-setup.log 2> /var/log/mongo-setup.error.log
Run Code Online (Sandbox Code Playgroud)
这里是我的docker-compose.yml的摘录:
mongodb:
    build:
      context: …Run Code Online (Sandbox Code Playgroud) 我使用 jupyter notebook 在 python 中编写了一个代码,我想生成该程序的可执行文件。
运行时poetry add package,poetry 决定在没有我询问的情况下更新一些过时的依赖项:
$ poetry add -D ipython\nUsing version ^7.26.0 for ipython\n\nUpdating dependencies\nResolving dependencies... (6.8s)\n\nWriting lock file\n\nPackage operations: 13 installs, 2 updates, 0 removals\n\n  \xe2\x80\xa2 Installing ipython-genutils (0.2.0)\n  \xe2\x80\xa2 Installing parso (0.8.2)\n  \xe2\x80\xa2 Installing ptyprocess (0.7.0)\n  \xe2\x80\xa2 Installing traitlets (5.0.5)\n  \xe2\x80\xa2 Installing wcwidth (0.2.5)\n  \xe2\x80\xa2 Installing appnope (0.1.2)\n  \xe2\x80\xa2 Installing backcall (0.2.0)\n  \xe2\x80\xa2 Updating connexion (2.8.0 -> 2.9.0) <---------- "I never asked for this"\n  \xe2\x80\xa2 Installing jedi (0.18.0)\n  \xe2\x80\xa2 Installing matplotlib-inline (0.1.2)\n  \xe2\x80\xa2 Installing pexpect (4.8.0)\n …Run Code Online (Sandbox Code Playgroud) 有没有办法在 VSCode 中选择整个函数定义?这是我的开发工作流程中的一个重复操作,我想自动化它而不是使用鼠标。找不到它的快捷方式。当然应该有办法吗?
我使用 python/javascript 作为语言,安装了 Python (ms-python.python) 和 JavaScript 以及 TypeScript Nightly (ms-vscode.vscode-typescript-next) 扩展。
谢谢你!
我想使用诗歌分发一个 python 包并使其作为 cli 可执行,就像black, pipenv, poetry,flake8朋友一样。
示例用法如下:
\npython -m my-package [args]\nRun Code Online (Sandbox Code Playgroud)\n到目前为止,我已经成功构建了一个轮子并使用以下配置将其安装在 docker 映像上:
\npyproject.toml
[tool.poetry]\nname = "my-package\nversion = "0.1.0"\ndescription = "A cli tool"\nauthors = []\npackages = [\n    { include = "src/main.py" },\n]\n\n[build-system]\nrequires = ["poetry-core>=1.0.0"]\nbuild-backend = "poetry.core.masonry.api"\nRun Code Online (Sandbox Code Playgroud)\n构建命令:
\npoetry build -f wheel\npoetry export -o dist/requirements.txt\nRun Code Online (Sandbox Code Playgroud)\nDocker 镜像:
\nFROM python:3.8-slim as base\n\nCOPY dist/requirements.txt /requirements.txt\nRUN pip install --no-cache-dir --upgrade -r /requirements.txt\nARG APP_VERSION\nCOPY …Run Code Online (Sandbox Code Playgroud) 我正在尝试为特定项目安装pyodbc,但不幸的是,当我尝试进行安装时,无论命令如何,最终都会出现以下错误:
Command "/usr/local/bin/python3.5 -u -c "import setuptools,
tokenize;__file__='/tmp/pip-build-vw5rz5_t/pyodbc/setup.py';
exec(compile(getattr(tokenize, 'open', open)(__file__).read()
.replace('\r\n', '\n'), __file__, 'exec'))" install --record
/tmp/pip-p5vfq2hq-record/install-record.txt --single-version-
externally-managed --compile" failed with error code 1 in 
/tmp/pip-build-vw5rz5_t/pyodbc/
Run Code Online (Sandbox Code Playgroud)
显然,这里已经报告了这个错误,我完全知道这是一个python版本依赖错误。但是,我尝试了许多不同的方法来处理这个问题,包括 Stack Overflow 问题中的所有尝试,以及以下内容:
原始尝试:
sudo pip3 install pyodbc
Run Code Online (Sandbox Code Playgroud)谁能告诉我安装依赖于另一个 python 版本而不是默认 python 包的 python 包的正确方法吗?我有另一个在 python3.5 上运行的项目,所以我更愿意在 virtualenv 中进行安装。
谢谢你的帮助!
我正在为 Docker 构建一个非交互式可配置的 MongoDB 映像,目前的目标是能够以编程方式从配置文件加载身份验证用户。我目前的问题是,虽然我可以成功地将用户添加到数据库,但他们似乎不会在构建过程中持续存在,因此我的节点容器无法成功针对数据库进行身份验证。
这是我的 mongodb 实例的主要 dockerfile:
FROM mongo:latest
#Installing Node
RUN apt-get update && \
    apt-get install -y curl && \
    curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
    apt-get install -y nodejs
#Setting Up Mongo
WORKDIR /var/www/smq
COPY ./docker/mongo-setup.js mongo-setup.js
COPY ./.config/mongo /var/www/.config/mongo
RUN if [ -e /var/www/.config/mongo/mongod.conf ] ; then cp /var/www/.config/mongo/mongod.conf /etc/mongod.conf ; fi
RUN mongod --port 27017 & node mongo-setup.js && mongod --shutdown
CMD ["mongod", "--auth", "--port", "27017"]
Run Code Online (Sandbox Code Playgroud)
我的设置还依赖于 docker-compose:
  mongodb:
    build:
      context: …Run Code Online (Sandbox Code Playgroud) 设置:
为什么 Jest 的 expect 不能将 node.js 的 util.promisify 返回的承诺识别为 Promise 的实例?
以下失败:
const util = require('util');
const fn = util.promisify((opts, cb) => cb(null, {})); 
const promise = fn();
expect(promise).toBeInstanceOf(Promise)
Run Code Online (Sandbox Code Playgroud)
同样,以下失败:
const util = require('util');
const fn = util.promisify((opts, cb) => cb(null, {}));
const promise = fn();
expect(promise.then).toBeInstanceOf(Function);
Run Code Online (Sandbox Code Playgroud)
可以通过检查typeof promise.then“功能”来规避这个问题,但我对这种行为的原因很感兴趣。
非常感谢您提供的信息!
python ×5
docker ×2
dockerfile ×2
bash ×1
ecmascript-5 ×1
exe ×1
executable ×1
javascript ×1
jestjs ×1
mocking ×1
mongodb ×1
node.js ×1
pip ×1
pyodbc ×1
pytest ×1
python-3.3 ×1
python-3.5 ×1
python-wheel ×1