Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/_authors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

.. role:: raw-html(raw)
:format: html


.. _Adrin Jalali: https://github.com/adrinjalali

.. _Benjamin Bossan: https://github.com/BenjaminBossan

.. _Merve Noyan: https://github.com/merveenoyan
7 changes: 6 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. include:: _authors.rst

.. _changelog:

skops Changelog
Expand All @@ -10,8 +12,11 @@ skops Changelog
v0.2
----
- Tables, e.g. cross-validation results, can now be added to model cards using
the :meth:`.Card.add_table` method. :pr:`90` by :user:`Benjamin Bossan <BenjaminBossan>`
the :meth:`.Card.add_table` method. :pr:`90` by `Benjamin Bossan`_.
- Add method :meth:`.Card.render` which returns the model card as a string.
:pr:`94` by `Benjamin Bossan`_.
- Make :meth:`skops.hub_utils.init` atomic. Now it doesn't leave a trace on the
filesystem if it fails for some reason. :pr:`60` by `Adrin Jalali`_`

v0.1
----
Expand Down
24 changes: 14 additions & 10 deletions skops/hub_utils/_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,20 @@ def init(
)
dst.mkdir(parents=True, exist_ok=True)

shutil.copy2(src=model, dst=dst)

model_name = Path(model).name
_create_config(
model_path=model_name,
requirements=requirements,
dst=dst,
task=task,
data=data,
)
try:
shutil.copy2(src=model, dst=dst)

model_name = Path(model).name
_create_config(
model_path=model_name,
requirements=requirements,
dst=dst,
task=task,
data=data,
)
except Exception:
shutil.rmtree(dst)
raise


def update_env(
Expand Down
22 changes: 22 additions & 0 deletions skops/hub_utils/tests/test_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,28 @@ def test_create_config_invalid_text_data(temp_path):
)


def test_atomic_init(classifier_pickle, temp_path):
with pytest.raises(ValueError):
# this fails since we're passing an invalid task.
init(
model=classifier_pickle,
requirements=["scikit-learn"],
dst=temp_path,
task="tabular-classification",
data="invalid",
)

# this passes even though the above init has failed once, on the same
# destination path.
init(
model=classifier_pickle,
requirements=["scikit-learn"],
dst=temp_path,
task="tabular-classification",
data=iris.data,
)


def test_init_invalid_task(classifier_pickle, temp_path):
with pytest.raises(
ValueError, match="Task invalid not supported. Supported tasks are"
Expand Down