Ejemplo n.º 1
0
def main(argv):
    _ensure_cwd_is_fairlearn_root_dir()
    parser = build_argument_parser()
    args = parser.parse_args(argv)

    with _LogWrapper("yarn install of dependencies"):
        subprocess.check_call([args.yarn_path, "install"],
                              cwd=os.path.join(os.getcwd(),
                                               _widget_js_directory))

    with _LogWrapper("yarn build"):
        subprocess.check_call([args.yarn_path, "build:all"],
                              cwd=os.path.join(os.getcwd(),
                                               _widget_js_directory))

    with _LogWrapper("removal of extra directories"):
        shutil.rmtree(os.path.join(_widget_js_directory, "dist"))
        shutil.rmtree(os.path.join(_widget_js_directory, "lib"))
        shutil.rmtree(os.path.join(_widget_js_directory, "node_modules"))

    if args.assert_no_changes:
        with _LogWrapper(
                "comparison between old and newly generated widget files."):
            for file_path in _widget_generated_files:
                # git diff occasionally leaves out some of the JS files so use git status
                diff_result = subprocess.check_output(["git", "status"])
                if file_path in diff_result.decode('utf-8'):
                    raise Exception(
                        "File {} was unexpectedly modified.".format(file_path))
Ejemplo n.º 2
0
def main(argv):
    _ensure_cwd_is_fairlearn_root_dir()
    parser = build_argument_parser()
    args = parser.parse_args(argv)

    if _fairlearn_dev_version_env_var_name in os.environ:
        raise Exception("Environment variable {} must not be set".format(
            _fairlearn_dev_version_env_var_name))

    if args.target_type == "Test":
        os.environ[_fairlearn_dev_version_env_var_name] = args.dev_version

    with _LogWrapper("installation of fairlearn"):
        subprocess.check_call(["pip", "install", "-e", ".[customplots]"])

    with _LogWrapper("processing README.md"):
        process_readme("README.md", "README.md")

    with _LogWrapper("storing fairlearn version in {}".format(
            args.version_filename)):
        import fairlearn
        with open(args.version_filename, 'w') as version_file:
            version_file.write(fairlearn.__version__)

    with _LogWrapper("creation of packages"):
        subprocess.check_call(["python", "setup.py", "sdist", "bdist_wheel"])
Ejemplo n.º 3
0
def main(argv):
    _ensure_cwd_is_fairlearn_root_dir()
    parser = build_argument_parser()
    args = parser.parse_args(argv)

    with _LogWrapper("yarn install of dependencies"):
        subprocess.check_call([args.yarn_path, "install"],
                              cwd=os.path.join(os.getcwd(),
                                               _widget_js_directory))

    with _LogWrapper("yarn build"):
        subprocess.check_call([args.yarn_path, "build:all"],
                              cwd=os.path.join(os.getcwd(),
                                               _widget_js_directory))

    if args.use_local_changes:
        # Build visualizations from the visualization directory, and replace
        # the dependency in fairlearn/widget/js with it.
        with _LogWrapper("yarn install for visualizations"):
            subprocess.check_call([args.yarn_path, "install"],
                                  cwd=os.path.join(os.getcwd(),
                                                   _visualization_directory))

        with _LogWrapper("yarn build for visualizations"):
            subprocess.check_call([args.yarn_path, "build"],
                                  cwd=os.path.join(os.getcwd(),
                                                   _visualization_directory))

        rel_extension = ["node_modules", "fairlearn-dashboard", "rel"]
        with _LogWrapper("removing existing visualizations pulled from npm"):
            shutil.rmtree(os.path.join(_widget_js_directory, *rel_extension))

        with _LogWrapper(
                "copying built visualizations into fairlearn widget dependencies"
        ):
            shutil.copytree(os.path.join(_visualization_directory, "rel"),
                            os.path.join(_widget_js_directory, *rel_extension))

        with _LogWrapper("yarn build with copied local changes"):
            subprocess.check_call([args.yarn_path, "build"],
                                  cwd=os.path.join(os.getcwd(),
                                                   _widget_js_directory))

    else:
        with _LogWrapper("removal of extra directories"):
            shutil.rmtree(os.path.join(_widget_js_directory, "dist"))
            shutil.rmtree(os.path.join(_widget_js_directory, "lib"))
            shutil.rmtree(os.path.join(_widget_js_directory, "node_modules"))

        if args.assert_no_changes:
            with _LogWrapper(
                    "comparison between old and newly generated widget files."
            ):
                for file_path in _widget_generated_files:
                    # git diff occasionally leaves out some of the JS files so use git status
                    diff_result = subprocess.check_output(["git", "status"])
                    if file_path in diff_result.decode('utf-8'):
                        raise Exception(
                            "File {} was unexpectedly modified.".format(
                                file_path))
Ejemplo n.º 4
0
def main(argv):
    _ensure_cwd_is_fairlearn_root_dir()
    parser = build_argument_parser()
    args = parser.parse_args(argv)

    with _LogWrapper("yarn install of dependencies"):
        subprocess.check_call([args.yarn_path, "install"],
                              cwd=os.path.join(os.getcwd(), _widget_js_directory))

    with _LogWrapper("yarn build"):
        subprocess.check_call([args.yarn_path, "build"],
                              cwd=os.path.join(os.getcwd(), _widget_js_directory))
