Re: Is Python 3.7 supported? (py-uvicorn does not work)

From: Kubilay Kocak <koobs_at_FreeBSD.org>
Date: Thu, 19 Aug 2021 00:41:34 UTC
On 17/08/2021 9:56 am, Miroslav Lachman wrote:
> Hi,

Hi Miroslav,

If it's in tree then it's supported, in the sense that we accept issues 
for them and will endeavour to resolve reports.

Longer term, Python team will aim to move closer to tracking upstreams 
(CPython) definition of supported, which is essentially latest 
major.minor plus one minor version back (security and bugfixes).

> we are using Python 3.7 for hosted applications. New application 
> requires py-uvicorn so I built it in poudriere as usual. No errors. But 
> after installation on target machine uvicorn does not work spiting 
> following traceback:
> 
> Traceback (most recent call last):
>    File "/usr/local/bin/uvicorn", line 10, in <module>
>      from importlib.metadata import distribution
> ModuleNotFoundError: No module named 'importlib.metadata'

I couldn't see why/how uvicorn is using or calling importlib_metadata 
(it imports importlib, as the initial traceback line shows) in a cursory 
source review [1] . Something is transforming the import importlib call 
or falling back to importlib_metadata automatically for Python < 3.8, 
but I didn't investigate or isolate what.

Are all ports completely up to date with respect to latest versions in 
the tree?

> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>    File "/usr/local/bin/uvicorn", line 13, in <module>
>      from importlib_metadata import distribution
> ModuleNotFoundError: No module named 'importlib_metadata'
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>    File "/usr/local/bin/uvicorn", line 15, in <module>
>      from pkg_resources import load_entry_point
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 3242, in <module>
>      @_call_aside
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 3226, in _call_aside
>      f(*args, **kwargs)
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 3255, in _initialize_master_working_set
>      working_set = WorkingSet._build_master()
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 568, in _build_master
>      ws.require(__requires__)
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 886, in require
>      needed = self.resolve(parse_requirements(requirements))
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 772, in resolve
>      raise DistributionNotFound(req, requirers)
> pkg_resources.DistributionNotFound: The 'asgiref>=3.3.4' distribution 
> was not found and is required by uvicorn

But at a minimum it looks like the port is missing a RUN_DEPENDS on 
asgiref [2]

Maintainer is CC'd

> 
> 
> OK, py-importlib-metadata is probably missing so I tried to build it in 
> poudriere but it failed in configure stage with the following error:
> 
> ===>   py37-zipp-3.4.0 depends on package: py37-setuptools_scm>0 - found
> ===>   Returning to build of py37-zipp-3.4.0
> ===>   py37-zipp-3.4.0 depends on package: py37-setuptools>0 - found
> ===>   py37-zipp-3.4.0 depends on file: /usr/local/bin/python3.7 - found
> ===========================================================================
> =======================<phase: lib-depends    >============================
> ===========================================================================
> =======================<phase: configure      >============================
> ===>  Configuring for py37-zipp-3.4.0
> WARNING: The wheel package is not available.
> /usr/local/bin/python3.7: No module named pip
> Traceback (most recent call last):
>    File 
> "/usr/local/lib/python3.7/site-packages/setuptools/installer.py", line 
> 75, in fetch_build_egg
>      subprocess.check_call(cmd)
>    File "/usr/local/lib/python3.7/subprocess.py", line 363, in check_call
>      raise CalledProcessError(retcode, cmd)
> subprocess.CalledProcessError: Command '['/usr/local/bin/python3.7', 
> '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 
> '/tmp/tmpllmb234s', '--quiet', 'toml']' returned non-zero exit status 1.
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):
>    File "<string>", line 1, in <module>
>    File "setup.py", line 6, in <module>
>      setuptools.setup()
>    File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", 
> line 152, in setup
>      _install_setup_requires(attrs)
>    File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", 
> line 147, in _install_setup_requires
>      dist.fetch_build_eggs(dist.setup_requires)
>    File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", 
> line 782, in fetch_build_eggs
>      replace_conflicting=True,
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 768, in resolve
>      replace_conflicting=replace_conflicting
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 1051, in best_match
>      return self.obtain(req, installer)
>    File 
> "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 
> 1063, in obtain
>      return installer(requirement)
>    File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", 
> line 838, in fetch_build_egg
>      return fetch_build_egg(self, req)
>    File 
> "/usr/local/lib/python3.7/site-packages/setuptools/installer.py", line 
> 77, in fetch_build_egg
>      raise DistutilsError(str(e)) from e
> distutils.errors.DistutilsError: Command '['/usr/local/bin/python3.7', 
> '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 
> '/tmp/tmpllmb234s', '--quiet', 'toml']' returned non-zero exit status 1.
> *** Error code 1


This is https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=256872

Workaround, manually install py-toml or enable TOML option in 
setuptools_scm port options (which is disabled, causing this issue).

Reach out in #freebsd-python on Libera IRC if you need further help or 
have questions.

./koobs

[1] https://github.com/encode/uvicorn/search?q=importlib
[2] https://github.com/encode/uvicorn/blob/0.14.0/setup.py#L47


> Stop.
> make: stopped in /usr/ports/devel/py-zipp
> =>> Cleaning up wrkdir
> ===>  Cleaning for py37-zipp-3.4.0
> build of devel/py-zipp | py37-zipp-3.4.0 ended at Tue Aug 17 01:46:11 
> CEST 2021
> build time: 00:00:10
> !!! build failure encountered !!!
> 
> 
> Poudriere builder and the target machine are both FreeBSD 12.2 amd64.
> 
> Options in Poudriere are
> OPTIONS_UNSET= X11 GUI CUPS DOCS EXAMPLES NLS HAL
> DEFAULT_VERSIONS=apache=2.4 perl5=5.32 mysql=10.3m php=7.4 python=3.7 
> python3=3.7 pgsql=12 bdb=5
> 
> 
> Kind regards
> Miroslav Lachman
>