有没有办法忽略指定目录中发生的错误?
例如,目录D103 Missing docstring in public function内的每个文件都有错误/foo,我想忽略该错误。
是否可以在setup.cfg文件中设置这样的设置?
我有一个具有以下结构的项目:
proj
src
application
app.py
manage.py
migrations
Dockerfile
docker-compose.yaml
Run Code Online (Sandbox Code Playgroud)
我的目标是在 docker-compose 期间从应用程序目录运行迁移以在数据库中创建表。
python manage.py db upgrade
Run Code Online (Sandbox Code Playgroud)
文件
FROM python:3.7-alpine
ADD requirements.txt /code/
WORKDIR /code
RUN apk add --no-cache postgresql-dev gcc python3 musl-dev && \
pip3 install -r requirements.txt
ADD . /code
EXPOSE 5000
WORKDIR /code/src/application
CMD ["flask", "run", "--host=0.0.0.0"]
Run Code Online (Sandbox Code Playgroud)
docker-compose.yaml
---
version: "3"
services:
web:
links:
- "db"
build: .
ports:
- "5000:5000"
volumes:
- .:/code
depends_on:
- db
env_file:
- .env
db:
image: postgres:10
restart: always
environment:
- POSTGRES_USER=postgres …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 SQLAlchemy 设置时间戳列的值,但遇到以下错误:
column "timestamp" is of type timestamp without time zone but expression is of type numeric
Run Code Online (Sandbox Code Playgroud)
我的表如下所示:
class SomeTable(db.Model):
timestamp = Column(TIMESTAMP)
Run Code Online (Sandbox Code Playgroud)
插入尝试如下所示:
SomeTable(timestamp=time.time())
Run Code Online (Sandbox Code Playgroud)
当我使用 datetime.now() 而不是 time.time() 时,记录将插入到表中,但是当我从数据库中选择它时,它具有以下格式:
2019-04-02 11:44:24.801046
Run Code Online (Sandbox Code Playgroud)
所以看起来 TIMESTAMP 字段不存储时间戳格式。
这是常规的 postgres 行为吗?或者我错过了什么?
我正在尝试设置 pylint 以使用预提交。我已经查看了文档,但我仍然感到困惑。我不知道如何正确设置 .pre-commit-config.yaml。
你能提供最基本的模板吗?
- repo: myrepo
rev: '' # Don't know that to type here
hooks:
- id: pylint
Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以使用单个命令来安装文件中除命令中指定的依赖项之外的所有依赖项?我正在寻找这样的东西:
pip install -r req_file.txt --except unwanted_package
让我们想象一下这段代码:
try:
if condition1 and condition2: # some_exception may happen here
function1()
elif condition3 and condition4: # some_exception may happen here
function2()
else:
big
block
of
instructions
except some_exception:
big
block
of
instructions
Run Code Online (Sandbox Code Playgroud)
如您所见,我重复了大量的说明(两者相同)。有没有一种避免重复的方法,但是与将代码放入函数中有所不同吗?
某种不同的逻辑还是使用finally还是尝试?我只是想不通。
在此先感谢您的帮助!
代码如下:
class UserViewSet(ViewSet):
# ... Many other actions
def list(self):
# list implementation
def retrieve(self, request, pk):
# manual pk int validation
router = DefaultRouter()
router.register(r"users", UserViewSet, basename="users")
urlpatterns = router.urls
Run Code Online (Sandbox Code Playgroud)
现在 pk 未验证为 int,因此会向 db 发出请求,这是我想避免的。有什么方法可以在网址中添加这种类型的验证吗?我可以在不使用路由器的情况下实现这一点,如下所示:
urlpatterns = [
path('users/<int:pk>/', UserViewSet.as_view({'get': 'retrieve'}),
# many other actions have to be added seperately
]
Run Code Online (Sandbox Code Playgroud)
但我的视图集中有很多操作,所有操作都必须单独添加。有没有更干净的方法或包?
python-3.x ×5
python ×3
python-3.7 ×2
django ×1
docker ×1
exception ×1
flake8 ×1
flask ×1
git ×1
if-statement ×1
postgresql ×1
pylint ×1
sqlalchemy ×1
timestamp ×1