Skip to content

Commit

Permalink
Misc cleanup (#5129)
Browse files Browse the repository at this point in the history
* Deprecate `conda_build.noarch_python._force_dir`, use `os.makedirs(exist_ok=True)` instead
* Deprecate `conda_build.noarch_python._error_exit`
* Combine `on_win` & `ISWIN` constants
* Always use `on_*` constants
* Remove Python 2.7 and conda<4.7.0 fallback imports
* Relative imports
* Add pyupgrade
* Add flake8-implicit-str-concat
  • Loading branch information
kenodegard authored Jan 4, 2024
1 parent 739bfa1 commit a323ce5
Show file tree
Hide file tree
Showing 46 changed files with 572 additions and 843 deletions.
88 changes: 40 additions & 48 deletions conda_build/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@
"""
from __future__ import annotations

import sys as _sys

# imports are done locally to keep the api clean and limited strictly
# to conda-build's functionality.
import os
import sys
from os.path import dirname, expanduser, join
from pathlib import Path

# make the Config class available in the api namespace
from conda_build.config import DEFAULT_PREFIX_LENGTH as _prefix_length
from conda_build.config import Config, get_channel_urls, get_or_merge_config
from conda_build.utils import ensure_list as _ensure_list
from conda_build.utils import expand_globs as _expand_globs
from conda_build.utils import get_logger as _get_logger

from .config import DEFAULT_PREFIX_LENGTH as _prefix_length
from .config import Config, get_channel_urls, get_or_merge_config
from .deprecations import deprecated
from .utils import (
CONDA_PACKAGE_EXTENSIONS,
LoggingContext,
ensure_list,
expand_globs,
find_recipe,
get_logger,
get_skip_message,
on_win,
)


def render(
Expand All @@ -42,9 +48,9 @@ def render(
Returns a list of (metadata, needs_download, needs_reparse in env) tuples"""
from collections import OrderedDict

from conda_build.conda_interface import NoPackagesFoundError
from conda_build.exceptions import DependencyNeedsBuildingError
from conda_build.render import finalize_metadata, render_recipe
from .conda_interface import NoPackagesFoundError
from .exceptions import DependencyNeedsBuildingError
from .render import finalize_metadata, render_recipe

config = get_or_merge_config(config, **kwargs)

Expand Down Expand Up @@ -104,7 +110,7 @@ def render(

def output_yaml(metadata, file_path=None, suppress_outputs=False):
"""Save a rendered recipe in its final form to the path given by file_path"""
from conda_build.render import output_yaml
from .render import output_yaml

return output_yaml(metadata, file_path, suppress_outputs=suppress_outputs)

Expand All @@ -121,8 +127,7 @@ def get_output_file_paths(
Both split packages (recipes with more than one output) and build matrices,
created with variants, contribute to the list of file paths here.
"""
from conda_build.render import bldpkg_path
from conda_build.utils import get_skip_message
from .render import bldpkg_path

config = get_or_merge_config(config, **kwargs)

Expand Down Expand Up @@ -176,7 +181,7 @@ def get_output_file_path(
Both split packages (recipes with more than one output) and build matrices,
created with variants, contribute to the list of file paths here.
"""
log = _get_logger(__name__)
log = get_logger(__name__)
log.warn(
"deprecation warning: this function has been renamed to get_output_file_paths, "
"to reflect that potentially multiple paths are returned. This function will be "
Expand Down Expand Up @@ -222,20 +227,17 @@ def build(
If recipe paths are provided, renders recipe before building.
Tests built packages by default. notest=True to skip test."""
import os

from conda_build.build import build_tree
from conda_build.utils import find_recipe
from .build import build_tree

assert post in (None, True, False), (
"post must be boolean or None. Remember, you must pass "
"other arguments (config) by keyword."
)

recipes = []
for recipe in _ensure_list(recipe_paths_or_metadata):
for recipe in ensure_list(recipe_paths_or_metadata):
if isinstance(recipe, str):
for recipe in _expand_globs(recipe, os.getcwd()):
for recipe in expand_globs(recipe, os.getcwd()):
try:
recipe = find_recipe(recipe)
except OSError:
Expand Down Expand Up @@ -275,7 +277,7 @@ def test(
For a recipe folder, it renders the recipe enough to know what package to download, and obtains
it from your currently configuured channels."""
from conda_build.build import test
from .build import test

if hasattr(recipedir_or_package_or_metadata, "config"):
config = recipedir_or_package_or_metadata.config
Expand Down Expand Up @@ -335,7 +337,7 @@ def skeletonize(
# only relevant ones below
config = get_or_merge_config(config, **kwargs)
config.compute_build_id("skeleton")
packages = _ensure_list(packages)
packages = ensure_list(packages)

# This is a little bit of black magic. The idea is that for any keyword argument that
# we inspect from the given module's skeletonize function, we should hoist the argument
Expand Down Expand Up @@ -370,7 +372,7 @@ def skeletonize(

def develop(
recipe_dir,
prefix=_sys.prefix,
prefix=sys.prefix,
no_pth_file=False,
build_ext=False,
clean=False,
Expand All @@ -381,7 +383,7 @@ def develop(
This works by creating a conda.pth file in site-packages."""
from .develop import execute

recipe_dir = _ensure_list(recipe_dir)
recipe_dir = ensure_list(recipe_dir)
return execute(recipe_dir, prefix, no_pth_file, build_ext, clean, uninstall)


Expand All @@ -400,7 +402,7 @@ def convert(
portable, such as pure python, or header-only C/C++ libraries."""
from .convert import conda_convert

platforms = _ensure_list(platforms)
platforms = ensure_list(platforms)
if package_file.endswith("tar.bz2"):
return conda_convert(
package_file,
Expand Down Expand Up @@ -431,7 +433,7 @@ def test_installable(channel="defaults"):

def inspect_linkages(
packages,
prefix=_sys.prefix,
prefix=sys.prefix,
untracked=False,
all_packages=False,
show_files=False,
Expand All @@ -440,7 +442,7 @@ def inspect_linkages(
):
from .inspect_pkg import inspect_linkages

packages = _ensure_list(packages)
packages = ensure_list(packages)
return inspect_linkages(
packages,
prefix=prefix,
Expand All @@ -452,18 +454,18 @@ def inspect_linkages(
)


def inspect_objects(packages, prefix=_sys.prefix, groupby="filename"):
def inspect_objects(packages, prefix=sys.prefix, groupby="filename"):
from .inspect_pkg import inspect_objects

packages = _ensure_list(packages)
packages = ensure_list(packages)
return inspect_objects(packages, prefix=prefix, groupby=groupby)


def inspect_prefix_length(packages, min_prefix_length=_prefix_length):
from conda_build.tarcheck import check_prefix_lengths
from .tarcheck import check_prefix_lengths

config = Config(prefix_length=min_prefix_length)
packages = _ensure_list(packages)
packages = ensure_list(packages)
prefix_lengths = check_prefix_lengths(packages, config)
if prefix_lengths:
print(
Expand Down Expand Up @@ -538,14 +540,11 @@ def update_index(
current_index_versions=None,
**kwargs,
):
import os

import yaml

from conda_build.index import update_index as legacy_update_index
from conda_build.utils import ensure_list
from .index import update_index as legacy_update_index

dir_paths = [os.path.abspath(path) for path in _ensure_list(dir_paths)]
dir_paths = [os.path.abspath(path) for path in ensure_list(dir_paths)]

if isinstance(current_index_versions, str):
with open(current_index_versions) as f:
Expand Down Expand Up @@ -580,14 +579,11 @@ def debug(
your package's build or test phase.
"""
import logging
import os
import time
from fnmatch import fnmatch

from conda_build.build import build as run_build
from conda_build.build import test as run_test
from conda_build.utils import CONDA_PACKAGE_EXTENSIONS, LoggingContext, on_win

from .build import build as run_build
from .build import test as run_test
from .metadata import MetaData

is_package = False
Expand Down Expand Up @@ -702,15 +698,11 @@ def debug(
os.symlink(link_target, debug_source_loc)
except PermissionError as e:
raise Exception(
"You do not have the necessary permissions to create symlinks in {}\nerror: {}".format(
dn, str(e)
)
f"You do not have the necessary permissions to create symlinks in {dn}\nerror: {str(e)}"
)
except Exception as e:
raise Exception(
"Unknown error creating symlinks in {}\nerror: {}".format(
dn, str(e)
)
f"Unknown error creating symlinks in {dn}\nerror: {str(e)}"
)
ext = ".bat" if on_win else ".sh"

Expand Down
17 changes: 6 additions & 11 deletions conda_build/bdist_conda.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
"""
bdist_conda
"""

import sys
import time
from collections import defaultdict
Expand All @@ -13,12 +8,12 @@
from setuptools.dist import Distribution
from setuptools.errors import BaseError, OptionError

from conda_build import api
from conda_build.build import handle_anaconda_upload
from conda_build.conda_interface import StringIO, configparser, spec_from_line
from conda_build.config import Config
from conda_build.metadata import MetaData
from conda_build.skeletons import pypi
from . import api
from .build import handle_anaconda_upload
from .conda_interface import StringIO, configparser, spec_from_line
from .config import Config
from .metadata import MetaData
from .skeletons import pypi

# TODO: Add support for all the options that conda build has

Expand Down
Loading

0 comments on commit a323ce5

Please sign in to comment.