How to make trigger command using watchman? - watchman

Hi I will be using watchman to upload images. The images will have folders so I will be using .json to make the command.
These are my images:
/home/user/Documents/Images/folder1/image1.png
/home/user/Documents/Images/folder2/image2.png
I have a list of export environment variables watchman_env
export CONDA_ENV=image_uploader
export IMG_FOLDER=/home/user/Documents/Images
export UPLOADER_SCRIPT=/home/user/Documents/Script/uploader.sh
export PYTHON_UPLOADER=/home/user/Documents/Script/img_uploader.py
export JSON_TRIGGER=/home/user/Documents/Script/uploader.json
This is my uploader script, ~/Script/uploader.sh
. watchman_env
conda run -n $CONDA_ENV python $PYTHON_UPLOADER $IMG_FOLDER
This is my json configuration, ~/Script/uploader.json:
["trigger", "/home/user/Documents/Images", {
"name": "img_uploader",
"expression": ["match", "**/*.png"],
"command": ["/home/user/Documents/Script/uploader.sh"]
}]
I run the command using another bash file, init.sh, since I want to run some few more commands.
. watchman_env
watchman --json-command < $JSON_TRIGGER
When I run uploader.sh my python script uploads the two images. However, when I run init.sh, it does not trigger. What is wrong with my code? And is that correctly how to use json trigger?
wathman version: 4.9.0

I just added to the expression wholename and finally worked.
["trigger", "/home/user/Documents/Images", {
"name": "img_uploader",
"expression": ["match", "**/*.png", "wholename"],
"command": ["/home/user/Documents/Script/uploader.sh"]
}]

Related

How to connect jupyter to an existing environment WITHOUT altering that environment in any way

One can currently connect jupyter to an existing environment, if one installs ipykernel in that particular environment first (and then creates a "kernel" for that environment").
My question is how can that be achieved without touching the environment.
I tried creating a kernelspec.json file manually:
"argv": [
"/path/to/envs/myenv/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "myenv",
"language": "python",
"metadata": {
"debugger": true
}
}
but that doesn't work.
Any hints (even regarding why my request is not sensible) are appreciated.

Running nx target only if file doesn't exist

I have a project which has a build step, however, I need to make sure that the file firebase.config.json exists before running the build command.
With that, I have two NPM scripts:
// package.json
{
...,
"nx": {
"targets": {
"prepare": {
"outputs": ["firebase.config.json"]
},
"build": {
"outputs": ["dist"],
"dependsOn": [
{
"target": "prepare",
"projects": "self"
}
]
}
}
},
"scripts": {
"prepare": "firebase apps:sdkconfig web $FIREBASE_APP_ID_SHOP --json | jq .result.sdkConfig > firebase.config.json",
"build": "VITE_FIREBASE_CONFIG=$(cat ./firebase.config.json) vite build",
},
...
}
So with the above, every time I run nx build app it will first run prepare and build the firebase.config.json file.
However, every time I make a change to any of the source files inside my project, prepare re-runs even though the firebase.config.json is already present.
Is it possible for nx to only run a target if the file declared under outputs is not present?
If you are in a bash environment you can modify your prepare script to be the following (note the original command has been shortened with ellipses for readability).
// package.json
{
"scripts":{
"prepare": "CONFIG=firebase.config.json; [ -f \"$CONFIG\" ] || firebase apps:sdkconfig ... | jq ... > \"$CONFIG\""
}
}
The above prepare script will still run, but it should not spend any time reproducing the configuration file if it already exists.
CONFIG=firebase.config.json is just putting our file in a bash environment variable so we can use it in multiple places (helps prevent typos). [ -f "$CONFIG" ] will return true if $CONFIG holds a filename which corresponds to an existing file. If it returns true, it will short-circuit the || (OR) command.
If you want further verification of this technique, you can test this concept at the terminal with the command [ -f somefile.txt ] || echo "File does not exist". If somefile.txt does not exist, then the echo will run. If the file does exist, then the echo will not run.
A slightly-related side-note: while you clearly can do this all in the package.json configuration, if your nx workspace is going to grow to include other libraries or applications, I highly recommend splitting up all your workspace configuration into the default nx configuration files: nx.json, workspace.json, and the per-project project.json files for the sake of readability/maintainability.
Best of luck!

problem loading in ${localEnv:TOKEN} into devcontainer.json

In my devcontainer.json for vscode, I am trying to load in a build variable. This variable is on my local machine's environment, my code looks like the following:
//build arguments
"build": {
"args": {
"TOKEN": "${localEnv:TOKEN}"
}
}
It seems like it works when I put in a direct string, or something like "${localEnv:HOME}", but it is not picking up this custom one. which is strange because I can do 'printenv TOKEN' and it prints out correctly.
any ideas on what I may be doing wrong?
Add your export BLA=1 to .profile, this was the only way VScode was able to pass through env variables to the devcontainer.
.devcontainer:
{
"name": "devcontainer",
"build": {
"dockerfile": "${localWorkspaceFolder}/Dockerfile",
"context": "${localWorkspaceFolder}",
},
"remoteEnv": {
"FOO": "${localEnv:FOO}",
"BAR": "${localEnv:BAR}",
}
}
First, ensure that you have the VS Code Terminal -> Integrated: Inherit Env setting set to true. This is described on the Advanced Container Configuration page:
Workarounds
If that doesn't fix your problem (it didn't for me), here are some of the workarounds that I have found:
Set the variables in your ~/.bashrc file (or export them temporarily in the terminal) and start VS Code from a bash prompt (the executable is code).
$ export TOKEN=tokenvalue
$ code
Set the variables in your ~/.pam_environment file (these are available session wide and are inherited by applications started with the launcher). You will need to logout and login or reboot for these to apply.
TOKEN=tokenvalue
Set the environment variables in one of your VS Code settings files (user or workspace) using the Terminal -> Integrated Env: Linux setting:
// Object with environment variables that will be added to the VS Code process to be used by the terminal on Linux. Set to `null` to delete the environment variable.
"terminal.integrated.env.linux": {
"TOKEN": "tokenvalue"
},

