Skip to content

Commit 9871679

Browse files
committed
fix: resolve linting errors in pathlib refactor
1 parent ef40b60 commit 9871679

10 files changed

+91
-84
lines changed

conda_smithy/cli.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def generate_feedstock_content(target_directory, source_recipe_dir):
4040
# If there is a source recipe, copy it now to the right dir
4141
if source_recipe_dir:
4242
try:
43-
configure_feedstock.copytree(source_recipe_dir, str(target_recipe_dir))
43+
configure_feedstock.copytree(
44+
source_recipe_dir, str(target_recipe_dir)
45+
)
4446
except Exception as e:
4547
import sys
4648

@@ -57,9 +59,7 @@ def generate_feedstock_content(target_directory, source_recipe_dir):
5759
forge_yml_recipe = Path(source_recipe_dir, "conda-forge.yml")
5860
yaml = YAML()
5961
if forge_yml_recipe.exists():
60-
feedstock_io.remove_file(
61-
target_recipe_dir.joinpath("conda-forge.yml")
62-
)
62+
feedstock_io.remove_file(target_recipe_dir.joinpath("conda-forge.yml"))
6363
try:
6464
with open(forge_yml_recipe, "r") as fp:
6565
_cfg = yaml.load(fp.read())

conda_smithy/configure_feedstock.py

+30-32
Original file line numberDiff line numberDiff line change
@@ -1175,16 +1175,19 @@ def _render_ci_provider(
11751175

11761176
# If the recipe has its own conda_forge_ci_setup package, then
11771177
# install that
1178-
if Path(
1179-
forge_dir,
1180-
forge_config["recipe_dir"],
1181-
"conda_forge_ci_setup",
1182-
"__init__.py",
1183-
).exists() and Path(
1184-
forge_dir,
1185-
forge_config["recipe_dir"],
1186-
"setup.py",
1187-
).exists():
1178+
if (
1179+
Path(
1180+
forge_dir,
1181+
forge_config["recipe_dir"],
1182+
"conda_forge_ci_setup",
1183+
"__init__.py",
1184+
).exists()
1185+
and Path(
1186+
forge_dir,
1187+
forge_config["recipe_dir"],
1188+
"setup.py",
1189+
).exists()
1190+
):
11881191
forge_config["local_ci_setup"] = True
11891192
else:
11901193
forge_config["local_ci_setup"] = False
@@ -1324,9 +1327,7 @@ def _circle_specific_setup(jinja_env, forge_config, forge_dir, platform):
13241327
)
13251328

13261329
# Fix permission of other shell files.
1327-
target_fnames = [
1328-
Path(forge_dir, ".circleci", "checkout_merge_commit.sh")
1329-
]
1330+
target_fnames = [Path(forge_dir, ".circleci", "checkout_merge_commit.sh")]
13301331
for target_fname in target_fnames:
13311332
set_exe_file(target_fname, True)
13321333

