Introduction to aactivator
aactivator is a straightforward yet effective tool designed to automate the process of activating and deactivating a project's environment whenever users enter or exit a project directory. This project utility enhances the workflow by ensuring that the proper environment is set up when needed and cleaned up when the user is finished.
Key Features
aactivator offers several important features:
- User Prompting: It asks for user confirmation before sourcing directories that have not been used before.
- Security Checks: It refrains from sourcing files if they can be altered by external sources, ensuring the safety of your project's environment.
- Shell Compatibility: Provides robust support for both
bash
andzsh
shells. - Reliable Testing: aactivator is thoroughly tested with integration tests for both supported shells.
Additionally, aactivator is compatible with Python versions 2.7 and 3.4+, and does not require any external dependencies beyond the Python standard library.
aactivator Interface
To facilitate its functioning, aactivator uses two specific files placed at the root of the project directory:
-
.activate.sh
: This script is used by the shell upon entering the directory. For Python projects utilizing virtual environments, it is efficient to create a symbolic link from.activate.sh
to thebin/activate
file within the virtual environment (e.g.,ln -s venv/bin/activate .activate.sh
). This link can be safely checked into version control systems like Git, using relative paths. -
.deactivate.sh
: Executed when exiting the directory, typically containing a simpledeactivate
command, but it can be modified based on the project's needs.
It's important to note that these files do not need to be executable, nor do they need a shebang line, as they are sourced rather than executed.
Installation Process
To integrate aactivator into your workflow, it is recommended that you add it to your shell's configuration file, ensuring it remains unobtrusive during regular use. Here are the installation options:
- Direct Copy: Copy the
aactivator.py
script onto your system and make it executable usingchmod +x aactivator.py
. - Pip Installation: Use
pip install aactivator
to install it system-wide, to your home directory, or within a virtual environment. - Debian Package: Install the Debian package for system-wide automation, which includes additional features like a man-page, accessible from the releases section on GitHub.
Once installed, activate aactivator by adding the following line to your shell config file, .bashrc
for bash or .zshrc
for zsh:
eval "$(aactivator init)"
This setup will ensure that aactivator functions correctly upon logging in.
Why Use aactivator?
For large projects, automatically sourcing virtual environments is a major advantage. It allows seamless execution of tools like pytest
as well as enabling the project to register command-line tools for contributors' use.
Security Considerations
Security is a top priority for aactivator. It incorporates two main protections:
- User Confirmation: aactivator prompts users before sourcing directories, enabling them to decide on sourcing based on trust.
- File Security: It ensures that environment files cannot be modified by untrusted sources by checking file permissions from the directory to the filesystem boundary.
Alternatives
There are several alternative tools to aactivator, such as:
- autoenv
- virtualenv-auto-activate
- yourlabs's shell function
- direnv
Each of these alternatives lacks one or more features that aactivator provides, such as security checks, deactivation capability, or comprehensive shell support.
In conclusion, aactivator presents a robust solution for project environment management, ensuring both efficiency and security.