C. Packaging basics - Hjorthmedh/Snudda GitHub Wiki

Modules

In order to create a package we will need a directory that Python can treat as a module.

Any directory with a file called __init__.py is a module. When you use import my_module Python will look through several directories for module folders named my_module and execute the __init__.py script in it.

We can use this to our advantage in snudda/__init__.py to import any important objects we want to be available to our users under snudda. such as snudda.Snudda. The collection of objects available in our root namespace is usually referred to as our public API.

We want a clean and easily understood well documented public API and command line interface. (good argparse help messages & snudda help etc)

Any python file in a module directory will be treated as a submodule. So a function example_function in snudda/file.py will be importable through from snudda.file import example_function.

Packages

We can use setuptools to package this neat collection of python files that users can import and distribute it on https://pypi.org. By uploading our package there users can install it with pip install snudda.

I created the file setup.py for you so that you can run this command to make new versions:

python3 setup.py sdist bdist_wheel

This will generate a wheel file in the dist folder. You'll need to register for an account on pypi. You can then use twine to upload it:

twine upload dist/<name-of>.whl
⚠️ **GitHub.com Fallback** ⚠️