Install additional packages in vscode dev container - visual-studio-code

I am using vscode as an editor. Using vscode ctrl+shift+p to open up the command pallet and used "Dev Containers: Create Dev container" to create a development container, And it created only one file .devcontainer/devcontainer.json .
{
"name": "Debian",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"features": {
"ghcr.io/devcontainers/features/docker-from-docker:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/go:1": {},
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/guiyomh/features/golangci-lint:0": {}
}
}
But I would like to install few other packages like jinja2-cli after installation of python/pip3 package mentioned in the features or may be install other OS related packages.
Where should packages should be specified ?

Check that this line is included in your devcontainer.json
"postCreateCommand": "pip3 install --user -r requirements.txt",
Then create a requirements.txt file on the same level as you .devcontainer folder (not inside of it, outside).
If you add a package name to the requirements.txt file, it'll be added to the devcontainer at build time.
You can see an example in this pull request I recently completed which needed a new package and I had to add it to my devcontainer in the last commit.
Side note: You'll see that I also updated my poetry.lock file in a previous commit (using the poetry add package-name in the command line) because that project uses poetry for package management too. You don't need to do that if you aren't using poetry.

Related

How to install vscode extension that is being developped locally from an unpacked directory

I am developping a VSCode extension that I want to try it out in the current VSCode instance, not in a new instance.
Is there a way to install the vscode extension that is developping locally from an unpacked directory, not from a .vsix file.
In Atom editor, I can use atom link to do that. Is there something similar in VSCode?
You can install the extension locally with code --install-extension and install a locally packaged extension. I am doing this with esbuild and yarn:
package.json
"scripts": {
"vscode:prepublish": "yarn run build:base --minify",
"build:base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node",
"build": "yarn build:base --sourcemap",
"package": "mkdirp dist && vsce package -o dist/noteberry.vsix --yarn",
"deploy:local": "yarn package && code --install-extension dist/ext.vsix --force"
...
},
mkdirp is an npm module to create folders.
Original Post
One easy solution without packaging as described in https://vscode-docs.readthedocs.io/en/stable/extensions/install-extension/ would be:
VS Code looks for extensions under your extensions folder
.vscode/extensions. Depending on your platform it is located:
Windows %USERPROFILE%\.vscode\extensions
Mac $HOME/.vscode/extensions
Linux $HOME/.vscode/extensions
If you want to load your extension or customization each time VS Code
runs, copy your project to a new folder under .vscode/extensions.
You could write a script to delete / copy over all files.

Equivalent of `python setup.py develop` in poetry

With setuptools, I could use python3 setup.py develop and my development directory could be found by python3 without setting PYTHONPATH or running install. Any change in the current development directory is immediately available without running python3 setup.py develop/install again. This saves quite a lot of time during the development.
Is there a poetry equivalent?
Update There is a feature request https://github.com/python-poetry/poetry/issues/1214
In poetry, the main project is installed as editable by default:
The current project is installed in editable mode by default.
-- Section "Installing dependencies only" of Poetry's documentation
It is also possible to install some dependencies as editable alongside the main project in the same virtual environment. For example:
[tool.poetry.dependencies]
Library = { path = "../Library/", develop = true }

vscode tests discovery with poetry (src layout)

Last time I've followed recommended src layout (https://hynek.me/articles/testing-packaging/) with using tox with great success.
However VSCODE tests discovery fails because src package cannot be imported. That is expected as we want to test installed package.
But how to debug my tests in vscode?
(Q author here: I've done research on that before posting the question, so sharing what I found)
Not solution
You could modify your PYTHONPATH to point to your src directory, but it breaks the main benefit from having separate src directory (read the link from OP).
Solution
Use pip install -e path/to/your/package (usually pip install -e .) to enable development mode and test versus your codebase as it would be installed.
After that your tests should be discovered properly. Otherwise it is different issue - read vs code OUTPUT console.
Note: this requires setup.py as a build backend
workaround for poetry
pyproject.toml
[build-system]
requires = [
"poetry-core>=1.0.0",
"setuptools" # to support local installations
]
then
poetry build --format sdist && tar --wildcards -xvf dist/*.tar.gz -O '*/setup.py' > setup.py
pip install -e .
Source: https://github.com/python-poetry/poetry/issues/34
TLDR: proper solution is outside of poetry scope, links to python-list discussions: https://github.com/python-poetry/poetry/issues/34#issuecomment-732478605

How do I Install a vscode plugin in Theia directly from a git repo?

I would like to install a VScode plugin in Theia. It works when I install by specifying the download location of the VSixPackage. Snippet of the package.json file:
.....
"scripts": {
"postinstall": "download-debug-adapters"
},
"adapterDir": "plugins",
"adapters": {
"vscode-cortex-debug": "https://marus25.gallery.vsassets.io/_apis/public/gallery/publisher/marus25/extension/Cortex-Debug/0.3.1/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
},
.....
There is a fork of the extension that has some features I require. How do I install a VSCode extension directly from a git repo, eg.: https://github.com/Marus/cortex-debug

The package is not available in a stable-enough version according to your minimum-stability setting

I don't really understand how Composer works with the minimum-stability setting.
I have two packages. Let's say, PackageA and PackageB.
The composer.json file of PackageA looks like this:
{
"name": "vendor/packagea",
"minimum-stability": "dev",
"require": {
"vendor/packageb": "dev"
}
}
So PackageA requires PackageB. The json of PackageB looks like this:
{
"name": "vendor/packageb",
"minimum-stability": "dev"
}
So both say minimum stability are dev. So I assume that when I do:
composer create-project vendor/packagea
But then it complains with the message:
[InvalidArgumentException]
Could not find package vendor/packagea with stability stable.
Which I find strange, because I would assume that setting the minimum stability to dev would pull the package from its "development" branch. Which in the case of github is always dev-master.
So I tried to install it by telling composer what branch to use:
composer create-project vendor/packagea testFolder dev-master
But then it complains that it can't find PackageB:
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package vendor/packageb dev could not be found.
Then how am I able to install my package? I'm still developing so I dont want to create a release for PackageA and PackageB yet...
There are two issues:
In create-project, by default the command uses the stable stability to look for the package to install, that's why it works if you specify dev-master but not by default. You could however also run composer create-project vendor/packagea -s dev
After while installing dependencies, I'm guessing that your package does not exist in a version just called dev, so it can't find it if you require it like that. Requiring dev-master would probably work, like:
{
"name": "vendor/packagea",
"minimum-stability": "dev",
"require": {
"vendor/packageb": "dev-master"
}
}
How did I fix this?
After installing Composer, run the following command to install the Composer Asset Plugin:
php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
Now choose one of the application templates to start installing Yii 2.0. An application template is a package that contains a skeleton of the Web application written in Yii.