resutil 0.1.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ name: Publish Python Package
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*" # タグが v で始まる場合にトリガー
7
+
8
+ jobs:
9
+ build-and-deploy:
10
+ runs-on: ubuntu-22.04
11
+
12
+ steps:
13
+ - name: Check out code
14
+ uses: actions/checkout@v5
15
+
16
+ - name: Set up uv
17
+ uses: astral-sh/setup-uv@v7
18
+
19
+ - name: Build (wheel and sdist)
20
+ run: uv build --no-sources
21
+
22
+ - name: Save build artifacts
23
+ uses: actions/upload-artifact@v4
24
+ with:
25
+ name: dist
26
+ path: dist/*
27
+
28
+ - name: Publish to PyPI
29
+ env:
30
+ TWINE_USERNAME: __token__
31
+ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
32
+ run: |
33
+ uvx --from twine==6.2.0 twine upload --skip-existing --non-interactive dist/*
@@ -0,0 +1,164 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ key*.json
163
+
164
+ resutil-conf*.yaml
@@ -0,0 +1 @@
1
+ 3.9.18
@@ -0,0 +1,24 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Python Debugger: Current File",
9
+ "type": "debugpy",
10
+ "request": "launch",
11
+ "program": "${file}",
12
+ "console": "integratedTerminal"
13
+ },
14
+ {
15
+ "name": "Debug CLI",
16
+ "type": "debugpy",
17
+ "request": "launch",
18
+ "module": "resutil.cli",
19
+ "args": [
20
+ "push", "-A",
21
+ ],
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "python.testing.pytestArgs": [
3
+ "tests"
4
+ ],
5
+ "python.testing.unittestEnabled": false,
6
+ "python.testing.pytestEnabled": true
7
+ }
resutil-0.1.19/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 nobkat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,300 @@
1
+ Metadata-Version: 2.4
2
+ Name: resutil
3
+ Version: 0.1.19
4
+ Summary: Resutil is a utility to manage experimental result data obtained from Python projects. It also manages dependency such as codes and input data with result data. Data is synced to the cloud for team sharing and collaboration.
5
+ Project-URL: Homepage, https://github.com/KatayamaLab/resutil
6
+ Project-URL: Issues, https://github.com/KatayamaLab/resutil/issues
7
+ Author-email: nobkat <katayama@rs.tus.ac.jp>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2024 nobkat
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Requires-Python: >=3.8
31
+ Requires-Dist: gitpython>=3.1.0
32
+ Requires-Dist: google-api-python-client>=2.133.0
33
+ Requires-Dist: google-auth-httplib2>=0.2.0
34
+ Requires-Dist: google-auth-oauthlib>=1.2.0
35
+ Requires-Dist: google-auth>=2.30.0
36
+ Requires-Dist: google-cloud-storage>=2.17.0
37
+ Requires-Dist: prompt-toolkit>=3.0.47
38
+ Requires-Dist: pytest-mock>=3.14.0
39
+ Requires-Dist: pyyaml>=6.0.0
40
+ Requires-Dist: rich>=13.7.0
41
+ Description-Content-Type: text/markdown
42
+
43
+ # Resutil
44
+ Japanese readme is [here](https://github.com/KatayamaLab/resutil/blob/main/README.ja.md)
45
+
46
+ ## What is Resutil
47
+
48
+ **Resutil** is a utility to manage experimental result data obtained from Python projects. It also manages dependency such as codes and input data with result data. Data is synced to Google Cloud Storage (or Google Drive) for team sharing and collaboration.
49
+
50
+ ## Why choose Resutil?
51
+
52
+ - **Simple**: Easy to install and can be quickly integrated into your project.
53
+ - **High Reproducibility**: Tracks programs, input data, and experimental results.
54
+ - **Open-source and free**: Join development to future release of Resutil.
55
+
56
+
57
+ ## Features
58
+
59
+ - Sync experimental data saved in a specific directory to Google Cloud Storage (default) or Google Drive after the program execution finished.
60
+ - Save information necessary to reproduce the experiment in a YAML file.
61
+ - Execution command
62
+ - Input files given as arguments (only files within folders managed by resutil)
63
+ - Git commit hash
64
+ - Uncommitted files
65
+ - Upload experimental data that hasn’t been uploaded yet.
66
+ - Download experimental data from the cloud using commands.
67
+ - Automatically download dependencies that do not existing at run time.
68
+
69
+ ## Installation
70
+
71
+ Open terminal and run
72
+
73
+ ```bash
74
+ pip install resutil
75
+ ```
76
+
77
+ Prepare a Google Cloud service account key JSON for Cloud Storage (downloaded later in the setup steps) and save it as `key.json` in your project root. A typical key file looks like:
78
+
79
+ ```json
80
+ {
81
+ "type": "service_account",
82
+ "project_id": "your-gcp-project",
83
+ "private_key_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
84
+ "private_key": "-----BEGIN PRIVATE KEY-----\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n-----END PRIVATE KEY-----\n",
85
+ "client_email": "resutil-bot@your-gcp-project.iam.gserviceaccount.com",
86
+ "client_id": "123456789012345678901",
87
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
88
+ "token_uri": "https://oauth2.googleapis.com/token"
89
+ }
90
+ ```
91
+
92
+ Initialize resutil
93
+
94
+ ```bash
95
+ $ cd your-project-root-directory
96
+ $ resutil init
97
+ Input project name (resutil): MyProj
98
+ Input directory name to store results (results): results
99
+ Do you want to add .gitignore to results? (Y/n): Y
100
+ Input storage_type (gcs/gdrive): gcs
101
+ Input key file_path (key.json): key.json
102
+ Do you want to add key.json to .gitignore? (Y/n): Y
103
+ Input bucket name: resutil
104
+ ✅ Initialized.
105
+ ```
106
+
107
+ The bucket name is your Cloud Storage bucket, and `resutil-conf.yaml` will be created with this configuration.
108
+
109
+ Modify main function in your project like:
110
+
111
+ ```python
112
+
113
+ # Import resutil
114
+ import resutil
115
+
116
+ # Add decorator before the main function
117
+ @resutil.main()
118
+ def main_func(params):
119
+ # A directory is automatically created, and its path is stored in params.ex_dir
120
+ ex_dir = params.ex_dir
121
+
122
+ # Execute the program HERE🚀
123
+ # Resutil will handle the rest
124
+
125
+ if __name__ == "__main__":
126
+ main_func()
127
+ ```
128
+
129
+
130
+ ## Usage
131
+
132
+ Run the program integrated with Resutil. You will first be prompted for a comment, and then an experiment result directory will be automatically created. This directory will include a name composed of a sequential alphabet, date, time, and your comment. The directory is then zipped and uploaded to the specified cloud storage after the program finishes.
133
+
134
+ ```bash
135
+ $ python sample.py
136
+
137
+ ✨ Running your code with Resutil
138
+
139
+ 📦 Connected to Google Cloud Storage
140
+ 📁 Bucket name: resutil
141
+ 📁 Project dir: your_project
142
+
143
+ 📝 Input comment for this experiment (press [tab] key for completion): nice-comment
144
+
145
+ 🔍 Unstaged files will be stored in the result dir:
146
+ - README.ja.md
147
+ - README.md
148
+ 🚀 Running the main function...
149
+
150
+ ### Your code's output
151
+
152
+ 🗂️ Uploading: aapfup_20240704T191555_nice-comment
153
+ ℹ️ There are 9 other experiment directories that have not been uploaded.
154
+ ✅ Done
155
+ ```
156
+
157
+ ## How to setup cloud storage for Resutil
158
+
159
+ Resutil supports Google Cloud Storage (default) and Google Drive. Below are the steps for each.
160
+
161
+ ### Google Cloud Storage (recommended)
162
+
163
+ 1. **Create a GCP project (if needed)**: In the [Google Cloud Console](https://console.cloud.google.com/), create or reuse a project.
164
+ 2. **Enable Cloud Storage API**: Open [API Library](https://console.cloud.google.com/apis/library), search for “Cloud Storage”, and enable it.
165
+ 3. **Create a bucket**: Go to [Cloud Storage Browser](https://console.cloud.google.com/storage/browser), click **Create Bucket**, and set a name (e.g., `resutil`) and location/class.
166
+ 4. **Create a service account**: In [IAM & Admin → Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts), click **Create Service Account** and name it (e.g., `resutil-bot`).
167
+ 5. **Grant permissions**: Give the service account the `Storage Object Admin` (or at least `Storage Object User` + `Storage Legacy Bucket Reader`) role for the bucket so it can read/write objects.
168
+ 6. **Create and download a key**: On the service account page, open **Keys** → **Add Key** → **Create new key** → choose **JSON**, then download `key.json` and place it in your project root (add to `.gitignore`).
169
+ 7. **Run `resutil init`**: Choose `gcs`, enter the path to `key.json`, and the bucket name you created.
170
+
171
+ ### Google Drive
172
+
173
+ 1. Create a folder in [Google Drive](https://drive.google.com/) and note the folder ID (the part after `folders/` in the URL).
174
+ 2. In Google Cloud Console, create/reuse a project and a service account; download a JSON key.
175
+ 3. Enable **Google Drive API** for the project.
176
+ 4. Share the Drive folder with the service account email from the JSON key, giving `Editor` access.
177
+ 5. Run `resutil init`, choose `gdrive`, set `key.json`, and provide the base folder ID.
178
+
179
+ ## Commands
180
+
181
+ ### `resutil init`
182
+
183
+ `resutil init` creates `resutil-conf.yaml` in your project folder such as:
184
+
185
+ ```yaml
186
+ project_name: MyProj
187
+ results_dir: results/
188
+ storage_type: gcs
189
+ storage_config:
190
+ backet_name: resutil # bucket name
191
+ key_file_path: key.json
192
+ ```
193
+
194
+ ### `resutil push`
195
+
196
+ The `resutil push` command is used to upload experimental data to the cloud that does not exist in the cloud result directory.
197
+
198
+ `resutil push [exp_name]` uploads experiment a specific directory to the cloud. Depending directorys included in `exp-config.yaml` are automtically uploaded. `--no-dependency` option restrain automatic dependency upload.
199
+
200
+ `resutil pull` will upload all experimental data to the cloud.
201
+
202
+ This is useful for keeping your local data up-to-date with the data stored in the cloud, especially when multiple people are working on the same project and updating the experimental data.
203
+
204
+ ### `resutil pull`
205
+
206
+ The `resutil pull` command is used to download a specific experimental data from the cloud that does not exist in the local result directory.
207
+
208
+ `resutil pull [exp_name]` downloads experiment directory from cloud. Depending directorys included in `exp-config.yaml` are automtically downlowded. `--no-dependency` option restrain automatic dependency download.
209
+
210
+ `resutil pull` will download all experimental data from the cloud that is not currently in your local result directory.
211
+
212
+ This is useful for keeping your local data up-to-date with the data stored in the cloud, especially when multiple people are working on the same project and updating the experimental data.
213
+
214
+ ### `resutil add`
215
+
216
+ The `resutil add` command is used to add an experiment directory without executing any code.
217
+
218
+ You can use it as follows: `resutil add [comment] -d [DEPENDENCY1] [DEPENDENCY2]...`. This command adds an experiment directory named "comment" and sets its dependencies. The dependencies are other experiments that this experiment depends on.
219
+
220
+ For example, if you have two experiments `exp1` and `exp2` and a new experiment depends on them, you can add the new experiment with the following command: `resutil add "new experiment" -d exp1 exp2`. This will create a new experiment directory named "new experiment" and set `exp1` and `exp2` as its dependencies.
221
+
222
+ ### `resutil list`
223
+
224
+ The `resutil list` command list experiments in the cloud storage.
225
+
226
+ ### `resutil rm`
227
+
228
+ The `resutil rm` command removes experiments. You can use it as follows: resutil `resutil rm [-l] [-r] EXPERIMENT1 [EXPERIMENT2]...`. `--local` or `-l` option removes only local experiment directory, whereas `--remote` or `-r` option for experiment data in cloud. Specifying neither options removes both experiments.
229
+
230
+ ### `resutil comment` **EXPERIMENTAL**
231
+
232
+ `resutil comment [EXPERIMENT] [COMMENT]` add or modify a comment following timestamp in the experiment name. Both local and cloud experiment name will change if existing. It should be noted that Resutil regards a differnt experimental name as a different experiment, and this does not affect the name of the same experiment other users have already pull.
233
+
234
+
235
+ ## Environment Valuable
236
+
237
+ When running code that integrates Resutil, you can use the following environment valuables:
238
+
239
+ `RESUTIL_COMMENT` Specifies a comment required at the start of execution. This prevents the need to prompt for a comment during execution.
240
+
241
+ `RESUTIL_NO_INTERACTIVE` Enables non-interactive mode. This prevents any user prompts during execution. This is useful when running as a batch job. If `RESUTIL_COMMENT` is not specified, no comment will be added to the experiment directory.
242
+
243
+ `RESUTIIL_REMOTE` Restrains from uploading results to the cloud storage.
244
+
245
+ `RESUTIL_DEBUG` Enables debug mode where a temporary directory is used as experiment directory. The temporary directory will not be unloaded to the cloud storage.
246
+
247
+ ## Saving checkpoint
248
+
249
+ For long-running executions, call `param.save_checkpoint()` to temporarily upload the data in the experiment directory.
250
+
251
+ ## Directory structure in the cloud storage
252
+
253
+ ```plain text
254
+ <bucket root>
255
+ ├── MyProj # Project directory
256
+ │ ├── aakuqj_20240511T174522_ex1.zip # zip file of Experiment directory
257
+ │ │ ├── resutil-exp.yaml # Experiment information
258
+ │ │ └── data.txt # Data (example)
259
+ │ ├── aamxrp_20240606T135747_ex2.zip
260
+ │ │ ├── resutil-exp.yaml
261
+ │ │ ├── data.txt
262
+ │ │ └── uncommited_files # Uncommitted files
263
+ │ │ └── main.py
264
+ │ ...
265
+
266
+ ├── OtherProj
267
+
268
+ ...
269
+ ```
270
+
271
+ Experiment directories are formatted as `xxxxxx_yyyymmddTHHMMSS_comment`, where xxxxxx is timestamped for easy ordering and tab completion in shells.
272
+
273
+ ## resutil-exp.yaml [WIP]
274
+
275
+ Each experiment directory has `resutil-exp.yaml`, which contains information to reproduce experimental results.
276
+
277
+ ``` yaml
278
+ cmd: Execution command
279
+ params: Options at runtime
280
+ hoo: xxx
281
+ bar: 123
282
+ dependency: Dependencies (automatically extracted from directories in the command)
283
+ - ex1
284
+ - ex2
285
+ ```
286
+
287
+ ## how to publish
288
+
289
+ 1. Change version number of `pyproject.toml`
290
+ 2. merge branch to `main`
291
+ 3. Add v*.*.* tag will automatically deploy to PyPI
292
+ 4. Add a [release note](https://github.com/KatayamaLab/resutil/releases) to GitHub such as:
293
+ ```
294
+ ## New Features
295
+ - Add `--resutil_debug` and `--resutil_no_remote` options for trial-and-error phase
296
+ - `-A` or `--all` options can be omitted for `resutil push/pull` commands
297
+
298
+ ## Bug Fixed
299
+ - Fix a bug resuitl does not works properly when git is not initialized
300
+ ```