ido50 / morgan

PyPI Mirror for Restricted/Offline Environments
Apache License 2.0
105 stars 7 forks source link

Inconsistent name when installing from local PyPi mirror #6

Closed sparfenyuk closed 1 year ago

sparfenyuk commented 1 year ago

Steps to reproduce:

  1. Use the following morgan.ini:
    [env.None]
    os_name = posix
    sys_platform = darwin
    platform_machine = arm64
    platform_python_implementation = CPython
    platform_system = Darwin
    python_version = 3.10
    python_full_version = 3.10.9
    implementation_name = cpython
    [requirements]
    fastapi= ==0.88.0
  2. Run morgan mirror
  3. Run morgan serve
  4. Try to install the package pip install FastAPI --index-url http://localhost:8080

Expected: the package installed successfully. What happens instead: failure

Looking in indexes: http://localhost:8080
Collecting FastAPI
  Obtaining dependency information for FastAPI from http://localhost:8080/fastapi/fastapi-0.88.0-py3-none-any.whl.metadata
  Downloading http://localhost:8080/fastapi/fastapi-0.88.0-py3-none-any.whl.metadata
     - 24.7 kB 241.5 MB/s 0:00:00
Discarding http://localhost:8080/fastapi/fastapi-0.88.0-py3-none-any.whl#sha256=263b718bb384422fe3d042ffc9a0c8dece5e034ab6586ff034f6b4b1667c3eee (from http://localhost:8080/fastapi/): Requested FastAPI from http://localhost:8080/fastapi/fastapi-0.88.0-py3-none-any.whl#sha256=263b718bb384422fe3d042ffc9a0c8dece5e034ab6586ff034f6b4b1667c3eee has inconsistent Name: expected 'FastAPI', but metadata has 'fastapi'
  Obtaining dependency information for FastAPI from http://localhost:8080/fastapi/fastapi-0.88.0.tar.gz.metadata
  Downloading http://localhost:8080/fastapi/fastapi-0.88.0.tar.gz.metadata
     - 24.7 kB 249.5 MB/s 0:00:00
Discarding http://localhost:8080/fastapi/fastapi-0.88.0.tar.gz#sha256=915bf304180a0e7c5605ec81097b7d4cd8826ff87a02bb198e336fb9f3b5ff02 (from http://localhost:8080/fastapi/): Requested FastAPI from http://localhost:8080/fastapi/fastapi-0.88.0.tar.gz#sha256=915bf304180a0e7c5605ec81097b7d4cd8826ff87a02bb198e336fb9f3b5ff02 has inconsistent Name: expected 'FastAPI', but metadata has 'fastapi'
ERROR: Could not find a version that satisfies the requirement FastAPI (from versions: 0.88.0)
ERROR: No matching distribution found for FastAPI
sparfenyuk commented 1 year ago

Note: I ran pypiserver instead, pointing it to the location with mirrored packages, and pip install worked.

ido50 commented 1 year ago

Looks like pip croaks when Morgan serves metadata files with the project name having different casing than what was given to pip. I guess I'll have to modify the metadata file before serving in this case. Working on it.

ido50 commented 1 year ago

Hmm, pip actually is sending the project name normalized (i.e. lowercased and underscores replaced with dashes), so Morgan isn't getting the actual name asked of pip. Looks like my only way to solve this is not to serve metadata files at all (if I disable them, it works). I'll have to think about it, because I don't want to lose that feature. If you ask pip for the normalized name (pip install fastapi) it works correctly. Maybe I'll add a command line flag to disable metadata files if you really want to use non-normalized names.

ido50 commented 1 year ago

I've released version 0.13.0 with a new --no-metadata flag that disables serving metadata files altogether. This works around the issue. I'll have to contact pip developers to understand why it behaves like that.