Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Refine the constructor of Project to hide repositories #1194

Merged
merged 19 commits into from
Jan 29, 2025

Conversation

thomass-dev
Copy link
Collaborator

@thomass-dev thomass-dev commented Jan 21, 2025

Closes #1160

This PR intends to ease the project API by centralizing all the action in the constructor.

To note:

  • Remove all actions from the CLI except "launch UI", which implicitly create the specified project.
  • Rename the command skore to skore-ui.
  • Release the constraints on project name.
  • Remove all project management scripts and open function in favor of the project class constructor.
  • Create implicitly the project when calling the constructor.
  • Add project clear function to allow user to explicitly clear a project.

# create project

import skore
project = skore.Project("project.skore")
# work on existing project

import skore
project = skore.Project("project.skore", exist_ok=True)
# work on existing project and clear explicitly

import skore
project = skore.Project("project.skore", exist_ok=True)
project.clear()
# work on existing project, but without knowing it

import skore
project = skore.Project("project.skore")

---------------------------------------------------------------------------
FileExistsError                           Traceback (most recent call last)
[...]
FileExistsError: Project 'project.skore' already exists.

@thomass-dev thomass-dev force-pushed the hide-repositories branch 3 times, most recently from 59ce513 to 70b8e12 Compare January 22, 2025 12:53
@thomass-dev thomass-dev force-pushed the hide-repositories branch 3 times, most recently from 7372569 to a10abe5 Compare January 28, 2025 16:28
@thomass-dev thomass-dev marked this pull request as ready for review January 28, 2025 17:03
Copy link
Contributor

github-actions bot commented Jan 28, 2025

Coverage

Coverage Report for backend
FileStmtsMissCoverMissing
venv/lib/python3.12/site-packages/skore
   __init__.py140100% 
   __main__.py880%3–19
   exceptions.py330%4–19
venv/lib/python3.12/site-packages/skore/cli
   __init__.py550%3–8
   cli.py16160%3–59
   color_format.py49490%3–116
venv/lib/python3.12/site-packages/skore/persistence
   __init__.py00100% 
venv/lib/python3.12/site-packages/skore/persistence/item
   __init__.py59491%89, 100–103
   altair_chart_item.py24193%15
   cross_validation_reporter_item.py1091289%28–41, 125–126, 259, 262
   item.py24196%86
   matplotlib_figure_item.py33195%18
   media_item.py240100% 
   numpy_array_item.py29194%16
   pandas_dataframe_item.py31194%14
   pandas_series_item.py31194%14
   pickle_item.py330100% 
   pillow_image_item.py32194%16
   plotly_figure_item.py25193%15
   polars_dataframe_item.py29194%14
   polars_series_item.py24193%14
   primitive_item.py25291%13–15
   sklearn_base_estimator_item.py31194%15
   skrub_table_report_item.py10186%11
venv/lib/python3.12/site-packages/skore/persistence/repository
   __init__.py30100% 
   item_repository.py59591%15–16, 202–203, 226
   view_repository.py19286%9–10
venv/lib/python3.12/site-packages/skore/persistence/storage
   __init__.py40100% 
   abstract_storage.py220100% 
   disk_cache_storage.py33195%44
   in_memory_storage.py200100% 
venv/lib/python3.12/site-packages/skore/persistence/view
   __init__.py20100% 
   view.py50100% 
venv/lib/python3.12/site-packages/skore/project
   __init__.py20100% 
   project.py62199%237
venv/lib/python3.12/site-packages/skore/sklearn
   __init__.py50100% 
   _base.py140497%91, 94, 168–>173, 183–184
   find_ml_task.py45195%71–>87, 80–>87, 86
   types.py20100% 
venv/lib/python3.12/site-packages/skore/sklearn/_cross_validation
   __init__.py60100% 
   metrics_accessor.py1630100% 
   report.py870100% 
venv/lib/python3.12/site-packages/skore/sklearn/_estimator
   __init__.py60100% 
   metrics_accessor.py265497%149–158, 183–>236, 191, 434–>437, 783–>786
   report.py120099%215–>221, 223–>225
   utils.py11110%1–19
venv/lib/python3.12/site-packages/skore/sklearn/_plot
   __init__.py40100% 
   precision_recall_curve.py121198%229–>246, 317
   prediction_error.py970100% 
   roc_curve.py1280100% 
   utils.py880100% 
venv/lib/python3.12/site-packages/skore/sklearn/cross_validation
   __init__.py20100% 
   cross_validation_helpers.py47490%104–>136, 123–126
   cross_validation_reporter.py35195%187
venv/lib/python3.12/site-packages/skore/sklearn/cross_validation/plots
   __init__.py00100% 
   compare_scores_plot.py292416%10, 28–116
   timing_plot.py292417%10, 26–123
venv/lib/python3.12/site-packages/skore/sklearn/train_test_split
   __init__.py00100% 
   train_test_split.py36294%16–17
venv/lib/python3.12/site-packages/skore/sklearn/train_test_split/warning
   __init__.py80100% 
   high_class_imbalance_too_few_examples_warning.py17378%16–18, 80
   high_class_imbalance_warning.py18288%16–18
   random_state_unset_warning.py11187%15
   shuffle_true_warning.py9091%44–>exit
   stratify_is_set_warning.py11187%15
   time_based_column_warning.py22189%17, 69–>exit
   train_test_split_warning.py5180%21
venv/lib/python3.12/site-packages/skore/ui
   __init__.py00100% 
   app.py30771%48–53, 65–67
   dependencies.py40100% 
   launch.py261539%36–57
   project_routes.py620100% 
