Skip to content

Commit 116be20

Browse files
committed
fixes
1 parent cff66b4 commit 116be20

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

unidep/_pixi_lock.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,22 @@ def _check_consistent_lock_files(
151151

152152
def _generate_sub_lock_file(
153153
feature_name: str,
154-
global_lock_data: dict[str, any],
154+
global_lock_data: dict[str, Any],
155155
yaml_obj: YAML,
156156
output_dir: Path,
157157
) -> Path:
158158
"""Generate a sub-lock file for a given feature.
159159
160160
Parameters
161161
----------
162-
- feature_name: The name of the feature (derived from the parent folder’s stem).
163-
- global_lock_data: The global lock file data as a dict.
164-
- yaml_obj: A ruamel.yaml YAML instance for dumping.
165-
- output_dir: The directory where the sublock file should be written.
162+
feature_name
163+
The name of the feature (derived from the parent folder's stem).
164+
global_lock_data
165+
The global lock file data as a dict.
166+
yaml_obj
167+
A ruamel.yaml YAML instance for dumping.
168+
output_dir
169+
The directory where the sublock file should be written.
166170
167171
Returns
168172
-------
@@ -178,32 +182,33 @@ def _generate_sub_lock_file(
178182
envs = global_lock_data.get("environments", {})
179183
env_data = envs.get(feature_name)
180184
if env_data is None:
181-
raise ValueError(f"Feature '{feature_name}' not found in the global lock file.")
185+
msg = f"Feature '{feature_name}' not found in the global lock file."
186+
raise ValueError(msg)
182187

183-
# Create a new lock dictionary with version and a single environment renamed "default".
188+
# Create a new lock dictionary with version and a single env renamed "default".
184189
new_lock = {
185190
"version": global_lock_data.get("version"),
186191
"environments": {"default": env_data},
187192
}
188193

189-
# Collect all URLs from the environments package list.
194+
# Collect all URLs from the environment's package list.
190195
used_urls = set()
191196
# The environment data is expected to have a "packages" key mapping each platform
192197
# to a list of package entry dicts.
193198
env_packages = env_data.get("packages", {})
194-
for platform, pkg_list in env_packages.items():
199+
for pkg_list in env_packages.values():
195200
for pkg_entry in pkg_list:
196201
# Assume each pkg_entry is a dict with one key: either "conda" or "pypi"
197-
for _, url in pkg_entry.items():
202+
for url in pkg_entry.values():
198203
used_urls.add(url)
199204

200-
# Filter the global packages list to include only those entries used in this environment.
205+
# Filter the global packages list to include only those entries used in this env.
201206
global_packages = global_lock_data.get("packages", [])
202-
filtered_packages = []
203-
for pkg in global_packages:
204-
# Check if either the value under "conda" or "pypi" is in used_urls.
205-
if (pkg.get("conda") in used_urls) or (pkg.get("pypi") in used_urls):
206-
filtered_packages.append(pkg)
207+
filtered_packages = [
208+
pkg
209+
for pkg in global_packages
210+
if (pkg.get("conda") in used_urls) or (pkg.get("pypi") in used_urls)
211+
]
207212
new_lock["packages"] = filtered_packages
208213

209214
# Write the new lock file into output_dir as "pixi.lock"
@@ -219,9 +224,7 @@ def pixi_lock_command(
219224
depth: int,
220225
directory: Path,
221226
files: list[Path] | None,
222-
platforms: list[
223-
any
224-
], # Platform type (import from unidep.platform_definitions if needed)
227+
platforms: list[Platform],
225228
verbose: bool,
226229
only_global: bool,
227230
ignore_pins: list[str],
@@ -234,7 +237,7 @@ def pixi_lock_command(
234237
This command first creates a global lock file (using _pixi_lock_global).
235238
Then, if neither only_global is True nor specific files were passed, it scans
236239
for requirements files in subdirectories. For each such file, it derives a
237-
feature name from the parent directorys stem and generates a sub-lock file
240+
feature name from the parent directory's stem and generates a sub-lock file
238241
that contains a single environment called "default" built from the corresponding
239242
environment in the global lock file.
240243
"""
@@ -257,7 +260,7 @@ def pixi_lock_command(
257260
skip_dependencies=skip_dependencies,
258261
extra_flags=extra_flags,
259262
)
260-
# If only_global is True or specific files were provided, do not generate sublock files.
263+
# If only_global or specific files were provided, do not generate sublock files.
261264
if only_global or files:
262265
return
263266

@@ -278,20 +281,15 @@ def pixi_lock_command(
278281
feature_name = req_file.resolve().parent.stem
279282
if verbose:
280283
print(
281-
f"🔍 Processing sublock for feature '{feature_name}' from file: {req_file}",
282-
)
283-
try:
284-
sublock_file = _generate_sub_lock_file(
285-
feature_name=feature_name,
286-
global_lock_data=global_lock_data,
287-
yaml_obj=yaml_obj,
288-
output_dir=req_file.parent,
289-
)
290-
except Exception as e: # noqa: BLE001
291-
print(
292-
f"⚠️ Error generating sublock for feature '{feature_name}' from {req_file}: {e}",
284+
f"🔍 Processing sublock for feature '{feature_name}' from file: {req_file}", # noqa: E501,
293285
)
294-
continue
286+
sublock_file = _generate_sub_lock_file(
287+
feature_name=feature_name,
288+
global_lock_data=global_lock_data,
289+
yaml_obj=yaml_obj,
290+
output_dir=req_file.parent,
291+
)
292+
295293
print(f"📝 Generated sublock file for '{req_file}': {sublock_file}")
296294
sub_lock_files.append(sublock_file)
297295

0 commit comments

Comments
 (0)