How do I get the relative path based on two absolute paths? - terminal

I need the relative path pointing to a certain directory.
I have this:
/a/b/ef
/a/b/g/h/i/
Now I want to create a relative symbolic link from the second folder to the first one, so it should look like this: ../../../ef
How do I extract the relative path based on two absolute paths in Terminal?
I’m on Mac OS X.

I found a solution using Python and this recipe.
Download and save the above as relpath.py, stop at --- 8< --- snip --- 8< --- snip --- 8< --- snip --- 8< ---
cd into the directory
Run python relpath.py install in Terminal
Then you can use the module from above
Here is my script, which uses the above module to create relative symlinks based on two directories: relsymlink.py Gist

Related

vscode debugger configuration: cwd

I'm trying to configure a debugger for my project.
Here is the problem.
The project folder structure can be simplified like this:
- Project Root
- X
- Y
- etc
I absolutely need to set the cwd in the debugger config as X, otherwise the binary won't run. If I set it as X, program runs, debugger (sort of) works: I see the call stack and the values of the variables. However, vscode cannot find the files with code and I can't see the lines being executed. VSCode also gives me an error:
Unable to open 'file.cpp':
Unable to read file '/blahblah/cwd/Y/file.cpp'
Error: unable to resolve non-existing file.
So the debugger rightfully uses the cwd as a prefix to the rest of the file path, but Y is not nested into X, it is actually in the same root directory.
Again, I absolutely need the binary to be called from the X directory. Is there any way to tell vscode the proper path to the code files in this case?
So here is what worked for me:
// added this to launch.json
"sourceFileMap: {
"proc/self/cwd" : "{workspaceFolder}"
}
From the VSCode docs:
sourceFileMap:
This allows mapping of the compile-time paths for source
to local source locations. It is an object of key/value pairs and will
resolve the first string-matched path. (example: "sourceFileMap": {
"/mnt/c": "c:\" } will map any path returned by the debugger that
begins with /mnt/c and convert it to c:\. You can have multiple
mappings in the object but they will be handled in the order
provided.)
My problem was that the directory from which I needed the process to run didn't match the directory where the source files are located. In the error message vscode gave me I saw the path it uses to try to find source files ("/proc/self/cwd"). So I mapped this path to the one I actually need (just the workspaceFolder in my case).

Running Cucumber (WATIR) tests in Jenkins, from multiple Feature directories

I am currently running Cucumber (WATIR) tests in Jenkins, with the standard directories structure running a set of features.
The directory structure is as follows -
Features
- Pages
-- main.rb
-- httparty_config.rb
-- page1.rb
-- page2.rb
- Step Definitions
-- page1_steps.rb
-- page2_steps.rb
feature_one.feature
feature_two.feature
I am now implementing multiple sites, and am wanting to share the same main class (and other configs for HTTParty etc, but separate each of the sites, into their own cucumber sub-directory (for cleanliness purposes).. The following tests run in Rubymine with no issues.
Env
- main.rb
- httparty_config.rb
Site_1
- Features
-- Pages
--- s1_page1.rb
--- s1_page2.rb
-- Step Definitions
--- s1_page1_steps.rb
--- s1_page2_steps.rb
- s1_feature_one.feature
- s1_feature_two.feature
Site_2
- Features
-- Pages
--- s2_page1.rb
--- s2_page2.rb
-- Step Definitions
--- s2_page1_steps.rb
--- s2_page2_steps.rb
- s2_feature_one.feature
- s2_feature_two.feature
When attempting to run a feature test in Jenkins using this structure, Jenkins fails, as it does not meet the required Cucumber structures.. It cannot find the Feature folder.
How can I keep the new multi-site structure and define the structure so that Jenkins knows where to find each feature, in the different directories?
OK.. So I was making that way more complicated than it needed to be.
I just needed to add a CD command in the Jenkins execute shell command
eg
#!/bin/bash
source /home/jenkins/.rvm/bin/rvm
rvm list
mv gemfile Gemfile
bundle install
cd Site_1
xvfb-run cucumber --format json -o cucumber.json

For Node.JS, where are the core modules in Win?

From the official api site it says that core modules are installed at the /lib folder of the root folder of NodeJS, but when I was trying to search for it I didn't see the /lib folder.
Any idea?
Additionally, after I've done a
var a = require("a.js");
is it possible to get the corresponding path to a.js?
that means /lib folder is in source code not your computer. you can see it in repository.
and
there are two patterns for require
absolute path: if the parameter is not started with ./' nor'../', it's absolute path. so node look for it in core module(it's compiled in node runtime) or `node_modules' that you installed locally using npm.
relative path: if the parameter is started with ./ or ../, it's relative path. so node look for it relative path to current position.
it's so simple. and you can use require.resolve('a.js') to get absolute system path. but core modules don't has path since it's built-in.
Although the accepted answer is good enough to resolve the question, it is worth mention that it has some misleading information regarding the patterns of required. From the very Reference Documentation of Node:
A module prefixed with '/' is an absolute path to the file. For example, require('/home/marco/foo.js') will load the file at /home/marco/foo.js.
A module prefixed with './' is relative to the file calling require(). That is, circle.js must be in the same directory as foo.js for require('./circle') to find it.
Without a leading '/' or './' to indicate a file, the module is either a "core module" or is loaded from a node_modules folder.

Why am I getting this error in my Primer3/eprimer3 Mac OSX build?

I'm getting this error on my mac osx build.
Primer3/eprimer3 issue:
Error: thermodynamic approach chosen, but path to thermodynamic parameters not specified
From:
http://www.mcardle.wisc.edu/mprime/help/primer3/primer3_manual.htm#globalTags
PRIMER_THERMODYNAMIC_PARAMETERS_PATH (string; default ./primer3_config)
This tag specifies the path to the directory that contains all the parameter files used by the thermodynamic approach. In Linux, there are two default locations that are tested if this tag is not defined: ./primer3_config/ and /opt/primer3_config/. For Windows, there is only one default location: .\primer3_config\.
I put the primer3_config in my PATH in bin and still cannot solve this issue. I even did:
export PRIMER_THERMODYNAMIC_PARAMETERS_PATH=/Users/jared/Downloads/primer3-2.3.2/src
and
export PRIMER_THERMODYNAMIC_PARAMETERS_PATH=/Users/jared/Downloads/primer3-2.3.2/src/primer3_config
to no avail.
According to the primer3 manual:
1.5. IMPORTANT: because PRIMER_THERMODYNAMIC_ALIGNMENT=1
PRIMER_THERMODYNAMIC_PARAMETERS_PATH must point to the right location.
This tag specifies the path to the directory that contains all the
parameter files used by the thermodynamic approach. In Linux, there
are two default locations that are tested if this tag is not
defined: ./primer3_config/ and /opt/primer3_config/. For Windows,
there is only one default location: .\primer3_config. If the the
parameter files are not in one these locations, be sure to set
PRIMER_THERMODYNAMIC_PARAMETERS_PATH.
So if you download and compile primer3 form source using the Make command, to get primer3 to run globally you need to copy the executueable, primer3_core, to your path and place the configuration directory, primer3_config in that same directory or at /opt/primer3_config
cd src
sudo cp primer3_core /usr/local/bin # or /usr/bin
sudo cp -r primer3_config /opt/
I has the same issue. I had installed Primer 3 using homebrew-science which was pretty painless. https://github.com/Homebrew/homebrew-science
I did try copying the primer3_config directory into the homebrew primer3 directory, ie:
/usr/local/Cellar/primer3/2.3.4/bin/primer3_config but this also did not work.
In the end I added the PRIMER_THERMODYNAMIC_PARAMETERS_PATH configuration to the primer 3 input file, and this worked. Note that the directory name must have a trailing slash. It is the last entry in the file below which is copied from the example file in the primer3 sources.
SEQUENCE_ID=example
SEQUENCE_TEMPLATE=GTAGTCAGTAGACNATGACNACTGACGATGCAGACNACACACACACACACAGCACACAGGTATTAGTGGGCCATTCGATCCCGACCCAAATCGATAGCTACGATGACG
SEQUENCE_TARGET=37,21
PRIMER_TASK=pick_detection_primers
PRIMER_PICK_LEFT_PRIMER=1
PRIMER_PICK_INTERNAL_OLIGO=1
PRIMER_PICK_RIGHT_PRIMER=1
PRIMER_OPT_SIZE=18
PRIMER_MIN_SIZE=15
PRIMER_MAX_SIZE=21
PRIMER_MAX_NS_ACCEPTED=1
PRIMER_PRODUCT_SIZE_RANGE=75-100
P3_FILE_FLAG=1
SEQUENCE_INTERNAL_EXCLUDED_REGION=37,21
PRIMER_EXPLAIN_FLAG=1
PRIMER_THERMODYNAMIC_PARAMETERS_PATH=/usr/local/Cellar/primer3/2.3.4/bin/primer3_config/
=
Then run it like this:
$ primer3_core < example2

Permanent Config File in Pylint

I've setup a custom configuration file for Pylint (name, conveniently, config). There has to be a way that I don't have to include --rcfile=config on every run. How can I set the config file permanently?
When you do not specify the --rcfile option, Pylint searches for a configuration file in the following order and uses the first one it finds:
pylintrc in the current working directory
If the current working directory is in a Python module, Pylint
searches up the hierarchy of Python modules until it finds a
pylintrc file. This allows you to specify coding standards on a
module-by-module basis. Of course, a directory is judged to be a
Python module if it contains an __init__.py file.
The file named by environment variable PYLINTRC
.pylintrc in your home directory, unless you have no home directory
or your home directory is /root
.pylintrc in the current working directory
/etc/pylintrc
Thus depending on the method you choose, Pylint can use a different configuration file based on the location of the code, the user or the machine.
Note that the configuration file only applies to Python files that are in modules. Thus, Pylint still uses its default rules when analyzing Python files in a directory with no __init__.py file.
For example, I have a bin/ directory containing command line applications. Ordinarily, this directory needs no __init__.py file because it is never imported. I had to add a bin/__init__.py file to get Pylint to analyze these Python files using my pylintrc file.
set the path to that file in the PYLINTRC environment variable, or rename the file $HOME/.pylintrc or /etc/pylintrc (the latter is probably only supported on *nix)
It can be done using .pre-commit-config.yaml. This snippet below need to be added to .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args: [
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=.pylintrc", # Link to your config file
"--load-plugins=pylint.extensions.docparams", # Load an extension
]

Resources