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
11 changes: 11 additions & 0 deletions .github/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## Breaking changes

<!-- the ones of this release, since the one before: replace them for the next one, or remove the section -->

- **The objects of the data model compare by value.** `a == b` is true for two objects of the same class with the same JSON (`serialize()`), also in the lists of the model (`in`, `count`, `remove`). It was true only for the same object: use `is` for that. `MoneroRpcConnection` compares the uri, the username, the password, the proxy uri, the zmq uri and the ssl verify.
- **The objects of the data model are not hashable.** `hash()` of one, putting it in a `set` or using it as a key of a `dict` raises `TypeError`: key them by what identifies them, as the hash of a tx, or by `id()`.
- **The raw RPC responses keep the types of their JSON**, in `send_json_request()` and the other raw requests of `MoneroRpcConnection`. A text stays a `str`, also when it looks like a number or a boolean, a large integer stays an `int` instead of becoming a `float`, `null` is `None`, and an empty list or object stays one.
- **Python 3.10 or later** is required: 3.8 and 3.9 are not supported anymore.
- **The macOS wheels need macOS 15 or later**: there is no wheel for macOS 14.
- **Type annotations:** `MoneroOutput.tx`, `MoneroTransfer.tx` and `MoneroRpcConnection.timeout_ms` can be `None`, and `MoneroTxQuery.include_outputs` is a `bool`: a type checker can report new errors.

## Which file to download

| Platform | File |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!.vscode/launch.json
!.vscode/tasks.json
!.vscode/extensions.json
!.vscode/extensions/
!.vscode/.env
/.env
# made by bin/generate_typings.sh
Expand Down
7 changes: 5 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"github.vscode-github-actions",
"timonwong.shellcheck",
"ryanluker.vscode-coverage-gutters",
"actboy168.tasks",
"ferrierbenjamin.fold-unfold-all-icone"
"ferrierbenjamin.fold-unfold-all-icone",
"compulim.indent4to2",
"kevinrose.vsc-python-indent",
"shardulm94.trailing-spaces",
"tamasfe.even-better-toml"
]
}
64 changes: 64 additions & 0 deletions .vscode/extensions/status-bar-buttons/builds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// The end of the builds of .vscode/tasks.json: a popup with the result and the time of the ones that failed or that were long, and the
// tests of the Testing panel read again after a build of the module, which they can not import while it is linked.

const vscode = require('vscode');

const BUILD = /^build: /;
// the build of the module that the tests import
const MODULE = 'build: monero-python';
// a shorter build that succeeds shows no popup, as the ones before each debug session
const LONG_MS = 30000;

function formatTime(milliseconds) {
const seconds = Math.round(milliseconds / 1000);
return seconds < 60 ? `${seconds} s` : `${Math.floor(seconds / 60)} min ${seconds % 60} s`;
}

function activate(context) {
// when each build started, by the name of its task
const starts = new Map();

function end(name, exitCode) {
const start = starts.get(name);
starts.delete(name);
// no exit code: the task was stopped
if (exitCode === undefined) {
return;
}
// not known for a build that started before a reload of the window
const time = start === undefined ? undefined : Date.now() - start;
if (exitCode !== 0) {
const after = time === undefined ? '' : ` after ${formatTime(time)}`;
vscode.window.showErrorMessage(`${name} failed${after}`, 'Show Terminal', 'Show Problems').then(choice => {
if (choice === 'Show Terminal') {
vscode.commands.executeCommand('workbench.action.terminal.focus');
} else if (choice === 'Show Problems') {
vscode.commands.executeCommand('workbench.actions.view.problems');
}
});
return;
}
if (name === MODULE) {
vscode.commands.executeCommand('testing.refreshTests');
}
if (time === undefined || time >= LONG_MS) {
const took = time === undefined ? '' : ` in ${formatTime(time)}`;
vscode.window.showInformationMessage(`${name} succeeded${took}`);
}
}

context.subscriptions.push(
vscode.tasks.onDidStartTask(event => {
if (BUILD.test(event.execution.task.name)) {
starts.set(event.execution.task.name, Date.now());
}
}),
vscode.tasks.onDidEndTaskProcess(event => {
if (BUILD.test(event.execution.task.name)) {
end(event.execution.task.name, event.exitCode);
}
}),
);
}

