From a1214783e01921c12d03e10a25615e755fefb75f Mon Sep 17 00:00:00 2001 From: Evan Bolyen Date: Fri, 10 Jan 2025 17:28:47 -0700 Subject: [PATCH] BUG: handle case-sensitive targets --- src/intersphinx.ts | 12 ++++++++---- src/inventory.spec.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/intersphinx.ts b/src/intersphinx.ts index fa5f1ca..d9c9daf 100644 --- a/src/intersphinx.ts +++ b/src/intersphinx.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import zlib from 'zlib'; import fetch from 'node-fetch'; import { isUrl } from 'myst-cli-utils'; -import type { Domains } from './types.js'; +import { Domains } from './types.js'; type Entry = { type: string; location: string; display?: string }; type InventoryItem = { location: string; display?: string }; @@ -132,7 +132,7 @@ export class Inventory { // wrong type value. type should be in the form of "{domain}:{objtype}" return; } - if (type === 'py:module' && this.getEntry({ type, name })) { + if (type === Domains.pyModule && this.getEntry({ type, name })) { // due to a bug in 1.1 and below, // two inventory entries are created // for Python modules, and the first @@ -153,8 +153,12 @@ export class Inventory { } if (resolvedLocation.endsWith('$')) { // Maybe move this to the parse function only? - resolvedLocation = - resolvedLocation.slice(0, -1) + entry.name.toLowerCase().replace(/\s+/g, '-'); + let name = entry.name; + if (entry.type == Domains.stdLabel || entry.type == Domains.stdTerm) { + name = entry.name.toLocaleLowerCase().replace(/\s+/g, '-'); + } + + resolvedLocation = resolvedLocation.slice(0, -1) + name; } const resolvedDisplay = !entry.display || entry.display.trim() === '-' ? undefined : entry.display.trim(); diff --git a/src/inventory.spec.ts b/src/inventory.spec.ts index c8a16ef..17b02e2 100644 --- a/src/inventory.spec.ts +++ b/src/inventory.spec.ts @@ -22,4 +22,16 @@ describe('Test Inventory', () => { expect(entry?.location?.includes('abc.html')).toBe(true); expect(entry?.type).toBe('std:doc'); }); + test('Python inventory - case sensitive names', async () => { + // Python 3.11 includes both `class Match()` and `def match()` as targets + const inv = new Inventory({ path: 'https://docs.python.org/3.11' }); + await inv.load(); + expect(inv._loaded).toBe(true); + const entryClass = inv.getEntry({ name: 're.Match' }); + expect(entryClass?.location?.endsWith('re.Match')).toBe(true); + expect(entryClass?.type).toBe('py:class'); + const entryFunc = inv.getEntry({ name: 're.match' }); + expect(entryFunc?.location?.endsWith('re.match')).toBe(true); + expect(entryFunc?.type).toBe('py:function'); + }); });