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

Move mindeps generation logic to separate function #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Shivansh-007
Copy link

from resolver.mindeps import get_min_deps

requirements = ['importlib-metadata>=3.2.0', "pytest>=4 ; extra == 'test'", "pytest-cov>=2 ; extra == 'test'"]
min_deps = get_min_deps(requirements)

print(min_deps)

@Shivansh-007
Copy link
Author

Can you let me know if there are any updates on this PR, @FFY00? I have been waiting for a while for this functionality to be available in resolver.

Copy link
Owner

@FFY00 FFY00 left a comment

Choose a reason for hiding this comment

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

@Shivansh-007 thank you for the contribution, and sorry for the delay 😓

FYI, in the future feel free to ping me as often as you think necessary, as that's helpful for me to not forget there's something blocked on me.

The PR looks good overall, but I have a few comments.

Comment on lines +103 to +108
def get_min_deps(
requirements: List[str],
reporter: Optional[resolvelib.BaseReporter] = None,
extras: Optional[Set[str]] = None,
markers: Optional[Dict[str, str]] = None
) -> Dict[str, str]:
Copy link
Owner

Choose a reason for hiding this comment

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

Let's try to avoid using specific data types unless necessary

Suggested change
def get_min_deps(
requirements: List[str],
reporter: Optional[resolvelib.BaseReporter] = None,
extras: Optional[Set[str]] = None,
markers: Optional[Dict[str, str]] = None
) -> Dict[str, str]:
def get_min_deps(
requirements: Collection[str],
reporter: Optional[resolvelib.BaseReporter] = None,
extras: Optional[Collection[str]] = None,
markers: Optional[Mapping[str, str]] = None
) -> Mapping[str, str]:

extras: Optional[Set[str]] = None,
markers: Optional[Dict[str, str]] = None
) -> Dict[str, str]:
reporter = reporter or resolvelib.BaseReporter
Copy link
Owner

Choose a reason for hiding this comment

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

nitpick: I'd prefer to be more explicit here, even if it takes an extra line.

Suggested change
reporter = reporter or resolvelib.BaseReporter
if not reporter:
reporter = resolvelib.BaseReporter

Comment on lines +95 to +100
class MinimumDependencyProvider(resolver.Provider):
def sort_candidates(
self,
candidates: Iterable[resolver.Candidate],
) -> Sequence[resolver.Candidate]:
return sorted(candidates, key=operator.attrgetter('version'), reverse=False)
Copy link
Owner

Choose a reason for hiding this comment

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

Is there any particular reason you moved this here? Unless there's a good reason not to, I think we should keep it in resolver.mindeps. Also notice that removing it from there breaks imports, this class is meant to be available for people to use.

)

extras = set(vars(args).get('extras', {})) | {''}
if any(arg in _MARKER_KEYS for arg in vars(args)):
extras = extras.copy() | {''} if extras else {''}
Copy link
Owner

Choose a reason for hiding this comment

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

nitpick:

The .copy() call shouldn't be needed here because the | operator does not mutate the set, it creates a new one.

Since extras will always be set now, you could just do extras = extras | {''}. Note that we can't do extras |= {''} because |= does mutate the original set 😅

But anyway, since we are changing the type hint to Collection, we need to rewrite this snippet anyway.

extras = set(vars(args).get('extras', {})) | {''}
if any(arg in _MARKER_KEYS for arg in vars(args)):
extras = extras.copy() | {''} if extras else {''}
if markers is not None and any(marker in _MARKER_KEYS for marker in markers):
Copy link
Owner

Choose a reason for hiding this comment

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

nitpick: I'd skip the is None, to simplify the condition.

Suggested change
if markers is not None and any(marker in _MARKER_KEYS for marker in markers):
if markers and any(marker in _MARKER_KEYS for marker in markers):

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.

2 participants