From 1c987b9a758abcaf791668df9f0070357176c5dd Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Sat, 29 Jul 2023 12:09:27 +0100 Subject: [PATCH] use the pypi-hosted repository --- Vagrantfile | 1 + hello-world-pypi-package/LICENSE | 19 ++++++ hello-world-pypi-package/README.md | 3 + hello-world-pypi-package/pyproject.toml | 22 +++++++ hello-world-pypi-package/requirements.txt | 32 ++++++++++ .../src/hello_world/__init__.py | 2 + provision/use-pypi-repository.sh | 58 +++++++++++++++++++ 7 files changed, 137 insertions(+) create mode 100644 hello-world-pypi-package/LICENSE create mode 100644 hello-world-pypi-package/README.md create mode 100644 hello-world-pypi-package/pyproject.toml create mode 100644 hello-world-pypi-package/requirements.txt create mode 100644 hello-world-pypi-package/src/hello_world/__init__.py create mode 100644 provision/use-pypi-repository.sh diff --git a/Vagrantfile b/Vagrantfile index aeffe76..ea35705 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -43,6 +43,7 @@ Vagrant.configure(2) do |config| config.vm.provision :shell, path: 'provision/use-maven-repository-from-gradle.sh' config.vm.provision :shell, path: 'provision/use-nuget-repository.sh' config.vm.provision :shell, path: 'provision/use-npm-repository.sh' + config.vm.provision :shell, path: 'provision/use-pypi-repository.sh' config.vm.provision :shell, path: 'provision/summary.sh' end diff --git a/hello-world-pypi-package/LICENSE b/hello-world-pypi-package/LICENSE new file mode 100644 index 0000000..8c0bff0 --- /dev/null +++ b/hello-world-pypi-package/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2023 Rui Lopes + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/hello-world-pypi-package/README.md b/hello-world-pypi-package/README.md new file mode 100644 index 0000000..94e0200 --- /dev/null +++ b/hello-world-pypi-package/README.md @@ -0,0 +1,3 @@ +# Hello World + +The Classic Hello World PyPI package. diff --git a/hello-world-pypi-package/pyproject.toml b/hello-world-pypi-package/pyproject.toml new file mode 100644 index 0000000..cf4e818 --- /dev/null +++ b/hello-world-pypi-package/pyproject.toml @@ -0,0 +1,22 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "hello-world" +version = "0.1.0" +authors = [ + { name="Rui Lopes", email="rgl@example.com" }, +] +description = "Hello World" +readme = "README.md" +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +[project.urls] +"Homepage" = "https://github.com/nexus-vagrant/hello-world-python-package" +"Bug Tracker" = "https://github.com/nexus-vagrant/issues" diff --git a/hello-world-pypi-package/requirements.txt b/hello-world-pypi-package/requirements.txt new file mode 100644 index 0000000..dffed35 --- /dev/null +++ b/hello-world-pypi-package/requirements.txt @@ -0,0 +1,32 @@ +bleach==6.0.0 +build==0.10.0 +certifi==2023.7.22 +cffi==1.15.1 +charset-normalizer==3.2.0 +cryptography==41.0.2 +docutils==0.20.1 +idna==3.4 +importlib-metadata==6.8.0 +jaraco.classes==3.3.0 +jeepney==0.8.0 +keyring==24.2.0 +markdown-it-py==3.0.0 +mdurl==0.1.2 +more-itertools==10.0.0 +packaging==23.1 +pkginfo==1.9.6 +pycparser==2.21 +Pygments==2.15.1 +pyproject_hooks==1.0.0 +readme-renderer==40.0 +requests==2.31.0 +requests-toolbelt==1.0.0 +rfc3986==2.0.0 +rich==13.4.2 +SecretStorage==3.3.3 +six==1.16.0 +tomli==2.0.1 +twine==4.0.2 +urllib3==2.0.4 +webencodings==0.5.1 +zipp==3.16.2 diff --git a/hello-world-pypi-package/src/hello_world/__init__.py b/hello-world-pypi-package/src/hello_world/__init__.py new file mode 100644 index 0000000..4ea1c75 --- /dev/null +++ b/hello-world-pypi-package/src/hello_world/__init__.py @@ -0,0 +1,2 @@ +def greet(name): + print(f'Hello, {name}!') diff --git a/provision/use-pypi-repository.sh b/provision/use-pypi-repository.sh new file mode 100644 index 0000000..ca994ea --- /dev/null +++ b/provision/use-pypi-repository.sh @@ -0,0 +1,58 @@ +#!/bin/bash +set -euxo pipefail + +nexus_domain=$(hostname --fqdn) + +rm -rf tmp/hello-world-pypi-package +install -d tmp +cp -r /vagrant/hello-world-pypi-package tmp +cd tmp/hello-world-pypi-package + +# create the venv. +apt-get install -y python3-venv +rm -rf .venv +python3 -m venv .venv +set +x && source .venv/bin/activate && set -x + +# create the hello_world package. +# see https://packaging.python.org/en/latest/tutorials/packaging-projects/ +# see https://help.sonatype.com/repomanager3/nexus-repository-administration/formats/pypi-repositories +# NB requirements.txt was created as: +# python3 -m pip install build twine +# python3 -m pip freeze >requirements.txt +python3 -m pip install -r requirements.txt +python3 -m build --wheel +python3 -m pip freeze >.venv/requirements.txt +diff -u requirements.txt .venv/requirements.txt || (echo ERROR: requirement.txt is not up-to-date && false) + +# upload. +export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt +cat >.venv/twine.conf <.venv/pip.conf <