Skip to content

Commit

Permalink
Merge branch 'master' into gh-3078
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Nov 28, 2024
2 parents 4277d33 + 676079d commit 4bac59b
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const config = {
singleline: { delimiter: 'semi', requireLast: false }
}],
'@stylistic/array-bracket-spacing': ['error', 'always', { singleValue: false }],
'@stylistic/object-curly-spacing': ['error', 'always', { arraysInObjects: false, objectsInObjects: false }],
'@stylistic/object-curly-spacing': 'off',
'@stylistic/new-parens': ['error', 'never'],
'@stylistic/quote-props': [ 'error', 'as-needed' ],
'@stylistic/arrow-parens': [ 'error', 'as-needed' ],
Expand Down
57 changes: 30 additions & 27 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install packaging xvfbwrapper
pip install -r requirements.txt
- name: install node
uses: actions/setup-node@v4
with:
Expand All @@ -43,15 +49,8 @@ jobs:
with:
path: |
~/.npm
~/.nocache/pip
${{ env.pythonLocation }}
key: ${{ runner.os }}-build-${{ env.pythonLocation }}-${{ env.cache-name }}-${{
hashFiles('package-lock.json') }}-${{ hashFiles('requirements.txt') }}
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install packaging xvfbwrapper
pip install -r requirements.txt
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json')
}}-${{ hashFiles('requirements.txt') }}
- name: install node packages
run: npm install

Expand Down Expand Up @@ -130,6 +129,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install packaging xvfbwrapper
pip install -r requirements.txt
- name: Cache python/node dependencies
id: cache
uses: actions/cache@v4
Expand All @@ -138,15 +143,8 @@ jobs:
with:
path: |
~/.npm
~/.nocache/pip
${{ env.pythonLocation }}
key: ${{ runner.os }}-build-${{ env.pythonLocation }}-${{ env.cache-name }}-${{
hashFiles('package-lock.json') }}-${{ hashFiles('requirements.txt') }}
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install packaging xvfbwrapper
pip install -r requirements.txt
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json')
}}-${{ hashFiles('requirements.txt') }}

- name: install ${{ matrix.client }}
run: |
Expand Down Expand Up @@ -221,6 +219,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install packaging xvfbwrapper
pip install -r requirements.txt
- name: install node
uses: actions/setup-node@v4
with:
Expand All @@ -233,15 +237,8 @@ jobs:
with:
path: |
~/.npm
~/.nocache/pip
${{ env.pythonLocation }}
key: ${{ runner.os }}-build-${{ env.pythonLocation }}-${{ env.cache-name }}-${{
hashFiles('package-lock.json') }}-${{ hashFiles('requirements.txt') }}
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install packaging xvfbwrapper
pip install -r requirements.txt
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json')
}}-${{ hashFiles('requirements.txt') }}
- name: install node packages
run: npm install

Expand Down Expand Up @@ -274,6 +271,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install packaging xvfbwrapper
pip install -r requirements.txt
- name: fetch test artifacts
uses: actions/download-artifact@v4
with:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/src/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ _anchors:
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
install_node: &install_node
name: install node
uses: actions/setup-node@v4
Expand All @@ -29,9 +30,7 @@ _anchors:
with:
path: |
~/.npm
~/.nocache/pip
${{ env.pythonLocation }}
key: ${{ runner.os }}-build-${{ env.pythonLocation }}-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('requirements.txt') }}
install_python_packages: &install_python_packages
name: install python packages
run: |
Expand Down Expand Up @@ -63,9 +62,9 @@ jobs:
if: github.event.head_commit.message == env.version && !startsWith(github.ref, 'refs/tags/')

- *install_python
- *install_python_packages
- *install_node
- *cache
- *install_python_packages
- *install_node_packages
- name: set slow/legacy/beta flags
run: ./util/action-flags
Expand Down Expand Up @@ -133,8 +132,8 @@ jobs:
with:
name: build-artifacts
- *install_python
- *cache
- *install_python_packages
- *cache

- name: install ${{ matrix.client }}
run: |
Expand Down Expand Up @@ -200,9 +199,9 @@ jobs:
with:
name: build-artifacts
- *install_python
- *install_python_packages
- *install_node
- *cache
- *install_python_packages
- *install_node_packages

