Package: enexis-friends-quiz
Friends QuizSuper quiz!This is a demo of dependency injection.Documentation onGitlab pages.Original repository:applications/401-datascience/use-cases/enexis_friends_quizArtifactory:enexis-friends-quizTODO: This is an auto-generated README file. Make sure to adjust it to your needs,
and remove sections that are not applicable for your software.Linting and TestingLocally on every commitOn every commit, some code formatting and checking tools are run bypre-commit.The test pipeline is configured in the.pre-commit-config.yaml.Note:youmustrunpoetry run pre-commit installeverytime you clone your
git repository. Else, the pre-commit hooks won't be run automatically.Running tests locallyOn your local machine, you can run tests by runningmake test.This usesToxto run tests for a variety
of Python versions.As a prerequisite you need to install all those Python version, e.g., withpyenv.To configure the Python versions under test, edit thetox.ini.With Github actionsAfter every push to Github, thecicd.yamlworkflow is run. It runs the tests in thetestsfolder for a bunch
of Python versions.It also uploads the code coverage report tocodecov.Note:for private repositories you need to acquire a token from codecov
and configure in thecicd.yamlworkflow file and in Github secrets.To configure which Python versions are tested, edit thepython-versionlist in thecicd.yamlworkflow file.How to release to PyPIYou can upload the package either from your local machine via twine, or
by using Github actions.The following instructions guide you through the process of releasing to the actual,
official PyPI.Further down, there are instructions to release to the PyPI test server, or to custom
Python Package indexes.Release with Github actionsTo make a release via Github actions, you need to create a release in
Github. When the release is published, the build-n-publish job in thecicdworkflow
is run.To create a release in Github you need to create a tag.For this project it is necessary that the tag matches the version number.
E.g., for version1.2.3the tag must be1.2.3.PrerequisitesCreate an API token in thePyPI account settings.
If you don't have a PyPI account yet, create one.Do not close the
page right away, you will never see the token again!Note:before you upload the package for the first time, you can
only create a global api token with access to all your packages. It ishighlyrecommended to replace it with a package-specific token after
you have published your package for the first time.In theGithub repository settings,
create a new environment namedproduction. If you are the only
contributor, you can leave all settings at the default.UnderSecrets -> actions,
create a new secret namedPYPI_API_TOKENand copy the token from PyPI
as value.Create a release and publish the package to PyPIMake sure thenamevariable in yourpyproject.tomlis correct.This will be the name of your package on PyPI!update the version number in thepyproject.toml.create a matching tag on your local machine and push it to the
Github repository:gittag1.2.3
gitpush--tagsInGithub actionsmake sure that the test workflow succeeds.In the Githubrelease tabclick "Draft a new release". Fill in the form. When you click publish,
thepublish-to-pypiworkflow is run.It checks that the tag matches the version number and then builds and
publishes the package toPyPI.Upload from the local machine (not recommended)twineallows to upload a package
from your local machine to PyPI.PrerequisitesYou need a PyPI API token. See prerequisites for the Github actions above
(you don't need to perform any actions on Github when using twine, so you
only need to perform step 1).ConfigurationThe PyPI credentials must be configured either via a configuration file
or via environment variables.
See thetwine documentationfor details.Since we are using an api token to authenticate with PyPI, the username
must be set to__token__, and the password is the actual token.When using the PyPI test server, the repository url must be set tohttps://test.pypi.org/legacy/.UsageThepublishtarget in theMakefilecalls twine to upload
a package to PyPI.Note:the upload command is deactivated by default to prevent accidental
uploads. You need to manually uncomment it before the first release.Here are the necessary steps:update the version number in thepyproject.tomlrunmake publish.Using a custom package repositoryWhile testing the release process of a public package, it is a good idea to first
release to the PyPI Test server.Sometimes, especially in corporate settings, it is necessary to upload packages to
a custom, often private, package repository.ReleasingTo release to a server other than the standard PyPI, you need to specify the respective
repository URL when uploading.Releasing to a custom repo with twineWith twine, you can specify the repository URL via the--repository-urlparameter.In the special case of the PyPI Test server, you can also specify--repository testpypi.# for Test PyPItwineupload--repositorytestpypidist/*# for any custom repositorytwineupload--repository-url<URL>dist/*In the context of this project, you can modify thepublishtarget in theMakefile.See alsoUsing TestPyPI.Releasing to a custom repo with Github actionsTo release to a custom repo with Github actions, you can follow the same process
as described above for the default PyPI. The only necessary change is adding arepository_urlentry to thepublish-to-pypi.yamlfile:-name:Publish package to TestPyPIuses:pypa/gh-action-pypi-publish@release/v1with:user: __token__password:${{ secrets.TEST_PYPI_API_TOKEN }}repository_url:https://test.pypi.org/legacy/For use with Test PyPI you need an account and an API token fromtest.pypi.org. Note that in the example above, that token is assumed to
be stored in theTEST_PYPI_API_TOKENsecret in Github.See alsoAdvanced release managementin the documentation of thepypi-publishGithub action.Installing from a custom package repositoryIf you have uploaded your package to a custom repository, install tools such as
pip and poetry won't find it by default. You need to configure them to use the
custom repository.Installing from a custom package repository with pipWith pip, you need to specify it via the--index-urlparameter. Often you want to
install custom packages from the private repo, but public dependencies from the regular
PyPI. In that case, specify the PyPI repo via--extra-index-url.For example:pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ friends_quizBeware thesecurity implications!Installing from a custom package repository with poetryTo install packages from a custom repository, add this to yourpyproject.toml:[[tool.poetry.source]]name="foo"url="https://test.pypi.org/simple/"secondary=true# if True, poetry will also search the default PyPI repositorydefault=true# if True, poetry will never search the default PyPI repositoryFor advanced configuration and authentication, take a look at thepoetry documentation.ContactMarius Helf
(marius.helf@enexis.nl)