def _install_packages(self, dependent_pkg_path, pkg_to_exclude):
        python_executable = self.context.venv.python_executable
        working_dir = self.context.package_root_path
        temp_dir = self.context.temp_path

        list_to_exclude = [pkg_to_exclude, 'azure-sdk-tools', 'azure-devtools']
        installed_pkgs = [
            p.split('==')[0]
            for p in get_installed_packages(self.context.venv.lib_paths)
            if p.startswith('azure-')
        ]
        logging.info("Installed azure sdk packages:{}".format(installed_pkgs))

        # Do not exclude list of packages in tools directory and so these tools packages will be reinstalled from repo branch we are testing
        root_path = os.path.abspath(
            os.path.join(dependent_pkg_path, "..", "..", ".."))
        tools_packages = find_tools_packages(root_path)
        installed_pkgs = [
            req for req in installed_pkgs if req not in tools_packages
        ]

        list_to_exclude.extend(installed_pkgs)
        # install dev requirement but skip already installed package which is being tested or present in dev requirement
        filtered_dev_req_path = filter_dev_requirements(
            dependent_pkg_path, list_to_exclude, dependent_pkg_path)

        # early versions of azure-sdk-tools had an unpinned version of azure-mgmt packages.
        # that unpinned version hits an a code path in azure-sdk-tools that hits this error.
        if filtered_dev_req_path and self.context.is_latest_depend_test == False:
            logging.info("Extending dev requirements with {}".format(
                OLDEST_EXTENSION_PKGS))
            extend_dev_requirements(filtered_dev_req_path,
                                    OLDEST_EXTENSION_PKGS)
        else:
            logging.info("Not extending dev requirements {} {}".format(
                filtered_dev_req_path, self.context.is_latest_depend_test))

        if filtered_dev_req_path:
            logging.info(
                "Extending dev requirement to include azure-sdk-tools")
            extend_dev_requirements(filtered_dev_req_path, [
                "../../../tools/azure-sdk-tools",
                "../../../tools/azure-devtools"
            ])
            logging.info("Installing filtered dev requirements from {}".format(
                filtered_dev_req_path))
            run_check_call(
                [
                    python_executable, "-m", "pip", "install", "-r",
                    filtered_dev_req_path
                ],
                dependent_pkg_path,
            )
        else:
            logging.info("dev requirements is not found to install")

        # install dependent package which is being verified
        run_check_call(
            [python_executable, "-m", "pip", "install", dependent_pkg_path],
            temp_dir)
def verify_packages(package_file_path):
    # this method verifies packages installed on machine is matching the expected package version
    # packages.txt file expects to have list of packages and version in format <package-name>==<version>

    packages = []
    with open(package_file_path, "r") as packages_file:
        packages = packages_file.readlines()
    packages = [p.replace('\n', '') for p in packages]

    # packages.txt is created by package installation script. But this script can be reused to verify installed packages
    # Add a sanity check to ensure content in file is in expected format
    invalid_lines = [p for p in packages if '==' not in p]
    if invalid_lines:
        logging.error("packages.txt has package details in invalid format. Expected format is <package-name>==<version>")
        sys.exit(1)

    # find installed and expected packages
    installed = dict(p.split('==') for p in get_installed_packages() if "==" in p)
    expected = dict(p.split('==') for p in packages)

    missing_packages = [pkg for pkg in expected.keys() if installed.get(pkg) != expected.get(pkg)]

    if missing_packages:
        logging.error("Version is incorrect for following package[s]")
        for package in missing_packages:
            logging.error("%s, Expected[%s], Installed[%s]", package, expected[package], installed[package])
        sys.exit(1)
    else:
        logging.info("Verified package version")
Exemplo n.º 3
0
 def _is_package_installed(self, package, version):
     # find env root and pacakge locations
     venv_root = self.context.venv.path
     site_packages = self.context.venv.lib_paths
     logging.info("Searching for packages in :{}".format(site_packages))
     installed_pkgs = get_installed_packages(site_packages)
     logging.info("Installed packages: {}".format(installed_pkgs))
     # Verify installed package version
     # Search for exact version or alpha build version of current version.
     pkg_search_string = "{0}=={1}".format(package, version)
     alpha_build_search_string = "{0}=={1}a".format(package, version)
     return any(p == pkg_search_string or p.startswith(alpha_build_search_string) for p in installed_pkgs)
Exemplo n.º 4
0
    def _install_packages(self, dependent_pkg_path, pkg_to_exclude):
        python_executable = self.context.venv.python_executable
        working_dir = self.context.package_root_path
        temp_dir = self.context.temp_path

        list_to_exclude = [
            pkg_to_exclude,
        ]
        installed_pkgs = [
            p.split('==')[0]
            for p in get_installed_packages(self.context.venv.lib_paths)
            if p.startswith('azure-')
        ]
        logging.info("Installed azure sdk packages:{}".format(installed_pkgs))

        # Do not exclude list of packages in tools directory and so these tools packages will be reinstalled from repo branch we are testing
        root_path = os.path.abspath(
            os.path.join(dependent_pkg_path, "..", "..", ".."))
        tools_packages = find_tools_packages(root_path)
        installed_pkgs = [
            req for req in installed_pkgs if req not in tools_packages
        ]

        list_to_exclude.extend(installed_pkgs)
        # install dev requirement but skip already installed package which is being tested or present in dev requirement
        filtered_dev_req_path = filter_dev_requirements(
            dependent_pkg_path, list_to_exclude, dependent_pkg_path)

        if filtered_dev_req_path:
            logging.info("Installing filtered dev requirements from {}".format(
                filtered_dev_req_path))
            run_check_call(
                [
                    python_executable, "-m", "pip", "install", "-r",
                    filtered_dev_req_path
                ],
                dependent_pkg_path,
            )
        else:
            logging.info("dev requirements is not found to install")

        # install dependent package which is being verified
        run_check_call(
            [python_executable, "-m", "pip", "install", dependent_pkg_path],
            temp_dir)
def get_installed_azure_packages(pkg_name_to_exclude):
    # This method returns a list of installed azure sdk packages
    installed_pkgs = [
        p.split("==")[0] for p in get_installed_packages()
        if p.startswith("azure-")
    ]

    # Get valid list of Azure SDK packages in repo
    pkgs = process_glob_string("", root_dir)
    valid_azure_packages = [
        path.basename(p) for p in pkgs if "mgmt" not in p and "-nspkg" not in p
    ]

    # Filter current package and any exlcuded package
    pkg_names = [
        p for p in installed_pkgs if p in valid_azure_packages
        and p != pkg_name_to_exclude and p not in EXCLUDED_PKGS
    ]

    logging.info("Installed azure sdk packages: %s", pkg_names)
    return pkg_names