Python¶
Here we refer to a "script" as a single file containing Python code, whereas a "package" refers to a directory tree containing an __init__.py
along with one or more files containing Python code.
Package a script¶
Given the following directory structure:
Initialize the flox
project with flox init
:
If the directory containing my_script.py
isn't already a git repository, flox init
will prompt you to initialize the git repository as well.
Commit the script to the git repository before continuing.
Next add a setup.py
.
A minimal setup.py
is shown below:
from setuptools import setup, find_packages
setup(
name='my_script',
version='1.0.0',
url='https://github.com/mypackage.git',
author='Author Name',
author_email='[email protected]',
description='Description of my package',
packages=find_packages(),
install_requires=['numpy >= 1.11.1', 'matplotlib >= 1.5.1'], # (1)!
entry_points={
'console_scripts': [
'my_script = my_script:my_func', # (2)!
]
},
py_modules = ['my_script'] # (3)!
)
- This is where you add your version requirements.
- This is how you make your script executable without
python3 my_script.py
. Themy_script
on the left side of=
is the name of the command, andmy_script:my_func
is<name of your script>:<function to call when executed>
. - This line contains the name of your script without the extension. It's required since the project is a single file and doesn't have an
__init__.py
.
This setup.py
is intentionally sparse to add as little overhead as possible to packaging your script.
The final step is to commit setup.py
to the git repository.
You should now be able to flox build
and call the command my_script
in result/bin/
.
If you see an error about a missing setup.py
, ensure that you've committed setup.py
before running flox build
.
Package a project¶
Given the following directory structure:
Initialize the flox
project with flox init
:
If the directory containing my_project
isn't already a git repository, flox init
will prompt you to initialize the git repository as well.
Commit the package to the git repository before continuing.
If you're using a Python project manager like poetry
, you'll need to create a setup.py
.
The setup.py
in the "Package a script" example is intentionally barebones and won't work with full Python packages.
See the setuptools documentation for details on how best to create your setup.py
.
The final step is to commit setup.py
to the git repository.
You should now be able to flox build
and examine the built project in result/bin
.
If you see an error about a missing setup.py
, ensure that you've committed setup.py
before running flox build
.