Visual Studio Code and subfolder-specific settings - visual-studio-code

My workspace root is a git repository containing couple of files and several git submodules. Each submodule have their own .vscode/settings.json. I was expecting VSCode to adjust its settings based on which submodule/subfolder I'm working in but it's not working as expected.
Is it possible?
I think it's possible if you use a multi-root workspace (which is supported since 1.18), but in my case I'd like to keep that single-root workspace.

I also couldn't find a decent answer for this, I did find an "hacky" workaround. I have the following project structure:
.
├── apps
│   ├── api
│   │   ├── Dockerfile
│   │   ├── .gitignore
│   │   ├── hhapi
│   │   ├── manage.py
│   │   ├── .pylintrc
│   │   ├── requirements.txt
│   │   ├── venv
│   │   └── .vscode
│   └── crawler
│   ├── crawler-crontab
│   ├── Dockerfile
│   ├── .gitignore
│   ├── hhcrawler
│   ├── .pylintrc
│   ├── requirements.txt
│   ├── .scrapy
│   ├── scrapy.cfg
│   ├── venv
│   └── .vscode
├── docker-compose.development.yml
├── docker-compose.production.yml
├── .gitignore
├── .gitlab-ci.yml
├── househunter.code-workspace
└── .vscode
└── settings.json
What I ended up doing was ignoring the apps directory on the project root and then add both apps to the workspace.
So the ./.vscode/settings.json looks like this:
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"apps": true
},
}
And the househunter.code-workspace file like so:
{
"folders": [
{
"path": "apps/api"
},
{
"path": "apps/crawler"
},
{
"name": "root",
"path": "."
}
],
"settings": {}
}
This is what I see on the editor:
And it is indeed following the subprojects settings.json. This is far from being a great solution, but for the time being was the only way I found to achieve this - I'd also love to see someone document a proper solution for this. :)

At the time of writing the feature is just not implemented. There's a feature request in the program's issue tracker filed on 17 August 2017: Monolithic structure, multiple project settings #32693.
Meanwhile, if you need it badly you have to abuse multi-root workspaces as described in Diogo's answer.

Related

Using GitHub Actions in a Single Repository with Multiple Projects

I am fairly competent in using GitHub actions to build a variety of languages, orchestrate deployments, and I've even done cross-repository actions using web-hooks, so I'd say that I'm pretty familiar with working with them.
I often find myself doing a lot of scratch projects to test out an API or making a demo, and these don't usually merit their own repositories, but I'd like to save them for posterity, rather than just making Gists out of them, Gists being largely impossible to search. I'd like to create a scratch repository, with folders per language, like:
.
└── scratch
├── go
│   ├── dancing
│   │   ├── LICENSE-APACHE
│   │   ├── LICENSE-MIT
│   │   ├── main.go
│   │   └── README.md
│   ├── gogettur
│   │   ├── LICENSE-APACHE
│   │   ├── LICENSE-MIT
│   │   ├── main.go
│   │   └── README.md
│   └── streeper
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── main.go
│   └── README.md
├── node
│   └── javawhat
│   ├── index.js
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   └── README.md
└── rust
├── logvalanche
│   ├── Cargo.toml
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── README.md
│   └── src
├── streamini
│   ├── Cargo.toml
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── README.md
│   └── src
└── zcini
├── Cargo.toml
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
└── src
I'd like to generalize GitHub actions per language, for Go, use go test ./... and go build, for Rust cargo test and cargo build, etc.
I know that what I could do is have a workflow for each created project, but this would be tedious, I'd end up copying and pasting most of the time, and every build would run on every change in the entire repository, and I don't want to be building node/javawhat if only rust/zcini has changed.
Therefore I have a few questions:
Is it possible to have a workflow only run when certain files have changed, rather than running everything every single time?
Is there a way to generalize my workflows so that every dir in rust/ uses the same generic workflow, or will I need one workflow per project in the repository?

Importing json resources inside .pex (Python Executable (format by Twitter))

