Skip to content

Commit

Permalink
fix: resolve linting errors in pathlib refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbaHerrerias committed Jun 10, 2024
1 parent ef40b60 commit 19e578d
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 87 deletions.
8 changes: 4 additions & 4 deletions conda_smithy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def generate_feedstock_content(target_directory, source_recipe_dir):
# If there is a source recipe, copy it now to the right dir
if source_recipe_dir:
try:
configure_feedstock.copytree(source_recipe_dir, str(target_recipe_dir))
configure_feedstock.copytree(
source_recipe_dir, str(target_recipe_dir)
)
except Exception as e:
import sys

Expand All @@ -57,9 +59,7 @@ def generate_feedstock_content(target_directory, source_recipe_dir):
forge_yml_recipe = Path(source_recipe_dir, "conda-forge.yml")
yaml = YAML()
if forge_yml_recipe.exists():
feedstock_io.remove_file(
target_recipe_dir.joinpath("conda-forge.yml")
)
feedstock_io.remove_file(target_recipe_dir.joinpath("conda-forge.yml"))
try:
with open(forge_yml_recipe, "r") as fp:
_cfg = yaml.load(fp.read())
Expand Down
62 changes: 30 additions & 32 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,16 +1175,19 @@ def _render_ci_provider(

# If the recipe has its own conda_forge_ci_setup package, then
# install that
if Path(
forge_dir,
forge_config["recipe_dir"],
"conda_forge_ci_setup",
"__init__.py",
).exists() and Path(
forge_dir,
forge_config["recipe_dir"],
"setup.py",
).exists():
if (
Path(
forge_dir,
forge_config["recipe_dir"],
"conda_forge_ci_setup",
"__init__.py",
).exists()
and Path(
forge_dir,
forge_config["recipe_dir"],
"setup.py",
).exists()
):
forge_config["local_ci_setup"] = True
else:
forge_config["local_ci_setup"] = False
Expand Down Expand Up @@ -1324,9 +1327,7 @@ def _circle_specific_setup(jinja_env, forge_config, forge_dir, platform):
)

# Fix permission of other shell files.
target_fnames = [
Path(forge_dir, ".circleci", "checkout_merge_commit.sh")
]
target_fnames = [Path(forge_dir, ".circleci", "checkout_merge_commit.sh")]
for target_fname in target_fnames:
set_exe_file(target_fname, True)

