diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 1993f35c..8154753d 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -5,15 +5,15 @@ on: [push] jobs: build: - runs-on: ubuntu:20.04 + runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.6", "3.7", "3.8", "3.9"] + python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -26,4 +26,11 @@ jobs: run: | cd $GITHUB_WORKSPACE/python python -m unittest discover -s $GITHUB_WORKSPACE/python/tests -t $GITHUB_WORKSPACE/python/tests - + + - name: Test CLI commands + run: | + source environment.bash + echo "rcnd command is running" + rcnd --help + echo "rcdb command is running" + rcdb --help diff --git a/bin/rcdb b/bin/rcdb index f6b6f008..5c870b06 100755 --- a/bin/rcdb +++ b/bin/rcdb @@ -1,3 +1,15 @@ -#!/bin/sh +#!/usr/bin/env python3 -/usr/bin/env python3 $RCDB_HOME/python/rcdb/rcdb_cli "$@" \ No newline at end of file +import os +import sys + +# Figure out where is python directory +this_file_dir = os.path.dirname(os.path.abspath(__file__)) +python_dir = os.path.join(this_file_dir, '..', 'python') + +# Add the directory to the Python modules search path +sys.path.insert(0, python_dir) + +# Import and run rcdb +from rcdb.rcdb_cli.app import rcdb_cli +rcdb_cli(prog_name="rcdb") diff --git a/bin/rcnd b/bin/rcnd new file mode 100755 index 00000000..d6f97494 --- /dev/null +++ b/bin/rcnd @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import os +import sys +import importlib.util + +# Figure out where is rcnd.py located +this_file_dir = os.path.dirname(os.path.abspath(__file__)) + +this_file_dir = os.path.dirname(os.path.abspath(__file__)) +python_dir = os.path.join(this_file_dir, '..', 'python') + +# Add the directory to the Python modules search path +sys.path.insert(0, python_dir) + +module_path = os.path.join(this_file_dir, '..', 'python', 'utilites', 'rcnd.py') +module_path = os.path.abspath(module_path) + +# Load the module from the specified file +spec = importlib.util.spec_from_file_location('rcnd', module_path) +rcnd = importlib.util.module_from_spec(spec) +spec.loader.exec_module(rcnd) + +# Now you can use functions from the module +rcnd.main() diff --git a/cpp/include/RCDB/SQLiteCpp.h b/cpp/include/RCDB/SQLiteCpp.h index e15d0d12..697c597a 100644 --- a/cpp/include/RCDB/SQLiteCpp.h +++ b/cpp/include/RCDB/SQLiteCpp.h @@ -159,78 +159,6 @@ namespace SQLite } // namespace SQLite -/** - * @file VariadicBind.h - * @ingroup SQLiteCpp - * @brief Convenience function for Statement::bind(...) - * - * Copyright (c) 2016 Paul Dreik (github@pauldreik.se) - * Copyright (c) 2016 Sebastien Rombauts (sebastien.rombauts@gmail.com) - * - * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt - * or copy at http://opensource.org/licenses/MIT) - */ - -#if (__cplusplus >= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) ) // c++14: Visual Studio 2015 - - -/// @cond -#include - -namespace SQLite -{ - -/// implementation detail for variadic bind. -namespace detail { -template -inline void invoke_with_index(F&& f, std::integer_sequence, const Args& ...args) -{ - std::initializer_list { (f(I+1, args), 0)... }; -} - -/// implementation detail for variadic bind. -template -inline void invoke_with_index(F&& f, const Args& ... args) -{ - invoke_with_index(std::forward(f), std::index_sequence_for(), args...); -} - -} // namespace detail -/// @endcond - -/** - * \brief Convenience function for calling Statement::bind(...) once for each argument given. - * - * This takes care of incrementing the index between each calls to bind. - * - * This feature requires a c++14 capable compiler. - * - * \code{.cpp} - * SQLite::Statement stm("SELECT * FROM MyTable WHERE colA>? && colB=? && colC -void bind(SQLite::Statement& s, const Args& ... args) -{ - static_assert(sizeof...(args) > 0, "please invoke bind with one or more args"); - - auto f=[&s](std::size_t index, const auto& value) - { - s.bind(index, value); - }; - detail::invoke_with_index(f, args...); -} - -} // namespace SQLite - -#endif // c++14 /** * @file Statement.h @@ -876,6 +804,81 @@ namespace SQLite } // namespace SQLite + +/** + * @file VariadicBind.h + * @ingroup SQLiteCpp + * @brief Convenience function for Statement::bind(...) + * + * Copyright (c) 2016 Paul Dreik (github@pauldreik.se) + * Copyright (c) 2016 Sebastien Rombauts (sebastien.rombauts@gmail.com) + * + * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt + * or copy at http://opensource.org/licenses/MIT) + */ + +#if (__cplusplus >= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) ) // c++14: Visual Studio 2015 + + +/// @cond +#include + +namespace SQLite +{ + +/// implementation detail for variadic bind. +namespace detail { +template +inline void invoke_with_index(F&& f, std::integer_sequence, const Args& ...args) +{ + std::initializer_list { (f(I+1, args), 0)... }; +} + +/// implementation detail for variadic bind. +template +inline void invoke_with_index(F&& f, const Args& ... args) +{ + invoke_with_index(std::forward(f), std::index_sequence_for(), args...); +} + +} // namespace detail +/// @endcond + +/** + * \brief Convenience function for calling Statement::bind(...) once for each argument given. + * + * This takes care of incrementing the index between each calls to bind. + * + * This feature requires a c++14 capable compiler. + * + * \code{.cpp} + * SQLite::Statement stm("SELECT * FROM MyTable WHERE colA>? && colB=? && colC +void bind(SQLite::Statement& s, const Args& ... args) +{ + static_assert(sizeof...(args) > 0, "please invoke bind with one or more args"); + + auto f=[&s](std::size_t index, const auto& value) + { + s.bind(index, value); + }; + detail::invoke_with_index(f, args...); +} + +} // namespace SQLite + +#endif // c++14 + + /** * @file Column.h * @ingroup SQLiteCpp @@ -2908,4 +2911,4 @@ namespace SQLite } // namespace SQLite -#endif // SQLITE_CPP_HEADER_ \ No newline at end of file +#endif // SQLITE_CPP_HEADER_ diff --git a/cpp/include/RCDB/SqLiteProvider.h b/cpp/include/RCDB/SqLiteProvider.h index 3629230e..68116d9a 100644 --- a/cpp/include/RCDB/SqLiteProvider.h +++ b/cpp/include/RCDB/SqLiteProvider.h @@ -6,7 +6,7 @@ #define RCDB_CPP_SQLITEPROVIDER_H #include -#include +#include "SQLiteCpp.h" #include #include #include "DataProvider.h" diff --git a/cpp/include/RCDB/StringUtils.h b/cpp/include/RCDB/StringUtils.h index 73631754..2d5eeb9c 100644 --- a/cpp/include/RCDB/StringUtils.h +++ b/cpp/include/RCDB/StringUtils.h @@ -38,12 +38,12 @@ class StringUtils { // trim from start (in place) static inline void ltrim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char c) { return !isspace(c); })); } // trim from end (in place) static inline void rtrim(std::string &s) { - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + s.erase(std::find_if(s.rbegin(), s.rend(), [](char c) { return !isspace(c); }).base(), s.end()); } // trim from both ends (in place) diff --git a/python/rcdb/__init__.py b/python/rcdb/__init__.py index 8ece3eed..38bf7f67 100644 --- a/python/rcdb/__init__.py +++ b/python/rcdb/__init__.py @@ -2,7 +2,7 @@ from .provider import RCDBProvider from .provider import ConfigurationProvider from .rcdb_cli.app import rcdb_cli as run_rcdb_cli - +from .errors import * # This thing separates cells in data blob blob_delimiter = "|" diff --git a/python/rcdb/rcdb_cli/ls.py b/python/rcdb/rcdb_cli/ls.py index 5b0efd6c..21e21c38 100644 --- a/python/rcdb/rcdb_cli/ls.py +++ b/python/rcdb/rcdb_cli/ls.py @@ -11,9 +11,7 @@ def ls(context, search, is_long): """Lists conditions""" - print(context) - exit(0) - + db = context.db assert isinstance(db, RCDBProvider) cnd_types = db.get_condition_types_by_name() diff --git a/python/tests/test_coda_parser.py b/python/tests/test_coda_parser.py index 86a42f3c..918ac926 100644 --- a/python/tests/test_coda_parser.py +++ b/python/tests/test_coda_parser.py @@ -12,7 +12,7 @@ class TestCodaParser(unittest.TestCase): """ Tests ConditionType, ConditionValue classes and their operations in provider""" def setUp(self): - self.this_dir = os.path.dirname(inspect.getfile(test_get_runs)) + self.this_dir = os.path.dirname(__file__) self.this_dir = os.path.normpath(self.this_dir) def test_parse_intermediate_file(self): diff --git a/python/utilites/rcnd.py b/python/utilites/rcnd.py index a40b5831..ec689ff9 100644 --- a/python/utilites/rcnd.py +++ b/python/utilites/rcnd.py @@ -217,7 +217,7 @@ def new_run(db, run_number): print("Created run number {}".format(run_number)) -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser(description=help_text, epilog=examples, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-c", "--connection", help="Connection string to database", metavar='', default="") @@ -320,3 +320,6 @@ def new_run(db, run_number): log.debug("No run_number, no condition_name. Show stats") print_stats(rcdb_db) exit(0) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/rcnd b/rcnd deleted file mode 100755 index e11ece81..00000000 --- a/rcnd +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -/usr/bin/env python $RCDB_HOME/python/rcnd.py "$@" -