Ejemplo n.º 5
0
def process_readme(input_file_name, output_file_name):
    sys.path.append(os.getcwd())
    import fairlearn
    target_version = fairlearn.__version__
    _logger.info("fairlearn version: %s", target_version)

    text_lines = []
    with _LogWrapper("reading file {}".format(input_file_name)):

        with open(input_file_name, 'r') as input_file:
            text_lines = input_file.readlines()

    result_lines = [_process_line(line, target_version) for line in text_lines]

    with _LogWrapper("writing file {}".format(output_file_name)):
        with open(output_file_name, 'w') as output_file:
            output_file.writelines(result_lines)
Ejemplo n.º 6
0
def _pip_backwards_compatibility():
    """Install extra pip packages for backwards compatibility

    This is specifically targeted at tempeh for v0.4.6.
    """
    extra_packages = ['tempeh']

    with _LogWrapper("Running pip install"):
        subprocess.check_call(["pip", "install"] + extra_packages)
Ejemplo n.º 7
0
def main(argv):
    _ensure_cwd_is_fairlearn_root_dir()
    parser = build_argument_parser()
    args = parser.parse_args(argv)

    with _LogWrapper("installation of fairlearn"):
        subprocess.check_call(["pip", "install", "-e", ".[customplots]"])

    with _LogWrapper("processing README.md"):
        process_readme("README.md", "README.md")

    with _LogWrapper("storing fairlearn version in {}".format(
            args.version_filename)):
        import fairlearn
        with open(args.version_filename, 'w') as version_file:
            version_file.write(fairlearn.__version__)

    with _LogWrapper("creation of packages"):
        subprocess.check_call(["python", "setup.py", "sdist", "bdist_wheel"])
Ejemplo n.º 8
0
def main(argv):
    parser = build_argument_parser()
    args = parser.parse_args(argv)

    with _LogWrapper("installation of interpret-text"):
        subprocess.check_call(["pip", "install", "./python"])

    with _LogWrapper("Check pip"):
        subprocess.check_call(["pip", "freeze"])

    with _LogWrapper("storing interpret-text version in {}".format(
            args.version_filename)):
        import interpret_text
        with open(args.version_filename, 'w') as version_file:
            version_file.write(interpret_text.__version__)

    with _LogWrapper("creation of packages"):
        subprocess.check_call(["python", "./setup.py", "sdist", "bdist_wheel"],
                              cwd="./python/")
Ejemplo n.º 9
0
def main(argv):
    _ensure_cwd_is_fairlearn_root_dir()
    parser = _build_argument_parser()
    args = parser.parse_args(argv)

    _pip_backwards_compatibility()

    with _LogWrapper("copying static files"):
        shutil.copytree(
            os.path.join(args.documentation_path, landing_page_directory),
            args.output_path)

    with _LogWrapper("running Sphinx-Multiversion"):
        subprocess.check_call(
            ["sphinx-multiversion", args.documentation_path, args.output_path])

    with _LogWrapper("copy of individual PNG"):
        shutil.copy2(os.path.join(args.documentation_path, extra_png_src_path),
                     os.path.join(args.output_path, "images"))
def _pin_requirements(src_file, dst_file):
    with _LogWrapper("Pinning {0} into {1}".format(src_file, dst_file)):

        _logger.debug("Reading file %s", src_file)
        text_lines = []
        with open(src_file, 'r') as f:
            text_lines = f.readlines()

        result_lines = [
            _process_line(current_line) for current_line in text_lines
        ]

        _logger.debug("Writing file %s", dst_file)
        with open(dst_file, 'w') as f:
            f.writelines(result_lines)
def _install_requirements_file(file_stem, fix_requirements):
    _logger.info("Processing %s", file_stem)

    if fix_requirements:
        source_file = "{0}.{1}".format(file_stem, _REQUIREMENTS_EXTENSION)
        requirements_file = "{0}{1}.{2}".format(file_stem, _INSERTION_FIXED,
                                                _REQUIREMENTS_EXTENSION)
        _pin_requirements(source_file, requirements_file)
    else:
        requirements_file = "{0}.{1}".format(file_stem,
                                             _REQUIREMENTS_EXTENSION)

    with _LogWrapper("Running pip on {0}".format(requirements_file)):
        command_args = ["pip", "install", "-r", requirements_file]
        subprocess.check_call(command_args)

    if fix_requirements:
        _logger.info("Removing temporary file %s", requirements_file)
        os.remove(requirements_file)
Ejemplo n.º 12
0
def main(argv):
    parser = build_argument_parser()
    args = parser.parse_args(argv)

    # extract minor version, e.g. '3.5'
    py_version = ".".join(platform.python_version().split(".")[:2])

    # override only if a requirements file for the specific version exists
    version_specific_requirements_file_path = "requirements-{}.txt".format(
        py_version)
    if os.path.exists(version_specific_requirements_file_path):
        input_file = version_specific_requirements_file_path
    else:
        input_file = 'requirements.txt'

    with _LogWrapper("Overriding {} with {}".format(args.output, input_file)):
        try:
            shutil.copyfile(input_file, args.output)
        except shutil.SameFileError:
            # destination is already identical with origin
            pass