小编syt*_*ech的帖子

在Flask路线的尾随斜线

以下面两条路线为例.

app = Flask(__name__)

@app.route("/somewhere")
def no_trailing_slash():
    #case one

@app.route("/someplace/")
def with_trailing_slash():
    #case two
Run Code Online (Sandbox Code Playgroud)

根据文档,以下内容被理解为:

  • 在第一种情况下,对路由的请求"/somewhere/"将返回404响应."/somewhere"已验证.

  • 如果是两个,"/someplace/"则有效"/someplace"并将重定向到"/someplace/"

我想看到的行为是"逆"情况下,两个行为.例如,"/someplace/"将重定向到"/someplace"而不是相反.有没有办法定义一个路由来采取这种行为?

根据我的理解,strict_slashes=False可以在路由上设置以在案例一中有效地获得案例二的相同行为,但我想要做的是使重定向行为始终重定向到没有尾部斜杠的URL .

我曾经想过使用的一个解决方案是使用404的错误处理程序,就像这样.(不确定这是否会起作用)

@app.errorhandler(404)
def not_found(e):
    if request.path.endswith("/") and request.path[:-1] in all_endpoints:
        return redirect(request.path[:-1]), 302
    return render_template("404.html"), 404
Run Code Online (Sandbox Code Playgroud)

但我想知道是否有更好的解决方案,比如某种类型的drop-in app配置,类似于strict_slashes=False我可以在全球范围内应用.也许是蓝图或网址规则?

python flask

16
推荐指数
3
解决办法
9484
查看次数

检查 Gitlab 管道中的变量是否为 null

当使用另一个 null 变量的内容声明它时,如何检查 Gitlab 管道中的 null 变量?VAR_NULL就像下面的变量当NO_VAR为 null 时:

variables:
  VAR_EMPTY: ""
  VAR_NULL: "${NO_VAR}"
Run Code Online (Sandbox Code Playgroud)

检查管道结果,其中仅VAR_EMPTY == ""评估NO_VAR == nulltrue,所有其他均为false

管道结果为了方便起见,截图,完整结果:https://gitlab.com/labaz/test-gitlab-pipeline-null-var/-/p ​​ipelines/ 493036820): 管道结果

完整的管道脚本https://gitlab.com/labaz/test-gitlab-pipeline-null-var/-/blob/main/.gitlab-ci.yml):

variables:
  VAR_EMPTY: ""
  VAR_NULL: "${NO_VAR}"

jobTest-Var_Empty-IsNull:       # This job runs in the build stage, which runs first.
  rules:
    - if: '$VAR_EMPTY == null'
  script:
    - 'echo "VAR_EMPTY IS null"'

jobTest-Var_Empty-IsEmpty:       # This job runs in the build stage, which …
Run Code Online (Sandbox Code Playgroud)

gitlab gitlab-ci

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

我编写的 GitHub Action 无法访问调用该操作的存储库文件

GitHub上有一个示例存储库,其中包含我正在处理的目录结构。要运行 GitHub Action,您只需转到存储库的 Action 选项卡并手动运行 Action。

\n
\n

我有一个自定义的 GitHub Action,以及pythonDocker 容器中的基础映像,但希望该python版本成为 GitHub Action 的输入。为此,我创建了第二个中间 Docker 容器,以使用python版本输入参数运行。

\n

我遇到的问题是我无权访问调用 GitHub Action 的原始存储库文件。例如,假设存储库被调用python-sample-project并且具有文件夹结构:

\n
python-sample-project\n\xe2\x94\x82   main.py\n\xe2\x94\x82   file1.py    \n\xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80folder1\n\xe2\x94\x82   \xe2\x94\x82   file2.py\n
Run Code Online (Sandbox Code Playgroud)\n

我看到了main.py,,file1.py并且folder1/file2.pyentrypoint.sh。但是,docker-action/entrypoint.sh我只看到 linux 文件夹结构和entrypoint.shdocker-action/Dockerfile.

\n