I'm using a Twitter engineered build tool pants to manage many projects inside my monorepo. It outputs .pex files when I complete a build, this is a binary that packages the bare minimum dependencies I need for each project and makes them a "binary" (actually an archive that's decompressed at runtime), my issue is a utility that my code has used for a long time fails to detect some .json files(now that I'm using pants) I have stored under my environments library. all my other code seems to run fine. I'm pretty sure it has to do with my config, perhaps I'm not storing the resources properly so my code can find it, though when I use unzip my_app.pex the resources I desire are in the package and located in the proper location(dir). Here is the method my utility uses to load the json resources:
if test_env:
file_name = "test_env.json"
elif os.environ["ENVIRONMENT_TYPE"] == "PROD":
file_name = "prod_env.json"
else:
file_name = "dev_env.json"
try:
json_file = importlib.resources.read_text("my_apps.environments", file_name)
except FileNotFoundError:
logger.error(f"my_apps.environments->{file_name} was not found")
exit()
config = json.loads(json_file)
here is the the BUILD file I use for these resource currently:
python_library(
dependencies=[
":dev_env",
":prod_env",
":test_env"
]
)
resources(
name="dev_env",
sources=["dev_env.json"]
)
resources(
name="prod_env",
sources=["prod_env.json"]
)
resources(
name="test_env",
sources=["test_env.json"]
)
and here is the BUILD file for the utility that calls these resources of which the python code above is what you saw:
python_library(
name="environment_handler",
sources=["environment_handler.py"],
dependencies=[
"my_apps/environments:dev_env",
"my_apps/environments:prod_env",
"my_apps/environments:test_env"
]
)
I always get an FileNotFoundError exception and I'm confused because the files are available to the runtime, what's causing these files to not be accessible? and is there a different format I need to set up the JSON resources as?
Also for context here is the decompressed .pex file(actually just the source-code dir):
├── apps
│   ├── __init__.py
│   └── services
│   ├── charts
│   │   ├── crud
│   │   │   ├── __init__.py
│   │   │   └── patch.py
│   │   ├── __init__.py
│   │   └── main.py
│   └── __init__.py
├── environments
│   ├── dev_env.json
│   ├── prod_env.json
│   └── test_env.json
├── __init__.py
├── models
│   ├── charts
│   │   ├── base.py
│   │   └── __init__.py
│   └── __init__.py
└── utils
├── api_queries
│   ├── common
│   │   ├── connections.py
│   │   └── __init__.py
│   └── __init__.py
├── calculations
│   ├── common
│   │   ├── __init__.py
│   │   └── merged_user_management.py
│   └── __init__.py
├── environment_handler.py
├── __init__.py
├── json_response_toolset.py
└── security_toolset.py
I figured it out: I changed the way I access the files within the library and it works perfectly before and after the build to .pex format. I used:
import pkgutil
#json_file = importlib.resources.read_text("my_apps.environments", file_name)
json_file = pkgutil.get_data("my_apps.environments", file_name).decode("utf-8")

Is there a way to flatten or merge single-folder folders in vs code explorer?

I don't know if there's a name for this kind of behavior.
I've seen it in IntelliJ, where single-folder folders are unified or flattened in the project tree pane, where instead of:
.
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │   └── somepkg
│   │   │   └── coreapi
│   │   │   ├── controllers
│   │   │   │   ├── AssetMutations.java
│   │   │   │   ├── HomeController.java
│   │   │   │   └── SessionsQuery.java
│   │   │   ├── CoreApiApplication.java
You see:
.
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com.somepkg.coreapi
│   │   │   ├── controllers
│   │   │   │   ├── AssetMutations.java
│   │   │   │   ├── HomeController.java
│   │   │   │   └── SessionsQuery.java
│   │   │   ├── CoreApiApplication.java
Is there a way to make vs code tree-view file explorer to show subfolders this way?
It looks like it is in the iteration plan for June, 2019.
See Iteration plan for June, 2019: release in July, 2019 and issue: merging single child directories.
Update: making it into v1.41 to be released in December, 2019. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_41.md#compact-folders-in-explorer
Compact folders in Explorer
In the File Explorer, we now render single child folders in a compact
form. In such a form, single child folders will be compressed in a
combined tree element. Useful for Java package structures, for
example.
Setting explorer.compactFolders controls this behavior. By default,
this setting is turned on.
So "explorer.compactFolders": false, will disable the feature.

How to include images in a jekyll project hosted on github?

I'm building a blog using jekyll and hosting it on github with gh-pages. The root of my project can be see seen below:
├── LICENSE
├── README.md
├── _config.yml
├── _img
│   ├── 2016-09-09\ 14.48.20.png
│   └── 2016-09-09\ 15.25.09.png
.
.
.
├── _posts
│   ├── 2016-09-08-seven-weeks-before-applying-to-devops-job.markdown
│   └── 2016-09-09-an-hour-with-ansible.md
.
.
.
├── _site
│   ├── 2016
│   │   └── 09
│   │   ├── 08
│   │   │   └── seven-weeks-before-applying-to-devops-job.html
│   │   └── 09
│   │   └── an-hour-with-ansible.html
│   ├── LICENSE
│   ├── README.md
│   ├── about
│   │   └── index.html
│   ├── css
│   │   └── main.css
│   ├── feed.xml
│   └── index.html
├── about.md
├── css
│   └── main.scss
├── feed.xml
└── index.html
The documentation gives the following example:
Because of Jekyll’s flexibility, there are many solutions to how to do this. One common solution is to create a folder in the root of the project directory called something like assets or downloads, into which any images, downloads or other resources are placed. Then, from within any post, they can be linked to using the site’s root as the path for the asset to include. Again, this will depend on the way your site’s (sub)domain and path are configured, but here are some examples (in Markdown) of how you could do this using the site.url variable in a post.
Including an image asset in a post:
... which is shown in the screenshot below:
![My helpful screenshot]({{ site.url }}/assets/screenshot.jpg)
I've tried several different ways but non are working once I push gh-pages up:
![]({{ site.github.url }}/_img/2016-09-09 14.48.20.png)
![]({{ site.url }}/_img/2016-09-09 15.25.09.png)
I've also tried "keeping" the _img directory by putting the following in my _config.yaml
# Build settings
markdown: kramdown
keep_files: ["_img"]
But this also is not working. So how do I include images in a jeykll project hosted on github?
Thanks for your help :)
Every folder beginning with an underscore won't be copied to the build destination. The most common way is to store images is to add them to a assets/img folder.
If you want to use _img you have to add to your _config.yml:
include:
- "_img"
Create a folder for your images, you can name it according to your wish (mine is "images")
Find the image address of that image that you want to include in your post
(You can do that by going to your folder image and right click on your image, then copy image address)
Now you use that address in your post without any problem.

