2727
2828logger = getLogger (__name__ )
2929
30- # TODO: consider replacing _either with _any or _or
31-
3230
3331class DependencyConflict :
3432 required : str | None = None
@@ -37,13 +35,10 @@ class DependencyConflict:
3735 required_either : Collection [str ] = []
3836 found_either : Collection [str ] = []
3937
40- # TODO: No longer requires required field
4138 def __init__ (
4239 self ,
4340 required : str | None = None ,
4441 found : str | None = None ,
45- # TODO: dangerous
46- # TODO: dangerous
4742 required_either : Collection [str ] = None ,
4843 found_either : Collection [str ] = None ,
4944 ):
@@ -55,27 +50,10 @@ def __init__(
5550
5651 def __str__ (self ):
5752 if not self .required and (self .required_either or self .found_either ):
58- print ("EITHER STRING" )
59- # TODO: make sure this formats correctly
6053 return f'DependencyConflict: requested any of the following: "{ self .required_either } " but found: "{ self .found_either } "'
61- print ("AND STRING" )
6254 return f'DependencyConflict: requested: "{ self .required } " but found: "{ self .found } "'
6355
6456
65- # TODO: Figure out if this should be a subclass of DependencyConflict.
66- # If now, change functions to return either and then ensure that all the dependents can handle the new value
67- # class DependencyConflictEither(DependencyConflict):
68- # required: Collection[str] = []
69- # found: Collection[str] = []
70-
71- # def __init__(self, required: Collection[str], found: Collection[str] = []):
72- # self.required = required
73- # self.found = found
74-
75- # def __str__(self):
76- # return f'DependencyConflictEither: requested: "{self.required}" but found: "{self.found}"'
77-
78-
7957class DependencyConflictError (Exception ):
8058 conflict : DependencyConflict
8159
@@ -96,59 +74,36 @@ def get_dist_dependency_conflicts(
9674 instruments_marker = {extra : instruments }
9775 instruments_either = "instruments_either"
9876 instruments_either_marker = {extra : instruments_either }
99- # print(f"dist: {dist}")
100- # print(f"dist.requires: {dist.requires}")
10177 if dist .requires :
10278 for dep in dist .requires :
103- print (f"dep: { dep } " )
10479 if extra not in dep :
105- print (f"Skipping dep: { dep } " )
10680 continue
10781 if instruments not in dep and instruments_either not in dep :
108- print (f"Skipping dep: { dep } " )
10982 continue
11083
11184 req = Requirement (dep )
112- # print(f"req: {req}")
11385 if req .marker .evaluate (instruments_marker ): # type: ignore
114- # print("Evaluated. Append")
11586 instrumentation_deps .append (req ) # type: ignore
11687 if req .marker .evaluate (instruments_either_marker ): # type: ignore
117- # print("Evaluated. either. Append")
118- # Need someway to separate
11988 instrumentation_either_deps .append (req ) # type: ignore
120- dc = get_dependency_conflicts (
89+ return get_dependency_conflicts (
12190 instrumentation_deps , instrumentation_either_deps
12291 ) # type: ignore
123- print (f"dep conf: { dc } " )
124- return dc
125- # return get_dependency_conflicts(instrumentation_deps, instrumentation_either_deps) # type: ignore
12692
12793
12894def get_dependency_conflicts (
12995 deps : Collection [
13096 str | Requirement
131- ], # Dependenciesall of which are required
97+ ], # Dependencies all of which are required
13298 deps_either : Collection [
13399 str | Requirement
134- # TODO: dangerous
135100 ] = None , # Dependencies any of which are required
136101) -> DependencyConflict | None :
137- # instruments_conflict = get_dependency_conflicts()
138- # if instruments_conflict:
139- # return instruments_conflict
140-
141- # instruments_either_conflict = get_dependency_conflicts_either()
142- # return instruments_either_conflict
143-
144102 for dep in deps :
145- # TODO: what is this?
146103 if isinstance (dep , Requirement ):
147- print ("REQUIREMENT" )
148104 req = dep
149105 else :
150106 try :
151- print ("NOT REQUIREMENT" )
152107 req = Requirement (dep )
153108 except InvalidRequirement as exc :
154109 logger .warning (
@@ -161,14 +116,11 @@ def get_dependency_conflicts(
161116 try :
162117 dist_version = version (req .name )
163118 except PackageNotFoundError :
164- # TODO: Technically this field should allow Requirements type. Tackle this in a separate PR.
165119 return DependencyConflict (dep )
166120
167121 if not req .specifier .contains (dist_version ):
168- # TODO: Technically this field should allow Requirements type
169122 return DependencyConflict (dep , f"{ req .name } { dist_version } " )
170123
171- # TODO: add eval of deps_either
172124 # If all the dependencies in "instruments" are present, check "instruments_either" for conflicts.
173125 if deps_either :
174126 return _get_dependency_conflicts_either (deps_either )
@@ -181,18 +133,14 @@ def _get_dependency_conflicts_either(
181133) -> DependencyConflict | None :
182134 if not deps_either :
183135 return None
184- # TODO: change to using DependencyConflict
185136 is_dependency_conflict = True
186137 required_either : Collection [str ] = []
187138 found_either : Collection [str ] = []
188139 for dep in deps_either :
189- # TODO: what is this?
190140 if isinstance (dep , Requirement ):
191- print ("REQUIREMENT" )
192141 req = dep
193142 else :
194143 try :
195- print ("NOT REQUIREMENT" )
196144 req = Requirement (dep )
197145 except InvalidRequirement as exc :
198146 logger .warning (
@@ -205,9 +153,6 @@ def _get_dependency_conflicts_either(
205153 try :
206154 dist_version = version (req .name )
207155 except PackageNotFoundError :
208- # print(f"PackageNotFoundError EITHER: {req.name}")
209- # TODO: anything here?
210- # return DependencyConflict(dep)
211156 required_either .append (str (dep ))
212157 continue
213158
@@ -220,9 +165,6 @@ def _get_dependency_conflicts_either(
220165 found_either .append (f"{ req .name } { dist_version } " )
221166
222167 if is_dependency_conflict :
223- # return DependencyConflict(dep, f"{req.name} {dist_version}")
224- # print (f"required_either: {required_either}")
225- # print (f"found_either: {found_either}")
226168 return DependencyConflict (
227169 required_either = required_either ,
228170 found_either = found_either ,
0 commit comments