-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
235 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
this file is generated by opendal/scripts/gen-pyi/main.rs and opendal.__base doesn't exists. | ||
DO NOT EDIT IT Manually | ||
""" | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from typing import overload, Literal, TypeAlias | ||
|
||
# `true`/`false`` in any case, for example, `true`/`True`/`TRUE` `false`/`False`/`FALSE` | ||
_bool: TypeAlias = str | ||
|
||
class _Base: | ||
@overload | ||
def __init__( | ||
self, | ||
scheme: Literal["s3"], | ||
*, | ||
root: str = ..., | ||
bucket: str = ..., | ||
enable_versioning: str = ..., | ||
endpoint: str = ..., | ||
region: str = ..., | ||
access_key_id: str = ..., | ||
secret_access_key: str = ..., | ||
session_token: str = ..., | ||
role_arn: str = ..., | ||
external_id: str = ..., | ||
role_session_name: str = ..., | ||
disable_config_load: str = ..., | ||
disable_ec2_metadata: str = ..., | ||
allow_anonymous: str = ..., | ||
server_side_encryption: str = ..., | ||
server_side_encryption_aws_kms_key_id: str = ..., | ||
server_side_encryption_customer_algorithm: str = ..., | ||
server_side_encryption_customer_key: str = ..., | ||
server_side_encryption_customer_key_md5: str = ..., | ||
default_storage_class: str = ..., | ||
enable_virtual_host_style: str = ..., | ||
batch_max_operations: str = ..., | ||
delete_max_size: str = ..., | ||
disable_stat_with_override: str = ..., | ||
checksum_algorithm: str = ..., | ||
disable_write_with_if_match: str = ..., | ||
) -> None: ... | ||
@overload | ||
def __init__(self, scheme, **kwargs: str) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
edition = "2021" | ||
name = "gen-pyi" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
syn = { version = "2.0.91", features = ['parsing', 'full', 'derive', 'printing', 'visit', 'visit-mut', 'extra-traits', 'proc-macro'] } | ||
proc-macro2 = { version = "1.0.91", features = ["span-locations"] } | ||
[[bin]] | ||
name = "gen-pyi" | ||
path = "main.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::fs; | ||
|
||
use syn::Ident; | ||
|
||
fn main() { | ||
let services = vec![("s3", "S3Config", "../../core/src/services/s3/config.rs")]; | ||
let mut s = fs::read_to_string("python.tmpl").expect("failed to open python template file"); | ||
|
||
for (service, struct_name, filename) in services { | ||
let src = fs::read_to_string(&filename).expect("unable to read file"); | ||
let syntax = syn::parse_file(&src).expect("unable to parse file"); | ||
|
||
// Debug impl is available if Syn is built with "extra-traits" feature. | ||
for item in syntax.items.iter() { | ||
let item = match item { | ||
syn::Item::Struct(item_type) => item_type, | ||
_ => { | ||
continue; | ||
} | ||
}; | ||
|
||
match item.ident.span().source_text() { | ||
None => { | ||
continue; | ||
} | ||
Some(s) => { | ||
if s != struct_name { | ||
println!("{} {}", s, s == struct_name); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
s.push_str(format!(" @overload\n").as_str()); | ||
s.push_str(format!(" def __init__(self,\n").as_str()); | ||
s.push_str(format!(r#"scheme: Literal["{service}"],"#).as_str()); | ||
s.push_str(format!("\n*,\n").as_str()); | ||
|
||
for f in item.fields.iter() { | ||
s.push_str( | ||
f.ident | ||
.clone() | ||
.unwrap() | ||
.span() | ||
.source_text() | ||
.unwrap() | ||
.as_ref(), | ||
); | ||
s.push_str(": "); | ||
let pyi_t = py_type(f.ty.clone()); | ||
s.push_str(pyi_t.as_ref()); | ||
s.push_str(" = ...,\n"); | ||
} | ||
|
||
s.push_str(")->None:...\n"); | ||
} | ||
} | ||
|
||
s.push_str(" @overload\n def __init__(self, scheme, **kwargs: str) -> None: ...\n"); | ||
|
||
fs::write(r"../../bindings/python/python/opendal/__base.pyi", s) | ||
.expect("failed to write result to file"); | ||
} | ||
|
||
fn py_type(t: syn::Type) -> String { | ||
let p = match t { | ||
_ => { | ||
return "str".into(); | ||
} | ||
syn::Type::Path(p) => p, | ||
}; | ||
|
||
match p.path.get_ident() { | ||
Some(idnt) => { | ||
if idnt.span().unwrap().source_text().unwrap() == "bool" { | ||
return "_bool".into(); | ||
} | ||
|
||
return "str".into(); | ||
} | ||
_ => { | ||
return "str".into(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
this file is generated by opendal/scripts/gen-pyi/main.rs and opendal.__base doesn't exists. | ||
|
||
DO NOT EDIT IT Manually | ||
""" | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from typing import overload,Literal,TypeAlias | ||
|
||
# `true`/`false`` in any case, for example, `true`/`True`/`TRUE` `false`/`False`/`FALSE` | ||
_bool: TypeAlias = str | ||
|
||
class _Base: |