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

Remove globals in policy module #466

Merged
merged 3 commits into from
Dec 29, 2023
Merged

Remove globals in policy module #466

merged 3 commits into from
Dec 29, 2023

Conversation

lkollar
Copy link
Contributor

@lkollar lkollar commented Nov 6, 2023

I started working on this when I created #460 and ran into the problem with the globals in the policy module once again. These globals make it very difficult to properly test simple changes as the module-level globals get initialised on the first import which usually happens before any mocking can be done.

This is a large PR, but most of the changes are just moving code around.

@lkollar lkollar self-assigned this Nov 6, 2023
@lkollar lkollar force-pushed the policy-refactor branch 2 times, most recently from 2d4b03b to 13d891f Compare November 7, 2023 22:36
Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (1a1ee6c) 92.04% compared to head (8c18c7c) 92.05%.
Report is 4 commits behind head on main.

Files Patch % Lines
src/auditwheel/policy/__init__.py 97.43% 1 Missing and 2 partials ⚠️
src/auditwheel/main_show.py 77.77% 0 Missing and 2 partials ⚠️
src/auditwheel/main_repair.py 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #466      +/-   ##
==========================================
+ Coverage   92.04%   92.05%   +0.01%     
==========================================
  Files          22       20       -2     
  Lines        1244     1246       +2     
  Branches      296      298       +2     
==========================================
+ Hits         1145     1147       +2     
  Misses         56       56              
  Partials       43       43              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lkollar lkollar marked this pull request as ready for review November 16, 2023 21:32
@lkollar lkollar requested a review from mayeut November 16, 2023 21:32
The policy module creates several globals on the module level, which
makes it very difficult to test code which interacts with the policies.

This patch creates a `WheelPolicies` class which encapsulates the
policy processing code and exposes functions to query the parsed
policies. Unfortunately, a lot of functions directly operate on
policies and these all need a new argument to take the new policy
object. This change should make testing substantially easier as policies
can be easily created on the fly and passed down to functions which
require these.
These had to be imported at the bottom to avoid a circular import. Now
that we got rid of the globals in the policy module, we can move these
into the right place.
The `external_versioned_symbols` and `versioned_symbols_policy`
functions used to live in two separate files, importing code from the
`__init__.py` file in the same module. As this file itself imports both
of these symbols, this creates a cirtular import. We can easily break
this by moving the two functions into the same `__init__.py` file.
@mayeut mayeut merged commit 3c0a415 into pypa:main Dec 29, 2023
19 of 21 checks passed
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.

3 participants