Distributing
#Pakcages
#pypi.org
This is a part of deadlinks deploy makefile
# ~~~ Deployments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
build-prod: venv clean ## Build disto (source & wheel) - Production
@ $(PYTHON) setup.py sdist bdist_wheel > /dev/null 2>&1
build-dev: venv clean ## Build disto (source & wheel) - Development
@ \
DEADLINKS_BRANCH=$(BRANCH) \
DEADLINKS_COMMIT=$(COMMIT) \
DEADLINKS_TAGGED=$(TAGGED) \
$(PYTHON) setup.py sdist bdist_wheel > /dev/null 2>&1
clean: ## Cleanup Build artifacts
@echo "Cleanup Temporary Files"
@rm -rf ${DIST}
@rm -rf ${BUILD}
@rm -f deadlinks/__develop__.py
deploy:
@ $(PYTHON) -m pip install --upgrade wheel twine -q
deploy-test: deploy build-dev ## PyPi Deploy (test.pypi.org)
twine upload --repository-url https://test.pypi.org/legacy/ dist/*;\
deploy-prod: deploy build-prod ## PyPi Deploy (pypi.org)
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*;\
pre-depeloy-check: venv clean deps ## Install Development Version
$(PYTHON) -m pip uninstall deadlinks -y
DEADLINKS_BRANCH=$(BRANCH) \
DEADLINKS_COMMIT=$(COMMIT) \
DEADLINKS_TAGGED=$(TAGGED) \
$(PYTHON) setup.py develop -q 2>&1 1> /dev/null
#PIP
pip install --help
Usage:
pip install [options] <requirement specifier> [package-index-options] ...
pip install [options] -r <requirements file> [package-index-options] ...
pip install [options] [-e] <vcs project url> ...
pip install [options] [-e] <local project path> ...
pip install [options] <archive url/path> ...
#Jupyter
You always can distribute Python code as Jupyter files to run the in Jupyter/Jupyterlab.
#Poetry
TODO: Write docs
poetry new poetry-demo
poetry build
poetry publish
#Containers
#Dockerfile
Most common way to build container image is to use Docker command (You also can build containers using Bazel
, podman
etc…)
# - Dockerfile -
ARG test_py_major_minor_version='3.11'
FROM docker.io/python:3.11-slim as BUILD
COPY . /tmp
WORKDIR /tmp
ARG PYTHONDONTWRITEBYTECODE="1" \
PYTHONUNBUFFERED="1" \
PYTHONFAULTHANDLER="1" \
PYTHONHASHSEED="random" \
PIP_DEFAULT_TIMEOUT="100"
# psycopg2 > libpq-dev, gcc
# pyodbc > unixodbc-dev, g++
# git > pip (installing remote)
RUN apt update \
&& apt install --no-install-recommends -y \
apt-utils \
git \
libpq-dev \
g++ \
gcc \
unixodbc-dev
RUN python3 -m pip install --upgrade pip
RUN ls -la && python3 -m pip install --no-cache-dir -r requirements.txt
RUN python3 -m pip uninstall pip wheel setuptools -y
RUN find / -type f -name "*.pyc" -exec rm -r {} \;
FROM gcr.io/distroless/python3-debian12:debug
LABEL maintainer "Oleg Butuzov <butuzov@made.ua>"
ENV PYTHONPATH=/usr/local/lib/python3.11/site-packages
COPY --from=BUILD ${PYTHONPATH} ${PYTHONPATH}
WORKDIR /app
COPY . .
CMD [ "-V" ]
ENTRYPOINT [ "python3" ]
# - hello.py -
#!/bin/python
# Copyright 2017 Google Inc. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import requests
parser = argparse.ArgumentParser()
parser.add_argument('root', type=str,
help='The root directory to walk.')
def main(args):
"""Prints the files that are inside the container, rooted at the first argument."""
print(requests.get("https://httpbin.org/get").text)
if __name__ == "__main__":
main(parser.parse_args())
# - .dockerignore -
Dockerfile
.dockerignore
# - requirements.txt -
requests
# psycopg2
# datahub
# dagster