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

feat: advertise constraints in setup.py #219

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@

import os
import re

import setuptools


def load_requirements(*requirements_paths):
"""
Load all requirements from the specified requirements files, including any constraints from other files that
are pulled in.
Load all requirements from the specified requirements files.

Requirements will include any constraints from files specified
with -c in the requirements files.
Returns a list of requirement strings.
"""
# UPDATED VIA SEMGREP - if you need to remove/modify this method remove this line and add a comment specifying why.

requirements = {}
constraint_files = set()

Expand All @@ -38,7 +43,9 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n
# constraints in place
if existing_version_constraints and existing_version_constraints != version_constraints:
raise BaseException(f'Multiple constraint definitions found for {package}:'
f' "{existing_version_constraints}" and "{version_constraints}".')
f' "{existing_version_constraints}" and "{version_constraints}".'
f'Combine constraints into one location with {package}'
f'{existing_version_constraints},{version_constraints}.')
if add_if_not_present or package in current_requirements:
current_requirements[package] = version_constraints

Expand All @@ -59,7 +66,8 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n
add_version_constraint_or_raise(line, requirements, False)

# process back into list of pkg><=constraints strings
return [f'{pkg}{version or ""}' for (pkg, version) in sorted(requirements.items())]
constrained_requirements = [f'{pkg}{version or ""}' for (pkg, version) in sorted(requirements.items())]
return constrained_requirements]


def is_requirement(line):
Expand Down
Loading