Skip to content

Commit 95dc38d

Browse files
authored
Update documentation (#128)
1 parent 6040378 commit 95dc38d

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

crates/pet-python-utils/src/executable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn find_executable(env_path: &Path) -> Option<PathBuf> {
2525
env_path.join("python3.exe"),
2626
]
2727
.into_iter()
28-
.find(|path| path.exists())
28+
.find(|path| path.is_file())
2929
}
3030

3131
#[cfg(unix)]
@@ -37,7 +37,7 @@ pub fn find_executable(env_path: &Path) -> Option<PathBuf> {
3737
env_path.join("python3"),
3838
]
3939
.into_iter()
40-
.find(|path| path.exists())
40+
.find(|path| path.is_file())
4141
}
4242

4343
pub fn find_executables<T: AsRef<Path>>(env_path: T) -> Vec<PathBuf> {

crates/pet/src/jsonrpc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,15 @@ impl RefreshResult {
161161
pub fn handle_refresh(context: Arc<Context>, id: u32, params: Value) {
162162
let params = match params {
163163
Value::Null => json!({}),
164+
Value::Array(_) => json!({}),
164165
_ => params,
165166
};
166-
match serde_json::from_value::<RefreshOptions>(params.clone()) {
167+
match serde_json::from_value::<Option<RefreshOptions>>(params.clone()) {
167168
Ok(refresh_options) => {
169+
let refresh_options = refresh_options.unwrap_or(RefreshOptions {
170+
search_kind: None,
171+
search_paths: None,
172+
});
168173
// Start in a new thread, we can have multiple requests.
169174
thread::spawn(move || {
170175
// Ensure we can have only one refresh at a time.

docs/sample.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ async function configure(connection) {
104104
* Refresh the environment
105105
*
106106
* @param {import("vscode-jsonrpc").MessageConnection} connection
107-
* @param {undefined | 'global' | 'workspace'} searchScope
107+
* @param {undefined | { searchKind?: string } | { searchPaths?: string[] } } search Defaults to searching for all environments on the current machine.
108+
* Have a look at the JSONRPC.md file for more information.
108109
*/
109-
async function refresh(connection, searchScope) {
110+
async function refresh(connection, search) {
110111
environments.length = 0;
111-
const { duration } = await connection.sendRequest("refresh", { searchScope });
112-
const scope = searchScope
113-
? ` (in ${searchScope} scope)`
112+
const { duration } = await connection.sendRequest("refresh", search);
113+
const scope = search
114+
? ` (in ${JSON.stringify(search)})`
114115
: "(in machine scope)";
115116
console.log(
116117
`Found ${environments.length} environments in ${duration}ms ${scope}`
@@ -122,7 +123,7 @@ async function refresh(connection, searchScope) {
122123
*
123124
* @param {import("vscode-jsonrpc").MessageConnection} connection
124125
*/
125-
async function clear(connection, searchScope) {
126+
async function clear(connection) {
126127
await connection.sendRequest("clear");
127128
}
128129

@@ -151,41 +152,30 @@ async function resolve(connection, executable) {
151152
}
152153
}
153154

154-
/**
155-
* Gets all possible information about the Python executable provided.
156-
* This will spawn the Python executable (if not already done in the past).
157-
* This must be used only if some of the information already avaialble is not sufficient.
158-
*
159-
* E.g. if a Python env was discovered and the version information is not know,
160-
* but is requried, then call this method.
161-
* If on the other hand, all of the information is already available, then there's no need to call this method.
162-
* In fact it would be better to avoid calling this method, as it will spawn a new process & consume resouces.
163-
*
164-
* @param {String} searchPath Workspace Directory, directory with environments, Python environment path or python executable.
165-
* @param {import("vscode-jsonrpc").MessageConnection} connection
166-
*/
167-
async function find(connection, searchPath) {
168-
const environments = await connection.sendRequest("find", { searchPath });
169-
console.log(`Found ${environments.length} environments in ${searchPath}`);
170-
}
171-
172155
async function main() {
173156
const connection = await start();
174157

175158
// First request to the server, to configure the server.
176159
await configure(connection);
177160

178161
await refresh(connection);
179-
// Search for environments in the defined workspace folders.
180-
await refresh(connection, "workspace");
181162

182163
// Search for environments in the specified folders.
183164
// This could be a folder thats not part of the workspace and not in any known location
184165
// I.e. it could contain environments that have not been discovered (due to the fact that its not a common/known location).
185-
await find(connection, "/Users/user_name/temp");
166+
await refresh(connection, {
167+
searchPaths: [
168+
"/Users/user_name/temp",
169+
"/Users/user_name/demo/.venv",
170+
"/Users/user_name/demo/.venv/bin/python",
171+
],
172+
});
186173
// Search for environments in the specified python environment directory.
187-
await find(connection, "/Users/user_name/demo/.venv");
188-
await find(connection, "/Users/user_name/demo/.venv/bin");
174+
await refresh(connection, {
175+
searchPaths: ["/Users/user_name/demo/.venv/bin", "/usr/local/bin/python3"],
176+
});
177+
// Search for environments of a particular kind.
178+
await refresh(connection, { searchKind: "Conda" });
189179

190180
// Possible this env was discovered, and the version or prefix information is not known.
191181
await resolve(connection, "/usr/local/bin/python3");

0 commit comments

Comments
 (0)