Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-building Python Package with postCreateCommand, fails in Github CodeSpaces #10686

Open
oliverangelil opened this issue Feb 7, 2025 · 3 comments
Assignees
Labels
containers Issue in vscode-remote containers

Comments

@oliverangelil
Copy link

oliverangelil commented Feb 7, 2025

When opening my repo in CodeSpaces, I'm getting a Permission denied error after invoking a bash script to run using postCreateCommand.
My overarching goal is to not have to manually type commands every time after the container has started, to build the Python Package (I want this to be able to run tests in the CodeSpaces terminal with pytest, and also have all the dependencies installed):

The commands I have to type out on every new instance of CodeSpace are:

uv venv myenv
source myenv/bin/activate

uv pip install -e .

My pyproject.toml looks like:

[project]
name = "GenAI-Linkedin-PostWriter"
version = "0.1.0"
license = {file = "LICENSE"}
description = "GenAI LinkedIn Post Writer"
readme = "README.md"
requires-python = ">=3.12"

dependencies = [
    "numpy>=2.2.2",
    "pyright>=1.1.393",
    "pytest>=7.4.3",
    "ruff>=0.9.5",
]

[project.optional-dependencies]
test = [
    "ruff>=0.9.5",
    "pytest>=7.4.3",
    "pytest-cov>=4.1.0",
]

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["."]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.uv]
package = true

And my .devcontainer.json like:

{
	"name": "Python 3",
	// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
	"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",
	"features": {
		// "ghcr.io/jsburckhardt/devcontainer-features/ruff:1": {},
		"ghcr.io/va-h/devcontainers-features/uv:1": {}
		// "ghcr.io/hspaans/devcontainer-features/pytest:1": {},
	},
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],

	// Use 'postCreateCommand' to run commands after the container is created.
	"postCreateCommand": "./.devcontainer/postCreateCommand.sh",

	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
	  	// Add the IDs of extensions you want installed when the container is created.
	  		"extensions": [
				"github.copilot",
				"charliermarsh.ruff",
				"github.vscode-github-actions",
				"ms-python.vscode-pylance"
	  		]
		}
  	},
}

And /.devcontainer/postCreateCommand.sh, like:

uv venv myenv
source myenv/bin/activate

uv pip install -e .

And the code spaces creation log:

2025-02-07 21:52:54.935Z: ./.devcontainer/postCreateCommand.sh
2025-02-07 21:52:55.392Z: /bin/sh: 1: ./.devcontainer/postCreateCommand.sh: Permission denied
2025-02-07 21:52:55.579Z: postCreateCommand failed with exit code 126. Skipping any further user-provided commands.

2025-02-07 21:52:55.588Z: Error: Command failed: /bin/sh -c ./.devcontainer/postCreateCommand.sh

@vs-code-engineering vs-code-engineering bot added the containers Issue in vscode-remote containers label Feb 7, 2025
@joshspicer
Copy link
Member

joshspicer commented Feb 7, 2025

Could you confirm that your script file is marked as executable?

You can do that by running chmod +x .devcontainer/postCreateCommand.sh on the script file, committing that change into your repo, and then try creating a new codespace.

@oliverangelil
Copy link
Author

oliverangelil commented Feb 8, 2025

Thanks @joshspicer - where in the repo would I put chmod +x .devcontainer/postCreateCommand.sh? Maybe as a onCreateCommand or updateContentCommand before the postCreateCommand (ref)?

@oliverangelil
Copy link
Author

oliverangelil commented Feb 8, 2025

I actually tried what you said and it worked... the venv myenv has been created.

I didn't expect that running chmod +x .devcontainer/postCreateCommand.sh interactively would persist in code to the next CodeSpaces session.

Although myenv has been created; the source command has been used to activate the venv; and the packages have been installed with uv pip install -e ., when I access the bash terminal in CodeSpaces, the venv myenv is not activated in the session. I have to then type source myenv/bin/activate

I thought the bash script already activated it? Is there a separate way to get some commands to run for the bash terminal to activate the venv automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Issue in vscode-remote containers
Projects
None yet
Development

No branches or pull requests

3 participants