@@ -1483,14 +1484,13 @@ def _render_template_exe_files(
14831484
forge_config, jinja_env, template_files, forge_dir
14841485
):
14851486
for template_file in template_files:
1486-
template = jinja_env.get_template(
1487-
Path(template_file).name + ".tmpl"
1488-
)
1487+
template = jinja_env.get_template(Path(template_file).name + ".tmpl")
14891488
target_fname = str(Path(forge_dir, template_file))
14901489
new_file_contents = template.render(**forge_config)
1491-
if target_fname in get_common_scripts(forge_dir) and Path(
1492-
target_fname
1493-
).exists():
1490+
if (
1491+
target_fname in get_common_scripts(forge_dir)
1492+
and Path(target_fname).exists()
1493+
):
14941494
with open(target_fname, "r") as fh:
14951495
old_file_contents = fh.read()
14961496
if old_file_contents != new_file_contents:
@@ -1723,9 +1723,7 @@ def _github_actions_specific_setup(
17231723
def render_github_actions(
17241724
jinja_env, forge_config, forge_dir, return_metadata=False
17251725
):
1726-
target_path = Path(
1727-
forge_dir, ".github", "workflows", "conda-build.yml"
1728-
)
1726+
target_path = Path(forge_dir, ".github", "workflows", "conda-build.yml")
17291727
template_filename = "github-actions.yml.tmpl"
17301728
fast_finish_text = ""
17311729

@@ -2152,6 +2150,7 @@ def _update_dict_within_dict(items, config):
21522150
config[key] = value
21532151
return config
21542152

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

21922191
# check for conda-smithy 2.x matrix which we can't auto-migrate
21932192
# to conda_build_config
2194-
if file_config.get("matrix") and not Path(
2195-
forge_dir, config["recipe_dir"], "conda_build_config.yaml"
2196-
).exists():
2193+
if (
2194+
file_config.get("matrix")
2195+
and not Path(
2196+
forge_dir, config["recipe_dir"], "conda_build_config.yaml"
2197+
).exists()
2198+
):
21972199
raise ValueError(
21982200
"Cannot rerender with matrix in conda-forge.yml."
21992201
" Please migrate matrix to conda_build_config.yaml and try again."
@@ -2480,9 +2482,7 @@ def get_cfp_file_path(temporary_directory):
24802482

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

2483-
cf_pinning_file = Path(
2484-
temporary_directory, "conda_build_config.yaml"
2485-
)
2485+
cf_pinning_file = Path(temporary_directory, "conda_build_config.yaml")
24862486
cf_pinning_ver = pkg.version
24872487

24882488
assert cf_pinning_file.exists()
@@ -2581,9 +2581,7 @@ def make_jinja_env(feedstock_directory):
25812581
# Load templates from the feedstock in preference to the smithy's templates.
25822582
env = SandboxedEnvironment(
25832583
extensions=["jinja2.ext.do"],
2584-
loader=FileSystemLoader(
2585-
[Path(forge_dir, "templates"), tmplt_dir]
2586-
),
2584+
loader=FileSystemLoader([Path(forge_dir, "templates"), tmplt_dir]),
25872585
)
25882586
return env
25892587

@@ -2800,4 +2798,4 @@ def main(
28002798
)
28012799

28022800
args = parser.parse_args()
2803-
main(args.forge_file_directory)
2801+
main(args.forge_file_directory)

conda_smithy/lint_recipe.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ def lintify_meta_yaml(
224224
# 4: The recipe should have some tests.
225225
if not any(key in TEST_KEYS for key in test_section):
226226
a_test_file_exists = recipe_dir is not None and any(
227-
(Path(recipe_dir, test_file)).exists()
228-
for test_file in TEST_FILES
227+
(Path(recipe_dir, test_file)).exists() for test_file in TEST_FILES
229228
)
230229
if not a_test_file_exists:
231230
has_outputs_test = False
@@ -858,7 +857,7 @@ def check_pins_build_and_requirements(top_level):
858857
with open(Path(file_dir, "licenses.txt"), "r") as f:
859858
expected_licenses = f.readlines()
860859
expected_licenses = set([l.strip() for l in expected_licenses])
861-
with open(Path(file_dir,"license_exceptions.txt"), "r") as f:
860+
with open(Path(file_dir, "license_exceptions.txt"), "r") as f:
862861
expected_exceptions = f.readlines()
863862
expected_exceptions = set([l.strip() for l in expected_exceptions])
864863
if set(filtered_licenses) - expected_licenses:

conda_smithy/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def get_feedstock_about_from_meta(meta) -> dict:
3030
# - if a subpackage has about, it's used as is
3131
# therefore we need to parse the yaml again just to get the about section...
3232
if "parent_recipe" in meta.meta["extra"]:
33-
recipe_meta = Path(meta.meta["extra"]["parent_recipe"]["path"], "meta.yaml")
33+
recipe_meta = Path(
34+
meta.meta["extra"]["parent_recipe"]["path"], "meta.yaml"
35+
)
3436

3537
with io.open(recipe_meta, "rt") as fh:
3638
content = render_meta_yaml("".join(fh))

tests/conftest.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ def config_yaml(testing_workdir, recipe_dirname):
112112

113113
@pytest.fixture(scope="function")
114114
def noarch_recipe(config_yaml, recipe_dirname, request):
115-
with open(
116-
Path(config_yaml, recipe_dirname, "meta.yaml"), "w"
117-
) as fh:
115+
with open(Path(config_yaml, recipe_dirname, "meta.yaml"), "w") as fh:
118116
fh.write(
119117
"""
120118
package:
@@ -216,9 +214,7 @@ def stdlib_recipe(config_yaml, request):
216214
home: home
217215
"""
218216
)
219-
with open(
220-
Path(config_yaml, "recipe", "stdlib_config.yaml"), "w"
221-
) as f:
217+
with open(Path(config_yaml, "recipe", "stdlib_config.yaml"), "w") as f:
222218
f.write(
223219
"""\
224220
c_stdlib:
@@ -246,9 +242,7 @@ def stdlib_recipe(config_yaml, request):
246242
@pytest.fixture(scope="function")
247243
def stdlib_deployment_target_recipe(config_yaml, stdlib_recipe):
248244
# append to existing stdlib_config.yaml from stdlib_recipe
249-
with open(
250-
Path(config_yaml, "recipe", "stdlib_config.yaml"), "a"
251-
) as f:
245+
with open(Path(config_yaml, "recipe", "stdlib_config.yaml"), "a") as f:
252246
f.write(
253247
"""\
254248
MACOSX_DEPLOYMENT_TARGET: # [osx]
@@ -318,7 +312,9 @@ def recipe_migration_cfep9(config_yaml, request):
318312
"""
319313
)
320314

321-
Path(config_yaml, ".ci_support", "migrations").mkdir(parents=True, exist_ok=True)
315+
Path(config_yaml, ".ci_support", "migrations").mkdir(
316+
parents=True, exist_ok=True
317+
)
322318
with open(
323319
Path(config_yaml, ".ci_support", "migrations", "zlib.yaml"),
324320
"w",
@@ -346,7 +342,9 @@ def recipe_migration_cfep9(config_yaml, request):
346342
def recipe_migration_cfep9_downgrade(config_yaml, recipe_migration_cfep9):
347343
# write a downgrade migrator that lives next to the current migrator.
348344
# Only this, more recent migrator should apply.
349-
Path(config_yaml, ".ci_support", "migrations").mkdir(parents=True, exist_ok=True)
345+
Path(config_yaml, ".ci_support", "migrations").mkdir(
346+
parents=True, exist_ok=True
347+
)
350348
with open(
351349
Path(config_yaml, ".ci_support", "migrations", "zlib-downgrade.yaml"),
352350
"w",
@@ -372,7 +370,9 @@ def recipe_migration_cfep9_downgrade(config_yaml, recipe_migration_cfep9):
372370

373371
@pytest.fixture(scope="function")
374372
def recipe_migration_win_compiled(config_yaml, py_recipe):
375-
Path(config_yaml, ".ci_support", "migrations").mkdir(parents=True, exist_ok=True)
373+
Path(config_yaml, ".ci_support", "migrations").mkdir(
374+
parents=True, exist_ok=True
375+
)
376376
with open(
377377
Path(config_yaml, ".ci_support", "migrations", "vc-migrate.yaml"),
378378
"w",

tests/test_cli.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,7 @@ def test_regenerate(py_recipe, testing_workdir):
306306
feedstock_config=None,
307307
commit=False,
308308
no_check_uptodate=True,
309-
exclusive_config_file=str(
310-
Path(recipe, "recipe", "short_config.yaml")
311-
),
309+
exclusive_config_file=str(Path(recipe, "recipe", "short_config.yaml")),
312310
check=False,
313311
temporary_directory=str(dest_dir.joinpath("temp")),
314312
)

tests/test_configure_feedstock.py

+25-19
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ def test_py_matrix_on_github(py_recipe, jinja_env):
193193
assert matrix_dir.is_dir()
194194
# single matrix entry - readme is generated later in main function
195195
assert len(list(matrix_dir.iterdir())) == 2
196-
assert Path(py_recipe.recipe, ".github", "workflows", "conda-build.yml").exists()
196+
assert Path(
197+
py_recipe.recipe, ".github", "workflows", "conda-build.yml"
198+
).exists()
197199

198200

199201
def test_py_matrix_on_azure(py_recipe, jinja_env):
@@ -256,9 +258,7 @@ def test_stdlib_deployment_target(
256258
)
257259
# this configuration should be run
258260
assert stdlib_deployment_target_recipe.config["azure"]["enabled"]
259-
matrix_dir = Path(
260-
stdlib_deployment_target_recipe.recipe, ".ci_support"
261-
)
261+
matrix_dir = Path(stdlib_deployment_target_recipe.recipe, ".ci_support")
262262
assert matrix_dir.is_dir()
263263
with open(matrix_dir.joinpath("osx_64_.yaml")) as f:
264264
lines = f.readlines()
@@ -354,9 +354,7 @@ def test_upload_on_branch_appveyor(upload_on_branch_recipe, jinja_env):
354354
assert upload_on_branch_recipe.config["upload_on_branch"] == "foo-branch"
355355

356356
# Check that the parameter is in the generated file.
357-
with open(
358-
Path(upload_on_branch_recipe.recipe, ".appveyor.yml")
359-
) as fp:
357+
with open(Path(upload_on_branch_recipe.recipe, ".appveyor.yml")) as fp:
360358
content = yaml.safe_load(fp)
361359
assert "%APPVEYOR_REPO_BRANCH%" in content["deploy_script"][0]
362360
assert "UPLOAD_ON_BRANCH=foo-branch" in content["deploy_script"][-2]
@@ -498,9 +496,9 @@ def test_render_with_all_skipped_generates_readme(skipped_recipe, jinja_env):
498496
def test_render_windows_with_skipped_python(python_skipped_recipe, jinja_env):
499497
config = python_skipped_recipe.config
500498
config["provider"]["win"] = "appveyor"
501-
config["exclusive_config_file"] = str(Path(
502-
python_skipped_recipe.recipe, "recipe", "long_config.yaml"
503-
))
499+
config["exclusive_config_file"] = str(
500+
Path(python_skipped_recipe.recipe, "recipe", "long_config.yaml")
501+
)
504502
configure_feedstock.render_appveyor(
505503
jinja_env=jinja_env,
506504
forge_config=config,
@@ -625,8 +623,12 @@ def test_migrator_cfp_override(recipe_migration_cfep9, jinja_env):
625623

626624
def test_migrator_delete_old(recipe_migration_cfep9, jinja_env):
627625
cfp_file = recipe_migration_cfep9.config["exclusive_config_file"]
628-
cfp_migration_dir = Path(cfp_file).parent.joinpath("share", "conda-forge", "migrations")
629-
recipe_path = Path(recipe_migration_cfep9.recipe, ".ci_support", "migrations", "zlib.yaml")
626+
cfp_migration_dir = Path(cfp_file).parent.joinpath(
627+
"share", "conda-forge", "migrations"
628+
)
629+
recipe_path = Path(
630+
recipe_migration_cfep9.recipe, ".ci_support", "migrations", "zlib.yaml"
631+
)
630632
assert recipe_path.exists()
631633
cfp_migration_dir.mkdir(parents=True, exist_ok=True)
632634
configure_feedstock.render_azure(
@@ -653,7 +655,7 @@ def test_migrator_downgrade_recipe(
653655
".ci_support",
654656
"migrations",
655657
)
656-
assert (len(list(migrations_dir.iterdir())) == 2)
658+
assert len(list(migrations_dir.iterdir())) == 2
657659

658660
with open(
659661
Path(
@@ -678,8 +680,10 @@ def test_migrator_compiler_version_recipe(
678680
forge_dir=recipe_migration_win_compiled.recipe,
679681
)
680682

681-
migrations_dir = Path(recipe_migration_win_compiled.recipe, ".ci_support", "migrations")
682-
assert (len(list(migrations_dir.iterdir())) == 1)
683+
migrations_dir = Path(
684+
recipe_migration_win_compiled.recipe, ".ci_support", "migrations"
685+
)
686+
assert len(list(migrations_dir.iterdir())) == 1
683687

684688
dir = Path(recipe_migration_win_compiled.recipe, ".ci_support")
685689
rendered_variants = [item.name for item in dir.iterdir()]
@@ -784,9 +788,9 @@ def test_conda_forge_yaml_empty(config_yaml):
784788
def test_noarch_platforms_bad_yaml(config_yaml, caplog):
785789
load_forge_config = lambda: configure_feedstock._load_forge_config( # noqa
786790
config_yaml,
787-
exclusive_config_file=str(Path(
788-
config_yaml, "recipe", "default_config.yaml"
789-
)),
791+
exclusive_config_file=str(
792+
Path(config_yaml, "recipe", "default_config.yaml")
793+
),
790794
)
791795

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

813817
forge_yml = config_yaml_path.joinpath("conda-forge.yml")
814-
forge_yml_alt = config_yaml_path.joinpath(".config", "feedstock-config.yml")
818+
forge_yml_alt = config_yaml_path.joinpath(
819+
".config", "feedstock-config.yml"
820+
)
815821

816822
forge_yml_alt.parent.mkdir()
817823
forge_yml.rename(forge_yml_alt)

0 commit comments

Comments
 (0)