How should I download specific file type from folder (and ONLY it's subfolders) using wget or httrack?

I'm trying to use HTTrack or Wget do download some .docx files from a website. I want to do this only for a folder and it's subfolders. Ex: www.examplewebsite.com/doc (this goes down 5 more levels)
How would be a good way to do this?
The previous proposed answer is ludicrous considering the "spider" option has ALWAYS specifically NOT DOWNLOADED, but instead followed.
Better late than never, but here is the command you seek to both mirror the desired file extension files locally, but then as a bonus pull down the target html and auto-adjust it so that if you open it locally and click the links, they will have been altered and adjusted accordingly to now point to the local drive.
wget -e robots=off -r -k -A docx,doc "https://<url>"
If this works for you, I would appreciate the answer points!
You can use --spider with -r (recursive option ) and have --accept to filter the files of your intrest
wget --spider -r --accept "*.docx" <url>
Usage
wget -r -np -A pdf,doc https://web.cs.ucla.edu/~harryxu/
Result
tree
└── web.cs.ucla.edu
├── ~harryxu
│   ├── papers
│   │   ├── chianina-pldi21.pdf
│   │   ├── dorylus-osdi21.pdf
│   │   ├── genc-pldi20.pdf
│   │   ├── jaaru-asplos21.pdf
│   │   ├── jportal-pldi21.pdf
│   │   ├── li-sigcomm20.pdf
│   │   ├── trimananda-fse20.pdf
│   │   ├── vigilia-sec18.pdf
│   │   ├── vora-asplos17.pdf
│   │   ├── wang-asplos17.pdf
│   │   ├── wang-osdi18.pdf
│   │   ├── wang-osdi20.pdf
│   │   ├── wang-pldi19.pdf
│   │   └── zuo-eurosys19.pdf