在我使用的 Alpine 示例中,操作entrypoint.sh脚本如下所示:

\n
python-sample-project\n\xe2\x94\x82   main.py\n\xe2\x94\x82   file1.py    \n\xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80folder1\n\xe2\x94\x82   \xe2\x94\x82   file2.py\n
Run Code Online (Sandbox Code Playgroud)\n

docker-action/有一个Dockerfile脚本entrypoint.sh,应该使用 Alpine(或 Python)的动态版本为内部容器运行

\n …

python github docker github-actions

9
推荐指数
1
解决办法
4714
查看次数

当密钥仍然有效时,为什么 Gitlab CI 会重新上传缓存

在 gitlab CI 文件中用于 Angular 项目;我使用 package-lock.json 文件的校验和作为密钥来定义全局缓存。这样缓存仅在 package-lock.json 文件更改时失效。

cache:
  key:
    files:
      - package-lock.json
  paths:
    - node_modules/
    - .npm
Run Code Online (Sandbox Code Playgroud)

问题:即使缓存密钥仍然有效,缓存仍然会上传。(见图片缓存名称没有改变)

在此输入图像描述

我希望缓存仅在失效时才上传,有什么办法可以实现这一点吗?或者有什么其他备注建议?

node-modules gitlab gitlab-ci angular

9
推荐指数
1
解决办法
838
查看次数

docker executor 与 docker dind 镜像

我是 gitlabci 的新手。我想了解为什么我们需要 docker dind 镜像才能在 GitLab CI 作业中构建 docker 镜像。为什么我们不能使用docker执行器,在脚本下运行docker命令呢?

当我们注册 docker executor gitlab runner 时,我们选择一个镜像。再次在 gitlabci 中,我们在image:services:字段下选择一个镜像。那么这是否意味着这个 GitLab CI 作业容器在 docker 执行器容器内运行?

gitlab-ci

7
推荐指数
1
解决办法
3105
查看次数

配置 gitlab-ci.yml 文件时出现问题。配置应该实现一个脚本:或一个触发器:关键字

我正在尝试在 gitlab 上创建我的第一个 CI。我有一个 Angular 应用程序,带有 nx-workspace (monorepo),这是我的完整 ci 文件:

image: node:16-alpine
stages:
  - setup
  - test

install-dependencies:
  stage: setup
  only:
    - develop

.distributed:
  interruptible: true
  only:
    - develop
  needs: ["install-dependencies"]
  artifacts:
    paths:
      - node_modules/.cache/nx

workspace-lint:
  stage: test
  extends: .distributed
  script:
    - npx nx workspace-lint

format-check:
  stage: test
  extends: .distributed
  script:
    - npx nx format:check

lint:
  stage: test
  extends: .distributed
  script:
    - npx nx affected --base=HEAD~1 --target=lint --parallel=3

test:
  stage: test
  extends: .distributed
  script:
    - npx nx affected --base=HEAD~1 --target=test …
Run Code Online (Sandbox Code Playgroud)

yaml gitlab gitlab-ci angular

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

在运行时向 django 模型添加属性?

具体来说,我有 django 模型对象,我想在运行时添加属性。如果这适用于 Django 之外的任何 python 类,那就太好了。

我有以下型号

模型.py

class person(models.Model):
    # ...
    firstname=models.TextField(max_length=100)
    lastname=models.TextField(max_length=100)
    type=models.TextField(max_length=100)
    address = models.ForeignKey(address, null=True)

class event(models.Model):
    date=models.DateTimeField(auto_now=True )
    name=models.CharField(max_length=100)     
    attendees = models.ManyToManyField(person)

def main():
    p = person()
    p.fisrtsname="Firsty"
    p.lastname="Lasty"
    p.addnewproperty(newtemporaryproperty)
    p.newtemporaryproperty="This is a new temporary property"
Run Code Online (Sandbox Code Playgroud)

当我使用时

person.newtemporaryproperty=property("")
Run Code Online (Sandbox Code Playgroud)

