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

Store the state and database files in ~/.conda-store by default #554

Closed

Conversation

asmeurer
Copy link
Contributor

Still some issues that need to be worked out here. Also will need #549 to be merged and rebased first.

This work is part of #513.

Description

This pull request:

  • a
  • b
  • c

Pull request checklist

  • Did you test this change locally?
  • Did you update the documentaion (if required)?
  • Did you add/update relevant tests for this change (if required)?

Additional information

@costrouc
Copy link
Member

Much saner default considering before how it would just write to your current directory. Agree this is needed.

@asmeurer
Copy link
Contributor Author

Also need to double check that there aren't any places that were relying on the default values without configuring it (e.g., in the Docker setup).

There is currently an issue where it is not able to access the database file
correctly, which I am still figuring out.
@asmeurer asmeurer force-pushed the standalone-state-home-dir branch from 0ade4c6 to fbe6145 Compare August 30, 2023 21:13
@asmeurer asmeurer mentioned this pull request Sep 15, 2023
3 tasks
@netlify
Copy link

netlify bot commented Sep 15, 2023

Deploy Preview for kaleidoscopic-dango-0cf31d ready!

Name Link
🔨 Latest commit 08cc13b
🔍 Latest deploy log https://app.netlify.com/sites/kaleidoscopic-dango-0cf31d/deploys/6528696958777b00087c99b5
😎 Deploy Preview https://deploy-preview-554--kaleidoscopic-dango-0cf31d.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@asmeurer
Copy link
Contributor Author

Hmm, previously I was having issues where the database file was not being initialized properly, but now I'm not. I'm not sure if something else changed in the interim that changed this, or if I'm just not doing the same steps I was before. It would be helpful if someone else can test this (just run conda-store-server --standalone, or alternatively run conda-store-server and conda-store-worker separately, and see if it appears to function and that there aren't any errors printed to the console).

@trallard
Copy link
Collaborator

@nkaretnikov to test

@@ -200,7 +201,7 @@ class CondaStore(LoggingConfigurable):
)

database_url = Unicode(
"sqlite:///conda-store.sqlite",
"sqlite:///" + str(PosixPath.home()) + "/.conda-store/conda-store.sqlite",
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to remove Posix, it doesn't work on Windows:

-        "sqlite:///" + str(PosixPath.home()) + "/.conda-store/conda-store.sqlite",
+        "sqlite:///" + str(Path.home()) + "/.conda-store/conda-store.sqlite",

Tested on Windows: after rebasing on #559 and fixing the Posix thing, the server started (python -m conda_store_server.server) and stored state files in the home dir.
Screen Shot 2023-10-01 at 19 42 39

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested on Linux: works without changes.

% ls -1
conda-store.sqlite
conda-store-state
% pwd
/home/nkaretnikov/.conda-store

Copy link
Contributor

Choose a reason for hiding this comment

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

Verified that this env builds on Linux and is available after restart (with the same state dir):

channels:
- conda-forge
dependencies:
- python
- pip:
  - nothing
- ipykernel
- pytest
- requests
description: ''
name: test-env
prefix: null
variables: null

Server was started via python -m conda_store_server.server --standalone.

Copy link
Contributor Author

@asmeurer asmeurer Oct 2, 2023

Choose a reason for hiding this comment

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

Are you sure about that? PosixPath is used for URLs because URLs always use forward slashes, even on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See for instance 80d9ea8

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure about that? PosixPath is used for URLs because URLs always use forward slashes, even on Windows.

Have you tested on Windows? When I ran it on Windows, it raised an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently on Windows you have to use pathlib.PurePosixPath instead of pathlib.PosixPath

@@ -87,7 +88,7 @@ class CondaStore(LoggingConfigurable):
)

