Skip to content

Commit 1565cab

Browse files
committed
fix(python): Print tree by default with python cli
Fixes #106
1 parent 7be8be3 commit 1565cab

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

interfaces/python/infomap_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ def main():
22
import sys
33
import infomap as im
44
args = " ".join(sys.argv[1:])
5-
infomap = im.Infomap(im.Config(args, True))
5+
conf = im.Config(args, True)
6+
infomap = im.Infomap(conf)
67
infomap.run()
78

89

src/core/InfomapBase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void InfomapBase::run(std::string parameters)
216216
std::string currentParameters = io::Str() << m_initialParameters << (parameters.empty() ? "" : " ") << parameters;
217217
if (currentParameters != m_currentParameters) {
218218
m_currentParameters = currentParameters;
219-
this->setConfig(Config::fromString(m_currentParameters, this->requireFileInput));
219+
this->setConfig(Config::fromString(m_currentParameters, this->isCLI));
220220
m_network.setConfig(*this);
221221
}
222222

@@ -329,9 +329,9 @@ void InfomapBase::run(Network& network)
329329

330330
// If used as a library, we may want to reuse the network instance, else clear to use less memory
331331
// TODO: May have to use some meta data for output?
332-
#ifndef AS_LIB
333-
network.clearLinks();
334-
#endif
332+
if (this->isCLI) {
333+
network.clearLinks();
334+
}
335335

336336
if (haveMemory())
337337
Log(2) << "Run Infomap with memory..." << std::endl;

src/io/Config.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ const std::string FlowModel::undirdir = "undirdir";
1515
const std::string FlowModel::outdirdir = "outdirdir";
1616
const std::string FlowModel::rawdir = "rawdir";
1717

18-
Config Config::fromString(std::string flags, bool requireFileInput)
18+
Config Config::fromString(std::string flags, bool isCLI)
1919
{
2020
Config conf;
21-
conf.requireFileInput = requireFileInput;
21+
conf.isCLI = isCLI;
2222

2323
ProgramInterface api("Infomap",
2424
"Implementation of the Infomap clustering algorithm based on the Map Equation (see www.mapequation.org)",
2525
INFOMAP_VERSION);
2626

2727
api.setGroups({"Input", "Algorithm", "Accuracy", "Output"});
2828

29-
std::vector<std::string> optionalOutputDir; // Used if !requireFileInput
29+
std::vector<std::string> optionalOutputDir; // Used if !isCLI
3030
// --------------------- Input options ---------------------
31-
if (requireFileInput)
31+
if (isCLI)
3232
{
3333
api.addNonOptionArgument(conf.networkFile, "network_file",
3434
"File containing the network data. Assumes a link list format if no Pajek formatted heading.", "Input");
@@ -207,7 +207,7 @@ Config Config::fromString(std::string flags, bool requireFileInput)
207207
"Parallelize the inner-most loop for greater speed. This may give some accuracy tradeoff.", "Accuracy", true);
208208

209209
// --------------------- Output options ---------------------
210-
// if (requireFileInput)
210+
// if (isCLI)
211211
// {
212212
// api.addNonOptionArgument(conf.outDirectory, "out_directory",
213213
// "The directory to write the results to");
@@ -235,10 +235,10 @@ Config Config::fromString(std::string flags, bool requireFileInput)
235235
if (!optionalOutputDir.empty())
236236
conf.outDirectory = optionalOutputDir[0];
237237

238-
if (!requireFileInput && conf.outDirectory == "")
238+
if (!isCLI && conf.outDirectory == "")
239239
conf.noFileOutput = true;
240240

241-
if (!conf.noFileOutput && conf.outDirectory == "" && requireFileInput)
241+
if (!conf.noFileOutput && conf.outDirectory == "" && isCLI)
242242
{
243243
throw InputDomainError("Missing out_directory");
244244
}
@@ -307,12 +307,10 @@ void Config::adaptDefaults()
307307
}
308308
}
309309

310-
#ifndef AS_LIB
311310
// Of no output format specified, use tree as default (if not used as a library).
312-
if (!haveModularResultOutput()) {
311+
if (isCLI && !haveModularResultOutput()) {
313312
printTree = true;
314313
}
315-
#endif
316314

317315

318316
// if (!haveModularResultOutput())

src/io/Config.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct FlowModel {
5252
struct Config
5353
{
5454
// Input
55-
bool requireFileInput = false;
55+
bool isCLI = false;
5656
std::string networkFile = "";
5757
std::vector<std::string> additionalInput;
5858
std::string inputFormat = "";
@@ -164,13 +164,13 @@ struct Config
164164
// adaptDefaults();
165165
}
166166

167-
Config(std::string flags, bool requireFileInput = false)
167+
Config(std::string flags, bool isCLI = false)
168168
{
169-
*this = Config::fromString(flags, requireFileInput);
169+
*this = Config::fromString(flags, isCLI);
170170
}
171171

172172
Config(const Config& other) :
173-
requireFileInput(other.requireFileInput),
173+
isCLI(other.isCLI),
174174
networkFile(other.networkFile),
175175
additionalInput(other.additionalInput),
176176
inputFormat(other.inputFormat),
@@ -270,7 +270,7 @@ struct Config
270270

271271
Config& operator=(const Config& other)
272272
{
273-
requireFileInput = other.requireFileInput;
273+
isCLI = other.isCLI;
274274
networkFile = other.networkFile;
275275
additionalInput = other.additionalInput;
276276
inputFormat = other.inputFormat;
@@ -369,7 +369,7 @@ struct Config
369369

370370
Config& cloneAsNonMain(const Config& other)
371371
{
372-
requireFileInput = other.requireFileInput;
372+
isCLI = other.isCLI;
373373
networkFile = other.networkFile;
374374
additionalInput = other.additionalInput;
375375
inputFormat = other.inputFormat;
@@ -579,7 +579,7 @@ struct Config
579579
return error != "";
580580
}
581581

582-
static Config fromString(std::string flags, bool requireFileInput = false);
582+
static Config fromString(std::string flags, bool isCLI = false);
583583
};
584584

585585
}

0 commit comments

Comments
 (0)