Skip to content
Snippets Groups Projects
Commit aa3b06ab authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

Merge branch 'version' into 'main'

Version

See merge request !17
parents 5353b95b e55b1a81
No related branches found
No related tags found
1 merge request!17Version
Pipeline #520425 passed with warnings
...@@ -8,3 +8,5 @@ data ...@@ -8,3 +8,5 @@ data
*csv *csv
*npy *npy
dist dist
app-version.json
.venv
variables:
POETRY_CACHE_DIR: ${CI_PROJECT_DIR}/.poetry
PYTHONUNBUFFERED: 1
image: ${CI_REGISTRY}/devops/images/usgs/python:3.8 image: ${CI_REGISTRY}/devops/images/usgs/python:3.10
# Do not run for merge requests # Do not run for merge requests
workflow: workflow:
...@@ -27,7 +24,7 @@ default: ...@@ -27,7 +24,7 @@ default:
Init: Init:
artifacts: artifacts:
paths: paths:
- ${POETRY_CACHE_DIR} - .venv
script: script:
- poetry install - poetry install
stage: init stage: init
...@@ -72,6 +69,10 @@ Example: ...@@ -72,6 +69,10 @@ Example:
#### ####
PyPi: PyPi:
image:
name: ${CI_REGISTRY}/devops/images/usgs/python:3.10
docker:
user: root
needs: needs:
- Format Check - Format Check
- Init - Init
...@@ -79,6 +80,8 @@ PyPi: ...@@ -79,6 +80,8 @@ PyPi:
only: only:
- tags@ghsc/nshmp/ncm/TherMod - tags@ghsc/nshmp/ncm/TherMod
script: script:
- apt-get install -y git
- poetry run app_version
- pip install twine - pip install twine
- poetry version ${CI_COMMIT_TAG} - poetry version ${CI_COMMIT_TAG}
- poetry build - poetry build
......
This diff is collapsed.
...@@ -4,3 +4,7 @@ url = "https://code.usgs.gov/api/v4/projects/2294/packages/pypi" ...@@ -4,3 +4,7 @@ url = "https://code.usgs.gov/api/v4/projects/2294/packages/pypi"
[repositories.TherMod] [repositories.TherMod]
url = "https://code.usgs.gov/api/v4/projects/1404/packages/pypi" url = "https://code.usgs.gov/api/v4/projects/1404/packages/pypi"
[virtualenvs]
create = true
in-project = true
...@@ -7,10 +7,11 @@ maintainers = ["Brandon Clayton <bclayton@usgs.gov>"] ...@@ -7,10 +7,11 @@ maintainers = ["Brandon Clayton <bclayton@usgs.gov>"]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = ">=3.8.1,<3.12" python = ">=3.8.1,<3.12"
ncm-database = "^0.4.0" ncm-database = "^0.5.2"
netcdf4 = "^1.6.4" netcdf4 = "^1.6.4"
numpy = "1.24.0" numpy = "1.24.0"
scipy = "1.10.0" scipy = "1.10.0"
gitpython = "^3.1.43"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
pylint = "^2.17.5" pylint = "^2.17.5"
...@@ -19,6 +20,7 @@ flake8 = "^6.0.0" ...@@ -19,6 +20,7 @@ flake8 = "^6.0.0"
isort = "^5.12.0" isort = "^5.12.0"
[tool.poetry.scripts] [tool.poetry.scripts]
app_version = "scripts:app_version"
setup = "scripts:setup" setup = "scripts:setup"
database = "scripts:database" database = "scripts:database"
thermod = "scripts:thermod" thermod = "scripts:thermod"
......
""" Scripts for Poetry """ Scripts for Poetry
""" """
import json
import os import os
import re
import sys import sys
from subprocess import check_call from subprocess import check_call
...@@ -10,6 +12,33 @@ from subprocess import check_call ...@@ -10,6 +12,33 @@ from subprocess import check_call
_project = "thermod" _project = "thermod"
def app_version():
import git
version_file = open(f"{_project}/resources/app-version.json", "w+")
try:
repo = git.Repo(".")
gitHash = repo.head.commit.hexsha
version = repo.git.describe(tags=True, first_parent=True, always=True)
url = os.environ.get("CI_PROJECT_URL", repo.remotes.origin.url)
if "gitlab-ci-token" in url:
url = re.sub(r"gitlab-ci-token\:.*@", "", url)
version_info = dict(
gitHash=gitHash,
projectName="ncm-ws",
url=url,
version=version,
)
version_file.write(json.dumps(version_info, indent=2))
except Exception as error:
print("Failed to create version file. Writing blank file.")
version_file.write(json.dumps("{}"))
def setup(): def setup():
# Setup GitHooks # Setup GitHooks
os.system("git config core.hookspath .githooks") os.system("git config core.hookspath .githooks")
...@@ -41,8 +70,8 @@ def help(): ...@@ -41,8 +70,8 @@ def help():
def format_check(): def format_check():
# Check code format # Check code format
check_call(["isort", "--check", "--diff", ".", "--skip", ".poetry"]) check_call(["isort", "--check", "--diff", ".", "--skip", ".venv"])
check_call(["black", "--check", "--diff", ".", "--exclude", ".poetry"]) check_call(["black", "--check", "--diff", ".", "--exclude", ".venv"])
def format(): def format():
......
from thermod.ther_mod import * from thermod.ther_mod import *
from thermod.version import thermod_version
"""
Author: U.S Geological Survey
Description: Returns the app version info
"""
import json
from os import path
def thermod_version():
with open(f"{path.dirname(__file__)}/resources/app-version.json") as file:
return json.loads(file.read())
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