module.exports = { activate };
21 changes: 21 additions & 0 deletions .vscode/extensions/status-bar-buttons/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// A button of the status bar that can wait for the task of another one.

const vscode = require('vscode');

// the higher the priority, the more to the left
function createButton(context, priority, name) {
const item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, priority);
item.name = name;
context.subscriptions.push(item);

return function show({ text, tooltip, command, waitsFor }) {
item.text = text;
item.tooltip = waitsFor ? `Waits for "${waitsFor}" to end` : tooltip;
// a button that waits is gray, and a click on it does nothing
item.color = waitsFor ? new vscode.ThemeColor('disabledForeground') : undefined;
item.command = waitsFor ? undefined : command;
item.show();
};
}

module.exports = { createButton };
100 changes: 100 additions & 0 deletions .vscode/extensions/status-bar-buttons/docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// The button of the network of the integration tests: "Setup Docker" when it is down, "Stop Docker" when it is up, with a warning icon
// when some of its services do not run. The commands are the ones of the tasks of .vscode/tasks.json, which the button runs.

const childProcess = require('child_process');
const vscode = require('vscode');
const { createButton } = require('./button');
const running = require('./running');

const SETUP = {
task: 'tests: setup docker',
label: 'Setup Docker',
icon: 'play',
tooltip: 'setup docker environment for integration tests',
};
const STOP = {
task: 'tests: stop docker',
label: 'Stop Docker',
icon: 'stop-circle',
tooltip: 'stop the Docker environment for integration tests',
};
const COMMAND = 'moneroPython.runDockerTask';
// the services that the task of the setup starts
const SERVICES = ['node_1', 'node_2', 'xmr_wallet_1', 'xmr_wallet_2', 'xmr_wallet_3'];
// the names of the services that run, one for each line
const PS_ARGS = ['compose', '-f', 'tests/docker-compose.yml', 'ps', '--services', '--status', 'running'];
// between two checks, while the window has the focus. A check is a process that ends on its own: one that waits for the events of docker
// would stay when the extensions of VS Code crash
const CHECK_MS = 5000;
// a check that does not answer is given up
const TIMEOUT_MS = 10000;

function activate(context) {
const cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
const show = createButton(context, 50.3, 'Docker Test Network');
let shown = SETUP;
// the services that run
let services = [];
let checks = 0;
let pending = 0;
let disposed = false;

function render() {
// while one of the two tasks runs, its button stays, with a spinning icon
const busy = [SETUP, STOP].find(button => running.isRunning(button.task));
shown = busy || (services.length > 0 ? STOP : SETUP);
const missing = SERVICES.filter(service => !services.includes(service));
const partial = !busy && shown === STOP && missing.length > 0;
const icon = busy ? 'sync~spin' : partial ? 'warning' : shown.icon;
show({
text: `$(${icon}) ${shown.label}`,
tooltip: partial ? `Not running: ${missing.join(', ')}. Click to ${shown.tooltip}` : shown.tooltip,
command: COMMAND,
waitsFor: busy ? undefined : running.blocker([SETUP.task, STOP.task]),
});
}

function check() {
const current = ++checks;
pending++;
childProcess.execFile('docker', PS_ARGS, { cwd, timeout: TIMEOUT_MS }, (error, stdout) => {
pending--;
// an older check that ends late does not replace the result of a newer one
if (disposed || current !== checks) {
return;
}
// without docker the button is the one of the setup, whose task says what is wrong
services = error ? [] : stdout.split('\n').map(line => line.trim()).filter(Boolean);
render();
});
}

// for the changes made from a terminal
const timer = setInterval(() => {
if (vscode.window.state.focused && pending === 0) {
check();
}
}, CHECK_MS);

running.onChange(render);
context.subscriptions.push(
vscode.commands.registerCommand(COMMAND, () => vscode.commands.executeCommand('workbench.action.tasks.runTask', shown.task)),
vscode.tasks.onDidEndTask(() => check()),
vscode.window.onDidChangeWindowState(state => {
if (state.focused) {
check();
}
}),
{
dispose() {
disposed = true;
clearInterval(timer);
},
},
);

render();
check();
}