- run: npm run release
Expand Down Expand Up @@ -230,6 +229,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- *install_python
- *install_python_packages
- name: fetch test artifacts
uses: actions/download-artifact@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions content/ZoteroPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ZoteroPane {
const items = zp.getSelectedItems()
toClipboard(await Translators.queueJob({
translatorID,
displayOptions: {},
displayOptions: { worker: true },
scope: { type: 'items', items },
}))
}
Expand Down Expand Up @@ -414,7 +414,7 @@ class ZoteroPane {
try {
return await Translators.queueJob({
translatorID: Translators.bySlug.BetterBibTeXJSON.translatorID,
displayOptions: { exportNotes: true, dropAttachments: true, Normalize: true },
displayOptions: { worker: true, exportNotes: true, dropAttachments: true, Normalize: true },
scope,
timeout: 40,
})
Expand Down
1 change: 1 addition & 0 deletions content/auto-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const queue = new class TaskQueue {
useJournalAbbreviation: ae.useJournalAbbreviation,
biblatexAPA: ae.biblatexAPA || false,
biblatexChicago: ae.biblatexChicago || false,
worker: true,
}

const jobs: ExportJob[] = [{
Expand Down
2 changes: 1 addition & 1 deletion content/better-bibtex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ $Patcher$.schedule(Zotero.Translate.Export.prototype, 'translate', original => f
if (useWorker) {
return Translators.queueJob({
translatorID,
displayOptions,
displayOptions: {...displayOptions, worker: true},
translate: this,
scope: { ...this._export, getter: this._itemGetter },
path: this.location?.path,
Expand Down
1 change: 1 addition & 0 deletions content/cayw/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export const Formatter = new class { // eslint-disable-line @typescript-eslint/n
const displayOptions = {
exportNotes: [ 'yes', 'y', 'true' ].includes((options.exportNotes || '').toLowerCase()),
useJournalAbbreviation: [ 'yes', 'y', 'true' ].includes((options.useJournalAbbreviation || '').toLowerCase()),
worker: !options.worker || [ 'yes', 'y', 'true' ].includes((options.worker || '').toLowerCase()),
}

return await Translators.queueJob({ translatorID, displayOptions, scope: { type: 'items', items }})
Expand Down
4 changes: 2 additions & 2 deletions content/json-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class NSItem {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return await Translators.queueJob({
translatorID: Translators.getTranslatorId(translator),
displayOptions: {},
displayOptions: { worker: true },
scope: { type: 'items', items: await getItemsAsync(found.map(key => key.itemID)) }, // eslint-disable-line @typescript-eslint/no-unsafe-return
})
}
Expand Down Expand Up @@ -537,7 +537,7 @@ class NSItem {
// I need the cleanup BCJ does
const csl = JSON.parse(await Translators.queueJob({
translatorID: Translators.getTranslatorId('Better CSL JSON'),
displayOptions: { custom: true },
displayOptions: { worker: true, custom: true },
scope: { type: 'items', items },
}))

Expand Down
4 changes: 2 additions & 2 deletions content/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function to_s(obj: any): string {
return JSON.stringify(obj, replacer(), 2)
}

export function format(...msg): void {
msg.map(to_s).join(' ')
export function format(...msg): string {
return msg.map(to_s).join(' ')
}

export const log = new class {
Expand Down
23 changes: 6 additions & 17 deletions content/translators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Shim } from './os'
import * as client from './client'
const $OS = client.is7 ? Shim : OS
import merge from 'lodash.merge'
import { pick } from './object'
import { Cache } from './db/cache'
import { Serializer } from './item-export-format'

Expand Down Expand Up @@ -224,25 +225,14 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
}

public async queueJob(job: ExportJob): Promise<string> {
return await this.queue.add(async () => {
const translator = this.byId[job.translatorID]
const displayOptions = this.displayOptions(job.translatorID, job.displayOptions)
if (typeof translator?.displayOptions.worker === 'boolean' && displayOptions.worker) {
return await this.exportItemsByWorker(job)
}
else {
return await this.exportItems(job)
}
})
return await this.queue.add(() => this.exportItems(job))
}

private async exportItemsByWorker(job: ExportJob): Promise<string> {
// trace('exportItemsByWorker: requested')
if (job.path && job.canceled) return ''
await Zotero.BetterBibTeX.ready
if (job.path && job.canceled) return ''

// trace('exportItemsByWorker: preparing')
const displayOptions = {
...this.displayOptions(job.translatorID, job.displayOptions),
exportPath: job.path || undefined,
Expand Down Expand Up @@ -372,9 +362,7 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
},
})

// trace('exportItemsByWorker: starting cache completion')
await Cache.ZoteroSerialized.fill(items, this.serializer)
// trace('exportItemsByWorker: cache completion completed')

config.data.items = items.map(item => item.id)
prepare.update()
Expand All @@ -391,7 +379,6 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint

prepare.done()

// trace('exportItemsByWorker: prepare finished')
this.worker.postMessage({ kind: 'start', config })

if (typeof job.timeout === 'number') {
Expand All @@ -413,13 +400,15 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
}

public displayOptions(translatorID: string, displayOptions: any): any {
return merge({}, this.byId[translatorID]?.displayOptions || {}, displayOptions)
const defaults = this.byId[translatorID]?.displayOptions || {}
return pick(merge({}, defaults, displayOptions), Object.keys(defaults))
}

private async exportItems(job: ExportJob): Promise<string> {
public async exportItems(job: ExportJob): Promise<string> {
await Zotero.BetterBibTeX.ready

const displayOptions = this.displayOptions(job.translatorID, job.displayOptions)
if (displayOptions.worker) return await this.exportItemsByWorker(job)

const translation = new Zotero.Translate.Export

Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bac59b

Please sign in to comment.