Code Runner does not work for Python in VsCode

I can run python files in cmd promt and Vscode terminal (cmd prompt). When I try to run any programme with Code runner ("code-runner.runInTerminal": false), I get the following error:
[Running] python "c:\Users\MY PATH INCLUDING WHITESPACE\hello_world.py"
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
Here are the user settings (settings.json) I have tried:
"code-runner.executorMap": {
"python": "python",
},
"code-runner.executorMap": {
"python": "$pythonPath $fullFileName",
},
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName",
},
..but I always get the same error.
It seems like the problem could be related to code runner, but could have something to do with the setup of python on my machine.
It could potentially have something to do with the fact I have two python files for the location of python.exe:
(base) C:\>where python
C:\Users\<user_name>\AppData\Local\Continuum\anaconda3\python.exe
C:\Users\<user_name>\AppData\Local\Microsoft\WindowsApps\python.exe
This is the only difference I can think of to another machine where this actually works, but can't be sure.
Any ideas what the issue could be?
maybe try the following:
Change the executormap to:
"code-runner.executorMap": {
"python": "\"$pythonPath\" $fullFileName",
}
Also you could try to give a concrete python path, maybe create a venv and try there:
"python.pythonPath": "venv/bin/python"
If your directory tree has spaces - do this:
"code-runner.executorMap": {
"python": "\"$pythonPath\" -u $fullFileName",
}
This is in the case were the "python.pythonPath": "C:\Users\Documents and Settings\appdata\python\code\something something\script.py"
Spaces in the directory structure will abort the script and you'll get a response something like:
"C:\Users\Documents is not a valid directory."
So you need the escape character like someone above explained.

How do I define an extension for coffeeify with Budo dev server?

I'm trying to use coffeeify with budo so I do not have to add the extension to my require statements. I have tried passing these commands through budo's browserify options
budo src/app.coffee --live --serve bundle.js -- -t coffeeify --extension=".coffee"
budo src/app.coffee --live --serve bundle.js -- -t [coffeeify --extension=".coffee"]
I also tried inserting the browserify transform into my package.json
"browserify: {
"transform": ["coffeeify", {"extension": ".coffee"}]
}
Here is something that works for me (took me forever to figure it out, the hard part being getting watchify to work with coffeescript). Everything is in the package.yaml. Invoke npm start from your top folder and it will do the trick. npm puts all the locally installed node binaries in your PATH for you (they normally live under node_modules/.bin).
{
"name": "my-package",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "(cd src; budo app.coffee:bundle.js --dir . --live --verbose -- --extension=.coffee | garnish)"
},
"browserify": {
"extension": [ ".coffee" ],
"transform": [ ["coffeeify"], ["brfs"] ]
},
"devDependencies": {
"brfs": "1.4.1",
"browserify": "11.1.0",
"budo": "^5.1.5",
"coffee-script": "latest",
"coffeeify": "^1.1.0",
"garnish": "^3.2.1",
"watchify": "3.4.0"
}
}
I have my source code under the src folder, and a file named app.coffee which includes (or require in node.js terms) my whole application. I have an index.html in my src folder which reference the bundle.js through from an html script tag.
The command to start budo is inside my package.json. It does cd into my src folder first.
The trick is to specify some configuration in the browserify block: the extension .coffee needs to be present, and a list of transforms as well. I tried to have everything on the command line but never got it to work
After npm start is invoked, since I pass the --live argument to budo everything works like magic and edit/saves to my documents do trigger a browser reload/refresh.
To deploy or release you'll probably need another target to minify with uglify.js. I still have a script that does that manually in 2 steps, the first step calls browserify and the second step calls uglify.js explicitely.
As a remark, recent version of budo do the piping into garnish for you I've heard.
Another tip is to look at what the React folks are doing to transform their .jsx files, as it is in theory extremely close to what the coffeescript folks need to do. There seems to be a huge momentum around React so hopefully React people will have figured those build problems first.