Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: 'news' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`

  • I am trying to run my poetry based python project inside docker using docker compose
  • When I run the application, it works but it gives me this warning
ch_news_dev_python          | Warning: 'news' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`.
ch_news_dev_python          | 
ch_news_dev_python          | The support to run uninstalled scripts will be removed in a future release.
ch_news_dev_python          | 
ch_news_dev_python          | Run `poetry install` to resolve and get rid of this message.

My project structure

news
├── docker
│   ├── development
│   │   ├── ...
│   │   ├── python_server
│   │   │   └── Dockerfile
│   │   ├── .env
│   │   └── docker-compose.yml
│   ├── production
│   │   └── ...
│   └── test
│       └── ...
├── src
│   └── news
│       ├── __init__.py
│       ├── __main__.py
│       ├── app.py
│       └── ...
├── tests
├── .gitignore
├── pyproject.toml
├── poetry.lock
└── ...

My python_server/Dockerfile

FROM python:3.10.11-slim

ENV PYTHONDONTWRITEBYTECODE 1 \
    PYTHONUNBUFFERED 1

RUN apt-get update \
    && apt-get install --no-install-recommends -y gcc libffi-dev g++\
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

ENV POETRY_VERSION=1.5.0

RUN pip install "poetry==$POETRY_VERSION"

RUN groupadd --gid 10000 ch_news \
    && useradd --uid 10000 --gid ch_news --shell /bin/bash --create-home ch_news

WORKDIR /home/ch_news

COPY --chown=10000:10000 pyproject.toml poetry.lock ./

USER ch_news

RUN poetry install --no-root --no-ansi --without dev

COPY --chown=10000:10000 ./src ./

CMD ["poetry", "run", "news"]

My docker-compose file

version: '3.9' # optional since v1.27.0
name: ch_news_dev
services:
  ...

  ch_news_dev_python:
    build:
      context: ../..
      dockerfile: ./docker/development/python_server/Dockerfile
    container_name: ch_news_dev_python
    depends_on:
      ch_news_dev_postgres:
        condition: service_healthy
    env_file:
      - .env
    image: ch_news_dev_python_image
    networks:
      - network
    restart: 'always'
    volumes:
      - postgres_certs:/home/ch_news/certs

networks:
  network:
    driver: bridge

volumes:
  postgres_certs:
    driver: local
  postgres_data:
    driver: local

My pyproject.toml file

[tool.poetry]
authors = ["..."]
description = "..."
name = "news"
version = "0.1.0"

[tool.poetry.dependencies]
feedparser = "^6.0.10"
python = "^3.10"
aiohttp = "^3.8.4"
python-dateutil = "^2.8.2"
asyncpg = "^0.27.0"
loguru = "^0.7.0"

[tool.poetry.dev-dependencies]
commitizen = "^3.2.2"
pre-commit = "^3.3.2"
pytest = "^7.3.1"
pytest-cov = "^4.0.0"
tox = "^4.5.1"

bandit = "^1.7.5"
black = "^23.3.0"
darglint = "^1.8.1"
flake8 = "^6.0.0"
flake8-bugbear = "^23.5.9"
flake8-docstrings = "^1.7.0"
isort = "^5.12.0"
mypy = "^1.3.0"
pytest-clarity = "^1.0.1"
pytest-sugar = "^0.9.7"
typeguard = "^4.0.0"
xdoctest = "^1.1.0"
aioresponses = "^0.7.4"
pytest-asyncio = "^0.21.0"
types-python-dateutil = "^2.8.19"

[tool.poetry.group.dev.dependencies]
isort = "^5.12.0"
types-python-dateutil = "^2.8.19.7"
flake8-docstrings = "^1.7.0"
xdoctest = "^1.1.1"
pre-commit = "^3.3.2"
commitizen = "^3.2.2"
tox = "^4.5.1"
mypy = "^1.3.0"
pytest = "^7.3.1"
flake8-bugbear = "^23.5.9"
black = "^23.3.0"
pytest-asyncio = "^0.21.0"
bandit = "^1.7.5"
typeguard = "^4.0.0"
pytest-sugar = "^0.9.7"

[tool.coverage.run]
branch = true
omit = ["src/news/__main__.py", "src/news/app.py"]
source = ["news"]

[tool.pytest.ini_options]
pythonpath = "src"
addopts = [
    "--import-mode=importlib",
]

[tool.coverage.report]
fail_under = 95

[tool.isort]
profile = "black"
src_paths = ["src", "tests"]
skip_gitignore = true
force_single_line = true
atomic = true
color_output = true

[tool.mypy]
pretty = true
show_column_numbers = true
show_error_codes = true
show_error_context = true
ignore_missing_imports = true
strict = true
warn_unreachable = true

[tool.poetry.scripts]
news = "news.__main__:app"

[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "v$major.$minor.$patch$prerelease"
version = "0.0.1"
[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0"]

Can someone kindly tell me how to get rid of this warning?

UPDATE 1

Getting the warning even after removing --no-root

like image 246
PirateApp Avatar asked Jan 28 '26 14:01

PirateApp


1 Answers

Finally find some ways to understand the docs saying.

My structure:

├── cmd
│   ├──__init__.py
│   ├── some_command.py
│   └── ...
├── pyproject.toml
└── ...

First you need to add the cmd as a package in the pyproject.toml file

[tool.poetry]
...
#package-mode = false
...
packages = [
    { include = "cmd" }
]
...
[tool.poetry.scripts]
seed = "cmd.some_command:main"

In case you set the package-mode to false, the script will not be installed when run poetry install. So a warning will display:

Warning: 'seed' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`.

The support to run uninstalled scripts will be removed in a future release.

Run `poetry install` to resolve and get rid of this message.

But it will still run the command. Just remove the package-mode=false then install, the warning will disappear.

Hope everyone can fix this problem, as the scripts document on poetry as not so clear for everyone.

like image 138
Hootpy Avatar answered Jan 30 '26 02:01

Hootpy