How to use R styleR with pre-commit and renv - r

I have created a virtual environment with rvenv, so that I now have rvenv/ in my project root. I have also installed styler, and would like to have a pre-commit hook that will apply it to R code.
From here: https://github.com/lorenzwalthert/precommit/blob/master/.pre-commit-hooks.yaml is the following:
- id: style-files
name: style-files
description: style files with styler
args: [--style_pkg=styler, '--style_transformers=tidyverse_style(scope = "tokens")']
entry: inst/bin/style-files
language: script
files: '(\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$'
I'm confused about the path that should be given to entry:, in this snip it's a path to a global version of styler (or at least, I'm assuming so). But I would like to be able to use the version that I have installed in the virtual environment I assume.
My question is - how to go about doing this. If I shouldn't be using the version installed in renv/ then I'm happy to hear (and use) whatever the best practice is around creating a pre-commit hook to style R files that will work on mine and others systems.
Edit
Following the answer below worked, I had to install docopt as well (as outlined here).

Usually you rely on the remote repository to provide the configuration (such that you don't need all of the args / entry / etc. setup
for example if you want to use style-files from the repository you've listed you'd set this in your .pre-commit-config.yaml:
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.1.2
hooks:
- id: style-files
from there you can customize args / etc.

Related

Can I point pre-commit mypy hook to use a requirements.txt for the additional_dependencies?

I would like to use the exactly same version of flake8 in requirements.txt and in .pre-commit-config.yaml.
To avoid redundancy I would like to keep the version number of flake8 exactly once in my repo.
Can pre-commit.com read the version number of flake8 from requirements.txt?
it cannot
pre-commit intentionally does not read from the repository under test as this makes caching intractable
you can read more in this issue and the many duplicate issues linked there
for me, I no longer include flake8, etc. in my requirements files as pre-commit replaces the need to install linters / code formatters elsewhere
disclaimer: I created pre-commit

Insalling spack package with external MPI interface

I am trying to install a spack package in a cluster, and if I use
spack install namd
Spack download and install its own MPI interface. Since it is a cluster, I want to take advantage of the native MPI interface, that is personalized by the admin to work fast in the particular computer. How can tell to spack to use the already installed MPI interface (i.e. openmpi or mpich)?.
BTW, I am very new with spack. Thanks!
OK, I already figure it out by reading this page from spack web. I need to create a config file with spack config edit packages and add something like
packages:
openmpi:
buildable: False
modules:
openmpi#3.1.3%gcc#8.2.0 arch=linux-x86_64-centos7: /opt/modules/mpi/gcc/8/openmpi/3.1.3
all:
compiler: [gcc#8.2.0]
providers:
mpi: [openmpi#3.1.3]
Actually, I need to load first /opt/modules/compiladores/gcc/8 to make the /opt/modules/mpi/gcc/8/openmpi/3.1.3 visible, so I need something like
packages:
openmpi:
buildable: False
modules:
openmpi#3.1.3%gcc#8.2.0 arch=linux-x86_64-centos7:
- /opt/modules/compiladores/gcc/8
- /opt/modules/mpi/gcc/8/openmpi/3.1.3
But this does not work since it needs multiple external modules and it is not possible to specify more than one (see here).
Also, spack doesn't use the external module, it creates an internal one by coping and parsing. It will ignore module dependencies or environment variables from the original external module that might be important. modules.yaml needs also to be properly configured to set or prepend this environment variables.

Meteor - Test application using local package over the published one

I'm using Meteor 0.9.3, and I want to try to make some changes to a Meteor smart package. I'm using the package in my app already, let's call it: author:smartpackage.
First, I removed my reference to the published package:
meteor remove author:smartpackage
I've forked the repository on GitHub, and made a local clone in:
/somedir/meteor-smartpackage/
I've created a directory in my meteor app:
/meteor/myApp/packages
and created a symlink:
ln -s /somedir/meteor-smartpackage /meteor/myApp/packages/meteor-smartpackage
How do I now add this local package into my app? I've tried a variety of
meteor add xxxx
options, but I can't find the right command. Am I even close?
The steps you described look good to me, so maybe this is the symlink stuff which is messing around.
The proper way of maintaining private packages is to have a packages/ directory somewhere in your filesystem, let's say in ~/meteor/packages, then you have to set a special environment variable that is called PACKAGE_DIRS, which is looked up by the meteor command line tool to find local packages that reside out of official package repositories.
So let's set this environment variable in your .bashrc and resource it :
echo "export PACKAGE_DIRS=$HOME/meteor/packages" >> ~/.bashrc;
. ~/.bashrc
Then assuming your forked package resides in ~/meteor/packages, meteor add author:package should work normally.
Update to saimeunt's answer, for Meteor 1.2+
I found that loading the local package requires leaving out the author when running meteor add.
Loads Local Package
meteor add cocos2d-meteor
Loads Remote Package
meteor add jakelin:cocos2d-meteor

SaltStack: How to write pkgs by use regular expression in "sls"?

I use saltstack to deploy my servers.
I want to install all "tomcat7" pkgs on one server. So I write a sls file like this:
^tomcat7.*:
pkg:
- installed
- require:
- pkg: openjdk-7-jdk
But in the end, it receives an error:
----------
State: - pkg
Name: ^tomcat7.*
Function: installed
Result: False
Comment: Package ^tomcat7.* failed to install
Changes:
But in fact, the server has install all ^tomcat7.* packages sucessfully.
root#vagrant-ubuntu-raring-64:~# dpkg -l tomcat7*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=====================================================-===============================-===============================-===============================================================================================================
ii tomcat7 7.0.35-1~exp2ubuntu1.1 all Servlet and JSP engine
ii tomcat7-admin 7.0.35-1~exp2ubuntu1.1 all Servlet and JSP engine -- admin web applications
ii tomcat7-common 7.0.35-1~exp2ubuntu1.1 all Servlet and JSP engine -- common files
ii tomcat7-docs 7.0.35-1~exp2ubuntu1.1 all Servlet and JSP engine -- documentation
ii tomcat7-examples 7.0.35-1~exp2ubuntu1.1 all Servlet and JSP engine -- example web applications
ii tomcat7-user 7.0.35-1~exp2ubuntu1.1 all Servlet and JSP engine -- tools to create user instances
How to solve this problem? Am I need to write all ^tomcat7.* pkgs one by one?
So the problem here is that the pkg.installed state is checking the installed packages list for an exact match of ^tomcat7.*, without using regex. It finds that that package is not present, so it attempts to install it. The attempt works because the packaging system obviously does support regex. pkg.installed then checks the installed package list for ^tomcat7.* again (without regex), and finds it is still missing, so it reports an error.
The solution here could be to add another argument to pkg.installed which switches on regex matching. However, this makes the state less deterministic, because we will just search through the list of packages for a match on the regex, and will not verify that all the packages with that regex are installed. This could backfire if, for example, just the tomcat7 package had been installed previously. pkg.installed would see that there was a match, and not install the rest of the packages.
You'd be much better off to use the pkgs argument to give a list of all the exact packages you need. It is much more deterministic this way, and you know they will all be installed, even if one or more had been installed previously.

Loading Network.HTTP module in Haskell on GHC7.4.1

I am trying to load a file in GHCi (Windows 7 / Haskell Platform 2012.2.0.0 ) which starts with:
import Network.HTTP
import System.IO
...
But I get an error:
Could not find module `Network.HTTP'
This module is in HTTP package, right? So when I run >cabal list HTTP it finds the following:
* HTTP
Synopsis: A library for client-side HTTP
Default available version: 4000.2.3
Installed version: 4000.2.3
Homepage: https://github.com/haskell/HTTP
License: BSD3
Which means the package is installed right? What do I do wrong?
Thank you!
Having the package installed by cabal doesn't make it automatically available to your code. (For example, you could have installed 2 versions of some package, so it's not possible to determine automatically what to make available and what to hide).
Probably the simplest solution is to manage, build and run your project using cabal as well. See How to write a Haskell program, Section 2 describes (among other things) how to set up the files required by Cabal. In particular, your cabal file will contain a line similar to this:
build-depends: base, HTTP
See also Cabal User Guide.
Edit: You can try the following:
Create file test.cabal containing:
Name: test
Version: 0.0
Description: My network program
Build-Type: Simple
Cabal-Version: >=1.2
Executable test
Main-is: Test.hs
Build-Depends: base >= 4 && < 5, HTTP
(Replace Test.hs with your source file.) Then Run
cabal install --only-dependencies
this installs all required dependencies. If it all goes well, you can configure and build the project:
cabal configure
cabal build
Maybe to work interactively with your project, you could use cabal-ghci. I haven't tried it, but looks like it could be just what you need.

Resources