Skip to content

Commit 86e4417

Browse files
committed
++
1 parent 736385a commit 86e4417

2 files changed

Lines changed: 92 additions & 183 deletions

File tree

.clang-format

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,8 @@
1-
AccessModifierOffset: -4
2-
AlignAfterOpenBracket: Align
3-
AlignConsecutiveAssignments: true
4-
AlignEscapedNewlinesLeft: false
5-
AlignOperands: true
6-
AlignTrailingComments: true
7-
AllowAllParametersOfDeclarationOnNextLine: true
8-
AllowShortBlocksOnASingleLine: true
9-
AllowShortCaseLabelsOnASingleLine: true
10-
AllowShortFunctionsOnASingleLine: Inline
11-
AllowShortIfStatementsOnASingleLine: false
12-
AllowShortLoopsOnASingleLine: false
13-
AlwaysBreakAfterReturnType: None
14-
AlwaysBreakBeforeMultilineStrings: false
15-
AlwaysBreakTemplateDeclarations: true
16-
BreakBeforeBraces: Custom
17-
BraceWrapping:
18-
AfterFunction: true
19-
AfterClass: true
20-
AfterControlStatement: true
21-
AfterEnum: false
22-
AfterNamespace: true
23-
AfterStruct: true
24-
AfterUnion: true
25-
BeforeCatch: true
26-
BeforeElse: true
27-
BinPackArguments: true
28-
BinPackParameters: true
29-
BreakBeforeBinaryOperators: All
30-
BreakBeforeTernaryOperators: true
31-
BreakConstructorInitializersBeforeComma: true
32-
BreakStringLiterals: true
1+
IndentWidth: 2
2+
BasedOnStyle: 'google'
333
ColumnLimit: 100
34-
CommentPragmas: '^ IWYU pragma:'
35-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
36-
ConstructorInitializerIndentWidth: 4
37-
ContinuationIndentWidth: 4
38-
Cpp11BracedListStyle: true
39-
DerivePointerAlignment: false
40-
DisableFormat: false
41-
ExperimentalAutoDetectBinPacking: false
42-
IndentCaseLabels: true
43-
IndentWidth: 4
44-
IndentWrappedFunctionNames: false
45-
KeepEmptyLinesAtTheStartOfBlocks: false
46-
MaxEmptyLinesToKeep: 4
47-
NamespaceIndentation: Inner
48-
PenaltyBreakBeforeFirstCallParameter: 19
49-
PenaltyBreakComment: 300
50-
PenaltyBreakFirstLessLess: 120
51-
PenaltyBreakString: 1000
52-
PenaltyExcessCharacter: 1000000
53-
PenaltyReturnTypeOnItsOwnLine: 60
54-
PointerAlignment: Left
55-
ReflowComments: true
564
SortIncludes: false
57-
SpaceAfterTemplateKeyword: false
58-
SpaceBeforeAssignmentOperators: true
59-
SpaceBeforeParens: ControlStatements
60-
SpaceInEmptyParentheses: false
61-
SpacesBeforeTrailingComments: 1
62-
SpacesInAngles: false
63-
SpacesInCStyleCastParentheses: false
64-
SpacesInContainerLiterals: false
65-
SpacesInParentheses: false
66-
SpacesInSquareBrackets: false
67-
Standard: Cpp11
68-
TabWidth: 4
5+
QualifierAlignment: Right
696
UseTab: Never
7+
DerivePointerAlignment: false
8+
PointerAlignment: Left

mod.cpp

Lines changed: 87 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -33,139 +33,109 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333

3434
#include "maiken/module/init.hpp"
3535

