Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into romanov_new_alchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Dec 18, 2024
2 parents 5075c27 + 1746290 commit cca08b3
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 93 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
16 changes: 14 additions & 2 deletions bin/rcdb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#!/bin/sh
#!/usr/bin/env python3

/usr/bin/env python3 $RCDB_HOME/python/rcdb/rcdb_cli "$@"
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")
25 changes: 25 additions & 0 deletions bin/rcnd
Original file line number Diff line number Diff line change
@@ -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()
149 changes: 76 additions & 73 deletions cpp/include/RCDB/SQLiteCpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,78 +159,6 @@ namespace SQLite


} // namespace SQLite
/**
* @file VariadicBind.h
* @ingroup SQLiteCpp
* @brief Convenience function for Statement::bind(...)
*
* Copyright (c) 2016 Paul Dreik ([email protected])
* Copyright (c) 2016 Sebastien Rombauts ([email protected])
*
* 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 <initializer_list>

namespace SQLite
{

/// implementation detail for variadic bind.
namespace detail {
template<class F, class ...Args, std::size_t ... I>
inline void invoke_with_index(F&& f, std::integer_sequence<std::size_t, I...>, const Args& ...args)
{
std::initializer_list<int> { (f(I+1, args), 0)... };
}

/// implementation detail for variadic bind.
template<class F, class ...Args>
inline void invoke_with_index(F&& f, const Args& ... args)
{
invoke_with_index(std::forward<F>(f), std::index_sequence_for<Args...>(), 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<?");
* bind(stm,a,b,c);
* //...is equivalent to
* stm.bind(1,a);
* stm.bind(2,b);
* stm.bind(3,c);
* \endcode
* @param s statement
* @param args one or more args to bind.
*/
template<class ...Args>
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
Expand Down Expand Up @@ -876,6 +804,81 @@ namespace SQLite


} // namespace SQLite

/**
* @file VariadicBind.h
* @ingroup SQLiteCpp
* @brief Convenience function for Statement::bind(...)
*
* Copyright (c) 2016 Paul Dreik ([email protected])
* Copyright (c) 2016 Sebastien Rombauts ([email protected])
*
* 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 <initializer_list>

namespace SQLite
{

/// implementation detail for variadic bind.
namespace detail {
template<class F, class ...Args, std::size_t ... I>
inline void invoke_with_index(F&& f, std::integer_sequence<std::size_t, I...>, const Args& ...args)
{
std::initializer_list<int> { (f(I+1, args), 0)... };
}

/// implementation detail for variadic bind.
template<class F, class ...Args>
inline void invoke_with_index(F&& f, const Args& ... args)
{
invoke_with_index(std::forward<F>(f), std::index_sequence_for<Args...>(), 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<?");
* bind(stm,a,b,c);
* //...is equivalent to
* stm.bind(1,a);
* stm.bind(2,b);
* stm.bind(3,c);
* \endcode
* @param s statement
* @param args one or more args to bind.
*/
template<class ...Args>
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
Expand Down Expand Up @@ -2908,4 +2911,4 @@ namespace SQLite

} // namespace SQLite

#endif // SQLITE_CPP_HEADER_
#endif // SQLITE_CPP_HEADER_
2 changes: 1 addition & 1 deletion cpp/include/RCDB/SqLiteProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define RCDB_CPP_SQLITEPROVIDER_H

#include <sqlite3.h>
#include <SQLiteCpp/SQLiteCpp.h>
#include "SQLiteCpp.h"
#include <iostream>
#include <memory>
#include "DataProvider.h"
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/RCDB/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int>(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<int, int>(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)
Expand Down
2 changes: 1 addition & 1 deletion python/rcdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "|"
Expand Down
4 changes: 1 addition & 3 deletions python/rcdb/rcdb_cli/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_coda_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion python/utilites/rcnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='<string>', default="")
Expand Down Expand Up @@ -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()
4 changes: 0 additions & 4 deletions rcnd

This file was deleted.

0 comments on commit cca08b3

Please sign in to comment.