尝试向其添加值时收到“无法设置属性错误”。我可能用错了。

编辑

我想做的是查看模型中的每个人是否参加过活动。如果他们有,请在他们的名字旁边勾选一个复选框。这是附加的相关文件

表.py

class AttendeesTable(tables.Table):
    firstname = tables.Column()
    lastname = tables.Column()
    here = tables.TemplateColumn('<input id="attendee_{{ record.pk }}" {{ 
record.here }} type="checkbox" />',
                             verbose_name="Here?")

    class Meta:
        attrs = {'id': 'attendancetable', 'width': '100%', 'class': 'table 
table-hover'}
        template …
Run Code Online (Sandbox Code Playgroud)

python django

6
推荐指数
1
解决办法
5687
查看次数

为什么 gitlab 在提交时运行重复的管道?

我的工作内容如下.gitlab-ci.yml

stages:
  - stage1
  - stage2


job1:
  stage: stage1
  script:
    - echo "Running default stage1, pipeline_source=$CI_PIPELINE_SOURCE"

job2:
  stage: stage2
  rules:
    - if: $CI_PIPELINE_SOURCE == "push"
    - when: always
  script:
    - echo "Running STAGE2!   pipeline_source=$CI_PIPELINE_SOURCE"
Run Code Online (Sandbox Code Playgroud)

当我将此更改提交到合并请求分支时,似乎正在启动两个管道。

这是 gitlab 中的已知问题吗?或者我在这里理解有问题?

yaml gitlab gitlab-ci

6
推荐指数
2
解决办法
9073
查看次数

Codecov 覆盖率报告似乎错误地省略了 __init__.py 文件

我正在使用coverage并通过我的 Travis CI 构建codecov报告我的Github 项目的覆盖率。但是,在线报告出乎意料,因为它们与本地报告不匹配,因为它们__init__.py似乎省略了根文件。
我已经查看了coverage.py 和codecov 的文档,没有任何内容突出显示,但我觉得我可能遗漏了一些明显的内容。

当我运行测试并执行时coverage report- 结果符合预期并报告89%覆盖率。请注意,该behave_webdriver\__init__.py文件已包含在内。

Name                                     Stmts   Miss  Cover
------------------------------------------------------------
behave_webdriver\__init__.py               206     26    87%
behave_webdriver\conditions.py              58      5    91%
behave_webdriver\steps\__init__.py           2      0   100%
behave_webdriver\steps\actions.py           79     12    85%
behave_webdriver\steps\expectations.py     173     14    92%
------------------------------------------------------------
TOTAL                                      518     57    89%
Run Code Online (Sandbox Code Playgroud)

这也与codecov --dump travis build 上显示的 XML 报告一致。

但是,在线报告正在报告91%覆盖范围并且似乎省略了第一个__init__.py文件。

codecov 在线报告

我希望能够在__init__.py这里看到该文件,但它似乎在报告中被省略了。不知道为什么这没有出现。

目录中的另一个__init__.py文件确实 …

python coverage.py

5
推荐指数
0
解决办法
351
查看次数

gitlab-ci 运行程序需要很长时间才能从 S3 缓存下载/上传(没有“ServerAddress”)

我们有一个 gitlab 运行器在 AWS 上的 kubernetes 集群中运行。测试工作:

test-job:
  image: centos
  stage: build
  cache:
    paths:
     - output
  script:
    - mkdir -p output
    - date +"%Y-%m-%d" > output/date.txt
  tags:
    - docker
  when: always
takes about 4 minutes to run - but only 4s if i remove the "cache" section.
Run Code Online (Sandbox Code Playgroud)

我的跑步者的 config.toml 看起来像这样

[[runners]]
  name = "gitlab-runner..."
  url = "https://gitlab...."
  token = "....."
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    Type = "s3"
    Shared = true
    [runners.cache.s3]
      AccessKey = "...."
      SecretKey = "...."
      BucketName = …
Run Code Online (Sandbox Code Playgroud)

gitlab gitlab-ci-runner gitlab-runner

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