venv/lib/python3.12/site-packages/skore/utils
   __init__.py60100% 
   _accessor.py70100% 
   _logger.py21484%14–18
   _patch.py11546%19–35
   _progress_bar.py300100% 
   _show_versions.py310100% 
TOTAL269423691% 

Tests Skipped Failures Errors Time
587 3 💤 0 ❌ 0 🔥 2m 51s ⏱️

Copy link
Contributor

github-actions bot commented Jan 28, 2025

Documentation preview @ 435847f

@thomass-dev thomass-dev force-pushed the hide-repositories branch 3 times, most recently from 896f476 to ec80394 Compare January 29, 2025 09:16
@glemaitre
Copy link
Member

I'm almost happy with what I see:

  • I like some simplification here.
  • I don't like that we don't have the open anymore. We should be able to trigger the UI launch on the Python side. Having this in the Project constructor does not make any sense. So we will need a kind of factory. This open will have a symmetry between the CLI and Python. But it is orthogonal with the work here: It only need to create the project and attach the server info to it.

Copy link
Contributor

@MarieS-WiMLDS MarieS-WiMLDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these changes!! It should really make it easier for users to grasp how to create a project.

I have two additional comments:

  • the first one is about the delete function, it looks like a bit a function that would delete the project now. I don't really have an idea how to solve this. A mitigation could be to have a delete_project function (function that i'd like to have anyway, but it's not a great solution to be explicit about the purpose of delete)
  • I disagree with @glemaitre on the fact that the creation function should also open the UI. these are two different things, we should have a python func to launch UI indeed, but it would be dedicated to this and only this.

skore/src/skore/project/project.py Outdated Show resolved Hide resolved
skore/src/skore/project/project.py Show resolved Hide resolved
skore/src/skore/project/project.py Show resolved Hide resolved
skore/src/skore/cli/cli.py Show resolved Hide resolved
@glemaitre glemaitre self-requested a review January 29, 2025 11:12
@glemaitre
Copy link
Member

I disagree with @glemaitre on the fact that the creation function should also open the UI. these are two different things, we should have a python func to launch UI indeed, but it would be dedicated to this and only this.

@MarieS-WiMLDS Let's move the discussion in this #1002 since it will not impact this PR.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the discussion that we had and use if_exist="raise"/"load", I'm find with the current PR.

Copy link
Contributor

@MarieS-WiMLDS MarieS-WiMLDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Great simplification :) !!

@thomass-dev thomass-dev merged commit a8301b8 into main Jan 29, 2025
18 checks passed
@thomass-dev thomass-dev deleted the hide-repositories branch January 29, 2025 16:47
@rouk1
Copy link
Contributor

rouk1 commented Jan 29, 2025

I know I'm late to the show but if_exists default value to raise is very awkward to me. Indeed how do one rerun an cell containing a Project() statement if you don't now that kwarg ? (note that its not discoverable by IDE probably cause we do not have stubs I suppose).

To me reloading an existing project is something more common than creating one.

@glemaitre
Copy link
Member

I know I'm late to the show but if_exists default value to raise is very awkward to me.

Never too late and it was open to debate during the review.

One point that I took from @thomass-dev was that you could implicitly modify the DB, adding new version of items without taking care. And thus I thought that it would easier to go back to a less conservative way, with feedback.

Now, something that I'm figuring out (during my 🏃‍♂️) is that if clear would allow me to clean up for instance a specific run because I mess up, then I would be fine with if_exist="load" because I can easily go back.

@glemaitre
Copy link
Member

Indeed how do one rerun an cell containing a Project() statement if you don't now that kwarg ?

For sure, you error message should mention this kwargs to make you do the right choice (I did not read the updated code however).

@rouk1
Copy link
Contributor

rouk1 commented Jan 29, 2025

Another issue that I have with this PR is that as the project parameter of the create_app factory is no longer optional the server app is no longer easily debuggable.

i.e. when you run it from the command line you can not pass a path hence it crashes when run.

uvicorn  skore.ui.app:create_app --factory --reload --reload-dir skore/src --host 0.0.0.0 --port 22140 --timeout-graceful-shutdown 0 --log-level info
INFO:     Will watch for changes in these directories: ['/Users/rouk1/dev/skore/skore/src']
INFO:     Uvicorn running on http://0.0.0.0:22140 (Press CTRL+C to quit)
INFO:     Started reloader process [19757] using StatReload
ERROR:    Error loading ASGI app factory: create_app() missing 1 required positional argument: 'project'

This how you get to debug the FastAPI app in vscode.

{
  // launch.json
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Run webapp",
      "type": "debugpy",
      "request": "launch",
      "module": "uvicorn",
      "args": [
        "skore.ui.app:create_app",
        "--factory",
        "--reload",
        "--reload-dir",
        "skore/src",
        "--host",
        "0.0.0.0",
        "--port",
        "22140",
        "--timeout-graceful-shutdown",
        "0",
        "--log-level",
        "info"
      ],
      "console": "integratedTerminal",
      "jinja": true,
      "env": {
        "DEBUG": "1",
      }
    }
  ]
}

thomass-dev pushed a commit that referenced this pull request Jan 30, 2025
Follow-up for #1194 

Related to a question from @rouk1
#1194 (comment)

I think that we should improve the error message, whatever the default
value is.
@thomass-dev
Copy link
Collaborator Author

Thanks @rouk1 for your review, i will revert the create_app changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Refine the constructor of Project to be user-friendly
4 participants