store_directory = Unicode(
"conda-store-state",
str(Path.home() / ".conda-store" / "conda-store-state"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a variable for Path.home() / ".conda-store" and use it everywhere. For example: CONDA_STORE_DIR.

Copy link
Contributor

Choose a reason for hiding this comment

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

The location of CONDA_STORE_DIR needs to be printed when the server is started.

Ideally: you can even print something like "Found existing conda-store.sqlite in <dirname>" or "Creating conda-store.sqlite in <dirname>". Same for the rest of top-level state files/dirs.

Otherwise, we'll run into problems when reproducing issues. People will have no idea that some state was created somewhere. Up until now, it hasn't been a problem because files are more visible in the current project dir, since it's tracked by git.

@@ -179,6 +179,8 @@ def initialize(self, *args, **kwargs):

self.conda_store = CondaStore(parent=self, log=self.log)

self.conda_store.ensure_directories()
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for other reviewers: this runs:

os.makedirs(self.store_directory, exist_ok=True)

because store_directory might not exist.

@@ -24,9 +24,13 @@ def conda_store_config(tmp_path, request):

filename = pathlib.Path(tmp_path) / "database.sqlite"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not essential, but needs ".conda-store" here, to be consistent with how we run this outside of tests.

@asmeurer
Copy link
Contributor Author

asmeurer commented Oct 4, 2023

Adding another note here: I think it would be a good idea to rename ~/.conda-store/conda-store-state to just ~/.conda-store/state, which is not only cleaner and less redundant, but should help with #588 as well.

And use PurePosixPath instead of PosixPath, because PosixPath is not present
on Windows.
@asmeurer
Copy link
Contributor Author

asmeurer commented Oct 6, 2023

Tested this on Windows by manually merged it with #559

@asmeurer asmeurer marked this pull request as ready for review October 12, 2023 21:46
@asmeurer asmeurer changed the title [WIP] Store the state and database files in ~/.conda-store by default Store the state and database files in ~/.conda-store by default Oct 12, 2023
@asmeurer
Copy link
Contributor Author

I've addressed the review comments.

One thing worth being aware of here is that if anyone is running conda-store without configuring database_url or store_directory but just relying on the defaults, their setup will break. All the example configs do configure it, so hopefully that isn't happening.

@nkaretnikov
Copy link
Contributor

One thing worth being aware of here is that if anyone is running conda-store without configuring database_url or store_directory but just relying on the defaults, their setup will break. All the example configs do configure it, so hopefully that isn't happening.

Wait, I think it wasn't an issue before, no? Why is this required now? Like, I'm pretty sure I used to be able to just run with --standalone without passing the config option.

@asmeurer
Copy link
Contributor Author

The point is it will break existing installations if they were relying on the default configuration, because the defaults have changed.

@nkaretnikov
Copy link
Contributor

Ah, OK. How about at least printing an error message and suggesting users move stuff to a new location?
However, since the file names are also different now, it might still be confusing if we just provide written instructions.
Ideally, this would be done automatically if we're confident we don't overwrite user data in home or something like that.

@asmeurer
Copy link
Contributor Author

Hmm, the test failure is because tests conda_store object from the fixture isn't being used for some reason.

@nkaretnikov
Copy link
Contributor

@asmeurer The test failure looks legit. You also need to rebase.

________________ test_conda_store_register_environment_workflow ________________

...

ERROR    celery.app.trace:trace.py:270 Task task_update_storage_metrics[43b3f586-1076-4ec6-8185-6b17c6e0bda6] raised unexpected: FileNotFoundError(2, 'No such file or directory')
Traceback (most recent call last):
  File "/usr/share/miniconda/envs/conda-store-server-dev/lib/python3.10/site-packages/celery/app/trace.py", line 477, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/runner/work/conda-store/conda-store/conda-store-server/conda_store_server/worker/tasks.py", line 75, in task_update_storage_metrics
    conda_store.configuration(db).update_storage_metrics(
  File "/home/runner/work/conda-store/conda-store/conda-store-server/conda_store_server/orm.py", line 663, in update_storage_metrics
    disk_usage = shutil.disk_usage(store_directory)
  File "/usr/share/miniconda/envs/conda-store-server-dev/lib/python3.10/shutil.py", line 1280, in disk_usage
    st = os.statvfs(path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/.conda-store/state'

@nkaretnikov
Copy link
Contributor

Taking over this one. See #639.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done 💪🏾
Development

Successfully merging this pull request may close these issues.

5 participants