Yes!
When you want to deliver tools to your non-technical users without requiring them to install anything, you can put python into scm. In theory, you could setup some other tool and make them all install it so you can ensure that every time they sync they run pip install -r requirements.txt
and get all dependencies, but that's not always easy. If you're facing resistance to using python ("it's not compiled; everyone will have to install python"), then putting python in scm is the route for you!
If you were using Linux/Unix, you'd probably use the built-in package manager, so I'll assume you're using Windows. (Note: there are package managers for Windows like scoop, choco, and winget -- they're worth a look.)
You have two options for putting python in scm:
Read more about this package on why so many python installers.
If you want minimal python and to manually provide packages (no using pip),
this should be a good method. Theoretically, you can set yourself up to
install
packages
too. However, if you want any dev on your team to be able to install packages,
this is probably not a good option.
A regular python install. But we'll do things a bit different.
- Setup your scm ignores for
*.pyc
and __pycache__
- Install python to
C:\python3
- I was careful not to run python to avoid generating any temp files so they'd be easier to catch and ignore.
- Copy
C:\python3
into your project: c:\proj\tools\python3
- Uninstall python from
C:\python3
- this way your machine is just like your users. You can add the python in your project to your PATH or re-install python once you've confirmed everything works.
- Create a directory to hold your python modules:
c:\proj\tools\pymodules
- Create an empty
__init__.py
file in that folder: c:\proj\tools\pymodules\__init__.py
- Create a work.pth file with a relative path so python can find your python modules:
c:\proj\tools\python3\site-packages\work.pth
../../../pymodules
- Now commit everything.
- Run
python -m http.server 8000 --directory .
or some other python code so you can double check your ignores are correct.
Now you'll be able to use pip to install new packages and commit them to source control. If you create pymodules\work\__init__.py
(empty) and pymodules\work\example.py
:
print('Hello from example.py')
You can run it:
c:\proj\tools\python3\python.exe -m work.example
And import it:
import work.example
No messing with paths!
However, you likely need to ensure all of your users run python.exe directly and can't assume it's in their PATH. But since you know where it is in their project, that's not likely a problem. You can create one-click batch files that determine the path to python from their path:
%~dp0\..\..\python3\python.exe -m work.example
We've used something like this setup for years at my work and I recently set this up with the above steps on a new project. We have our project in svn and it works pretty well, but dumping this many files into git may be less desirable.