protoc failed to find the import - grpc

$ protoc --go_out=module=github.com/redmcme/go-protos:. \
--go-grpc_out=module=github.com/redmcme/go-protos:. \
--proto_path ../protos \
../protos/*/**
teams.team: File not found.
teams/season.proto:3:1: Import "teams.team" was not found or had errors.
teams/season.proto:22:18: "team.Team" is not defined.
Build command ^
$ ltt ../protos
../protos
├── skyblock
│ └── player.proto
└── teams
├── season.proto
└── team.proto
Directory tree ^
// team.proto
syntax = "proto3";
package teams.team;
option go_package = "github.com/redmcme/go-protos/teams/team";
...
Team proto ^
// season.proto
syntax = "proto3";
import "teams.team";
package teams.season;
option go_package = "github.com/redmcme/go-protos/teams/season";
Season proto ^
Does anyone know why protoc failed to find the import

import "teams.team" is wrong way
the true way is
import "team.proto" or import “teams/team.proto”

Related

How to access all file names in hydra config

I have a directory contains a bunch of txt files:
dir/train/[train1.txt, train2.txt, train3.txt]
I'm able to read a single file, if I define following in a config.yaml
file_name: ${paths.data_dir}/train/train1.txt
So I get the str and I used np.loadtxt(self.hparams.file_name)
I tried
file_name: ${paths.data_dir}/train/*
So I have List[str], I then loop over file_name
dat = []
for file in self.hparams.file_name:
dat.append(np.loadtxt(file))
but it didn't work out.
You could define an OmegaConf custom resolver for this:
# my_app.py
import pathlib
from pathlib import Path
from typing import List
from omegaconf import OmegaConf
yaml_data = """
paths:
data_dir: dir
file_names: ${pathlib_glob:${paths.data_dir}, 'train/*'}
"""
def pathlib_glob(data_dir: str, glob_pattern: str) -> List[str]:
"""Use Pathlib glob to get a list of filenames"""
data_dir_path = pathlib.Path(data_dir)
file_paths: List[Path] = [p for p in data_dir_path.glob(glob_pattern)]
filenames: List[str] = [str(p) for p in file_paths]
return filenames
OmegaConf.register_new_resolver("pathlib_glob", pathlib_glob)
cfg = OmegaConf.create(yaml_data)
assert cfg.file_names == ['dir/train/train3.txt', 'dir/train/train2.txt', 'dir/train/train1.txt']
Now, at the command line:
mkdir -p dir/train
touch dir/train/train1.txt
touch dir/train/train2.txt
touch dir/train/train3.txt
python my_app.py # the assertion passes

how to configure unit test in vscode for python unittest

I am using Python 3.6 and latest version of vscode.
My folder structure:
/folder
/src
src.py
/tests
src_test.py
src.py:
class Addition:
def __init__(self, a, b):
self.a = a
self.b = b
def run(self):
return self.a + self.b
src_test.py:
import unittest
from ..src.addition import Addition
class TestAddition(unittest.TestCase):
def test_addition(self):
inst = Addition(5, 10)
res = inst.run()
self.assertEqual(res, 16)
if( __name__ == "main"):
unittest.main()
here is my project settings.json:
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*_test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
Then under project root folder:
python3 -m unittest tests/src_test.py
File "/usr/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
ModuleNotFoundError: No module named 'tests.src_test'
You are missing an __init__.py file under the tests folder, and the import your module needs a tweak.
The __init__.py allows Python to go up in the folder structure and reach the src.py module (another __init__.py under src would be nice, but it is not necessary to make the vscode tests work).
This is a working folder structure:
.
├── src
│ └── src.py
└── tests
├── __init__.py
└── src_test.py
Also, change the line in src.py:
(OLD) from ..src.addition import Addition
(NEW) from src.src import Addition

Able To Reference Functions But, Not Classes in a Namespace

I'm able to reference functions from a namespace but, not classes. Here is the namespace file SeqLib/FermiAssembler.h"
#ifndef SEQLIB_FERMI_H
#define SEQLIB_FERMI_H
#include <string>
#include <cstdlib>
#include <iostream>
namespace SeqLib
{
void print_my_name(){ std::cout << "It's Crt" }
class FermiAssembler {
public:
FermiAssembler();
~FermiAssembler();
void AddReads(const BamRecordVector& brv);
};
}
I am able to call print_my_name() via SeqLib::print_my_name() but, not able to reference the FermiAssembler class via SeqLib::FermiAssembler f
Here is the C++ file within my /src
#include <iostream>
#include <Rcpp.h>
#include "SeqLib/FermiAssembler.h"
using namespace std;
// [[Rcpp::export]]
void whats_my_name(){
SeqLib::FermiAssembler f;
Here is the structure of the package
temp
seqLib
SeqLib
src
FermiAssembler.cpp
SeqLib
FermiAssembler.h
headerFiles
SeqLibCommon.h
src
hello_world.cpp
Makevars which contains PKG_CXXFLAGS= -I../SeqLib
Here is FermiAssembler.cpp defined
#include "SeqLib/FermiAssembler.h"
#define MAG_MIN_NSR_COEF .1
namespace SeqLib {
FermiAssembler::~FermiAssembler() {
ClearReads();
ClearContigs();
}
}
The error message is: Error in dyn.load(dllfile) :
unable to load shared object 'temp/seqLib/src/SeqLib.so':
temp/seqLib/src/SeqLib.so: undefined symbol: _ZN6SeqLib14FermiAssemblerD1Ev
update I have moved the entire submodule into the src folder as such:
# temp
# |─── src
# |────SeqLib
# |──────SeqLib
# |────── FermiAssembler.h
# |──────src
# |────── FermiAssembler.cpp
When you see an error referencing something like _ZN6SeqLib14FermiAssemblerD1Ev, the first step is to run it through a name demangler like c++filt, which should be included in any Linux distribution:
$ c++filt _ZN6SeqLib14FermiAssemblerD1Ev
# SeqLib::FermiAssembler::~FermiAssembler()
The problem is that in your header file you have declared a destructor for the class FermiAssembler, but did not provide a definition for it. Your options are
Remove the declaration entirely. If the destructor for this class is not doing anything special, such as freeing dynamically allocated memory, or logging information, etc., you should be fine with the default destructor generated by the compiler. However, if you provide a declaration such as you did above, you are telling the compiler "the destructor for this class needs to do something extra so don't generate one for me".
Provide an empty definition: ~FermiAssembler() {} (note the braces, which distinguish this from a declaration). This is equivalent to using the compiler-generated destructor, as described above.
Provide a non-empty definition. In this simple example the FermiAssembler class does not need a non-default destructor, but for the purpose of demonstration we will explore this option below.
Here is the file layout I will be using; you will need to adjust your #include paths, etc. accordingly:
tree example/
# example/
# ├── DESCRIPTION
# ├── example.Rproj
# ├── NAMESPACE
# ├── R
# │   └── RcppExports.R
# └── src
# ├── demo.cpp
# ├── FermiAssembler.cpp
# ├── FermiAssembler.h
# └── RcppExports.cpp
The header FermiAssembler.h now becomes:
#ifndef SEQLIB_FERMI_H
#define SEQLIB_FERMI_H
namespace SeqLib {
class BamRecordVector;
void print_my_name();
class FermiAssembler {
public:
FermiAssembler();
~FermiAssembler();
void AddReads(const BamRecordVector& brv);
};
} // SeqLib
#endif // SEQLIB_FERMI_H
Notice that I have also converted print_my_name to a function prototype, so it will also need to be defined in the corresponding source file. Additionally, you can move the previous #includes to the source file since they are no longer needed here:
// FermiAssembler.cpp
#include "FermiAssembler.h"
#include <iostream>
#include <Rcpp.h>
namespace SeqLib {
void print_my_name() {
std::cout << "It's Crt";
}
FermiAssembler::FermiAssembler()
{
Rcpp::Rcout << "FermiAssembler constructor\n";
}
FermiAssembler::~FermiAssembler()
{
Rcpp::Rcout << "FermiAssembler destructor\n";
}
} // SeqLib
Finally, the file that make use of this class:
// demo.cpp
#include "FermiAssembler.h"
// [[Rcpp::export]]
int whats_my_name() {
SeqLib::FermiAssembler f;
return 0;
}
After building and installing the package, it works as expected:
library(example)
whats_my_name()
# FermiAssembler constructor
# FermiAssembler destructor
# [1] 0
Update Regarding your question of "Can have source files in places other than the top level src/ directory?", yes you can, but I would generally advise against this as it will require a nontrivial Makevars file. Now using this layout,
tree example
# example
# ├── DESCRIPTION
# ├── example.Rproj
# ├── man
# ├── NAMESPACE
# ├── R
# │   └── RcppExports.R
# ├── SeqLib
# │   ├── SeqLib
# │   │   └── FermiAssembler.h
# │   └── src
# │   └── FermiAssembler.cpp
# └── src
# ├── demo.cpp
# ├── Makevars
# └── RcppExports.cpp
we have in the top level src/ directory (not SeqLib/src) this Makevars:
PKG_CXXFLAGS= -I../SeqLib
SOURCES = $(wildcard ../SeqLib/*/*.cpp *.cpp)
OBJECTS = $(wildcard ../SeqLib/*/*.o *.o) $(SOURCES:.cpp=.o)
Note that in the above example we are simply compiling all object files into the same shared library. If you need to, for example, compile intermediate shared or static libraries and link them to the final .so, then expect your Makevars to get a lot messier.
Rebuilding and installing,
library(example)
whats_my_name()
# FermiAssembler constructor
# FermiAssembler destructor
# [1] 0

Premake doesn't picking up dependencies

Recently I've changed from CMake to Premake (v5.0.0-alpha8) and I'm not quite sure how to achieve the the following in Premake.
I want to include some dependencies so in CMake I can do something like this:
target_link_libraries(${PROJECT_NAME}
${YALLA_ABS_PLATFORM}
${YALLA_LIBRARY})
The above will add the paths of these libraries (dir) to "Additional Include Directories" in the compiler and it will also add an entry (lib) to "Additional Dependencies" in the linker so I don't need to do anything special beyond calling target_link_libraries.
So I expected that when I'm doing something like this in Premake:
links {
YALLA_LIBRARY
}
I'd get the same result but I don't.
I also tried to use the libdirs but it doesn't really work, I mean I can't see the library directory and its subdirectories passed to the compiler as "Additional Include Directories" (/I) or Yalla.Library.lib passed to the the linker as "Additional Dependencies".
Here is the directory structure I use:
.
|-- src
| |-- launcher
| |-- library
| | `-- utils
| `-- platform
| |-- abstract
| `-- win32
`-- tests
`-- platform
`-- win32
The library dir is defined in Premake as follow:
project(YALLA_LIBRARY)
kind "SharedLib"
files {
"utils/string-converter.hpp",
"utils/string-converter.cpp",
"defines.hpp"
}
The platform dir is defined in Premake as follow:
project(YALLA_PLATFORM)
kind "SharedLib"
includedirs "abstract"
links {
YALLA_LIBRARY
}
if os.get() == "windows" then
include "win32"
else
return -- OS NOT SUPPORTED
end
The win32 dir is defined in Premake as follow:
files {
"event-loop.cpp",
"win32-exception.cpp",
"win32-exception.hpp",
"win32-window.cpp",
"win32-window.hpp",
"window.cpp"
}
And finally at the root dir I have the following Premake file:
PROJECT_NAME = "Yalla"
-- Sets global constants that represents the projects' names
YALLA_LAUNCHER = PROJECT_NAME .. ".Launcher"
YALLA_LIBRARY = PROJECT_NAME .. ".Library"
YALLA_ABS_PLATFORM = PROJECT_NAME .. ".AbstractPlatform"
YALLA_PLATFORM = PROJECT_NAME .. ".Platform"
workspace(PROJECT_NAME)
configurations { "Release", "Debug" }
flags { "Unicode" }
startproject ( YALLA_LAUNCHER )
location ( "../lua_build" )
include "src/launcher"
include "src/library"
include "src/platform"
I'm probably misunderstanding how Premake works due to lack of experience with it.
I solved it by creating a new global function and named it includedeps.
function includedeps(workspace, ...)
local workspace = premake.global.getWorkspace(workspace)
local args = { ... }
local args_count = select("#", ...)
local func = select(args_count, ...)
if type(func) == "function" then
args_count = args_count - 1
args = table.remove(args, args_count)
else
func = nil
end
for i = 1, args_count do
local projectName = select(i, ...)
local project = premake.workspace.findproject(workspace, projectName)
if project then
local topIncludeDir, dirs = path.getdirectory(project.script)
if func then
dirs = func(topIncludeDir)
else
dirs = os.matchdirs(topIncludeDir .. "/**")
table.insert(dirs, topIncludeDir)
end
includedirs(dirs)
if premake.project.iscpp(project) then
libdirs(dirs)
end
links(args)
else
error(string.format("project '%s' does not exist.", projectName), 3)
end
end
end
Usage:
includedeps(PROJECT_NAME, YALLA_LIBRARY)
or
includedeps(PROJECT_NAME, YALLA_PLATFORM, function(topIncludeDir)
return { path.join(topIncludeDir, "win32") }
end)
Update:
For this to work properly you need to make sure that when you include the dependencies they are included by their dependency order and not by the order of the directory structure.
So for example if I have the following dependency graph launcher --> platform --> library then I'll have to include them in the following order.
include "src/library"
include "src/platform"
include "src/launcher"
As opposed to the directory structure that in my case is as follow:
src/launcher
src/library
src/platform
If you will include them by their directory structure it will fail and tell you that "The project 'Yalla.Platform' does not exist."

Create task in grunt in another file

I wrote simple task in Grunt. Now, I would like to export this task to another file, and I have a problem with it.
How can I find file with my task? This task just searches string from website and putting it in the file. I'm trying load it by: grunt.loadTasks('grunt-find');
I have file (grunt-find) with find.js inside. But it doesn’t work... Can I have to add find.js somewhere else?
Thanks in advance.
grunt.loadTask() will load every JS file in the directory provided as argument; so, basically, you have to do something like:
grunt.loadTasks("tasks");
and you may have a directory called "tasks":
project root
|- tasks
|--- file.js
|- Gruntfile.js
If you find the "directory only" behavior of grunt.loadTask() annoying (i.e. want to keep external tasks definitions next to external task configuration), you can try something like that :
module.exports = function(grunt) {
var env = process.env.NODE_ENV || 'dev';
var _ = require('lodash');
/*** External config & tasks filepaths ***/
//we have 1 base config, and possibly many module-specific config
var configLocations = ['./grunt-config/default_config.js', './grunt-config/**/config.js'];
//we have 1 base tasks definition, and possibly many module-specific config
var tasksLocations = ['./grunt-config/default_tasks.js', './grunt-config/**/tasks.js'];
/* Typical project layout (matching with the globbing pattern above - adapt to your project structure) :
├── Gruntfile.js
├── package.json
├── grunt-config
│ ├── homepage
│ │ └── config.js
│ ├── navigation
│ │ └── config.js
│ ├── module1
│ │ ├── config.js
│ │ └── tasks.js
│ ├── default_config.js
│ ├── default_tasks.js
│ └── template_module_grunt.txt
├── website_directory1
│ ├── mdp
│ ├── multimedia-storage
│ ├── mv-commit.sh
│ ├── query
│ ├── temp
│ └── tmp
└── website_directory2
├── crossdomain.xml
├── css
├── favicon.ico
├── fonts
:
:
:
*/
/***************** External configuration management ***********************************/
var configFiles = grunt.file.expand({
filter: "isFile"
}, configLocations );
grunt.log.writeln('Gathering external configuration files'.underline.green);
grunt.log.writeln("configFiles : " + grunt.log.wordlist(configFiles, {
separator: ', ',
color: 'cyan'
}));
var configArray = configFiles.map(function(file) {
grunt.log.writeln("=> importing : " + file);
return require(file)(grunt, env);
});
var config = {};
configArray.forEach(function(element) {
config = _.merge(config, element);
});
grunt.initConfig(config);
/***************** Task loading & registering *******************************************/
// We load grunt tasks listed in package.json file
require('load-grunt-tasks')(grunt);
/****** External tasks registering ****************/
grunt.log.writeln('Gathering external task files'.underline.green);
var taskFiles = grunt.file.expand({
filter: "isFile"
}, tasksLocations);
grunt.log.writeln("task files : " + grunt.log.wordlist(taskFiles, {
separator: ', ',
color: 'cyan'
}));
taskFiles.forEach(function(path) {
grunt.log.writeln("=> loading & registering : " + path);
require(path)(grunt);
});
grunt.registerTask('default', ['jshint:gruntfile', 'logConfig']);
grunt.registerTask('checkGruntFile', 'Default task - check the gruntfile', function() {
grunt.log.subhead('* Tâche par défaut - aide et vérification du gruntfile *');
grunt.log.writeln('Exécutez "grunt -h" pour avoir plus d\'informations sur les tâches disponibles');
grunt.log.writeln('...');
grunt.log.subhead('Vérification du gruntfile...');
grunt.task.run(['jshint:gruntfile']);
});
//write the generated configuration (for debug)
grunt.registerTask('logConfig', 'Write the generated conf', function() {
//grunt.task.run(['attention:gruntfile']);
grunt.log.subhead('* Configuration générée : *');
grunt.log.writeln(JSON.stringify(config, undefined, 2));
});
};
Source : https://gist.github.com/0gust1/7683132

Resources