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

upload_data_files_to_figshare.py add missing figshare.publish_article() #237

Merged
merged 4 commits into from
Mar 26, 2025
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
18 changes: 17 additions & 1 deletion scripts/upload_data_files_to_figshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ def main(
article will be created.
pyproject (dict[str, Any]): Dictionary containing the project metadata.
max_file_size (int): Maximum file size in bytes to be uploaded automatically.
files (list[DataFiles] | None): List of DataFiles to upload.
files (list[DataFiles] | None): Which attributes of DataFiles to upload.
Defaults to all.
"""
article_is_new = False
if article_id is not None:
# Check if article exists and is accessible
if figshare.article_exists(article_id):
Expand Down Expand Up @@ -71,10 +73,12 @@ def main(

if article_id is None:
article_id = figshare.create_article(metadata)
article_is_new = True
print(
f"\n⚠️ Created new Figshare article with {article_id=}"
f"\nUpdate FIGSHARE_ARTICLE_ID in {__file__} with this ID!"
)
article_url = f"{figshare.ARTICLE_URL_PREFIX}/{article_id}"

try:
# Load existing YAML data if available
Expand Down Expand Up @@ -158,6 +162,18 @@ def main(
print("\nUpdated files:")
for idx, (data_file, url) in enumerate(updated_files.items(), start=1):
print(f"{idx}. {data_file}: {url}")

# Publish the article if any new files were added and it's not newly created
if article_is_new:
print(
"\n⚠️ Article was newly created. Please review it at "
f"{article_url} before publishing manually."
)
else:
print(
f"\nFiles were added or updated. Publishing article {article_url}"
)
figshare.publish_article(article_id)
else:
print("\nNo files were added or updated.")

Expand Down
14 changes: 11 additions & 3 deletions scripts/upload_model_preds_to_figshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def update_one_modeling_task_article(
) -> None:
"""Update or create a Figshare article for a modeling task."""
article_id = figshare.ARTICLE_IDS[f"model_preds_{task}"]
article_is_new = False

if article_id is not None:
# Check if article exists and is accessible
Expand All @@ -166,6 +167,7 @@ def update_one_modeling_task_article(
else:
metadata = get_article_metadata(task)
article_id = figshare.create_article(metadata)
article_is_new = True
print(
f"\n⚠️ Created new Figshare article for {task=} with {article_id=}"
f"\nUpdate figshare.ARTICLE_IDS with this ID!"
Expand Down Expand Up @@ -335,10 +337,16 @@ def find_file_keys(data: dict[str, Any], prefix: str = "") -> dict[str, str]:
):
print(f"{idx}. {model.name} {filename}: {url}")

# Publish the article if any new files were added and it's not a dry run
if (new_files or updated_files) and not dry_run:
print("\nNew or updated files were added. Publishing the article...")
# Publish the article if any new files were added, it's not a dry run,
# and the article wasn't newly created
if (new_files or updated_files) and not dry_run and not article_is_new:
print(f"\nFiles were added or updated. Publishing article {article_url}")
figshare.publish_article(article_id)
elif article_is_new:
print(
"\n⚠️ Article was newly created. Please review it at "
f"{article_url} before publishing manually."
)
else:
print("\nNo files were added or updated.")

Expand Down
30 changes: 15 additions & 15 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
},
"devDependencies": {
"@rollup/plugin-yaml": "^4.1.2",
"@stylistic/eslint-plugin": "^3.1.0",
"@stylistic/eslint-plugin": "^4.2.0",
"@sveltejs/adapter-static": "^3.0.8",
"@sveltejs/kit": "^2.17.2",
"@sveltejs/vite-plugin-svelte": "^4.0.3",
"@sveltejs/kit": "^2.20.2",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"d3-array": "^3.2.4",
"d3-scale": "^4.0.2",
"d3-scale-chromatic": "^3.1.0",
"elementari": "^0.2.7",
"eslint": "^9.20.1",
"eslint-plugin-svelte": "^2.46.1",
"hastscript": "^9.0.0",
"elementari": "^0.3.0",
"eslint": "^9.23.0",
"eslint-plugin-svelte": "^3.3.3",
"hastscript": "^9.0.1",
"iconify-icon": "^2.3.0",
"js-yaml": "^4.1.0",
"jsdom": "^26.0.0",
"json-schema-to-typescript": "^15.0.4",
"katex": "^0.16.21",
"mdsvex": "^0.12.3",
"prettier": "^3.5.1",
"prettier": "^3.5.3",
"prettier-plugin-svelte": "^3.3.3",
"rehype-autolink-headings": "^7.1.0",
"rehype-katex-svelte": "^1.2.0",
Expand All @@ -45,19 +45,19 @@
"remark-math": "6.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.1",
"svelte": "^5.20.1",
"svelte-check": "^4.1.4",
"svelte": "^5.25.3",
"svelte-check": "^4.1.5",
"svelte-multiselect": "11.0.0-rc.1",
"svelte-preprocess": "^6.0.3",
"svelte-toc": "^0.5.9",
"svelte-zoo": "^0.4.17",
"svelte2tsx": "^0.7.34",
"svelte2tsx": "^0.7.35",
"tslib": "^2.8.1",
"typescript": "5.7.3",
"typescript-eslint": "^8.24.1",
"typescript": "5.8.2",
"typescript-eslint": "^8.28.0",
"unified": "^11.0.5",
"vite": "^5.4.11",
"vitest": "^3.0.5"
"vite": "^6.2.3",
"vitest": "^3.0.9"
},
"prettier": {
"semi": false,
Expand Down

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions site/src/lib/MetricScatter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
</script>

<ScatterPlot
{x}
{y}
series={[{ x, y }]}
x_format="%b %y"
{y_label}
bind:tooltip_point
Expand Down
6 changes: 3 additions & 3 deletions site/src/lib/ModelCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</span>
{/each}
</nav>
<p>
<section class="metadata">
<span title="Date added">
<iconify-icon icon="ion:ios-calendar" inline></iconify-icon>
Added {model.date_added}
Expand Down Expand Up @@ -135,7 +135,7 @@
{/each}
</span>
{/if}
</p>
</section>
{#if show_details}
<div transition:fade|fly={{ duration: 200 }}>
<section transition:slide={{ duration: 200 }}>
Expand Down Expand Up @@ -244,7 +244,7 @@
gap: 6pt;
place-items: center;
}
p {
section.metadata {
display: grid;
gap: 5pt;
grid-template-columns: 1fr 1fr;
Expand Down
12 changes: 6 additions & 6 deletions site/src/lib/Nav.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<script lang="ts">
import { page } from '$app/stores'
import { page } from '$app/state'

interface Props {
routes: (string | [string, string])[];
style?: string | null;
routes: (string | [string, string])[]
style?: string | null
}

let { routes, style = null }: Props = $props();
let { routes, style = null }: Props = $props()

let is_current = $derived((path: string) => {
if (path === $page.url.pathname) return `page`
if (path !== `/` && $page.url.pathname.includes(path)) return `page`
if (path === page.url.pathname) return `page`
if (path !== `/` && page.url.pathname.includes(path)) return `page`
return undefined
})
</script>
Expand Down
18 changes: 9 additions & 9 deletions site/src/lib/PtableHeatmap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import type { Snapshot } from './$types'

interface Props {
heatmap_values: Record<string, number>;
color_scale?: string;
active_element: ChemicalElement;
log?: boolean; // log color scale
color_bar_props?: ComponentProps<ColorBar>;
heatmap_values: Record<string, number>
color_scale?: string
active_element: ChemicalElement | null
log?: boolean // log color scale
color_bar_props?: ComponentProps<typeof ColorBar>
}

let {
heatmap_values,
color_scale = $bindable(`Viridis`),
active_element = $bindable(),
active_element = $bindable(null),
log = $bindable(false),
color_bar_props = {}
}: Props = $props();
color_bar_props = {},
}: Props = $props()

export const snapshot: Snapshot = {
capture: () => ({ color_scale, log }),
Expand All @@ -35,7 +35,7 @@
show_photo={false}
>
{#snippet inset()}
<TableInset >
<TableInset>
<label for="log">Log color scale<Toggle id="log" bind:checked={log} /></label>
<PtableInset element={active_element} elem_counts={heatmap_values} />
<ColorBar
Expand Down
8 changes: 4 additions & 4 deletions site/src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<script lang="ts">
import { page } from '$app/stores'
import { page } from '$app/state'
import { homepage, name } from '$site/package.json'
import 'iconify-icon'

let online: boolean = $state(true)
</script>

<svelte:head>
<title>Error {$page.status} &bull; {name}</title>
<title>Error {page.status} &bull; {name}</title>
</svelte:head>

<svelte:window bind:online />

<div>
<h1>Error {String($page.status).replace(`0`, `😵`)}: {$page.error?.message}</h1>
{#if $page.status >= 500}
<h1>Error {String(page.status).replace(`0`, `😵`)}: {page.error?.message}</h1>
{#if page.status >= 500}
<p>
If page reloading doesn't help, please raise an issue on
<a href="{homepage}/issues" target="_blank" rel="noreferrer">GitHub</a>. Thanks! 🙏
Expand Down
30 changes: 8 additions & 22 deletions site/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<script lang="ts">
import { afterNavigate, goto } from '$app/navigation'
import { page } from '$app/stores'
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { Footer, Nav } from '$lib'
import { repository } from '$site/package.json'
import type { Snippet } from 'svelte'
import { type Snippet } from 'svelte'
import { CmdPalette } from 'svelte-multiselect'
import Toc from 'svelte-toc'
import { CopyButton, GitHubCorner } from 'svelte-zoo'
import { GitHubCorner } from 'svelte-zoo'
import '../app.css'

interface Props {
children?: Snippet
}

let { children }: Props = $props()

const routes = Object.keys(import.meta.glob(`./*/+page.{svelte,md}`)).map(
(filename) => `/` + filename.split(`/`)[1],
)

let url = $derived($page.url.pathname)
let url = $derived(page.url.pathname)
let headingSelector = $derived(
`main :is(${{ '/api': `h1, ` }[url] ?? ``}h2, h3, h4):not(.toc-exclude)`,
)
Expand Down Expand Up @@ -50,26 +49,13 @@
return { label: route, action: () => goto(route) }
},
)
afterNavigate(({ to }) => {
if (to?.route.id == `/models`) {
$effect.pre(() => {
if (page.url.pathname == `/models`) {
document.documentElement.style.setProperty(`--main-max-width`, `90em`)
} else {
document.documentElement.style.setProperty(`--main-max-width`, `50em`)
}

for (const node of document.querySelectorAll(`pre > code`)) {
// skip if <pre> already contains a button (presumably for copy)
const pre = node.parentElement
if (!pre || pre.querySelector(`button`)) continue

new CopyButton({
target: pre,
props: {
content: node.textContent ?? ``,
style: `position: absolute; top: 1ex; right: 1ex;`,
},
})
}
// TODO restore svelte-zoo CopyButton to code blocks
})
</script>

Expand Down
11 changes: 5 additions & 6 deletions site/src/routes/data/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

const elem_counts = import.meta.glob(
`./*-element-counts-by-{occurrence,composition}*.json`,
{
eager: true,
import: `default`,
},
{ eager: true, import: `default` },
)

let log = $state(false) // log color scale
Expand Down Expand Up @@ -109,8 +106,10 @@

{#snippet spacegroup_sunbursts()}
{#if browser}
<SpacegroupSunburstMp />
<SpacegroupSunburstWbm />
<div style="display: flex; gap: 2em; place-content: center;">
<SpacegroupSunburstMp />
<SpacegroupSunburstWbm />
</div>
{/if}
{/snippet}
</DataReadme>
Expand Down
15 changes: 9 additions & 6 deletions site/src/routes/data/mptrj/MPtrjElemCountsPtable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
interface Props extends ComponentProps<typeof PtableHeatmap> {
count_mode?: string
}

let { count_mode = `occurrence`, ...rest }: Props = $props()

const elem_counts = import.meta.glob(`../mp-trj-element-counts-by-*.json`, {
eager: true,
import: `default`,
})
}) as Record<string, Record<string, number>>

let mp_trj_elem_counts = elem_counts[`../mp-trj-element-counts-by-${count_mode}.json`]

let mp_trj_elem_counts = $derived(
elem_counts[`../mp-trj-element-counts-by-${count_mode}.json`],
)
$effect(() => {
if (!(`mp_trj_json_gz` in data_files)) {
throw `mp_trj_json_gz not found in data-files.yml`
}
})
</script>

<p>
Expand All @@ -25,7 +28,7 @@
</p>

<PtableHeatmap
heatmap_values={mp_trj_elem_counts}
{...rest}
heatmap_values={mp_trj_elem_counts}
color_bar_props={{ label: `MPtrj element counts by ${count_mode}` }}
/>
Loading
Loading