Skip to content

Commit

Permalink
Fix crash when using conda-pack on environments created with pixi (#305)
Browse files Browse the repository at this point in the history
* Make code more robust to slight difference in conda-meta formats

* add news entry

* Fix pre-commit lint

---------

Co-authored-by: Uwe L. Korn <uwelk@xhochy.com>
  • Loading branch information
melund and xhochy authored Jan 21, 2024
1 parent d3e2f31 commit ed92e48
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
21 changes: 13 additions & 8 deletions conda_pack/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ def load_environment(prefix, on_missing_cache='warn', ignore_editable_packages=F
with open(os.path.join(conda_meta, path)) as fil:
info = json.load(fil)

pkg = info['link']['source']
pkg = info['link']['source'] if info['link'] else ""

if not os.path.exists(pkg):
# Package cache is cleared, set file_mode='unknown' to properly
Expand Down Expand Up @@ -930,12 +930,17 @@ def load_environment(prefix, on_missing_cache='warn', ignore_editable_packages=F
file_mode=None))

# Add remaining conda metadata files
managed.add(os.path.join('conda-meta', 'history'))
files.append(File(os.path.join(conda_meta, 'history'),
os.path.join('conda-meta', 'history'),
is_conda=True,
prefix_placeholder=None,
file_mode=None))
if os.path.exists(os.path.join(conda_meta, "history")):
managed.add(os.path.join("conda-meta", "history"))
files.append(
File(
os.path.join(conda_meta, "history"),
os.path.join("conda-meta", "history"),
is_conda=True,
prefix_placeholder=None,
file_mode=None,
)
)

if missing_files and not ignore_missing_files:
packages = []
Expand Down Expand Up @@ -1019,7 +1024,7 @@ def rewrite_conda_meta(source):
if field in data:
data[field] = ""

if "link" in data and "source" in data["link"]:
if "link" in data and data["link"] and "source" in data["link"]:
data["link"]["source"] = ""

out = json.dumps(data, indent=True, sort_keys=True)
Expand Down
19 changes: 19 additions & 0 deletions news/support-pixi-environments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fix a crash when trying to use conda-pack environments created with [pixi](https://pixi.sh).

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit ed92e48

Please sign in to comment.