77
88import ast
99import os
10- import enum
10+ import jsondiff
1111import argparse
1212import importlib
1313import inspect
1919import subprocess
2020from enum import Enum
2121from typing import Dict , Union , Type , Callable
22+ from packaging_tools .venvtools import create_venv_with_package
2223from breaking_changes_allowlist import RUN_BREAKING_CHANGES_PACKAGES
2324from breaking_changes_tracker import BreakingChangesTracker
24- try :
25- # won't be able to import these in the created venv
26- from packaging_tools .venvtools import create_venv_with_package
27- import jsondiff
28- except (ModuleNotFoundError , ImportError ) as e :
29- pass
3025
3126
3227root_dir = os .path .abspath (os .path .join (os .path .abspath (__file__ ), ".." , ".." , ".." ))
@@ -99,9 +94,12 @@ def get_parameter_default(param: inspect.Parameter) -> None:
9994def get_property_names (node : ast .AST , attribute_names : Dict ) -> None :
10095 func_nodes = [node for node in node .body if isinstance (node , ast .FunctionDef )]
10196 if func_nodes :
102- assigns = [node for node in func_nodes [0 ].body if isinstance (node , ast .Assign )]
97+ assigns = [node for node in func_nodes [0 ].body if isinstance (node , ( ast .Assign , ast . AnnAssign ) )]
10398 if assigns :
10499 for assign in assigns :
100+ if hasattr (assign , "target" ):
101+ attr = assign .target
102+ attribute_names .update ({attr .attr : attr .attr })
105103 if hasattr (assign , "targets" ):
106104 for attr in assign .targets :
107105 if hasattr (attr , "attr" ) and not attr .attr .startswith ("_" ):
@@ -136,7 +134,7 @@ def get_properties(cls: Type) -> Dict:
136134 attribute_names = {}
137135
138136 path = inspect .getsourcefile (cls )
139- with open (path , "r" ) as source :
137+ with open (path , "r" , encoding = "utf-8-sig" ) as source :
140138 module = ast .parse (source .read ())
141139
142140 analyzer = ClassTreeAnalyzer (cls .__name__ )
@@ -149,9 +147,7 @@ def get_properties(cls: Type) -> Dict:
149147 for base_class in base_classes :
150148 try :
151149 path = inspect .getsourcefile (base_class )
152- if path .find ("azure" ) == - 1 :
153- continue
154- with open (path , "r" ) as source :
150+ with open (path , "r" , encoding = "utf-8-sig" ) as source :
155151 module = ast .parse (source .read ())
156152 except (TypeError , SyntaxError ):
157153 _LOGGER .info (f"Unable to create ast of { base_class } " )
@@ -288,8 +284,18 @@ def main(package_name: str, target_module: str, version: str, in_venv: Union[boo
288284 in_venv = True if in_venv == "true" else False # subprocess sends back string so convert to bool
289285
290286 if not in_venv :
291- packages = [f"{ package_name } =={ version } " , "aiohttp " ]
287+ packages = [f"{ package_name } =={ version } " , "jsondiff==1.2.0 " ]
292288 with create_venv_with_package (packages ) as venv :
289+ subprocess .check_call (
290+ [
291+ venv .env_exe ,
292+ "-m" ,
293+ "pip" ,
294+ "install" ,
295+ "-r" ,
296+ os .path .join (pkg_dir , "dev_requirements.txt" )
297+ ]
298+ )
293299 _LOGGER .info (f"Installed version { version } of { package_name } in a venv" )
294300 args = [
295301 venv .env_exe ,
@@ -368,7 +374,7 @@ def main(package_name: str, target_module: str, version: str, in_venv: Union[boo
368374 args = parser .parse_args ()
369375 in_venv = args .in_venv
370376 stable_version = args .stable_version
371-
377+ target_module = args . target_module
372378 pkg_dir = os .path .abspath (args .target_package )
373379 package_name = os .path .basename (pkg_dir )
374380 logging .basicConfig (level = logging .INFO )
@@ -377,9 +383,11 @@ def main(package_name: str, target_module: str, version: str, in_venv: Union[boo
377383 f"See http://aka.ms/azsdk/breaking-changes-tool to opt-in." )
378384 exit (0 )
379385
380- # TODO need to parse setup.py here to get the top module/namespace since not always the same.
381- # e.g. azure-storage-file-share and azure.storage.fileshare
382- target_module = package_name .replace ("-" , "." )
386+ if not target_module :
387+ from ci_tools .parsing import ParsedSetup
388+ pkg_details = ParsedSetup .from_path (pkg_dir )
389+ target_module = pkg_details .namespace
390+
383391 if not stable_version :
384392
385393 from pypi_tools .pypi import PyPIClient
@@ -392,5 +400,3 @@ def main(package_name: str, target_module: str, version: str, in_venv: Union[boo
392400 exit (0 )
393401
394402 main (package_name , target_module , stable_version , in_venv , pkg_dir )
395-
396-
0 commit comments