Skip to content
Snippets Groups Projects
Commit 1afb1319 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

initial

parents
No related branches found
No related tags found
No related merge requests found
*
!proj
!pyproject.toml
!LICENSE.txt
!README.md
build/
dist/
.venv/
.coverage/
.mypy/
stages:
- lint
- test
- build
- deploy
variables:
PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip
cache:
paths:
- .cache/pip
default:
image: python:3.10
tags: ["docker", "ssec_shared"]
lint:
stage: lint
script:
- pip install hatch
- hatch run lint
test:unit:
stage: test
script:
- pip install hatch
- hatch run test tests/unit
test:int:
stage: test
script:
- pip install hatch
- hatch run test tests/int
# Only for the default branch, no tags
build:
stage: build
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- pip install hatch
- hatch build
artifacts:
paths:
- ./dist/*.whl
- ./dist/*.tar.gz
# All default branch commits get an image
build:image:
stage: build
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_TAG =~ /\d+\.\d+\.\d+$/
image: docker:24.0.5
services:
- docker:24.0.5-dind
script:
- docker login -u "${SIPS_REGISTRY_USER}" -p "${SIPS_REGISTRY_TOKEN}" "${CI_REGISTRY}"
- docker build -t "${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}" .
- docker push "${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}"
- [[ -n "${CI_COMMIT_TAG}" ]] &&
docker build -t "${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}" . &&
docker push "${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}"
# Only for tagged X.X.X versions
prod:build:image:
stage: build
image: docker:24.0.5
rules:
- if: $CI_COMMIT_TAG =~ /\d+\.\d+\.\d+$/
services:
- docker:24.0.5-dind
variables:
img: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- docker build -t "${img}" .
- docker login -u "${SIPS_REGISTRY_USER}" -p "${SIPS_REGISTRY_TOKEN}" "${CI_REGISTRY}"
- docker push "${img}"
# Only deploy tagged X.X.X versions
prod:deploy:packages:
stage: deploy
rules:
- if: $CI_COMMIT_TAG =~ /\d+\.\d+\.\d+$/
variables:
HATCH_INDEX_REPO: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi
HATCH_INDEX_AUTH: $CI_JOB_TOKEN
script:
- hatch publish -y
FROM python:3.10 AS base
# ENV PIP_INDEX_URL=http://devpi.sips/sips/prod/+simple
# ENV PIP_TRUSTED_HOST=devpi.sips
ENV PIP_NO_CACHE_DIR="false"
RUN apt-get update && apt-get -yqq install --no-install-recommends \
dumb-init \
&& \
rm -rf /var/lib/apt/lists/*
FROM base AS dev
WORKDIR /code
COPY . .
RUN pip install hatch && \
hatch dep show requirements -p > project_requirements.txt && \
hatch dep show requirements > all_requirements.txt && \
hatch run python3 -m pip install -r all_requirements.txt
RUN hatch run python3 -m pip install -e . && \
hatch build
FROM base as app
COPY --from=dev /code/project_requirements.txt /tmp/requirements.txt
COPY --from=dev /code/dist/proj-*.whl /tmp/
RUN python -m pip install -r /tmp/requirements.txt /tmp/proj-*.whl
RUN useradd app
USER app
ENTRYPOINT ["dumb-init", "--"]
MIT License
Copyright (c) 2023-present Bruce Flynn <brucef@ssec.wisc.edu>
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.
# Python Project, 2023 Style
References:
* Python Packaging Authority [PyPA](https://www.pypa.io)
* Python Package Index [PyPI](https://pypi.org)
* [Pip](https://pip.pypa.io)
- "… the package installer for Python"
* [Hatch](https://hatch.pypa.io)
- "… modern, extensible Python project manager"​
* [Poetry](https://python-poetry.org)
- "Python packaging and dependency management made easy"​
* [Pipenv](https://pipenv.pypa.io)
- "… Python virutalenv management tool …"​
* [Setuptools](https://setuptools.pypa.io)
- "... fully-featured, actively-maintained, and stable library designed to facilitate packaging Python projects"
__version__ = "0.0.0"
import dateparser
def main():
print("Hello from proj")
now = dateparser.parse("now")
print(f"The time is {now}")
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "proj"
dynamic = ["version"]
description = 'My Project'
readme = "README.md"
requires-python = ">=3.10"
license = {file = "LICENSE.txt"}
keywords = []
authors = [{ name = "Bruce Flynn", email = "brucef@ssec.wisc.edu" }]
classifiers = ["Private :: Do Not Upload"]
dependencies = ["dateparser ~= 1.1"]
[project.urls]
Homepage = "https://gitlab.ssec.wisc.edu/brucef/pyproj"
[tool.hatch.version]
path = "proj/__init__.py"
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
# Define env vars for the default environment, e.g., PIP_* vars for pip configuration
# [tool.hatch.envs.default.env-vars]
# PIP_INDEX_URL = "<your index>"
# Scripts define here are runnable via hatch run <script>
# Note, env name is not required because this is the default environment
[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[tool.hatch.envs.lint]
detached = true
dependencies = [
"black>=23.1.0",
"mypy>=1.0.0",
"ruff>=0.0.243",
]
# Scripts define here are runnable via hatch run lint:<script>
[tool.hatch.envs.lint.scripts]
typing = "mypy --install-types --non-interactive {args:proj tests}"
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"style",
]
all = [
"style",
"typing",
]
[tool.hatch.publish.index]
# require -y to use hatch publish
disable = true
[tool.black]
target-version = ["py310"]
line-length = 120
skip-string-normalization = true
[tool.ruff]
target-version = "py310"
line-length = 120
select = [
"A",
"ARG",
"B",
"C",
"DTZ",
"E",
"EM",
"F",
"FBT",
"I",
"ICN",
"ISC",
"N",
"PLC",
"PLE",
"PLR",
"PLW",
"Q",
"RUF",
"S",
"T",
"TID",
"UP",
"W",
"YTT",
]
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
# Ignore complexity
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
]
[tool.ruff.isort]
known-first-party = ["proj"]
[tool.ruff.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]
[tool.coverage.run]
source_pkgs = ["proj", "tests"]
branch = true
parallel = true
omit = [
"proj/__init__.py",
]
[tool.coverage.paths]
proj = ["proj", "*/proj/proj"]
tests = ["tests", "*/proj/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
#!/bin/bash
#
# Release script that will bump the project version and commit and push
# the version file.
#
# This supports a limited, but reasonable, set of version specifiers.
#
# ASSUMES:
# 1. You are using Hatch
# 2. You have `version` in your `project.dynamic` list
#
set -e
if [[ ! "$1" =~ ^(major|minor|patch|dev)$ ]]; then
echo "USAGE: $0 <major|minor|patch|dev>"
exit 1
fi
# Bumps the version, i.e., sets the version in the version file specified in
# the hatch version file config.
hatch version $1
readonly ver=$(hatch version)
if git tag -l | grep ${ver} &> /dev/null; then
echo "Whoops!! Tag for version ${ver} already exists"
echo "You may have to manually revert the version before running this script again."
exit 1
fi
# Get the name of the file contain the version var __version__. This may need
# to be adjusted if version handing doesn't meet assumptions.
readonly verfile=$(find . -name \*.py | xargs grep -nE '^__version__ = ' | cut -d: -f1)
[[ -z ${verfile} ]] && echo "Failed to find version file" && exit 1
git commit -vm "bump version" "${verfile}"
git tag -am "bump to ${ver}" ${ver}
git push --follow-tags
# SPDX-FileCopyrightText: 2023-present Bruce Flynn <brucef@ssec.wisc.edu>
#
# SPDX-License-Identifier: MIT
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment