the anti-packaging system
Project description
sitepath - the anti-packaging system
When making an importable Python library, there needs to be a middle ground between:
- writing some code, and
- building a package that can publish to PyPI.
Your code's directory is a package already. No extra packaging is required.
Using sitepath along with pip can allow locally developed code to coexist with PyPI-available libraries.
Examples
The directory my_project has your Python code. Let's make it importable, work within virtual environments, and not need setup.py or pyproject.toml.
python -m sitepath symlink ./my_project
Done. It symlinked the directory to a user-writable site-packages directory.
If you don't want it importable anymore:
python -m sitepath unsymlink my_project
Done.
On Windows, you might get an error because symlinks are not supported unless you have special permissions. Instead, you can use:
python -m sitepath copy ./my_project
This creates a separate copy of your code in a user-writable site-packages directory.
If you want to remove it:
python -m sitepath uncopy my_project
If you like the using python setup.py develop or editable installs with pip install -e for development:
python -m sitepath develop ./my_project
This will add the given project path to my_project.sitepath.pth in a user-writeable site-packages directory.
If you want to stop developing:
python -m sitepath undevelop my_project
which will remove its .pth file from site-packages.
Installing
The sitepath anti-packaging system can bootstrap itself (assuming you have sitepath/ in your current working directory).
python -m sitepath copy sitepath
But if you really want it from PyPI:
pip install sitepath
Useful Features
Calling python -m sitepath prints out useful information about your Python (virtual) environment:
- relevant environment variables
- sys.executable
- sys.path
- user site-packages path
- active site-packages
- active
.pthfiles sitepathsymlinks/copies/develops
------------------------------------------------------------
sitepath
------------------------------------------------------------
VIRTUAL_ENV=/home/serwy/venv-py/iso
sys.executable = '/home/serwy/venv-py/iso/bin/python'
sys.path = [
'/home/serwy',
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/home/serwy/venv-py/iso/lib/python3.10/site-packages',
]
USER_SITE: '/home/serwy/.local/lib/python3.10/site-packages' (exists)
ENABLE_USER_SITE: False
Active site-packages:
/home/serwy/venv-py/iso/lib/python3.10/site-packages
Active .pth files:
/home/serwy/venv-py/iso/lib/python3.10/site-packages/distutils-precedence.pth
sitepath-symlinked packages: 1 found
/home/serwy/venv-py/iso/lib/python3.10/site-packages/sitepath --> /home/serwy/gitea/my-sitepath/sitepath
sitepath-copied packages: 0 found
sitepath-developed packages: 0 found
Available Commands
To see the list of commands:
python -m sitepath help
They are:
symlink [directory]unsymlink [name]copy [directory]uncopy [name]develop [directory]undevelop [name]info [names/directories]list [symlinks, copies, develops]mvp [name]help
Batch Processing
The -r <file> argument can be used to batch process a list of directories in a file and works for almost all commands. Blank lines and comment lines starting with # are ignored.
The list of linked/copied/developed packages can be saved:
python -m sitepath list copies > sitepath-copies.txt
and then re-loaded in a different virtual environment:
python -m sitepath copy -r sitepath-copies.txt
To uncopy the packages:
python -m sitepath uncopy -r sitepath-copies.txt
For the un* commands, -r requires that the path from the provided file matches the existing state found in the crumb, otherwise a mismatch failure occurs.
Using -nr will use the package name implied by each directory/file path and batches that instead. This ignores mismatched directory errors that may occur when using unlink/uncopy/undevelop.
Minimum Viable Packaging
If you want to have an initial pyproject.toml, use the mvp command and redirect
its output:
python -m sitepath mvp my_project > pyproject.toml
This pyproject.toml file should NOT be used to distribute the project on PyPI. It's missing many fields that should be completed first.
Commentary
Develop and .pth files
The preferred method is to use symlink instead of develop, if your platform permits it.
The develop command takes its name from the setuptools interface. It works by adding the parent directory containing your code to sys.path. On Python startup, the site module finds site-packages/*.pth files, which includes easy-install.pth populated by setuptool's develop command.
The downside of using develop (from setup.py and from sitepath) is that everything in the path is potentially top-level importable. This is a consequence of using .pth files.
Modifying site-packages
Commands that modify a site-packages directory leave a [package].sitepath crumb file for each package it copies/links, and this crumb is needed to modify or remove an existing package. This crumb distinguishes sitepath packages from everything else.
Building, Packaging and Distribution
Using sitepath removes the need of dealing with the tedious minutia of PyPA packaging requirements from early development stages. In time, more packaging may be needed, or sitepath may be adequate for your needs, especially for internally developed code without an internal package repository.
Symbolic Links
Unix, Linux, and MacOS have had symbolic links for decades, available without needing special privileges. While Windows has support for symbolic links, using them requires privileged permissions because of the implications of that platform's legacy design choices.
See Also:
- Standard Library:
- Packaging:
- Symlinks on Windows:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sitepath-0.4.0-py3-none-any.whl.
File metadata
- Download URL: sitepath-0.4.0-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c3ae0e474ab1a13bc83bf6fda9b24aead091db00341d998c9992c16cfa0080d
|
|
| MD5 |
ac33cc32714d673094f4284b7ce39e50
|
|
| BLAKE2b-256 |
d7eb221e3e400e6b00c7a19884a4361d45138e93b78f6705da74972d9b4bee0e
|