module.exports = { activate, SERVICES };
103 changes: 103 additions & 0 deletions .vscode/extensions/status-bar-buttons/docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// The button of the docs: "Build Docs" runs the task "docs: serve" of .vscode/tasks.json, with a spinning icon while the site is
// built and "Stop Docs" once it is served. A click while the task runs stops it. The other buttons wait while the site is built, not
// while it is served.

const net = require('net');
const vscode = require('vscode');
const { createButton } = require('./button');
const running = require('./running');

const TASK = 'docs: serve';
// the address of mkdocs serve, which listens on it only once the site is built
const HOST = '127.0.0.1';
const PORT = 8000;
const URL = `http://${HOST}:${PORT}`;
const COMMAND = 'moneroPython.toggleDocs';
// between two checks of the address while the site is built
const CHECK_MS = 1000;

function activate(context) {
const show = createButton(context, 50.2, 'Docs');
const executions = () => vscode.tasks.taskExecutions.filter(execution => execution.task.name === TASK);
let served = false;
let socket;
let checkTimer;

function render() {
if (!running.isRunning(TASK)) {
show({
text: '$(book) Build Docs',
tooltip: `Build and serve the docs at ${URL}`,
command: COMMAND,
waitsFor: running.blocker([TASK]),
});
} else if (!served) {
show({ text: '$(sync~spin) Building Docs', tooltip: 'Building the docs, click to stop', command: COMMAND });
} else {
const tooltip = new vscode.MarkdownString(`The docs are at [${URL}](${URL}), click to stop`);
show({ text: '$(stop-circle) Stop Docs', tooltip, command: COMMAND });
}
}

function stopChecking() {
clearTimeout(checkTimer);
if (socket) {
socket.removeAllListeners();
// an error of a connection that is given up is of no use
socket.on('error', () => {});
socket.destroy();
socket = undefined;
}
}

// tries to connect to the address until it answers, which is when the build ended
function check() {
socket = net.connect(PORT, HOST);
socket.once('connect', () => {
stopChecking();
served = true;
// which renders the buttons again
running.setIdle(TASK);
});
socket.once('error', () => {
checkTimer = setTimeout(check, CHECK_MS);
});
}

// at the start and at the end of the task
function restart() {
stopChecking();
served = false;
render();
if (running.isRunning(TASK)) {
check();
}
}

running.onChange(render);
context.subscriptions.push(
vscode.commands.registerCommand(COMMAND, () => {
if (running.isRunning(TASK)) {
executions().forEach(execution => execution.terminate());
} else {
vscode.commands.executeCommand('workbench.action.tasks.runTask', TASK);
}
}),
vscode.tasks.onDidStartTask(event => {
if (event.execution.task.name === TASK) {
restart();
}
}),
vscode.tasks.onDidEndTask(event => {
if (event.execution.task.name === TASK) {
restart();
}
}),
{ dispose: stopChecking },
);

// the task may run already, after a reload of the window
restart();
}

module.exports = { activate };
21 changes: 21 additions & 0 deletions .vscode/extensions/status-bar-buttons/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// The buttons of the status bar of the tasks of .vscode/tasks.json, which wait for each other and change with the state of what their
// task starts, the menu of the lint, the popups of the problems that a task found and of the end of the builds, and the refresh of the tests after one.

const builds = require('./builds');
const docker = require('./docker');
const docs = require('./docs');
const lint = require('./lint');
const running = require('./running');
const tasks = require('./tasks');

function activate(context) {
// first: the buttons ask it what runs
running.activate(context);
tasks.activate(context);
docker.activate(context);
docs.activate(context);
lint.activate(context);
builds.activate(context);
}

module.exports = { activate };
Loading
Loading