36-
namespace mkn
37-
{
38-
namespace python3
39-
{
36+
namespace mkn {
37+
namespace python3 {
4038

41-
class ModuleMaker : public maiken::Module
42-
{
43-
private:
39+
class ModuleMaker : public maiken::Module {
40+
private:
4441
#if defined(_WIN32)
45-
const bool config_expected = 0;
42+
const bool config_expected = 0;
4643
#else
47-
const bool config_expected = 1;
44+
const bool config_expected = 1;
4845
#endif
49-
bool pyconfig_found = 0;
50-
std::string HOME, PY = "python3", PYTHON, PY_CONFIG = "python-config",
51-
PY3_CONFIG = "python3-config", PATH = mkn::kul::env::GET("PATH");
52-
mkn::kul::Dir bin;
53-
std::shared_ptr<kul::cli::EnvVar> path_var;
46+
bool pyconfig_found = 0;
47+
std::string HOME, PY = "python3", PYTHON, PY_CONFIG = "python-config",
48+
PY3_CONFIG = "python3-config", PATH = mkn::kul::env::GET("PATH");
49+
mkn::kul::Dir bin;
50+
std::shared_ptr<kul::cli::EnvVar> path_var;
5451

55-
protected:
56-
static void VALIDATE_NODE(YAML::Node const& node)
57-
{
58-
using namespace mkn::kul::yaml;
59-
Validator({NodeValidator("args")}).validate(node);
60-
}
52+
protected:
53+
static void VALIDATE_NODE(YAML::Node const& node) {
54+
using namespace mkn::kul::yaml;
55+
Validator({NodeValidator("args")}).validate(node);
56+
}
6157

62-
public:
63-
void init(maiken::Application& a, YAML::Node const& /*node*/)
64-
KTHROW(std::exception) override
65-
{
66-
bool finally = 0;
67-
if (!kul::env::WHICH(PY.c_str()))
68-
PY = "python";
69-
PYTHON = mkn::kul::env::GET("PYTHON");
70-
if (!PYTHON.empty())
71-
PY = PYTHON;
58+
public:
59+
void init(maiken::Application& a, YAML::Node const& /*node*/) KTHROW(std::exception) override {
60+
bool finally = 0;
61+
if (!kul::env::WHICH(PY.c_str())) PY = "python";
62+
PYTHON = mkn::kul::env::GET("PYTHON");
63+
if (!PYTHON.empty()) PY = PYTHON;
7264
#if defined(_WIN32)
73-
if (PY.rfind(".exe") == std::string::npos)
74-
PY += ".exe";
65+
if (PY.rfind(".exe") == std::string::npos) PY += ".exe";
7566
#endif
76-
mkn::kul::Process p(PY);
77-
mkn::kul::ProcessCapture pc(p);
78-
HOME = mkn::kul::env::GET("PYTHON3_HOME");
79-
if (!HOME.empty())
80-
{
67+
mkn::kul::Process p(PY);
68+
mkn::kul::ProcessCapture pc(p);
69+
HOME = mkn::kul::env::GET("PYTHON3_HOME");
70+
if (!HOME.empty()) {
8171
#if defined(_WIN32)
82-
bin = mkn::kul::Dir(HOME);
83-
if (!bin)
84-
KEXCEPT(kul::Exception, "$PYTHON3_HOME does not exist");
72+
bin = mkn::kul::Dir(HOME);
73+
if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME does not exist");
8574
#else
86-
bin = mkn::kul::Dir("bin", HOME);
87-
if (!bin)
88-
KEXCEPT(kul::Exception, "$PYTHON3_HOME/bin does not exist");
75+
bin = mkn::kul::Dir("bin", HOME);
76+
if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME/bin does not exist");
8977
#endif
90-
path_var = std::make_shared<kul::cli::EnvVar>("PATH", bin.real(),
91-
mkn::kul::cli::EnvVarMode::PREP);
92-
mkn::kul::env::SET(path_var->name(), path_var->toString().c_str());
93-
p.var(path_var->name(), path_var->toString());
94-
};
78+
path_var =
79+
std::make_shared<kul::cli::EnvVar>("PATH", bin.real(), mkn::kul::cli::EnvVarMode::PREP);
80+
mkn::kul::env::SET(path_var->name(), path_var->toString().c_str());
81+
p.var(path_var->name(), path_var->toString());
82+
};
9583
#if defined(_WIN32)
96-
pyconfig_found = false; // doesn't exist on windows (generally)
84+
pyconfig_found = false; // doesn't exist on windows (generally)
9785
#else
98-
pyconfig_found = mkn::kul::env::WHICH(PY3_CONFIG.c_str());
86+
pyconfig_found = mkn::kul::env::WHICH(PY3_CONFIG.c_str());
9987
#endif
100-
if (!pyconfig_found)
101-
{
102-
pyconfig_found = mkn::kul::env::WHICH(PY_CONFIG.c_str());
103-
PY3_CONFIG = PY_CONFIG;
104-
}
105-
try
106-
{
107-
p << "-c"
108-
<< "\"import sys; print(sys.version_info[0])\"";
109-
p.start();
88+
if (!pyconfig_found) {
89+
pyconfig_found = mkn::kul::env::WHICH(PY_CONFIG.c_str());
90+
PY3_CONFIG = PY_CONFIG;
91+
}
92+
try {
93+
p << "-c"
94+
<< "\"import sys; print(sys.version_info[0])\"";
95+
p.start();
11096

111-
if (!pyconfig_found && config_expected)
112-
{
113-
finally = 1;
114-
KEXCEPT(kul::Exception, "python-config does not exist on path");
115-
}
116-
}
117-
catch (const mkn::kul::Exception& e)
118-
{
119-
KERR << e.stack();
120-
}
121-
catch (const std::exception& e)
122-
{
123-
KERR << e.what();
124-
}
125-
catch (...)
126-
{
127-
KERR << "UNKNOWN ERROR CAUGHT";
128-
}
129-
if (finally)
130-
exit(2);
131-
using namespace mkn::kul::cli;
97+
if (!pyconfig_found && config_expected) {
98+
finally = 1;
99+
KEXCEPT(kul::Exception, "python-config does not exist on path");
100+
}
101+
} catch (mkn::kul::Exception const& e) {
102+
KERR << e.stack();
103+
} catch (std::exception const& e) {
104+
KERR << e.what();
105+
} catch (...) {
106+
KERR << "UNKNOWN ERROR CAUGHT";
107+
}
108+
if (finally) exit(2);
109+
using namespace mkn::kul::cli;
132110

133-
std::string extension;
134-
if (pyconfig_found)
135-
{
136-
mkn::kul::os::PushDir pushd(a.project().dir());
137-
mkn::kul::Process p(PY3_CONFIG);
138-
mkn::kul::ProcessCapture pc(p);
139-
p << "--extension-suffix";
140-
if (path_var)
141-
p.var(path_var->name(), path_var->toString());
142-
p.start();
143-
extension = pc.outs();
144-
}
145-
else
146-
{
147-
mkn::kul::Process p(PY);
148-
mkn::kul::ProcessCapture pc(p);
149-
p << "-c"
150-
<< "\"import sysconfig; "
151-
"print(sysconfig.get_config_var('EXT_SUFFIX'))\"";
152-
p.start();
153-
extension = pc.outs();
154-
}
155-
a.m_cInfo.lib_ext = mkn::kul::String::LINES(extension)[0]; // drop EOL
156-
a.m_cInfo.lib_prefix = "";
157-
a.mode(maiken::compiler::Mode::SHAR);
158-
}
159-
};
160-
} // namespace python3
161-
} // namespace mkn
111+
std::string extension;
112+
if (pyconfig_found) {
113+
mkn::kul::os::PushDir pushd(a.project().dir());
114+
mkn::kul::Process p(PY3_CONFIG);
115+
mkn::kul::ProcessCapture pc(p);
116+
p << "--extension-suffix";
117+
if (path_var) p.var(path_var->name(), path_var->toString());
118+
p.start();
119+
extension = pc.outs();
120+
} else {
121+
mkn::kul::Process p(PY);
122+
mkn::kul::ProcessCapture pc(p);
123+
p << "-c"
124+
<< "\"import sysconfig; "
125+
"print(sysconfig.get_config_var('EXT_SUFFIX'))\"";
126+
p.start();
127+
extension = pc.outs();
128+
}
129+
a.m_cInfo.lib_ext = mkn::kul::String::LINES(extension)[0]; // drop EOL
130+
a.m_cInfo.lib_prefix = "";
131+
a.mode(maiken::compiler::Mode::SHAR);
132+
}
133+
};
134+
} // namespace python3
135+
} // namespace mkn
162136

163-
extern "C" MKN_KUL_PUBLISH maiken::Module* maiken_module_construct()
164-
{
165-
return new mkn::python3::ModuleMaker;
137+
extern "C" MKN_KUL_PUBLISH maiken::Module* maiken_module_construct() {
138+
return new mkn::python3::ModuleMaker;
166139
}
167140

168-
extern "C" MKN_KUL_PUBLISH void maiken_module_destruct(maiken::Module* p)
169-
{
170-
delete p;
171-
}
141+
extern "C" MKN_KUL_PUBLISH void maiken_module_destruct(maiken::Module* p) { delete p; }

0 commit comments

Comments
 (0)