Skip to content

Commit 3d61541

Browse files
authored
Merge pull request #229 from bpuchala/v0.2a2_install
0.2a2 bug fixes and 'casm-calc'
2 parents 1d5e2ec + 6c0b7a7 commit 3d61541

26 files changed

Lines changed: 1115 additions & 573 deletions

SConstruct

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# http://www.scons.org/doc/production/HTML/scons-user.html
22
# This is: Sconstruct
33

4-
import os, glob, copy, shutil, subprocess, imp, re
4+
import sys, os, glob, copy, shutil, subprocess, imp, re
55

66
from os.path import join
77

@@ -575,13 +575,24 @@ if 'configure' in COMMAND_LINE_TARGETS:
575575
def check_module(module_name):
576576
print "Checking for Python module '" + module_name + "'... ",
577577
try:
578-
imp.find_module(module_name)
579-
res = 1
580-
print "yes"
581-
except:
582-
res = 0
583-
print "no"
584-
return res
578+
res = imp.find_module(module_name)
579+
if res:
580+
print "yes"
581+
return 1
582+
except ImportError:
583+
pass
584+
for item in sys.path:
585+
importer = sys.path_importer_cache.get(item)
586+
if importer:
587+
try:
588+
result = importer.find_module(module_name, [item])
589+
if result:
590+
print "yes"
591+
return 1
592+
except ImportError:
593+
pass
594+
print "no"
595+
return 0
585596

