question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix packager.py name normalization

See original GitHub issue

After deployment we noticed that our application didn’t work anymore: [ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'sqlalchemy'

Our requirements.txt file has the following, so no problem there:

$ grep -i sqlalchemy requirements.txt 
SQLAlchemy==1.3.9

While debugging we noticed that the resulting deployment has sqlalchemy files in the wrong location:

$ unzip -l 5a76ade4f39e704f0925422520b454f2-python3.7.zip | grep -i 'sqlalchemy[^/]*/[^/]*$'
     4621  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/__init__.py
     5648  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/processors.py
     2377  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/schema.py
     3377  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/types.py
     2990  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/inspection.py
     6693  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/log.py
    16938  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/exc.py
    12721  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/interfaces.py
    51669  2019-10-29 17:49   SQLAlchemy-1.3.9.data/purelib/sqlalchemy/events.py
       11  2019-10-29 17:49   SQLAlchemy-1.3.9.dist-info/top_level.txt
      104  2019-10-29 17:49   SQLAlchemy-1.3.9.dist-info/WHEEL
     1100  2019-10-29 17:49   SQLAlchemy-1.3.9.dist-info/LICENSE
    23329  2019-10-29 17:49   SQLAlchemy-1.3.9.dist-info/RECORD
     7240  2019-10-29 17:49   SQLAlchemy-1.3.9.dist-info/METADATA

It looks like packager.py does in fact have the code to move purelib back to the root directory – function _install_purelib_and_platlib – however, it is not working as intended.

While debugging further with print()s we noticed that wheel.data_dir variable is just wrong:

    @property
    def data_dir(self):
        # type: () -> str
        # The directory format is {distribution}-{version}.data
        return '%s-%s.data' % (self._name, self._version)

This yields sqlalchemy-1.3.9.data rather than SQLAlchemy-1.3.9.data and therefore the code in _install_purelib_and_platlib doesn’t execute. The reason is the normalization function:

    def _normalize_name(self, name):
        # type: (str) -> str
        # Taken directly from PEP 503
        return re.sub(r"[-_.]+", "-", name).lower()

I don’t think package names should be forced lower-case like that – even though in theory they should be lower-case, in practice our requirements.txt does have quite a few upper-cased package names and identifiers:

$ grep '^[A-Z]' requirements.txt 
PyMySQL==0.9.3
SQLAlchemy==1.3.10
SQLAlchemy-FullText-Search==0.2.5
SQLAlchemy-Utils==0.34.2
WeasyPrint==50

I am creating a pull request to fix this issue, and after using it our deployment is able to successfully use SQLAlchemy package again.

$ unzip -l bf895adfe5c60f297701196b732057ca-python3.7.zip | grep -i 'sqlalchemy[^/]*/[^/]*$'
     4621  2019-10-29 22:03   sqlalchemy/__init__.py
     5648  2019-10-29 22:03   sqlalchemy/processors.py
     2377  2019-10-29 22:03   sqlalchemy/schema.py
     3377  2019-10-29 22:03   sqlalchemy/types.py
     2990  2019-10-29 22:03   sqlalchemy/inspection.py
     6693  2019-10-29 22:03   sqlalchemy/log.py
    16938  2019-10-29 22:03   sqlalchemy/exc.py
    12721  2019-10-29 22:03   sqlalchemy/interfaces.py
    51669  2019-10-29 22:03   sqlalchemy/events.py
       11  2019-10-29 22:03   SQLAlchemy-1.3.8.dist-info/top_level.txt
      104  2019-10-29 22:03   SQLAlchemy-1.3.8.dist-info/WHEEL
     1100  2019-10-29 22:03   SQLAlchemy-1.3.8.dist-info/LICENSE
    23329  2019-10-29 22:03   SQLAlchemy-1.3.8.dist-info/RECORD
     7240  2019-10-29 22:03   SQLAlchemy-1.3.8.dist-info/METADATA

Thanks! John Vencky

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
johnvenckycommented, Dec 17, 2019

@stealthycoin did you have a chance to take a look at it? Thanks.

0reactions
jameslscommented, Feb 25, 2020

Trying to track down this issue. Here’s the set of steps I tried. Are people still running into this? I’d like to repro this myself, but it seems to work as I expect when I ran on ubuntu. https://github.com/aws/chalice/issues/1356#issuecomment-590981069

Read more comments on GitHub >

github_iconTop Results From Across the Web

Revisiting distribution name normalization - Packaging
In warehouse#10072, flit is attempting to apply PEP 503 normalization rules to distribution filenames but this shift from the status quo ...
Read more >
Python package set: normalize all attribute names #49691
Yes, use pytho(nix) to generate a list of attribute names, and check with the PyPI index whether a package exists with that name....
Read more >
Python package name normalization - CodeArtifact
CodeArtifact normalizes package names before storing them, which means the package names in CodeArtifact may be different than the name provided when the ......
Read more >
Python setup tools normalizes version name based on ...
As the Python Package Index is intended solely for indexing and hosting upstream projects, it MUST NOT allow the use of local version ......
Read more >
[RTFACT-8476] PyPI doesn't normalize package names - JFrog
Where "packagename" is the normalized package name (that is, downcased and with runs of certain characters replaced with -).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found