<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>40388</bug_id>
          
          <creation_ts>2021-07-07 02:04:36 +0300</creation_ts>
          <short_desc>load_entry_point загружает бинарники из /usr/bin</short_desc>
          <delta_ts>2021-09-06 11:18:24 +0300</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Development</classification>
          <product>Sisyphus</product>
          <component>python3-module-pkg_resources</component>
          <version>unstable</version>
          <rep_platform>x86_64</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>NOTABUG</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P5</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Vitaly Lipatov">lav</reporter>
          <assigned_to name="Stanislav Levin">slev</assigned_to>
          <cc>antohami</cc>
    
    <cc>cas</cc>
    
    <cc>cow</cc>
    
    <cc>evg</cc>
    
    <cc>george</cc>
    
    <cc>grenka</cc>
    
    <cc>imz</cc>
    
    <cc>kotopesutility</cc>
    
    <cc>lav</cc>
    
    <cc>nbr</cc>
    
    <cc>qa_viy</cc>
    
    <cc>rider</cc>
    
    <cc>sem</cc>
    
    <cc>shaba</cc>
    
    <cc>sin</cc>
    
    <cc>slev</cc>
    
    <cc>toni</cc>
    
    <cc>vitty</cc>
    
    <cc>viy</cc>
          
          <qa_contact>qa-sisyphus</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>200075</commentid>
    <comment_count>0</comment_count>
    <who name="Vitaly Lipatov">lav</who>
    <bug_when>2021-07-07 02:04:36 +0300</bug_when>
    <thetext>Схема с entry_points.txt вызывает проблемы пересечения с *.py файлами из /usr/bin/

Например
$ cat entry_points.txt 
[console_scripts]
html2text = html2text.cli:main
из пакета python3.module-html2text

приводит к попытке загрузить /usr/bin/html2text.py (от python2 модуля), и в итоге провал:

$ python3 
...
&gt;&gt;&gt; from pkg_resources import load_entry_point
&gt;&gt;&gt; load_entry_point(&apos;html2text==2020.1.16&apos;, &apos;console_scripts&apos;, &apos;html2text&apos;)()
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/usr/lib/python3/site-packages/pkg_resources/__init__.py&quot;, line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File &quot;/usr/lib/python3/site-packages/pkg_resources/__init__.py&quot;, line 2793, in load_entry_point
    return ep.load()
  File &quot;/usr/lib/python3/site-packages/pkg_resources/__init__.py&quot;, line 2411, in load
    return self.resolve()
  File &quot;/usr/lib/python3/site-packages/pkg_resources/__init__.py&quot;, line 2417, in resolve
    module = __import__(self.module_name, fromlist=[&apos;__name__&apos;], level=0)
ModuleNotFoundError: No module named &apos;html2text.cli&apos;; &apos;html2text&apos; is not a package
&gt;&gt;&gt; 


Начинает с текущего каталога (с каталога, откуда вызван скрипт, то есть /usr/bin/):