Expand Down Expand Up @@ -1483,14 +1484,13 @@ def _render_template_exe_files(
forge_config, jinja_env, template_files, forge_dir
):
for template_file in template_files:
template = jinja_env.get_template(
Path(template_file).name + ".tmpl"
)
template = jinja_env.get_template(Path(template_file).name + ".tmpl")
target_fname = str(Path(forge_dir, template_file))
new_file_contents = template.render(**forge_config)
if target_fname in get_common_scripts(forge_dir) and Path(
target_fname
).exists():
if (
target_fname in get_common_scripts(forge_dir)
and Path(target_fname).exists()
):
with open(target_fname, "r") as fh:
old_file_contents = fh.read()
if old_file_contents != new_file_contents:
Expand Down Expand Up @@ -1723,9 +1723,7 @@ def _github_actions_specific_setup(
def render_github_actions(
jinja_env, forge_config, forge_dir, return_metadata=False
):
target_path = Path(
forge_dir, ".github", "workflows", "conda-build.yml"
)
target_path = Path(forge_dir, ".github", "workflows", "conda-build.yml")
template_filename = "github-actions.yml.tmpl"
fast_finish_text = ""

Expand Down Expand Up @@ -2152,6 +2150,7 @@ def _update_dict_within_dict(items, config):
config[key] = value
return config


def _read_forge_config(forge_dir, forge_yml=None):
# Load default values from the conda-forge.yml file
with open(CONDA_FORGE_YAML_DEFAULTS_FILE, "r") as fh:
Expand Down Expand Up @@ -2191,9 +2190,12 @@ def _read_forge_config(forge_dir, forge_yml=None):

# check for conda-smithy 2.x matrix which we can't auto-migrate
# to conda_build_config
if file_config.get("matrix") and not Path(
forge_dir, config["recipe_dir"], "conda_build_config.yaml"
).exists():
if (
file_config.get("matrix")
and not Path(
forge_dir, config["recipe_dir"], "conda_build_config.yaml"
).exists()
):
raise ValueError(
"Cannot rerender with matrix in conda-forge.yml."
" Please migrate matrix to conda_build_config.yaml and try again."
Expand Down Expand Up @@ -2480,9 +2482,7 @@ def get_cfp_file_path(temporary_directory):

logger.debug(list(Path(temporary_directory).iterdir()))

cf_pinning_file = Path(
temporary_directory, "conda_build_config.yaml"
)
cf_pinning_file = Path(temporary_directory, "conda_build_config.yaml")
cf_pinning_ver = pkg.version

assert cf_pinning_file.exists()
Expand Down Expand Up @@ -2581,9 +2581,7 @@ def make_jinja_env(feedstock_directory):
# Load templates from the feedstock in preference to the smithy's templates.
env = SandboxedEnvironment(
extensions=["jinja2.ext.do"],
loader=FileSystemLoader(
[Path(forge_dir, "templates"), tmplt_dir]
),
loader=FileSystemLoader([Path(forge_dir, "templates"), tmplt_dir]),
)
return env

Expand Down Expand Up @@ -2800,4 +2798,4 @@ def main(
)

args = parser.parse_args()
main(args.forge_file_directory)
main(args.forge_file_directory)
4 changes: 1 addition & 3 deletions conda_smithy/feedstock_content/build-locally.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ def lintify_meta_yaml(
# 4: The recipe should have some tests.
if not any(key in TEST_KEYS for key in test_section):
a_test_file_exists = recipe_dir is not None and any(
(Path(recipe_dir, test_file)).exists()
for test_file in TEST_FILES
(Path(recipe_dir, test_file)).exists() for test_file in TEST_FILES
)
if not a_test_file_exists:
has_outputs_test = False
Expand Down Expand Up @@ -858,7 +857,7 @@ def check_pins_build_and_requirements(top_level):
with open(Path(file_dir, "licenses.txt"), "r") as f:
expected_licenses = f.readlines()
expected_licenses = set([l.strip() for l in expected_licenses])
with open(Path(file_dir,"license_exceptions.txt"), "r") as f:
with open(Path(file_dir, "license_exceptions.txt"), "r") as f:
expected_exceptions = f.readlines()
expected_exceptions = set([l.strip() for l in expected_exceptions])
if set(filtered_licenses) - expected_licenses:
Expand Down
4 changes: 3 additions & 1 deletion conda_smithy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def get_feedstock_about_from_meta(meta) -> dict:
# - if a subpackage has about, it's used as is
# therefore we need to parse the yaml again just to get the about section...
if "parent_recipe" in meta.meta["extra"]:
recipe_meta = Path(meta.meta["extra"]["parent_recipe"]["path"], "meta.yaml")
recipe_meta = Path(
meta.meta["extra"]["parent_recipe"]["path"], "meta.yaml"
)

with io.open(recipe_meta, "rt") as fh:
content = render_meta_yaml("".join(fh))
Expand Down
24 changes: 12 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def config_yaml(testing_workdir, recipe_dirname):

@pytest.fixture(scope="function")
def noarch_recipe(config_yaml, recipe_dirname, request):
with open(
Path(config_yaml, recipe_dirname, "meta.yaml"), "w"
) as fh:
with open(Path(config_yaml, recipe_dirname, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
Expand Down Expand Up @@ -216,9 +214,7 @@ def stdlib_recipe(config_yaml, request):
home: home
"""
)
with open(
Path(config_yaml, "recipe", "stdlib_config.yaml"), "w"
) as f:
with open(Path(config_yaml, "recipe", "stdlib_config.yaml"), "w") as f:
f.write(
"""\
c_stdlib:
Expand Down Expand Up @@ -246,9 +242,7 @@ def stdlib_recipe(config_yaml, request):
@pytest.fixture(scope="function")
def stdlib_deployment_target_recipe(config_yaml, stdlib_recipe):
# append to existing stdlib_config.yaml from stdlib_recipe
with open(
Path(config_yaml, "recipe", "stdlib_config.yaml"), "a"
) as f:
with open(Path(config_yaml, "recipe", "stdlib_config.yaml"), "a") as f:
f.write(
"""\
MACOSX_DEPLOYMENT_TARGET: # [osx]
Expand Down Expand Up @@ -318,7 +312,9 @@ def recipe_migration_cfep9(config_yaml, request):
"""
)

Path(config_yaml, ".ci_support", "migrations").mkdir(parents=True, exist_ok=True)
Path(config_yaml, ".ci_support", "migrations").mkdir(
parents=True, exist_ok=True
)
with open(
Path(config_yaml, ".ci_support", "migrations", "zlib.yaml"),
"w",
Expand Down Expand Up @@ -346,7 +342,9 @@ def recipe_migration_cfep9(config_yaml, request):
def recipe_migration_cfep9_downgrade(config_yaml, recipe_migration_cfep9):
# write a downgrade migrator that lives next to the current migrator.
# Only this, more recent migrator should apply.
Path(config_yaml, ".ci_support", "migrations").mkdir(parents=True, exist_ok=True)
Path(config_yaml, ".ci_support", "migrations").mkdir(
parents=True, exist_ok=True
)
with open(
Path(config_yaml, ".ci_support", "migrations", "zlib-downgrade.yaml"),
"w",
Expand All @@ -372,7 +370,9 @@ def recipe_migration_cfep9_downgrade(config_yaml, recipe_migration_cfep9):

@pytest.fixture(scope="function")
def recipe_migration_win_compiled(config_yaml, py_recipe):
Path(config_yaml, ".ci_support", "migrations").mkdir(parents=True, exist_ok=True)
Path(config_yaml, ".ci_support", "migrations").mkdir(
parents=True, exist_ok=True
)
with open(
Path(config_yaml, ".ci_support", "migrations", "vc-migrate.yaml"),
"w",
Expand Down
4 changes: 1 addition & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ def test_regenerate(py_recipe, testing_workdir):
feedstock_config=None,
commit=False,
no_check_uptodate=True,
exclusive_config_file=str(
Path(recipe, "recipe", "short_config.yaml")
),
exclusive_config_file=str(Path(recipe, "recipe", "short_config.yaml")),
check=False,
temporary_directory=str(dest_dir.joinpath("temp")),
)
Expand Down
44 changes: 25 additions & 19 deletions tests/test_configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ def test_py_matrix_on_github(py_recipe, jinja_env):
assert matrix_dir.is_dir()
# single matrix entry - readme is generated later in main function
assert len(list(matrix_dir.iterdir())) == 2
assert Path(py_recipe.recipe, ".github", "workflows", "conda-build.yml").exists()
assert Path(
py_recipe.recipe, ".github", "workflows", "conda-build.yml"
).exists()


def test_py_matrix_on_azure(py_recipe, jinja_env):
Expand Down Expand Up @@ -256,9 +258,7 @@ def test_stdlib_deployment_target(
)
# this configuration should be run
assert stdlib_deployment_target_recipe.config["azure"]["enabled"]
matrix_dir = Path(
stdlib_deployment_target_recipe.recipe, ".ci_support"
)
matrix_dir = Path(stdlib_deployment_target_recipe.recipe, ".ci_support")
assert matrix_dir.is_dir()
with open(matrix_dir.joinpath("osx_64_.yaml")) as f:
lines = f.readlines()
Expand Down Expand Up @@ -354,9 +354,7 @@ def test_upload_on_branch_appveyor(upload_on_branch_recipe, jinja_env):
assert upload_on_branch_recipe.config["upload_on_branch"] == "foo-branch"

# Check that the parameter is in the generated file.
with open(
Path(upload_on_branch_recipe.recipe, ".appveyor.yml")
) as fp:
with open(Path(upload_on_branch_recipe.recipe, ".appveyor.yml")) as fp:
content = yaml.safe_load(fp)
assert "%APPVEYOR_REPO_BRANCH%" in content["deploy_script"][0]
assert "UPLOAD_ON_BRANCH=foo-branch" in content["deploy_script"][-2]
Expand Down Expand Up @@ -498,9 +496,9 @@ def test_render_with_all_skipped_generates_readme(skipped_recipe, jinja_env):
def test_render_windows_with_skipped_python(python_skipped_recipe, jinja_env):
config = python_skipped_recipe.config
config["provider"]["win"] = "appveyor"
config["exclusive_config_file"] = str(Path(
python_skipped_recipe.recipe, "recipe", "long_config.yaml"
))
config["exclusive_config_file"] = str(
Path(python_skipped_recipe.recipe, "recipe", "long_config.yaml")
)
configure_feedstock.render_appveyor(
jinja_env=jinja_env,
forge_config=config,
Expand Down Expand Up @@ -625,8 +623,12 @@ def test_migrator_cfp_override(recipe_migration_cfep9, jinja_env):

def test_migrator_delete_old(recipe_migration_cfep9, jinja_env):
cfp_file = recipe_migration_cfep9.config["exclusive_config_file"]
cfp_migration_dir = Path(cfp_file).parent.joinpath("share", "conda-forge", "migrations")
recipe_path = Path(recipe_migration_cfep9.recipe, ".ci_support", "migrations", "zlib.yaml")
cfp_migration_dir = Path(cfp_file).parent.joinpath(
"share", "conda-forge", "migrations"
)
recipe_path = Path(
recipe_migration_cfep9.recipe, ".ci_support", "migrations", "zlib.yaml"
)
assert recipe_path.exists()
cfp_migration_dir.mkdir(parents=True, exist_ok=True)
configure_feedstock.render_azure(
Expand All @@ -653,7 +655,7 @@ def test_migrator_downgrade_recipe(
".ci_support",
"migrations",
)
assert (len(list(migrations_dir.iterdir())) == 2)
assert len(list(migrations_dir.iterdir())) == 2

with open(
Path(
Expand All @@ -678,8 +680,10 @@ def test_migrator_compiler_version_recipe(
forge_dir=recipe_migration_win_compiled.recipe,
)

migrations_dir = Path(recipe_migration_win_compiled.recipe, ".ci_support", "migrations")
assert (len(list(migrations_dir.iterdir())) == 1)
migrations_dir = Path(
recipe_migration_win_compiled.recipe, ".ci_support", "migrations"
)
assert len(list(migrations_dir.iterdir())) == 1

dir = Path(recipe_migration_win_compiled.recipe, ".ci_support")
rendered_variants = [item.name for item in dir.iterdir()]
Expand Down Expand Up @@ -784,9 +788,9 @@ def test_conda_forge_yaml_empty(config_yaml):
def test_noarch_platforms_bad_yaml(config_yaml, caplog):
load_forge_config = lambda: configure_feedstock._load_forge_config( # noqa
config_yaml,
exclusive_config_file=str(Path(
config_yaml, "recipe", "default_config.yaml"
)),
exclusive_config_file=str(
Path(config_yaml, "recipe", "default_config.yaml")
),
)

with open(Path(config_yaml, "conda-forge.yml"), "a+") as fp:
Expand All @@ -811,7 +815,9 @@ def test_forge_yml_alt_path(config_yaml):
)

forge_yml = config_yaml_path.joinpath("conda-forge.yml")
forge_yml_alt = config_yaml_path.joinpath(".config", "feedstock-config.yml")
forge_yml_alt = config_yaml_path.joinpath(
".config", "feedstock-config.yml"
)

forge_yml_alt.parent.mkdir()
forge_yml.rename(forge_yml_alt)
Expand Down
Loading

0 comments on commit 19e578d

Please sign in to comment.