cnaas-sync (0.3.8)
Installation
pip install --index-url cnaas-sync
About this package
Sync Scripts for NI and Nav
Make the script executable by running the following command:
chmod u+x run.py
The general command follows this rule:
cli.py nav|ni file-path [--options]
To update, for example, Nav, use the following command:
cli.py --target nav --config-file /home/user/config.ini
The config.ini
file should be structured like this:
[NAV]
NAV_BASE_URL=
NAV_API_KEY=
[NI]
NI_BASE_URL=
NI_USER_EMAIL=
NI_USER_API_KEY=
[NMS]
NMS_BASE_URL=
NMS_JWT_TOKEN=
Optional parameters can be added to overwrite values in the config file. For instance, the command below uses the NMS JWT token "rti" instead of the one provided in the config file:
run.py nav /home/user/config.ini -nmsjwt rti
cnaas-sync-cli --config-file /opt/ni/cnaas_sync_config.ini -t nav
The list of parameters includes: ["nav_base_url", "nav_api_key", "ni_base_url", "ni_user_name", "ni_api_key", "nms_base_url", "nms_jwt_token"]
Testing
Run the tests using the following command:
pytest -v tests/test.py
Test with pytest
> pytest tests
Test with nox
> nox --sessions tests
nox
list all sessions
nox --list
list all sessions by activating only lint
nox --list --sessions lint
Run a specific session called lint
nox --sessions lint
Run a specific session called formatter
nox --sessions formatter
Run a specific session called formatter
nox --sessions tests
Run all the sessions in current noxfile:
nox
Run a specific session ang generate a report:
nox --sessions tests --report nox-report.json
- nox -f api/noxfile.py --list
- nox -f api/noxfile.py -s formatter
- nox -f api/noxfile.py --list
- nox -f api/noxfile.py -s lint
- nox -f api/noxfile.py -s tests --report nox-report.json
Pre-commit
pre-commit --version
Deployment to the Platform
https://forgejo.org/docs/v1.19/user/packages/pypi/
The .pipirc File
The .pipirc
file is used to define configuration for package indexes ("repositories") when uploading packages with twine or flit. An example file looks like this:
[distutils]
index-servers =
test_cnaas_sync
platform_cnaas
[test_cnaas_sync]
repository = https://platform.sunet.se/api/packages/{username}/pypi
username = {username}
password = [password or token]
[platform_cnaas]
repository = https://platform.sunet.se/api/packages/{owner}/pypi
username = {username}
password = [password or token]
The owner
can be either a specific user ('albert') or an organization ('cnaas').
Publication
To publish, run the following command:
python3 -m twine upload --repository test_cnaas_sync /path/to/files/*
Replace /path/to/files/
with the location of your Python package on your disk or in the cloud. The package files should have the extensions .tar.gz and .whl.
/path/to/files/* Remember the wildcard is an requirement and cannot be omitted.
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
Poetry
poetry config -h
poetry config --list
poetry config repositories.main_sunet https://platform.sunet.se/api/packages/SUNET/pypi
poetry config http-basic.main_sunet <username> <password>
poetry publish --build --repository main_sunet
Check packages at: (SUNET-packages)[https://platform.sunet.se/SUNET/-/packages]
Installation
To install a PyPI package from the package registry, execute the following command:
pip install --index-url https://platform.sunet.se/api/packages/{owner}/pypi/simple/ cnaas-sync
Add a username and password if required:
pip install --index-url https://{username}:{password}@platform.sunet.se/api/packages/{owner}/pypi/simple/ cnaas-sync
Add the following extra index URL to download dependencies from the Python default package repository:
--extra-index-url https://pypi.org/simple