stat(&quot;/usr/lib/python3/site-packages/html2text-2020.1.16-py3.7.egg-info/entry_points.txt&quot;, {st_mode=S_IFREG|0644, st_size=50, ...}) = 0
openat(AT_FDCWD, &quot;/usr/lib/python3/site-packages/html2text-2020.1.16-py3.7.egg-info/entry_points.txt&quot;, O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=50, ...}) = 0
ioctl(3, TCGETS, 0x7fff5e33dfd0)        = -1 ENOTTY (Неприменимый к данному устройству ioctl)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=50, ...}) = 0
read(3, &quot;[console_scripts]\nhtml2text = ht&quot;..., 51) = 50
read(3, &quot;&quot;, 1)                          = 0
close(3)                                = 0
stat(&quot;/usr/bin&quot;, {st_mode=S_IFDIR|0755, st_size=147456, ...}) = 0
stat(&quot;/usr/bin/html2text/__init__.cpython-37m.so&quot;, 0x7fff5e33cfc0) = -1 ENOTDIR (Это не каталог)
stat(&quot;/usr/bin/html2text/__init__.cpython-37m-x86_64-linux-gnu.so&quot;, 0x7fff5e33cfc0) = -1 ENOTDIR (Это не каталог)
stat(&quot;/usr/bin/html2text/__init__.abi3.so&quot;, 0x7fff5e33cfc0) = -1 ENOTDIR (Это не каталог)
stat(&quot;/usr/bin/html2text/__init__.so&quot;, 0x7fff5e33cfc0) = -1 ENOTDIR (Это не каталог)
stat(&quot;/usr/bin/html2text/__init__.py&quot;, 0x7fff5e33cfc0) = -1 ENOTDIR (Это не каталог)
stat(&quot;/usr/bin/html2text/__init__.pyc&quot;, 0x7fff5e33cfc0) = -1 ENOTDIR (Это не каталог)
stat(&quot;/usr/bin/html2text&quot;, {st_mode=S_IFREG|0755, st_size=182312, ...}) = 0
stat(&quot;/usr/bin/html2text.py&quot;, {st_mode=S_IFREG|0755, st_size=32121, ...}) = 0

Мне кажется, для дистрибутива это вредное свойство — загружать модули из /usr/bin.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>200709</commentid>
    <comment_count>1</comment_count>
    <who name="Stanislav Levin">slev</who>
    <bug_when>2021-07-19 14:43:46 +0300</bug_when>
    <thetext>Механизм entrypoints от setuptools здесь ни при чем.

Это ожидаемое поведение Python:
https://docs.python.org/3/tutorial/modules.html#the-module-search-path

То есть директория, содержащая входящий скрипт, - это &apos;/usr/bin&apos;.
Например,

```console
[root@localhost .in]# cat /usr/bin/some_python_script
#!/usr/bin/python3

import os
import sys


print(os.getcwd())
print(sys.path)
[root@localhost .in]# /usr/bin/some_python_script
/.in
[&apos;/usr/bin&apos;, &apos;/usr/lib64/python39.zip&apos;, &apos;/usr/lib64/python3.9&apos;, &apos;/usr/lib64/python3.9/lib-dynload&apos;, &apos;/usr/lib64/python3/site-packages&apos;, &apos;/usr/lib/python3/site-packages&apos;]
```

Существует режим &quot;изоляции&quot;:
```
       -I     Run Python in isolated mode. This also implies -E and -s. In isolated
              mode sys.path contains neither the script&apos;s directory nor the  user&apos;s
              site-packages   directory.  All  PYTHON*  environment  variables  are
              ignored, too.  Further restrictions may be  imposed  to  prevent  the
              user from injecting malicious code.
```

Определение module в Python:
&gt; A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.


На мой взгляд, не стоит помещать модули Python в &apos;/usr/bin&apos; в общем случае.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>202157</commentid>
    <comment_count>2</comment_count>
    <who name="Vitaly Lipatov">lav</who>
    <bug_when>2021-08-31 01:41:29 +0300</bug_when>
    <thetext>(Ответ для Stanislav Levin на комментарий #1)
...
&gt; На мой взгляд, не стоит помещать модули Python в &apos;/usr/bin&apos; в общем случае.
Правильно ли я понимаю, что в нашем случае это означает,
что в /usr/bin не должно быть файлов *.py ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>202350</commentid>
    <comment_count>3</comment_count>
    <who name="Stanislav Levin">slev</who>
    <bug_when>2021-09-06 11:18:24 +0300</bug_when>
    <thetext>(Ответ для Vitaly Lipatov на комментарий #2)
&gt; (Ответ для Stanislav Levin на комментарий #1)
&gt; ...
&gt; &gt; На мой взгляд, не стоит помещать модули Python в &apos;/usr/bin&apos; в общем случае.
&gt; Правильно ли я понимаю, что в нашем случае это означает,
&gt; что в /usr/bin не должно быть файлов *.py ?

Такого ограничения нет. Чтобы не шарахаться от всех неожиданных импортов, существует режим изоляции.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>