docstring-generator-ext 2.0.1__tar.gz → 2.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/PKG-INFO +1 -1
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/docstring_generator_ext.egg-info/PKG-INFO +1 -1
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/pyproject.toml +1 -1
- docstring_generator_ext-2.0.2/src/GoogleDocstring.cpp +145 -0
- docstring_generator_ext-2.0.2/src/IDocstringFormat.cpp +39 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/docstringFormat.cpp +17 -11
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/parser.hpp +1 -0
- docstring_generator_ext-2.0.1/src/GoogleDocstring.cpp +0 -121
- docstring_generator_ext-2.0.1/src/IDocstringFormat.cpp +0 -32
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/MANIFEST.in +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/README.md +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/docstring_generator_ext.egg-info/SOURCES.txt +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/docstring_generator_ext.egg-info/dependency_links.txt +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/docstring_generator_ext.egg-info/requires.txt +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/docstring_generator_ext.egg-info/top_level.txt +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/setup.cfg +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/setup.py +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/FunctionFormat.cpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/FunctionFormat.hpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/GoogleDocstring.hpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/IDocstringFormat.hpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/NumpyDocstring.cpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/NumpyDocstring.hpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/ReStructuredDocstring.cpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/ReStructuredDocstring.hpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/docComparator.cpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/docComparator.hpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/docstringFormat.hpp +0 -0
- {docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/parser.cpp +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#include "GoogleDocstring.hpp"
|
|
2
|
+
|
|
3
|
+
#include <format>
|
|
4
|
+
|
|
5
|
+
#include "parser.hpp"
|
|
6
|
+
|
|
7
|
+
void GoogleDocstring::check_current_docstring() noexcept {
|
|
8
|
+
auto current_py_tab = get_tabs();
|
|
9
|
+
auto google_args_begin = functionInfo.docstring.docstring.find("Args:");
|
|
10
|
+
|
|
11
|
+
if (google_args_begin < std::string::npos) {
|
|
12
|
+
functionInfo.docstring.docstring = functionInfo.docstring.docstring.substr(
|
|
13
|
+
0,
|
|
14
|
+
google_args_begin - (current_py_tab.size() + 1)
|
|
15
|
+
);
|
|
16
|
+
functionInfo.docstring.end_line = functionInfo.docstring.start_line + google_args_begin;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
std::string GoogleDocstring::docstringArgs() noexcept {
|
|
21
|
+
auto current_py_tab = get_tabs();
|
|
22
|
+
|
|
23
|
+
std::string result;
|
|
24
|
+
result.reserve(256); // rough upfront guess for typical arg count
|
|
25
|
+
|
|
26
|
+
if (!functionInfo.docstring.docstring.empty()) {
|
|
27
|
+
result += functionInfo.docstring.docstring;
|
|
28
|
+
result += "\n";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (functionInfo.args.empty())
|
|
32
|
+
return "";
|
|
33
|
+
|
|
34
|
+
if (PY_TAB != current_py_tab) {
|
|
35
|
+
result += current_py_tab;
|
|
36
|
+
current_py_tab += PY_TAB;
|
|
37
|
+
} else {
|
|
38
|
+
result += PY_TAB;
|
|
39
|
+
current_py_tab = PY_TAB + PY_TAB;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
int idx = 0;
|
|
43
|
+
const int last_idx = functionInfo.args.size();
|
|
44
|
+
result += "Args:\n";
|
|
45
|
+
for (const auto &val : functionInfo.args) {
|
|
46
|
+
++idx;
|
|
47
|
+
result += current_py_tab;
|
|
48
|
+
result += val.name;
|
|
49
|
+
if (!val.type.empty()) {
|
|
50
|
+
result += " (";
|
|
51
|
+
result += val.type;
|
|
52
|
+
if (!val.default_value.empty()) {
|
|
53
|
+
result += ", optional";
|
|
54
|
+
}
|
|
55
|
+
result += ")";
|
|
56
|
+
}
|
|
57
|
+
if (!val.description.empty()) {
|
|
58
|
+
result += ": ";
|
|
59
|
+
result += val.description;
|
|
60
|
+
}
|
|
61
|
+
if (!val.default_value.empty()) {
|
|
62
|
+
result += " (default is ";
|
|
63
|
+
result += val.default_value;
|
|
64
|
+
result += ")";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (idx < last_idx) {
|
|
68
|
+
result += "\n";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
std::string GoogleDocstring::docstringReturn() noexcept {
|
|
75
|
+
std::string result;
|
|
76
|
+
result.reserve(256); // rough upfront guess for typical arg count
|
|
77
|
+
|
|
78
|
+
auto current_py_tab = get_tabs();
|
|
79
|
+
|
|
80
|
+
if (!functionInfo.returns.description.empty() || !functionInfo.returns.type.empty()) {
|
|
81
|
+
result += "\n";
|
|
82
|
+
|
|
83
|
+
if (PY_TAB != current_py_tab) {
|
|
84
|
+
result += PY_TAB;
|
|
85
|
+
} else {
|
|
86
|
+
result += PY_TAB;
|
|
87
|
+
current_py_tab = PY_TAB + PY_TAB;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
result += "Returns:\n";
|
|
91
|
+
result += current_py_tab;
|
|
92
|
+
|
|
93
|
+
if (!functionInfo.returns.type.empty()) {
|
|
94
|
+
result += std::format("{}: ", functionInfo.returns.type);
|
|
95
|
+
}
|
|
96
|
+
if (!functionInfo.returns.description.empty()) {
|
|
97
|
+
result += functionInfo.returns.description;
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
result = "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
std::string GoogleDocstring::docstringExceptions() noexcept {
|
|
107
|
+
if (functionInfo.exceptions.empty())
|
|
108
|
+
return "\n";
|
|
109
|
+
|
|
110
|
+
std::string result;
|
|
111
|
+
result.reserve(256); // rough upfront guess for typical arg count
|
|
112
|
+
auto current_py_tab = get_tabs();
|
|
113
|
+
|
|
114
|
+
result += "\n";
|
|
115
|
+
|
|
116
|
+
if (PY_TAB != current_py_tab) {
|
|
117
|
+
result += PY_TAB;
|
|
118
|
+
} else {
|
|
119
|
+
result += PY_TAB;
|
|
120
|
+
current_py_tab = PY_TAB + PY_TAB;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
result += "Raises:\n";
|
|
124
|
+
result += current_py_tab;
|
|
125
|
+
|
|
126
|
+
int idx = 0;
|
|
127
|
+
const int last_exception = functionInfo.exceptions.size();
|
|
128
|
+
for (const auto &[name, description] : functionInfo.exceptions) {
|
|
129
|
+
++idx;
|
|
130
|
+
|
|
131
|
+
if (!name.empty()) {
|
|
132
|
+
result += std::format("{}: ", name);
|
|
133
|
+
}
|
|
134
|
+
if (!description.empty()) {
|
|
135
|
+
result += description;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
result += "\n";
|
|
139
|
+
if (idx < last_exception) {
|
|
140
|
+
result += current_py_tab;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#include "IDocstringFormat.hpp"
|
|
2
|
+
#include "parser.hpp"
|
|
3
|
+
#include <sstream>
|
|
4
|
+
|
|
5
|
+
[[ nodiscard ]] std::string DocstringFormat::docstring() noexcept {
|
|
6
|
+
std::string result;
|
|
7
|
+
result.reserve(1024); // rough upfront guess for typical arg count
|
|
8
|
+
const auto current_pytab = get_tabs();
|
|
9
|
+
|
|
10
|
+
result += current_pytab;
|
|
11
|
+
result += R"(""")";
|
|
12
|
+
if (functionInfo.docstring.docstring.empty()) {
|
|
13
|
+
result += "\n";
|
|
14
|
+
}
|
|
15
|
+
if (const auto argTxt = docstringArgs(); !argTxt.empty()) {
|
|
16
|
+
result += argTxt;
|
|
17
|
+
}
|
|
18
|
+
if (const auto returnTxt = docstringReturn(); !returnTxt.empty())
|
|
19
|
+
result += docstringReturn();
|
|
20
|
+
if (const auto exceptionTxt = docstringExceptions(); !exceptionTxt.empty())
|
|
21
|
+
result += docstringExceptions();
|
|
22
|
+
|
|
23
|
+
result += current_pytab;
|
|
24
|
+
result += R"(""")";
|
|
25
|
+
if (functionInfo.docstring.docstring.empty()) {
|
|
26
|
+
result += "\n";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[[ nodiscard ]] std::string DocstringFormat::get_tabs() const noexcept {
|
|
33
|
+
auto current_py_tab = PY_TAB;
|
|
34
|
+
for (uint32_t idx = 0; idx < (functionInfo.offset / 4); ++idx) {
|
|
35
|
+
current_py_tab += PY_TAB;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return current_py_tab;
|
|
39
|
+
}
|
|
@@ -52,7 +52,7 @@ void parse_file(std::string &file_path, DocstringFormatStyle &formatStyle) {
|
|
|
52
52
|
)) {
|
|
53
53
|
FunctionInfo function_info = analyze_function(obj, ast_module);
|
|
54
54
|
function_info.update_descriptions(formatStyle);
|
|
55
|
-
infos.emplace_back();
|
|
55
|
+
infos.emplace_back(function_info);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -165,19 +165,25 @@ void write_to_file_position(
|
|
|
165
165
|
lines.insert(lines.begin() + start_pos, docstring_format->docstring());
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
{
|
|
169
|
+
std::ofstream out_file(file_path);
|
|
170
|
+
if (!out_file.is_open()) {
|
|
171
|
+
py::print("Error: Unable to open file for writing.");
|
|
172
|
+
std::cerr << "Error: Unable to open file for writing.\n";
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
169
175
|
|
|
170
|
-
|
|
171
|
-
lines
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (line[line.size() - 1] != '\n') {
|
|
175
|
-
|
|
176
|
+
std::string output;
|
|
177
|
+
output.reserve(lines.size() * 80); // rough estimate
|
|
178
|
+
for (const auto &line : lines) {
|
|
179
|
+
output += line;
|
|
180
|
+
if (line.empty() || line[line.size() - 1] != '\n') {
|
|
181
|
+
output += '\n';
|
|
176
182
|
}
|
|
177
183
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
out_file.write(output.data(), static_cast<std::streamsize>(output.size()));
|
|
185
|
+
out_file.close();
|
|
186
|
+
}
|
|
181
187
|
}
|
|
182
188
|
|
|
183
189
|
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
#include "GoogleDocstring.hpp"
|
|
2
|
-
|
|
3
|
-
#include "parser.hpp"
|
|
4
|
-
|
|
5
|
-
void GoogleDocstring::check_current_docstring() noexcept {
|
|
6
|
-
auto current_py_tab = get_tabs();
|
|
7
|
-
auto google_args_begin = functionInfo.docstring.docstring.find("Args:");
|
|
8
|
-
|
|
9
|
-
if (google_args_begin < std::string::npos) {
|
|
10
|
-
functionInfo.docstring.docstring = functionInfo.docstring.docstring.substr(
|
|
11
|
-
0,
|
|
12
|
-
google_args_begin - (current_py_tab.size() + 1)
|
|
13
|
-
);
|
|
14
|
-
functionInfo.docstring.end_line = functionInfo.docstring.start_line + google_args_begin;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
std::string GoogleDocstring::docstringArgs() noexcept {
|
|
19
|
-
std::stringstream sstream;
|
|
20
|
-
auto current_py_tab = get_tabs();
|
|
21
|
-
|
|
22
|
-
if (!functionInfo.docstring.docstring.empty()) {
|
|
23
|
-
sstream << functionInfo.docstring.docstring;
|
|
24
|
-
sstream << "\n";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (PY_TAB != current_py_tab) {
|
|
28
|
-
sstream << current_py_tab;
|
|
29
|
-
current_py_tab += PY_TAB;
|
|
30
|
-
} else {
|
|
31
|
-
sstream << PY_TAB;
|
|
32
|
-
current_py_tab = PY_TAB + PY_TAB;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
sstream << "Args:\n";
|
|
36
|
-
std::ranges::for_each(functionInfo.args,
|
|
37
|
-
[&sstream, ¤t_py_tab](const FunctionParameter &val) {
|
|
38
|
-
sstream << current_py_tab << val.name;
|
|
39
|
-
if (!val.type.empty()) {
|
|
40
|
-
sstream << " (" << val.type;
|
|
41
|
-
if (!val.default_value.empty()) {
|
|
42
|
-
sstream << ", optional";
|
|
43
|
-
}
|
|
44
|
-
sstream << ")";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!val.description.empty()) {
|
|
48
|
-
sstream << ": " << val.description;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!val.default_value.empty()) {
|
|
52
|
-
sstream << " (default is " << val.default_value << ")\n";
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
return sstream.str();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
std::string GoogleDocstring::docstringReturn() noexcept {
|
|
61
|
-
std::stringstream sstream;
|
|
62
|
-
auto current_py_tab = get_tabs();
|
|
63
|
-
|
|
64
|
-
if (!functionInfo.returns.description.empty() || !functionInfo.returns.type.empty()) {
|
|
65
|
-
sstream << "\n";
|
|
66
|
-
|
|
67
|
-
if (PY_TAB != current_py_tab) {
|
|
68
|
-
sstream << PY_TAB;
|
|
69
|
-
} else {
|
|
70
|
-
sstream << PY_TAB;
|
|
71
|
-
current_py_tab = PY_TAB + PY_TAB;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
sstream << "Returns:\n";
|
|
75
|
-
sstream << current_py_tab;
|
|
76
|
-
|
|
77
|
-
if (!functionInfo.returns.type.empty()) {
|
|
78
|
-
sstream << functionInfo.returns.type << ": ";
|
|
79
|
-
}
|
|
80
|
-
if (!functionInfo.returns.description.empty()) {
|
|
81
|
-
sstream << functionInfo.returns.description;
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
sstream << "";
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return sstream.str();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
std::string GoogleDocstring::docstringExceptions() noexcept {
|
|
91
|
-
if (functionInfo.exceptions.empty())
|
|
92
|
-
return "\n";
|
|
93
|
-
|
|
94
|
-
std::stringstream sstream;
|
|
95
|
-
auto current_py_tab = get_tabs();
|
|
96
|
-
|
|
97
|
-
sstream << "\n";
|
|
98
|
-
|
|
99
|
-
if (PY_TAB != current_py_tab) {
|
|
100
|
-
sstream << PY_TAB;
|
|
101
|
-
} else {
|
|
102
|
-
sstream << PY_TAB;
|
|
103
|
-
current_py_tab = PY_TAB + PY_TAB;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
sstream << "Raises:\n";
|
|
107
|
-
sstream << current_py_tab;
|
|
108
|
-
|
|
109
|
-
for (const auto &[name, description] : functionInfo.exceptions) {
|
|
110
|
-
if (!name.empty()) {
|
|
111
|
-
sstream << name << ": ";
|
|
112
|
-
}
|
|
113
|
-
if (!description.empty()) {
|
|
114
|
-
sstream << description;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
sstream << "\n";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return sstream.str();
|
|
121
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#include "IDocstringFormat.hpp"
|
|
2
|
-
#include "parser.hpp"
|
|
3
|
-
#include <sstream>
|
|
4
|
-
|
|
5
|
-
[[ nodiscard ]] std::string DocstringFormat::docstring() noexcept {
|
|
6
|
-
std::stringstream sstream;
|
|
7
|
-
const auto current_pytab = get_tabs();
|
|
8
|
-
|
|
9
|
-
sstream << current_pytab << R"(""")";
|
|
10
|
-
if (functionInfo.docstring.docstring.empty()) {
|
|
11
|
-
sstream << "\n";
|
|
12
|
-
}
|
|
13
|
-
sstream << docstringArgs();
|
|
14
|
-
sstream << docstringReturn();
|
|
15
|
-
sstream << docstringExceptions();
|
|
16
|
-
|
|
17
|
-
sstream << current_pytab << R"(""")";
|
|
18
|
-
if (functionInfo.docstring.docstring.empty()) {
|
|
19
|
-
sstream << "\n";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return sstream.str();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
[[ nodiscard ]] std::string DocstringFormat::get_tabs() const noexcept {
|
|
26
|
-
auto current_py_tab = PY_TAB;
|
|
27
|
-
for (uint32_t idx = 0; idx < (functionInfo.offset / 4); ++idx) {
|
|
28
|
-
current_py_tab += PY_TAB;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return current_py_tab;
|
|
32
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/ReStructuredDocstring.cpp
RENAMED
|
File without changes
|
{docstring_generator_ext-2.0.1 → docstring_generator_ext-2.0.2}/src/ReStructuredDocstring.hpp
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|