Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "standard" cogment release scripts #1

Merged
merged 8 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[{*.py,*.yml,*.toml}]
indent_size = 4

[*.sh]
switch_case_indent = true

# Ignore the entire ".venv" directory.
[.venv/**]
ignore = true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ tutorial/*.html
.idea
vizdoom.ini

lib/
lib/
71 changes: 66 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,70 @@
stages:
- lint
- lint
- build
- publish

licenses_checker:
stage: lint
image: registry.gitlab.com/ai-r/cogment/license-checker:latest
script:
- license-checker
stage: lint
image: registry.gitlab.com/ai-r/cogment/license-checker:latest
script:
- license-checker

shellcheck:
image: koalaman/shellcheck-alpine:stable
stage: lint
before_script:
- shellcheck --version
script:
- shellcheck $(find . -name '*.sh' | xargs)

shfmt:
image: mvdan/shfmt:v3.7.0-alpine
stage: lint
before_script:
- shfmt --version
script:
- shfmt -d .

.base:
image: python:3.10
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
before_script:
- mkdir -p ${PIP_CACHE_DIR}
- python -m venv .venv
- source .venv/bin/activate
- pip install -r requirements.txt
- pip install -e .
cache:
- paths:
- .cache/pip
- key:
files:
- requirements.txt
- setup.cfg
paths:
- ".venv"

build_sdist:
extends: .base
stage: build
script:
- echo "to be implemented"
# TODO
# - python -m build
# - twine check dist/*
artifacts:
expire_in: 1 week
paths:
- dist/*.tar.gz
- dist/*.whl

publish_to_pypi:
extends: .base
stage: publish
needs:
- build_sdist
script:
- python -m twine upload dist/* --non-interactive -u $PYPI_USERNAME -p $PYPI_PASSWORD
rules:
- if: $CI_COMMIT_TAG
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Initial release
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,21 @@ Terminology:
- Model: a relatively raw PyTorch (or other?) model, inheriting from `nn.Module`
- Agent: a model wrapped in some utility class to interact with np arrays
- Actor: a cogment service that may involve models and/or actors

## Release process

People having maintainers rights of the repository can follow these steps to release a version **MAJOR.MINOR.PATCH**. The versioning scheme follows [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

1. Run `./scripts/create_release_branch.sh MAJOR.MINOR.PATCH`, this will automatically:
- update the version of the package, in `cogment_lab/version.py`,
- create a release branch with this changes at `release/vMAJOR.MINOR.PATCH` and push it.
2. On the release branch:
- Make sure the changelog, at `CHANGELOG.md`, reflects the changes since the last release,
- Fix any issue, making sure that te build passes on CI,
- Commit and push any changes.
3. Run `./scripts/tag_release.sh MAJOR.MINOR.PATCH`, this will automatically:
- create the specific version section in the changelog and push it to the release branch,
- merge the release branch in `main`,
- create the release tag and,
- update the `develop` to match the latest release.
4. The CI will automatically publish the package to PyPI.
14 changes: 7 additions & 7 deletions bin/docker_entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export DISPLAY=:0
display=0
file="/tmp/.X11-unix/X$display"
for i in $(seq 1 10); do
if [ -e "$file" ]; then
break
fi
if [ -e "$file" ]; then
break
fi

echo "Waiting for $file to be created (try $i/10)"
sleep "$i"
echo "Waiting for $file to be created (try $i/10)"
sleep "$i"
done
if ! [ -e "$file" ]; then
echo "Timing out: $file was not created"
exit 1
echo "Timing out: $file was not created"
exit 1
fi

exec "$@"
8 changes: 5 additions & 3 deletions cogment_lab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
# limitations under the License.

from __future__ import annotations

import logging

from cogment_lab.process_manager import Cogment
from cogment.utils import logger

logger.addHandler(logging.NullHandler())
from cogment_lab.process_manager import Cogment
from cogment_lab.version import __version__


__version__ = "0.0.1"
logger.addHandler(logging.NullHandler())


__all__ = ["Cogment"]
15 changes: 15 additions & 0 deletions cogment_lab/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 AI Redefined Inc. <[email protected]>
#
# 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.

__version__ = "0.1.0"
35 changes: 13 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ dependencies = [
"numpy",
"opencv-python>=4.8",
"fastapi>=0.105",
"pillow>=9.0"
"pillow>=9.0",
]

[project.scripts]
cogmentlab = "cogment_lab.cli.cli:main"

[tool.hatch.version]
path = "cogment_lab/__init__.py"
path = "cogment_lab/version.py"

[tool.hatch.build.targets.sdist]
include = [
"/cogment_lab",
]
include = ["/cogment_lab"]

# Package ######################################################################

Expand All @@ -56,16 +54,8 @@ dev = [
"jupyter>=1.0.0",
"jupyterlab>=3.5.3",
]
coltra = [
"coltra>=0.2.1",
"torch",
"wandb>=0.13.9",
]
grid2op = [
"Grid2Op==1.9.6",
"lightsim2grid",
"numba==0.56.4",
]
coltra = ["coltra>=0.2.1", "torch", "wandb>=0.13.9"]
grid2op = ["Grid2Op==1.9.6", "lightsim2grid", "numba==0.56.4"]

[project.urls]
Homepage = "https://cogment.ai/lab"
Expand All @@ -80,9 +70,10 @@ include-package-data = true
include = ["cogment_lab", "cogment_lab.*"]

[tool.setuptools.package-data]
cogment_lab = [
"py.typed",
]
cogment_lab = ["py.typed"]

[tool.setuptools.dynamic.version]
attr = "cogment_lab.version.__version__"

# Linters and Test tools #######################################################

Expand Down Expand Up @@ -121,8 +112,8 @@ reportInvalidTypeVarUse = "none"
# reportUnknownParameterType = "warning" # -> raises 1327 warnings
# reportUnknownVariableType = "warning" # -> raises 2585 warnings
# reportUnknownArgumentType = "warning" # -> raises 2104 warnings
reportGeneralTypeIssues = "none" # -> commented out raises 489 errors
reportUntypedFunctionDecorator = "none" # -> pytest.mark.parameterize issues
reportGeneralTypeIssues = "none" # -> commented out raises 489 errors
reportUntypedFunctionDecorator = "none" # -> pytest.mark.parameterize issues

reportPrivateUsage = "warning"
reportUnboundVariable = "warning"
Expand Down Expand Up @@ -156,7 +147,7 @@ exclude = [
"node_modules",
"venv",
"scripts",
"cogment_lab/generated"
"cogment_lab/generated",
]

# Same as Black.
Expand Down Expand Up @@ -189,4 +180,4 @@ indent-style = "space"
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
line-ending = "auto"
77 changes: 77 additions & 0 deletions scripts/commons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash

####
# Helper functions & variables
####

ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
export ROOT_DIR

GIT_REMOTE="origin"
export GIT_REMOTE

# Let's check if we have GNU sed or BSD sed
if sed --help >/dev/null 2>&1; then
# There is a '--help' option, it is GNU BSD
SED_NL="\\n"
else
SED_NL="\\
"
fi
export SED_NL

# Generic functions

## join_by
## Examples:
## $ join_by "-delimiter-" "a" "b" "c"
## "a-delimiter-b-delimiter-c"
function join_by() {
local delimiter=$1
shift
local strings=$1
shift
printf %s "${strings}" "${@/#/$delimiter}"
}

## array_contains
## Examples:
## $ array_contains "foo" "bar" "foobaz"
## 1
##
## $ array_contains "foo" "bar" "foo" "baz"
## 0
function array_contains() {
local seeking=$1
shift
local array=("$@")
shift
for element in "${array[@]}"; do
if [[ "${element}" == "${seeking}" ]]; then
return 0
fi
done
return 1
}

# Version related functions

VERSION_SED_REGEX="[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\(-[a-zA-Z0-9]\{1,\}\)\{0,1\}"

function validate_version() {
local input_version=$1
shift
local parsed_version
parsed_version=$(sed -n "s/^v\{0,1\}\(${VERSION_SED_REGEX}\)$/\1/p" <<<"${input_version}")
printf %s "${parsed_version}"
}

function retrieve_package_version() {
sed -n "s/^__version__[[:blank:]]*\=[[:blank:]]*\"\(${VERSION_SED_REGEX}\)\"/\1/p" "${ROOT_DIR}/cogment_lab/version.py"
}

function update_package_version() {
local version=$1
sed -i.bak "/^__version__[[:blank:]]*\=/s/${VERSION_SED_REGEX}/${version}/" "${ROOT_DIR}/cogment_lab/version.py"
retrieve_package_version
}
Loading
Loading