Skip to content

A zero-dependency script skeleton for bootstrapping a developer's environment for an existing Python project

License

Notifications You must be signed in to change notification settings

JerilynFranz/python-env-bootstrap

Repository files navigation

python-env-bootstrap

A zero-dependency script skeleton for robustly bootstrapping a developer's environment for onboarding to an existing Python project.

Who is this for?

This is for Python project maintainers who want to make it as easy as possible for new developers to get their development environment setup and ready to go with as little friction as possible.

Overview

Designed to work with Python 3.8 or later, it handles the bootstrapping of the tooling and modules environment for developing in a project without any dependencies except for Python's built-in libraries and network access.

It automatically creates a virtual environment and installs all required PyPI modules into that virtual environment while handling common issues such as platform, Python version, and pip version differences.

New in recent versions:

  • VCS Hook Installation: The script can automatically detect and install pre-commit hooks for both Git and Mercurial repositories. This helps ensure that code quality checks or other automated actions are run before each commit, improving consistency and reducing manual setup for contributors. The hook scripts are expected to be located in a hooks/ directory at the root of the project, but this can be customized as needed.
  • PowerShell Execution Policy Support: On Windows, the script can detect if it is running in a PowerShell environment and will attempt to set the execution policy as needed to allow activation scripts to run. This reduces friction for Windows users and helps avoid common activation issues.

Note

It DOES NOT setup a new project

It is NOT for creating a new Python project - it is just for onboarding a developer to an existing project quickly and easily.

Customization and Usage

You use it by copying the standalone bootstrap script into your own project's repository and updating the POST_INSTALL_MESSAGE string, the TOOL_USAGE_INSTRUCTIONS string, and the BOOTSTRAP_MODULES list of InstallSpec instances to match your project's PyPI modules environment requirements.

There are currently two versions of the script provided:

It has no external dependencies except that it requires at least the specified version of Python and network access to PyPI.

To setup an environment you just run

python3 bootstrap.py

with the appropriate path to the script.

It has sensible defaults for virtual environment location, module versions, and other settings but you can customize them by modifying the constants at the top of the script.

It has the following command-line options: - -h, --help : Show help message and exit. - --yes, -y : Automatically confirm and proceed without prompting. - --debug : Enable debug output. - --no-debug : Disable debug output. - -q, --quiet : Suppress non-error output. - -v, --verbose : Enable verbose output (default). - --force-hooks : Force (re)installation of VCS hooks, even if they already exist.

VCS Hooks: If your project uses Git or Mercurial, the script will attempt to install pre-commit hooks automatically. You can customize the hook scripts or disable this feature as needed.

PowerShell Support: On Windows, the script will attempt to set the PowerShell execution policy to allow activation scripts to run, reducing setup issues for Windows users.

That's it. That's everything.

The copy of the script here is configured to install tox and uv but you can easily use it to setup anything installable via pip.

Note

If you use it to install uv, it will bootstrap uv first and use it to install everything else much faster than pip does (highly recommended).

It does not try to be a build system or a project kickstarter. It does one thing and does it pretty well: Get the environment for the developer up and running. If you need additional things done such as running post-environment install actions, they are easily added to it using the 'run_command' function so as to keep the 'one-stop-setup' vibe.

Why not just use pip -r requirements.txt?

This script is not trying to replace pip or requirements.txt files. It is trying to complement them (not replace them) by providing a zero-dependency, frictionless way to get a developer's environment set up and ready to go with minimal effort.

It is designed to be a single script that you can run to get everything set up without having to worry about whether pip is installed, whether the right version of Python is being used, whether the virtual environment is activated, whether the right platform-specific issues are handled, installation order of dependencies, etc. It works with requirements.txt files under the hood if you want to use them, but it abstracts away all the common issues that come up when setting up a Python development environment.

I like the 'run just one thing' approach to completely setup a developer's environment.

This script handles a lot of the common issues that come up when setting up a Python development environment such as:

  • Creating and managing a virtual environment automatically
  • Handling platform differences (Windows vs Unix-like)
  • Handling different Python versions
  • Ensuring pip is up to date before installing anything
  • Optionally using uv to speed up installations
  • Providing clear and actionable error messages when things go wrong
  • Customizable post-install messages and instructions
  • Minimal dependencies (only requires Python 3.8+)

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests on the GitHub repository.

To initialize a development environment for contributing to this project, clone the repository, change to the repository directory, run the bootstrap.py script and then activate the created virtual environment:

git clone https://github.com/JerilynFranz/python-env-bootstrap
cd python-env-bootstrap
python3 bootstrap.py
source venv/bin/activate  # On Windows use `env\Scripts\activate`

Yes. It's that simple.

About

A zero-dependency script skeleton for bootstrapping a developer's environment for an existing Python project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published