Copy a folder with files and folders - gruntjs

I have a subdir and in there, there are many more folders and files. So what I want is to copy the subdir with all the folders and files.
This is what it looks like now:
.
├── Gruntfile.js
└── src
├── a
└── subdir
└── b
└──subdir2
└── c
└──subdir3
└── d
└──subdir4
└── e
This is how I want it to look after using Grunt:
.
├── Gruntfile.js
└── src
├── a
└── subdir
└── b
└──subdir2
└── c
└──subdir3
└── d
└──subdir4
└── e
└── dist
└── subdir
└── b
└──subdir2
└── c
└──subdir3
└── d
└──subdir4
└── e
This is what I've tried so far, but it just isn't working. It copies everything also src folder and file a:
copy: {
expand: true,
src: 'src/subdir/*',
dest: 'dist/'
}

Use:
{
expand: true,
cwd: 'src/',
src: 'subdir/**',
dest: 'dist/'
},
The cwd option is here for that

Related

How can I adjust the output folder when using the knitr button in RMarkdown?

If I have the following folder structure...
├── README.md
│
├── project.RProj
│
├── data
│ ├── some_data.csv
│
│
├── notebooks
│ ├── analysis.Rmd
│
├── output
How do I change the yaml in my RMarkdown file to output the HTML file to the output folder instead of in the notebook folder when using the knit button?
I would like to be able to click knit in RMarkdown and end up with...
├── README.md
│
├── project.RProj
│
├── data
│ ├── some_data.csv
│
│
├── notebooks
│ ├── analysis.Rmd
│
├── output
│ ├── analysis.html
I have seen that Yihui has a good example of how to edit outputs to add the date in the R Markdown cookbook (https://bookdown.org/yihui/rmarkdown-cookbook/custom-knit.html). Pasted below. But I would like to have an example for this specific use case.
knit: (function(input, ...) {
rmarkdown::render(
input,
output_file = paste0(
xfun::sans_ext(input), '-', Sys.Date(), '.html'
),
envir = globalenv()
)
})
You can specify the output_dir argument, in your case a basic YAML header looks like this:
---
title: "Test"
output: html_document
knit: (function(input, ...) {
rmarkdown::render(
input,
output_dir = "../output"
)
})
---
Here is how you can specify both: the output directory, and add the current date to the name of your output file within YAML heading:
---
title: "test"
author: "myName"
date: "`r Sys.Date()`"
output: html_document
knit: (function(input, ...) {
rmarkdown::render(
input,
output_dir = "../outReports",
output_file =file.path("../outReports",glue::glue('test_{Sys.Date()}'
)))
})
---

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

.NET Angular using RequireJS

I created a new ASP.NET Empty Web Application in Visual Studios 2013. I have an angular project with the following directory structure:
├───TestProject
│ ├───index.html
│ ├───package.json
│ ├───Web.config
│ ├───app
│ │ ├───app.module.js
│ │ ├───main.js
│ ├───bin
│ ├───node_modules
│ │ ├───google-distance
│ │ │ └───test
│ │ ├───json-stringify-safe
│ │ │ └───test
│ │ ├───qs
│ │ ├───request
│ │ │ └───lib
│ ├───obj
│ │ └───Debug
│ │ └───TempPE
│ ├───Properties
│ └───Scripts
└───packages
├───angularjs.1.6.1
│ └───content
│ └───Scripts
│ └───i18n
│ └───ngLocale
├───AngularJS.Core.1.6.1
│ └───content
│ └───Scripts
└───RequireJS.2.3.2
└───content
└───Scripts
Here's what my packages.json looks like:
{
"name": "google-distance",
"version": "1.0.1",
"main": "index",
"description": "A simple node.js wrapper for Google's Distance Matrix API",
"author": {
"name": "Edward Look",
"email": "edwlook#gmail.com",
"url": "http://edwardlook.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/edwlook/node-google-distance.git"
},
"keywords": [
"google",
"maps",
"distance",
"matrix",
"api"
],
"dependencies": {
"google-distance": "~1.0.1"
}
}
I ran npm install and it created the node_modules folder. At the top of my main.js file I have:
var distance = require('../node_modules/google-distance/index.js');
But every time I load the page the console says:
require.js:168 Uncaught Error: Module name "../node_modules/google-distance/index.js" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
at makeError (require.js:168)
at Object.localRequire [as require] (require.js:1433)
at requirejs (require.js:1794)
at main.js:2
What am I doing wrong? How do I use the google-distance module?
Normally you should require it as follows;
var distance = require('google-distance');
The way node will look for modules is as follows;
It will perform a hierarchical directory search for "node_modules" and "google-distance" in the following ways:
./node_modules/google-distance.js
./node_modules/google-distance/index.js
./node_modules/google-distance/package.json
Also, it looks like you should use the asynchronous callback version of require to load this library.
require(['google-distance'], function (distance) {
//package is now loaded.
});
From the require FAQ:
MODULE NAME ... HAS NOT BEEN LOADED YET FOR CONTEXT: ... This occurs
when there is a require('name') call, but the 'name' module has not
been loaded yet. If the error message includes Use require([]), then
it was a top-level require call (not a require call inside a define()
call) that should be using the async, callback version of require to
load the code.
http://requirejs.org/docs/errors.html#notloaded

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

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