Skip to content

Commit

Permalink
feat: Reconcile mismatches between setup.py in template and updater
Browse files Browse the repository at this point in the history
Just comment wording that has drifted apart over time, though.
  • Loading branch information
timmc-edx committed Aug 11, 2023
1 parent c170f69 commit a0c0dde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n
package = regex_match.group(1)
version_constraints = regex_match.group(2)
existing_version_constraints = current_requirements.get(package, None)
# fine to add constraints to an unconstrained package,
# raise an error if there are already constraints in place
# It's fine to add constraints to an unconstrained package,
# but raise an error if there are already 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}".'
Expand All @@ -58,8 +58,8 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n
if add_if_not_present or package in current_requirements:
current_requirements[package] = version_constraints

# read requirements from .in
# store the path to any constraint files that are pulled in
# Read requirements from .in files and store the path to any
# constraint files that are pulled in.
for path in requirements_paths:
with open(path) as reqs:
for line in reqs:
Expand Down
11 changes: 6 additions & 5 deletions scripts/update_setup_py_load_requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rules:
requirements = {}
constraint_files = set()
# groups "my-package-name<=x.y.z,..." into ("my-package-name", "<=x.y.z,...")
# groups "pkg<=x.y.z,..." into ("pkg", "<=x.y.z,...")
requirement_line_regex = re.compile(r"([a-zA-Z0-9-_.\[\]]+)([<>=][^#\s]+)?")
def add_version_constraint_or_raise(current_line, current_requirements, add_if_not_present):
Expand All @@ -30,8 +30,8 @@ rules:
package = regex_match.group(1)
version_constraints = regex_match.group(2)
existing_version_constraints = current_requirements.get(package, None)
# it's fine to add constraints to an unconstrained package, but raise an error if there are already
# constraints in place
# It's fine to add constraints to an unconstrained package,
# but raise an error if there are already 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}".'
Expand All @@ -40,7 +40,8 @@ rules:
if add_if_not_present or package in current_requirements:
current_requirements[package] = version_constraints
# process .in files and store the path to any constraint files that are pulled in
# Read requirements from .in files and store the path to any
# constraint files that are pulled in.
for path in requirements_paths:
with open(path) as reqs:
for line in reqs:
Expand All @@ -49,7 +50,7 @@ rules:
if line and line.startswith('-c') and not line.startswith('-c http'):
constraint_files.add(os.path.dirname(path) + '/' + line.split('#')[0].replace('-c', '').strip())
# process constraint files and add any new constraints found to existing requirements
# process constraint files: add constraints to existing requirements
for constraint_file in constraint_files:
with open(constraint_file) as reader:
for line in reader:
Expand Down

0 comments on commit a0c0dde

Please sign in to comment.