Skip to content

CreatePythonProject

Rob Nagler edited this page Sep 13, 2024 · 9 revisions

Create a New Python Project at RadiaSoft

PyKern automates the creation of a Python module or library that will be ready for use with PyPI, Read The Docs and related services.

Here are simplified instructions for RadiaSoft projects.

You must have pykern installed so pip install pykern if you don't have it installed.

Create a GitHub repository with no files, e.g. radiasoft/rsfriction.

Initialize the project directory, install (locally), and push to GitHub:

cd ~/src/radiasoft
git clone https://github.com/radiasoft/rsfriction
cd rsfriction
pykern projex init-rs-tree 'Python library for simulating the dynamical friction force exerted on ions by magnetized electrons'
git commit -am 'initial setup'
pip install -e .
git push

Set Up ReadTheDocs

To compile the documentation on ReadTheDocs, you'll need to import the project. Go to ReadTheDocs Dashboard and click on Import a Project.

This will show you a list of repositories, click on the [+] next to the repository you want to import.

Click Next then Finish. Next click on Admin which brings you to Settings:

  • Enter a Description:
  • Check Build pull requests for this project
  • Uncheck Disable Google Analytics
  • Enter project homepage. If there is none, enter https://git.radiasoft.org/<project>

Click on Save.

You may want to edit docs/index.rst with a longer description.

To test in your development environment.

cd <top-level>
pykern sphinx build 

Pushing to PyPI

Projex can push your project to PyPI. This should be done through our DevOps team on production servers. If you want to test, use TestPyPI.

If you haven't already done so, register at TestPyPI. You may want to setup your ~/.pypirc with an API token:

[testpypi]
username = __token__
password = <your TestPyPI API Token>

Next, install (or upgrade) build and twine:

pip install --upgrade twine build

Finally, build the project, e.g. rsfriction, and upload to testpypi:

cd ~/src/radiasoft/rsfriction
python -m build
twine upload --repository testpypi $(find dist -type f -mmin -1)