Package: sitepath
sitepath - the anti-packaging systemWhen making an importable Python library, there needs to be a middle ground between:writing some code, andbuilding a package that can publish to PyPI.Your code's directoryisa package already. No extra packaging is required.Usingsitepathalong withpipcan allow locally developed code to coexist with PyPI-available libraries.ExamplesThe directorymy_projecthas 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_projectDone. It symlinked the directory to a user-writable site-packages directory.If you don't want it importable anymore:python -m sitepath unsymlink my_projectDone.On Windows, you might get an error because symlinks are not supported unless you havespecial permissions.Instead, you can use:python -m sitepath copy ./my_projectThis 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_projectIf you like the usingpython setup.py developor editable installs withpip install -efor development:python -m sitepath develop ./my_projectThis will add the given project path tomy_project.sitepath.pthin a user-writeable site-packages directory.If you want to stop developing:python -m sitepath undevelop my_projectwhich will remove its.pthfile from site-packages.InstallingThesitepathanti-packaging system can bootstrap itself (assuming you havesitepath/in your current working directory).python -m sitepath copy sitepathBut if you really want it from PyPI:pip install sitepathUseful FeaturesCallingpython -m sitepathprints out useful information about your Python (virtual) environment:relevant environment variablessys.executablesys.pathuser site-packages pathactive site-packagesactive.pthfilessitepathsymlinks/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 foundAvailable CommandsTo see the list of commands:python -m sitepath helpThey are:symlink [directory]unsymlink [name]copy [directory]uncopy [name]develop [directory]undevelop [name]info [names/directories]list [symlinks, copies, develops]mvp [name]helpBatch ProcessingThe-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.txtand then re-loaded in a different virtual environment:python -m sitepath copy -r sitepath-copies.txtTo uncopy the packages:python -m sitepath uncopy -r sitepath-copies.txtFor theun*commands,-rrequires that the path from the provided file matches the existing state found in the crumb, otherwise a mismatch failure occurs.Using-nrwill 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 PackagingIf you want to have an initialpyproject.toml, use themvpcommand and redirect
its output:python -m sitepath mvp my_project > pyproject.tomlThispyproject.tomlfile should NOT be used to distribute the project on PyPI.It's missing many fields that should be completed first.CommentaryDevelop and .pth filesThe preferred method is to usesymlinkinstead ofdevelop, if your platform permits it.Thedevelopcommand takes its name from the setuptools interface. It works by adding the parent directory containing your code tosys.path. On Python startup, thesite modulefindssite-packages/*.pthfiles, which includeseasy-install.pthpopulated by setuptool's develop command.The downside of usingdevelop(from setup.py and from sitepath) is that everything in the path is potentially top-level importable. This is a consequence of using.pthfiles.Modifying site-packagesCommands that modify a site-packages directory leave a[package].sitepathcrumb 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 DistributionUsingsitepathremoves 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 LinksUnix, 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:https://docs.python.org/3/library/site.htmlPackaging:https://packaging.python.org/en/latest/tutorials/packaging-projects/https://docs.python.org/3/distributing/index.html#publishing-python-packageshttps://packaging.python.org/en/latest/guides/tool-recommendations/#packaging-tool-recommendationsSymlinks on Windows:https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-linkshttps://docs.python.org/3/library/os.html#os.symlink