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

Searching the documentation with filters #131

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6dbc6f0
setup branch
polibb Nov 10, 2020
3b931f6
Merge branch 'master' into search-docs
polibb Nov 22, 2020
353ff0d
Merge branch 'master' into search-docs
polibb Nov 27, 2020
c6711a7
improve code readability
polibb Dec 11, 2020
80686ab
Merge branch 'master' into search-docs
polibb Dec 11, 2020
e23988f
minor fixes
polibb Dec 19, 2020
c48b293
python script readability improvements
polibb Jan 16, 2021
6b4bfc3
Merge branch 'master' into search-docs
polibb Jan 21, 2021
7110fa7
extract data structures for readability
polibb Jan 21, 2021
ab0e46f
fix build
robertylewis Jan 21, 2021
67b7951
use class instead of dict for structure field names
robertylewis Jan 21, 2021
1228ce8
Merge pull request #1 from leanprover-community/search-docs
polibb Jan 24, 2021
67287f0
Merge pull request #2 from leanprover-community/search-docs-class
polibb Jan 24, 2021
d965133
small fixes
polibb Feb 7, 2021
ac59932
main py script structure fixes
polibb Feb 10, 2021
7341c7d
Merge branch 'search-docs' of https://github.com/pokixu/doc-gen into …
polibb Feb 10, 2021
a932deb
Merge branch 'master' into search-docs
polibb Mar 20, 2021
be8c23e
Merge branch 'master' into search-docs
polibb Mar 28, 2021
15eb701
cleanup comments
polibb Mar 28, 2021
a37d600
searchable data export structure
polibb Mar 29, 2021
ccb7abf
searchable data lists per file name
polibb Mar 29, 2021
e7f6812
data structure for searching done
polibb Apr 3, 2021
d8212ca
searchable json holds files togethere with declarations
polibb May 1, 2021
c21ebe6
Merge branch 'master' into search-docs
polibb May 3, 2021
8d4da88
building leanpkg increases commit #
polibb May 3, 2021
8dddd0a
searching through index; styling; WIP filters
polibb May 4, 2021
5432001
add filters to UI
polibb May 8, 2021
4c78d9c
show all results implementation
polibb May 11, 2021
3d52ff2
clean up and version of mathlib commits up
polibb May 12, 2021
0028904
filter searching on top of results
polibb May 14, 2021
c7a94a3
lean version reference
polibb May 14, 2021
ada2c1a
no errors on nullable elements; add loading when render all too slow
polibb May 15, 2021
8b8b257
Merge remote-tracking branch 'upstream/master'
polibb May 15, 2021
c01f230
trim query whitespace before searching
polibb May 17, 2021
14355ad
remove unnecessary files
polibb May 17, 2021
d71a7da
Change extension from .json to .bmp
gebner Jun 29, 2021
e4765ef
Merge branch 'master' into master
robertylewis Aug 12, 2021
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
60 changes: 60 additions & 0 deletions import_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import subprocess
from typing import NamedTuple, List
from pathlib import Path
import json
import toml

class ImportName(NamedTuple):
project: str
parts: List[str]
raw_path: Path

@classmethod
def of(cls, fname: str):
fname = Path(fname)
path_info = [(p.resolve(), get_name_from_leanpkg_path(p)) for p in lean_paths]
path_details = "".join(f" - {p}\n" for p, _ in path_info)

for p, name in path_info:
try:
rel_path = fname.relative_to(p)
except ValueError:
pass
else:
return cls(name, rel_path.with_suffix('').parts, fname)

raise RuntimeError(
f"Cannot determine import name for {fname}; it is not within any of the directories returned by `lean --path`:\n"
f"{path_details}"
f"Did you generate `export.json` using a different Lean installation to the one this script is running with?")

@property
def name(self):
return '.'.join(self.parts)

@property
def url(self):
return '/'.join(self.parts) + '.html'

def get_name_from_leanpkg_path(p: Path) -> str:
""" get the package name corresponding to a source path """
if p.parts[-5:] == Path('bin/../lib/lean/library').parts or p.parts[-3:] == Path('bin/../library').parts:
return "core"

# try the toml
p_leanpkg = p / '..' / 'leanpkg.toml'
try:
f = p_leanpkg.open()
except FileNotFoundError:
pass
else:
with f:
parsed_toml = toml.loads(f.read())
return parsed_toml['package']['name']

return '<unknown>'

lean_paths = [
Path(p)
for p in json.loads(subprocess.check_output(['lean', '--path']).decode())['path']
]
4 changes: 2 additions & 2 deletions leanpkg.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "."
version = "0.1"
lean_version = "leanprover-community/lean:3.27.0"
lean_version = "leanprover-community/lean:3.30.0"
path = "src"

[dependencies]
mathlib = {git = "https://github.com/leanprover-community/mathlib", rev = "97d13d7561ef9c9a21587cf62324f8b2d215a7f8"}
mathlib = {git = "https://github.com/leanprover-community/mathlib", rev = "87adde497c62a4e4e8fdd0fd5cfc46a2d1bd5371"}
53 changes: 53 additions & 0 deletions mathlib_data_structures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class mathlibStructures:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, that would make sense to make those inherit from enum.Enum also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try using Enum at first, yes, but there was some issue - not sure what it was since I haven't focused on that in a while. Actually none of the classes here are used at the moment, this is going to be included in another PR which focuses on organizational structure of the python script itself, so that it's easier to read and update. I should probably remove this file from this PR and will look into using Enums again for the next one where those will be needed.

DECLARATIONS = 'decls'
TACTICS = 'tactic_docs'
MODULE_DESCRIPTIONS = 'mod_docs'
NOTES = 'notes'
INSTANCES = 'instances'

class declaration:
NAME = 'name'
IS_META = 'is_meta'
ARGS = 'args'
TYPE = 'type'
DOC_STRING = 'doc_string'
FILENAME = 'filename'
LINE = 'line'
ATTRIBUTES = 'attributes'
EQUATIONS = 'equations'
KIND = 'kind'
STRUCTURE_FIELDS = 'structure_fields'
CONSTRUCTORS = 'constructors'

class declarationKindsSource:
THEOREM = 'thm'
CONST = 'cnst'
AXIOM = 'ax'

class declarationKindsDestination:
STRUCTURE = 'structure'
INDUCTIVE = 'inductive'
THEOREM = 'theorem'
CONST = 'const'
AXIOM = 'axiom'

class tactic:
NAME = 'name'
CATEGORY = 'category'
DECL_NAMES = 'decl_names'
TAGS = 'tags'
DESCRIPTION = 'description'
IMPORT = 'import'

class tacticCategories:
TACTIC = 'tactic'
COMMAND = 'command'
HOLE_COMMAND = 'hole_command'
ATTRIBUTE = 'attribute'

class generalPages:
INDEX = 'index'
TACTICS = 'tactics'
COMMANDS = 'commands'
HOLE_COMMANDS = 'hole_commands'
ATTRIBUTES = 'notes'
Loading