Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent pip package name that breaks pip install of requirements.txt #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rtyley
Copy link

@rtyley rtyley commented Oct 22, 2023

This PR fixes two packaging inconsistencies in the sam-hq project:

Distribution Package (pip install problem)

In particular, the wrong Distribution Package name (ie the name used by pip), will cause a fatal error when trying to use pip's ability to install directly from VCS, eg with a line like this in a project's requirements.txt:

segment-anything-hq @ git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625

The error is:

WARNING: Generating metadata for package segment-anything-hq produced metadata for project name segment-anything

If I change my requirements file to point at the branch for this PR, including the simple metadata fix in setup.py, the pip install of the requirements file succeeds, and my code using HQ-SAM succeeds:

segment-anything-hq @ git+https://github.com/rtyley/sam-hq@patch-1

Error logs from pip install

This is just with the current main branch of sam-hq:

Collecting segment-anything-hq@ git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625 (from -r requirements.txt (line 9))
  Cloning https://github.com/SysCV/sam-hq (to revision 5fd027ec559806dec9f876b56938175a63dfc625) to /private/var/folders/28/pjfz24p92bxcj5j7gsnnk9xm0000gp/T/pip-install-cmpqwucv/segment-anything-hq_bd753024d0a540f5bcb3225886933667
  Running command git clone --filter=blob:none --quiet https://github.com/SysCV/sam-hq /private/var/folders/28/pjfz24p92bxcj5j7gsnnk9xm0000gp/T/pip-install-cmpqwucv/segment-anything-hq_bd753024d0a540f5bcb3225886933667
  Running command git rev-parse -q --verify 'sha^5fd027ec559806dec9f876b56938175a63dfc625'
  Running command git fetch -q https://github.com/SysCV/sam-hq 5fd027ec559806dec9f876b56938175a63dfc625
  Resolved https://github.com/SysCV/sam-hq to commit 5fd027ec559806dec9f876b56938175a63dfc625
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
  WARNING: Generating metadata for package segment-anything-hq produced metadata for project name segment-anything. Fix your #egg=segment-anything-hq fragments.
Discarding git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625: Requested segment-anything from git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625 (from -r requirements.txt (line 9)) has inconsistent name: expected 'segment-anything-hq', but metadata has 'segment-anything'

Import Package

The HQ-SAM documentation says the Import Package is segment-anything-hq:

from segment_anything_hq import sam_model_registry

To fix the code to match the documentation we need to rename the /segment-anything/ folder to /segment-anything-hq/.

@rtyley rtyley marked this pull request as draft October 23, 2023 07:20
This project is released as `segment-anything-hq` in pip:

https://pypi.org/project/segment-anything-hq/

...but the setup here just said `segment_anything`, which seems to be the cause of this error message:

```
WARNING: Generating metadata for package segment-anything-hq produced metadata for project name segment-anything
```

...while trying to pip install a requirements file that had a line like this:

```
segment-anything-hq @ git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625
```

Full error logs:
```
Collecting segment-anything-hq@ git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625 (from -r requirements.txt (line 9))
  Cloning https://github.com/SysCV/sam-hq (to revision 5fd027e) to /private/var/folders/28/pjfz24p92bxcj5j7gsnnk9xm0000gp/T/pip-install-cmpqwucv/segment-anything-hq_bd753024d0a540f5bcb3225886933667
  Running command git clone --filter=blob:none --quiet https://github.com/SysCV/sam-hq /private/var/folders/28/pjfz24p92bxcj5j7gsnnk9xm0000gp/T/pip-install-cmpqwucv/segment-anything-hq_bd753024d0a540f5bcb3225886933667
  Running command git rev-parse -q --verify 'sha^5fd027ec559806dec9f876b56938175a63dfc625'
  Running command git fetch -q https://github.com/SysCV/sam-hq 5fd027e
  Resolved https://github.com/SysCV/sam-hq to commit 5fd027e
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
  WARNING: Generating metadata for package segment-anything-hq produced metadata for project name segment-anything. Fix your #egg=segment-anything-hq fragments.
Discarding git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625: Requested segment-anything from git+https://github.com/SysCV/sam-hq@5fd027ec559806dec9f876b56938175a63dfc625 (from -r requirements.txt (line 9)) has inconsistent name: expected 'segment-anything-hq', but metadata has 'segment-anything'
```

See also: pypa/pipenv#5445 (comment)
name="segment_anything",
name="segment_anything_hq",
Copy link
Author

@rtyley rtyley Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the crucial fix for the "Generating metadata for package segment-anything-hq produced metadata for project name segment-anything" error - here, we're correcting the Distribution Package name as used by pip, rather than the Import Package.

See also pypa/pipenv#5445 (comment)

known_myself=segment_anything
known_myself=segment_anything_hq
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of configuration isn't crucial - it only relates to isort configuration, to ensure that when python code imports are sorted, they are sorted in a sensible fashion. Strangely, although isort documents several other known_... settings (eg known_third_party), it doesn't document known_myself, and that identifier doesn't appear anywhere in the isort codebase.

@@ -2,7 +2,7 @@
import torch
import matplotlib.pyplot as plt
import cv2
from segment_anything import sam_model_registry, SamPredictor
from segment_anything_hq import sam_model_registry, SamPredictor
Copy link
Author

@rtyley rtyley Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we're updating the Import Package in this example to match the name given in the HQ-SAM documentation:

from segment_anything_hq import sam_model_registry

Note that in order for this to work, we need to rename the /segment-anything/ folder to /segment-anything-hq/ (which in Git, means a lot of files get their paths renamed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant