Skip to main content

Analyse poetry dependencies and comment on gitlab

Project description

Poetry dependencies scanner & gitlab commenter

This project consists of two scripts.

One analyses the poetry.lock and pyproject.toml files it receives and produces an output listing the outdated packages.

The other takes an input and posts it as a comment on a Gitlab merge request.

Here's how we use them:

# .gitlab-ci.yml

scan-deps:
  stage: test
  image: deps-scanner
  allow_failure: true
  script:
    - scan-deps poetry.lock pyproject.toml | comment-gitlab
  only:
    - merge_requests

The deps-scanner image is built from the Dockerfile in this repository.

Here's an example of what the output looks like in a merge request for this repository:

Comment screenshot

Installation

python -m pip install poetry-deps-scanner

Dependencies analysis

The following snippet is an example output the first script may produce:

 Name        │ Type   │ Source        │ Message
─────────────┼────────┼───────────────┼───────────────────────────────────────
 command-log │ direct │ xxxxx.itsf.io │ current=1.0.0 -> latest=2.0.0
 coverage    │ direct │ pypi.org      │ current=6.3.2 -> latest=6.4.1
 asgiref     │ trans. │ pypi.org      │ current=3.5.1 -> latest=3.5.2
 grpclib     │ trans. │ github.com    │ Couldn't compare versions.
 requests    │ error  │               │ ValueError (Hello world)

The Type column indicates whether the package is a direct or transitive dependency, or if there has been an uncaught exception:

  • direct means the package is a direct dependency.
  • trans. means the package is a transitive dependency: the dependency of a direct dependency or of a transitive dependency.
  • error means there has been an uncaught error. The exception class and message are displayed in the Message column

This is computed by using the pyproject.toml if given. If this file is not provided on the command line, the column will be empty.

A dependency is considered direct if it is present in the pyproject.toml.

Gitlab comment

The comment_gitlab.py script requires some environment variables to properly work:

  • BOT_USERNAME: The username for the bot user
  • BOT_TOKEN: A Gitlab access token for the bot user (see https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html)
  • CI_SERVER_URL: The URL of the Gitlab instance where to post
  • CI_PROJECT_ID: The ID of the project containing the MR to post on
  • CI_MERGE_REQUEST_IID: The IID of the merge request to comment on

The last three variables are automatically populated by Gitlab CI when running a job as part of a detached pipeline (for a merge request). Notice the only: [merge_requests] in the .gitlab-ci.yml above.

Of course, you can also provide them manually to integrate with any other build system.

If a comment from the bot user already exists, it will be replaced, in order to reduce the noise. In other words, there will be at most one comment from the bot on a given merge request. It will contain the results of the latest check.

Build the docker image outside ITSF

The Dockerfile inside the repository references images from our internal Docker registry proxy. You can easily build it on your own by removing the nexus.itsf.io:5005/ prefix.

# on Ubuntu
sed -i 's/nexus.itsf.io:5005\///g' Dockerfile
# on macOS
sed -e 's/nexus.itsf.io:5005\///g' -i "" Dockerfile
# then
docker build -t deps-scanner .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poetry-deps-scanner-2.0.0.post2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file poetry-deps-scanner-2.0.0.post2.tar.gz.

File metadata

  • Download URL: poetry-deps-scanner-2.0.0.post2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0

File hashes

Hashes for poetry-deps-scanner-2.0.0.post2.tar.gz
Algorithm Hash digest
SHA256 5f490a83d16b9207bba265c47bd772f2fb19be916c2a634ef390c23ac8012124
MD5 f62d5197b54fcd8d1f10d440899f0274
BLAKE2b-256 57c39a82479232e8eca311dfb8a78f4d86e9d1dcd18de08ebaa864d98e4f32a9

See more details on using hashes here.

File details

Details for the file poetry_deps_scanner-2.0.0.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_deps_scanner-2.0.0.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 612739f2b692bbbbf9f7944a3ecfc56bb077066550c6d8d7b4cd48745050f62a
MD5 1f50ff7ed0a13ae4dd82d4f58851425e
BLAKE2b-256 7c14f2e32362d867f91fed6e8a6476e81617c44d26b2e5450b1cc4e4e810287c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page