Skip to content

Commit

Permalink
cleaner build (tidied #include abc everywhere)
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Nov 19, 2024
1 parent fb4be72 commit 10b4275
Show file tree
Hide file tree
Showing 100 changed files with 1,068 additions and 768 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions dev/07-test-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

# cmd

echo "====================================="
echo "===== TESTING COMMAND LINE TOOL ====="
echo "====================================="

make clean

make

./redatam test/uru2011mini/uru2011mini.dic test/uru2011mini/dic-to-csv

./redatam test/uru2011mini/uru2011mini.dicx test/uru2011mini/dicx-to-csv

validate_csv() {
local file=$1
local expected_lines=$2
local expected_columns=$3

# Get the number of lines
actual_lines=$(wc -l < "$file")
# Get the number of columns (assuming the first line contains the headers)
actual_columns=$(head -n 1 "$file" | awk -F';' '{print NF}')

if [[ "$actual_lines" -eq "$expected_lines" && "$actual_columns" -eq "$expected_columns" ]]; then
echo "Validation passed for $file"
else
echo "Validation failed for $file: expected $expected_lines lines and $expected_columns columns, but got $actual_lines lines and $actual_columns columns"
exit 1
fi
}

validate_csv "test/uru2011mini/dic-to-csv/SEXO.csv" 38 4
validate_csv "test/uru2011mini/dicx-to-csv/SEXO.csv" 38 4

# r

echo "========================="
echo "===== TESTING R PKG ====="
echo "========================="

cd rpkg

Rscript -e "devtools::clean_dll(); devtools::check()"

cd ..

# py

echo "=========================="
echo "===== TESTING PY PKG ====="
echo "=========================="

cd pypkg

source venv/bin/activate
rm -rf build dist redatam.egg-info
pip install --use-pep517 .
python tests/basic-test.py
deactivate

cd ..
5 changes: 0 additions & 5 deletions include/database/RedatamDatabase.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef REDATAMLIB_REDATAMDATABASE_HPP
#define REDATAMLIB_REDATAMDATABASE_HPP

#include <stdexcept> // invalid_argument
#include <string>
#include <vector>

#include "Entity.hpp"

namespace RedatamLib {
Expand All @@ -13,7 +9,6 @@ using std::vector;

class RedatamDatabase {
public:
// Throws invalid_argument
explicit RedatamDatabase(const string &fileName);
~RedatamDatabase() = default;

Expand Down
5 changes: 0 additions & 5 deletions include/entities/Entity.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#ifndef REDATAMLIB_ENTITY_HPP
#define REDATAMLIB_ENTITY_HPP

#include <memory>
#include <string>
#include <utility> // pair
#include <vector>

#include "ByteArrayReader.hpp"
#include "Variable.hpp"

Expand Down
6 changes: 2 additions & 4 deletions include/exporters/CSVExporter.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#ifndef REDATAMLIB_CSVEXPORTER_HPP
#define REDATAMLIB_CSVEXPORTER_HPP

#include <mutex>
#include <string>
#include <vector>

#include "Entity.hpp"
#include "Variable.hpp"

#include <mutex>

namespace RedatamLib {
using std::mutex;
using std::string;
Expand Down
2 changes: 0 additions & 2 deletions include/exporters/XMLExporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "pugixml.hpp"

namespace RedatamLib {

using std::string;
using std::vector;

Expand All @@ -29,7 +28,6 @@ class XMLExporter {

static string GetVarType(VarType type);
};

} // namespace RedatamLib

#endif // REDATAMLIB_XMLEXPORTER_HPP
8 changes: 3 additions & 5 deletions include/readers/FuzzyEntityParser.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#ifndef REDATAMLIB_FUZZYENTITYPARSER_HPP
#define REDATAMLIB_FUZZYENTITYPARSER_HPP

#include "ByteArrayReader.hpp"
#include "Entity.hpp"

#include <string>
#include <unordered_map>
#include <utility> // pair
#include <vector>

#include "ByteArrayReader.hpp"
#include "Entity.hpp"

namespace RedatamLib {

using std::pair;
using std::string;
using std::unordered_map;
Expand Down Expand Up @@ -38,7 +37,6 @@ class FuzzyEntityParser {
static void AssignChildren(vector<Entity> &entitites,
unordered_map<string, Entity *> mapping);
};

} // namespace RedatamLib

#endif // REDATAMLIB_FUZZYENTITYPARSER_HPP
9 changes: 4 additions & 5 deletions include/readers/FuzzyVariableParser.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef REDATAMLIB_FUZZYVARIABLEPARSER_HPP
#define REDATAMLIB_FUZZYVARIABLEPARSER_HPP

#include "ByteArrayReader.hpp"
#include "Entity.hpp"

#include <mutex>
#include <string>
#include <utility> // pair
#include <utility> // pair
#include <vector>

#include "ByteArrayReader.hpp"
#include "Entity.hpp"
#include "Variable.hpp"

namespace RedatamLib {
using std::mutex;
using std::pair;
Expand Down
9 changes: 2 additions & 7 deletions include/readers/XMLParser.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#ifndef REDATAMLIB_XMLPARSER_HPP
#define REDATAMLIB_XMLPARSER_HPP

#include <iostream>
#include <memory> // shared_ptr
#include <string>
#include <utility> // pair
#include <vector>

#include "Entity.hpp"
#include "Variable.hpp"
#include "pugixml.hpp"

#include <iostream>

namespace RedatamLib {
using std::pair;
using std::shared_ptr;
Expand Down
2 changes: 0 additions & 2 deletions include/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <system_error> // error_code, generic_category

namespace RedatamLib {

using std::error_code;
using std::generic_category;
using std::strerror;
Expand Down Expand Up @@ -45,7 +44,6 @@ template <typename E> void ThrowIfBad(bool is_good_, const string &e_msg_) {
throw E(e_msg_);
}
}

} // namespace RedatamLib

#endif // REDATAMLIB_UTILS_HPP
10 changes: 5 additions & 5 deletions pypkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ pip install pandas numpy pybind11
pip install --use-pep517 .
```

As an optional step, you can run the tests:
As a developer, be sure to delete the previous build after doing changes and re-installing:

```bash
python tests/basic-test.py
rm -rf build dist redatam.egg-info
pip install --use-pep517 .
```

As a developer, be sure to delete the previous build after doing changes and re-installing:
As an optional step, you can run the tests:

```bash
rm -rf build dist redatam.egg-info
pip install --use-pep517 .
python tests/basic-test.py
```

## Processed data
Expand Down
6 changes: 4 additions & 2 deletions pypkg/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "redatamlib/entity/RedatamDatabase.hpp"
#include <string>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <string>

#include "redatamlib/database/RedatamDatabase.hpp"

pybind11::dict export_redatam_to_dict(const std::string &dicFilePath) {
try {
Expand Down
8 changes: 4 additions & 4 deletions pypkg/redatam.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ redatam.egg-info/dependency_links.txt
redatam.egg-info/not-zip-safe
redatam.egg-info/requires.txt
redatam.egg-info/top_level.txt
redatamlib/utils.cpp
redatamlib/utils.hpp
redatamlib/database/RedatamDatabase.cpp
redatamlib/database/RedatamDatabase.hpp
redatamlib/entity/Entity.cpp
redatamlib/entity/Entity.hpp
redatamlib/entity/RedatamDatabase.cpp
redatamlib/entity/RedatamDatabase.hpp
redatamlib/entity/Variable.cpp
redatamlib/entity/Variable.hpp
redatamlib/exporters/ParentIDCalculator.cpp
Expand All @@ -35,6 +33,8 @@ redatamlib/readers/FuzzyVariableParser.cpp
redatamlib/readers/FuzzyVariableParser.hpp
redatamlib/readers/XMLParser.cpp
redatamlib/readers/XMLParser.hpp
redatamlib/utils/utils.cpp
redatamlib/utils/utils.hpp
vendor/pugiconfig.hpp
vendor/pugixml.cpp
vendor/pugixml.hpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
#include <cctype> // std::tolower
#include <pybind11/pybind11.h>
#include <stdexcept> // std::invalid_argument
#include <string> // find_last_of, substr, npos
#include "RedatamDatabase.hpp"

#include <string> // find_last_of, substr, npos

#include "FuzzyEntityParser.hpp"
#include "PyDictExporter.hpp"
#include "RedatamDatabase.hpp"
#include "XMLParser.hpp"
#include "utils.hpp" // ThrowIfBad, GetFileExtension
#include "utils/utils.hpp" // ThrowIfBad, GetFileExtension

namespace RedatamLib {

using pybind11::dict;
using pybind11::print;
using std::invalid_argument;
using std::string;
using std::vector;

RedatamDatabase::RedatamDatabase(const string &fileName) {
pybind11::print("Opening dictionary file...");
print("Opening dictionary file...");
OpenDictionary(fileName);
}

pybind11::dict RedatamDatabase::ExportPyLists() const {
ListExporter exporter("");
dict RedatamDatabase::ExportPyLists() const {
PyDictExporter exporter("");
return exporter.ExportAllPy(m_entities);
}

void RedatamDatabase::OpenDictionary(const string &fileName) {
string ext = GetFileExtension(fileName);

if (".dic" == ext) {
if (ext == ".dic") {
FuzzyEntityParser parser(fileName);
m_entities = parser.ParseEntities();
} else if (".dicx" == ext) {
} else if (ext == ".dicx") {
XMLParser parser;
m_entities = parser.ParseFile(fileName);
} else {
ThrowIfBad<invalid_argument>(
false,
invalid_argument(
"Error: Dictionary file's extension must be .dic or .dicx ."));
false, "Error: Dictionary file's extension must be .dic or .dicx.");
}
}

} // namespace RedatamLib
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
#ifndef REDATAMLIB_REDATAMDATABASE_HPP
#define REDATAMLIB_REDATAMDATABASE_HPP

#include <string>
#include <vector>
#include <pybind11/pybind11.h>

#include "Entity.hpp"
#include <pybind11/pybind11.h>

namespace RedatamLib {
using pybind11::dict;
using std::string;
using std::vector;

class RedatamDatabase {
public:
// Throws invalid_argument
public:
explicit RedatamDatabase(const string &fileName);
~RedatamDatabase() = default;

RedatamDatabase(const RedatamDatabase &) = delete;
RedatamDatabase &operator=(const RedatamDatabase &) = delete;

pybind11::dict ExportPyLists() const;
dict ExportPyLists() const;

private:
private:
vector<Entity> m_entities;

void OpenDictionary(const string &fileName);
};

} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_REDATAMDATABASE_HPP
#endif // REDATAMLIB_REDATAMDATABASE_HPP
Loading

0 comments on commit 10b4275

Please sign in to comment.