rustpython-doc as external module

not to archive every version of them to repository
This commit is contained in:
Jeong Yunwon committed 2022-05-11 21:43:12 +09:00
1 parent 39e3f8faff
commit e609aca7ea
7 files changed
+17 -2247

No files matched your search

Generated
+9
View File
@@ -1679,11 +1679,20 @@ dependencies = [
"quote",
"rustpython-bytecode",
"rustpython-compiler",
"rustpython-doc",
"syn",
"syn-ext",
"textwrap 0.15.0",
]
[[package]]
name = "rustpython-doc"
version = "0.1.0"
source = "git+https://github.com/RustPython/__doc__?branch=main#66be54cd61cc5eb29bb4870314160c337a296a32"
dependencies = [
"once_cell",
]
[[package]]
name = "rustpython-jit"
version = "0.1.2"
+1
View File
@@ -22,3 +22,4 @@ once_cell = "1.10.0"
textwrap = { version = "0.15.0", default-features = false }
indexmap = "1.8.1"
itertools = "0.10.3"
rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" }
-2213
View File
File diff suppressed because it is too large. Load diff
-30
View File
@@ -1,30 +0,0 @@
use once_cell::sync::Lazy;
use std::collections::HashMap;
pub(crate) type Result = std::result::Result<Option<&'static str>, ()>;
pub(crate) fn try_read(path: &str) -> Result {
static DATABASE: Lazy<HashMap<&str, Option<&str>>> = Lazy::new(|| {
let data = include!("../docs.rsinc");
let mut map = HashMap::with_capacity(data.len());
for (item, doc) in data {
map.insert(item, doc);
}
map
});
DATABASE.get(path).copied().ok_or(())
}
pub(crate) fn try_module_item(module: &str, item: &str) -> Result {
try_read(&format!("{}.{}", module, item))
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_module_item() {
let doc = try_module_item("array", "_array_reconstructor").unwrap();
assert!(doc.is_some());
}
}
+1 -1
View File
@@ -13,7 +13,6 @@ mod error;
mod util;
mod compile_bytecode;
mod doc;
mod from_args;
mod pyclass;
mod pymodule;
@@ -23,6 +22,7 @@ mod pystructseq;
use error::{extract_spans, Diagnostic};
use proc_macro2::TokenStream;
use quote::ToTokens;
use rustpython_doc as doc;
use syn::{parse_macro_input, AttributeArgs, DeriveInput, Item};
fn result_to_tokens(result: Result<TokenStream, impl Into<Diagnostic>>) -> proc_macro::TokenStream {
+2 -1
View File
@@ -191,7 +191,8 @@ fn generate_class_def(
) -> Result<TokenStream> {
let doc = attrs.doc().or_else(|| {
let module_name = module_name.unwrap_or("builtins");
crate::doc::try_module_item(module_name, name)
crate::doc::Database::shared()
.try_module_item(module_name, name)
.ok()
.flatten()
.map(str::to_owned)
+4 -2
View File
@@ -89,7 +89,8 @@ pub fn impl_pymodule(attr: AttributeArgs, module_item: Item) -> Result<TokenStre
let module_name = context.name.as_str();
let module_extend_items = context.module_extend_items.validate()?;
let doc = doc.or_else(|| {
crate::doc::try_read(module_name)
crate::doc::Database::shared()
.try_path(module_name)
.ok()
.flatten()
.map(str::to_owned)
@@ -320,7 +321,8 @@ impl ModuleItem for FunctionItem {
let (tokens, py_names) = {
let module = args.module_name();
let doc = args.attrs.doc().or_else(|| {
crate::doc::try_module_item(module, &py_name)
crate::doc::Database::shared()
.try_module_item(module, &py_name)
.ok() // TODO: doc must exist at least one of code or CPython
.flatten()
.map(str::to_owned)