586597
conf = Configure(
587598
env.Clone(LIBPATH=install_lib_paths,
@@ -619,12 +630,12 @@ if 'configure' in COMMAND_LINE_TARGETS:
619630
if not check_module(module_name):
620631
if_failed("Python module '" + module_name + "' is not installed")
621632
if not check_module('pbs'):
622-
if_failed("""
623-
Python module '%s' is not installed
633+
print """
634+
Python module 'pbs' is not installed
624635
This module is only necessary for setting up and submitting DFT jobs
625636
**It is not the module available from pip**"
626637
It is available from: https://github.com/prisms-center/pbs
627-
""" % module_name)
638+
"""
628639

629640

630641
print "Configuration checks passed."

apps/casm/casm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace CASM;
99
int main(int argc, char *argv[]) {
1010

1111
PrimClex *_primclex = nullptr;
12-
CommandArgs args(argc, argv, _primclex, default_log(), default_err_log());
12+
CommandArgs args(argc, argv, _primclex, fs::path(), default_log(), default_err_log());
1313

1414
return casm_api(args);
1515

include/casm/app/DirectoryStructure.hh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace CASM {
6565
return _all_settings("ref", calc_settings_dir(calctype));
6666
}
6767

68-
/// \brief Check filesystem directory structure and return list of all cluster expansion names
68+
/// \brief Check filesystem directory structure and return list of all property names
6969
std::vector<std::string> all_property() const {
7070
return _all_settings("clex", m_root / m_clex_dir);
7171
}
@@ -272,13 +272,13 @@ namespace CASM {
272272
}
273273

274274
/// \brief Returns path to eci directory
275-
fs::path eci_dir(std::string clex, std::string calctype, std::string ref, std::string bset, std::string eci) const {
276-
return clex_dir(clex) / _calctype(calctype) / _ref(ref) / _bset(bset) / _eci(eci);
275+
fs::path eci_dir(std::string property, std::string calctype, std::string ref, std::string bset, std::string eci) const {
276+
return clex_dir(property) / _calctype(calctype) / _ref(ref) / _bset(bset) / _eci(eci);
277277
}
278278

279279
/// \brief Returns path to eci.json
280-
fs::path eci(std::string clex, std::string calctype, std::string ref, std::string bset, std::string eci) const {
281-
return eci_dir(clex, calctype, ref, bset, eci) / "eci.json";
280+
fs::path eci(std::string property, std::string calctype, std::string ref, std::string bset, std::string eci) const {
281+
return eci_dir(property, calctype, ref, bset, eci) / "eci.json";
282282
}
283283

284284

@@ -297,8 +297,8 @@ namespace CASM {
297297
// -- deprecated ------------------------------------
298298

299299
/// \brief Returns path to eci.out
300-
fs::path eci_out(std::string clex, std::string calctype, std::string ref, std::string bset, std::string eci) const {
301-
return eci_dir(clex, calctype, ref, bset, eci) / "eci.out";
300+
fs::path eci_out(std::string property, std::string calctype, std::string ref, std::string bset, std::string eci) const {
301+
return eci_dir(property, calctype, ref, bset, eci) / "eci.out";
302302
}
303303

304304
/// \brief Query aliases file

include/casm/app/ProjectSettings.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace CASM {
3636
std::string _eci) :
3737
name(_name), property(_property), calctype(_calctype), ref(_ref), bset(_bset), eci(_eci) {}
3838

39+
void print(std::ostream &sout, bool is_default, int indent = 0) const;
40+
3941
std::string name;
4042
std::string property;
4143
std::string calctype;

include/casm/app/casm_functions.hh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CASM_FUNCTIONS_HH
22
#define CASM_FUNCTIONS_HH
33

4+
#include <wordexp.h>
45
#include "casm/CASM_global_definitions.hh"
56
#include "casm/casm_io/Log.hh"
67

@@ -37,23 +38,51 @@ namespace CASM {
3738
/// \brief Data structure holding basic CASM command info
3839
struct CommandArgs {
3940

41+
/// \brief CommandArgs constructor
4042
CommandArgs(int _argc,
4143
char *_argv[],
4244
PrimClex *_primclex = nullptr,
45+
fs::path _root = fs::path(),
4346
Log &_log = default_log(),
4447
Log &_err_log = default_err_log());
4548

49+
/// \brief CommandArgs constructor
50+
CommandArgs(std::string _args,
51+
PrimClex *_primclex = nullptr,
52+
fs::path _root = fs::path(),
53+
Log &_log = default_log(),
54+
Log &_err_log = default_err_log());
55+
56+
CommandArgs(const CommandArgs &other) = delete;
57+
CommandArgs(CommandArgs &&other) = delete;
58+
CommandArgs &operator=(const CommandArgs &) = delete;
59+
CommandArgs &operator=(CommandArgs &&) = delete;
60+
61+
/// \brief CommandArgs destructor
62+
~CommandArgs();
63+
4664
int argc;
4765
char **argv;
4866
PrimClex *primclex;
67+
fs::path root;
4968
Log &log;
5069
Log &err_log;
5170

52-
fs::path root;
71+
/// stores error codes when attempting to parse std::string _args -> argc, argv
72+
int parse_result;
73+
5374
bool is_help;
5475
bool write_log;
5576
std::string command;
5677

78+
private:
79+
80+
void _init();
81+
82+
/// Used when parsing std::string args -> argc, argv
83+
bool m_free_p;
84+
wordexp_t m_p;
85+
5786
};
5887

5988
typedef std::function<int (const CommandArgs &)> Command;
@@ -65,6 +94,9 @@ namespace CASM {
6594
/// \brief Executes CASM commands specified by args
6695
int casm_api(const CommandArgs &args);
6796

97+
// /// \brief Executes casm_api in specified working directory
98+
// int casm_api(const CommandArgs &args, fs::path working_dir);
99+
68100

69101

70102
/// \brief If !_primclex, construct new PrimClex stored in uniq_primclex, then

include/ccasm/api.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ extern "C" {
3838
bool clear_clex);
3939

4040

41-
int casm_capi(char *args, cPrimClex *primclex, costream *log, costream *debug_log, costream *err_log);
41+
int casm_capi(char *args, cPrimClex *primclex, char *root, costream *log, costream *debug_log, costream *err_log);
4242

4343
}

python/casm/casm/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
"""A package of wrappers for running input codes to casm"""
2-
from casm import *
3-
from noindent import *
4-
__all__ = dir()
2+
from casm import API, project_path, jobname
3+
from noindent import NoIndent, NoIndentEncoder
4+
__all__ = [
5+
'API',
6+
'project_path',
7+
'jobname',
8+
'NoIndent',
9+
'NoIndentEncoder'
10+
]

0 commit comments

Comments
 (0)