Skip to content

Commit

Permalink
refactor(util): move functions out of util
Browse files Browse the repository at this point in the history
make project installable on Jython
add devcontainer
add Jython install tests

BREAKING CHANGE: deprecate incendium.util functions
  • Loading branch information
cesarcoatl committed Apr 30, 2024
1 parent ca1658a commit 23e0aa9
Show file tree
Hide file tree
Showing 31 changed files with 1,144 additions and 254 deletions.
2 changes: 1 addition & 1 deletion .cz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ version_scheme = "pep440"
version = "2023.4.0"
update_changelog_on_bump = true
version_files = [
"setup.cfg:version"
"src/incendium/__version__.py:version"
]
18 changes: 18 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "incendium",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"settings": {
"python.defaultInterpreterPath": "/opt/python/2/bin/python"
}
}
},
"onCreateCommand": "pre-commit install && pre-commit install --hook-type commit-msg"
}
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab

[{*.md,*.yaml,*.yml}]
indent_style = space
indent_size = 2
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/jython.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
workflow_call:

jobs:
pylint:
runs-on: ubuntu-22.04
env:
JYTHON_VERSION: '2.7.3'
JYTHON_CACHE_DIR: '~/.cache/jython'
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Set up Jython
uses: coatl-dev/actions/setup-jython@v3
id: setup-jython
with:
jython-version: ${{ env.JYTHON_VERSION }}

- name: Cache Jython
uses: actions/cache@v4
with:
path: ${{ env.JYTHON_CACHE_DIR }}
key: jy-${{ steps.setup-jython.outputs.jython-path }}-${{ runner.os }}-${{ hashFiles('setup.py') }}

- name: Test installation on Jython
run: |
make install JYTHON_CACHE_DIR=${{ env.JYTHON_CACHE_DIR }}
70 changes: 62 additions & 8 deletions .github/workflows/pip-compile-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,65 @@ on:

jobs:
pip-compile-upgrade:
uses: coatl-dev/workflows/.github/workflows/pip-compile-upgrade.yml@v3
with:
path: requirements.txt
python-version: '2.7'
secrets:
gh-token: ${{ secrets.COATL_BOT_GH_TOKEN }}
gpg-sign-passphrase: ${{ secrets.COATL_BOT_GPG_PASSPHRASE }}
gpg-sign-private-key: ${{ secrets.COATL_BOT_GPG_PRIVATE_KEY }}
runs-on: ubuntu-latest
env:
PYTHON2_VERSION: '2.7'
PYTHON3_VERSION: '3.12'

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: pip-compile-requirements
uses: coatl-dev/actions/pip-compile@v3
with:
path: requirements.txt
python-version: ${{ env.PYTHON2_VERSION }}

- name: pip-compile-dev-requirements
uses: coatl-dev/actions/pip-compile@v3
with:
path: requirements/dev.txt
python-version: ${{ env.PYTHON2_VERSION }}

- name: pip-compile-build-requirements
uses: coatl-dev/actions/pip-compile@v3
with:
path: requirements/build.txt
python-version: ${{ env.PYTHON3_VERSION }}

- name: Detect changes
id: git-diff
uses: coatl-dev/actions/simple-git-diff@v3

- name: Import GPG key
if: ${{ steps.git-diff.outputs.diff == 'true' }}
id: gpg-import
uses: coatl-dev/actions/gpg-import@v3
with:
passphrase: ${{ secrets.COATL_BOT_GPG_PASSPHRASE }}
private-key: ${{ secrets.COATL_BOT_GPG_PRIVATE_KEY }}

- name: Build commit message
if: ${{ steps.git-diff.outputs.diff == 'true' }}
run: |
echo "chore(requirements): pip-compile upgrade" > "$RUNNER_TEMP/commit.txt"
{
echo ""
echo "updates:"
git status --porcelain | awk 'match($1, "M") {print " - " $2}'
} >> "$RUNNER_TEMP/commit.txt"
- name: Commit and push changes
if: ${{ steps.git-diff.outputs.diff == 'true' }}
run: |
git checkout -B coatl-dev-pip-compile-upgrade
git add -u
git commit --file="${RUNNER_TEMP}/commit.txt"
git push --force --set-upstream origin coatl-dev-pip-compile-upgrade
- name: Create pull request
if: ${{ steps.git-diff.outputs.diff == 'true' }}
uses: coatl-dev/actions/pr-create@v3
with:
gh-token: ${{ secrets.COATL_BOT_GH_TOKEN }}
8 changes: 6 additions & 2 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ on:
- main
paths:
- 'src/**'
- pyproject.toml
- Makefile
- requirements.txt
- setup.cfg
- setup.py
- tox.ini

jobs:
jython:
uses: ./.github/workflows/jython.yml

tox:
needs: jython
uses: coatl-dev/workflows/.github/workflows/tox-docker.yml@v3
13 changes: 6 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ jobs:
needs: pre-commit
uses: coatl-dev/workflows/.github/workflows/pylint.yml@v3

jython:
needs: pylint
uses: ./.github/workflows/jython.yml

tox:
needs:
- pre-commit
- pylint
needs: jython
uses: coatl-dev/workflows/.github/workflows/tox-docker.yml@v3

pypi-publish:
needs:
- pre-commit
- pylint
- tox
needs: tox
uses: coatl-dev/workflows/.github/workflows/pypi-upload.yml@v3
with:
python-version: '2.7'
Expand Down
3 changes: 3 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
César Román <[email protected]> César Román <[email protected]>
César Román <[email protected]> César Román <[email protected]>
César Román <[email protected]> Cesar Roman <[email protected]>
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ repos:
language: system
files: ^src/
types: [python]
- repo: https://github.com/coatl-dev/hadolint-coatl
rev: 2.12.0.3
hooks:
- id: hadolint
22 changes: 14 additions & 8 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ persistent=yes

# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
py-version=3.10
py-version=3.12

# Discover python modules and packages in the file system subtree.
recursive=no
Expand Down Expand Up @@ -190,8 +190,7 @@ good-names=i,
k,
ex,
Run,
_,
to
_

# Good variable names regexes, separated by a comma. If names match any regex,
# they will always be accepted
Expand Down Expand Up @@ -338,7 +337,7 @@ indent-after-paren=4
indent-string=' '

# Maximum number of characters on a single line.
max-line-length=88
max-line-length=100

# Maximum number of lines in a module.
max-module-lines=1000
Expand Down Expand Up @@ -426,13 +425,14 @@ disable=consider-using-f-string,
no-member,
redefined-builtin,
super-with-arguments,
unnecessary-pass,
useless-object-inheritance,

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once). See also the "--disable" option for examples.
enable=c-extension-no-member
enable=


[METHOD_ARGS]
Expand Down Expand Up @@ -464,6 +464,11 @@ max-nested-blocks=5
# printed.
never-returning-functions=sys.exit,argparse.parse_error

# Let 'consider-using-join' be raised when the separator to join on would be
# non-empty (resulting in expected fixes of the type: ``"- " + " -
# ".join(items)``)
suggest-join-with-non-empty-separator=yes


[REPORTS]

Expand All @@ -478,8 +483,9 @@ evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor
# used to format the message information. See doc for all details.
msg-template=

# Set the output format. Available formats are text, parseable, colorized, json
# and msvs (visual studio). You can also give a reporter class, e.g.
# Set the output format. Available formats are: text, parseable, colorized,
# json2 (improved json format), json (old json format) and msvs (visual
# studio). You can also give a reporter class, e.g.
# mypackage.mymodule.MyReporterClass.
#output-format=

Expand Down Expand Up @@ -514,7 +520,7 @@ min-similarity-lines=4
max-spelling-suggestions=4

# Spelling dictionary name. No available dictionaries : You need to install
# both the python package and the system dependency for enchant to work..
# both the python package and the system dependency for enchant to work.
spelling-dict=

# List of comma separated words that should be considered directives if they
Expand Down
56 changes: 56 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# hadolint global ignore=DL3008,DL3042
FROM coatldev/six:3.12 as base

ENV JYTHON_VERSION 2.7.3
ENV JYTHON_HOME /opt/jython/${JYTHON_VERSION}

RUN set -eux; \
\
apt-get update --quiet; \
apt-get install --yes --no-install-recommends \
openjdk-17-jre \
; \
rm -rf /var/lib/apt/lists/*

# >============================================================================<

FROM base as jython

RUN set -eux; \
\
apt-get update --quiet; \
apt-get install --yes --no-install-recommends \
wget \
; \
rm -rf /var/lib/apt/lists/*

WORKDIR /tmp

RUN set -eux; \
\
wget -q "https://repo1.maven.org/maven2/org/python/jython-installer/${JYTHON_VERSION}/jython-installer-${JYTHON_VERSION}.jar"; \
\
java -jar "jython-installer-${JYTHON_VERSION}.jar" \
--silent \
--type standard \
--directory "$JYTHON_HOME"

# >============================================================================<

FROM base as final

COPY --from=jython ${JYTHON_HOME}/ ${JYTHON_HOME}/

ENV PATH ${JYTHON_HOME}/bin:$PATH

COPY requirements /tmp/requirements/

RUN set -eux; \
\
python2 -m pip install --requirement \
/tmp/requirements/dev.txt; \
\
python3 -m pip install --requirement \
/tmp/requirements/build.txt

CMD ["/bin/bash"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2021 César Román
Copyright (c) 2020-2024 coatl.dev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
JYTHON_CACHE_DIR := ~/.cache/jython

.DEFAULT_GOAL := help

##@ Help

.PHONY: help clean check init install install-clean install-force install-nocache install-nodeps

help: ## Display this help message.
@awk \
'BEGIN { \
FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n" \
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " \033[36m%-16s\033[0m %s\n", $$1, $$2 \
} \
/^##@/ { \
printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
} ' \
$(MAKEFILE_LIST)

##@ Cleanup

clean: ## Uninstall all Jython packages.
@ echo "Uninstalling all Jython packages…"
jython -m pip freeze | xargs jython -m pip uninstall -y

##@ Initialize

check: ## Check if Jython is installed.
@echo "Cheking if Jython is installed…"
@if ! command -v jython &> /dev/null; then \
echo "Jython is not installed. Please install Jython before proceeding."; \
exit 1; \
fi

init: ## Run check and create required directories for other targets.
@echo "Initializing…"
@mkdir -p "$(JYTHON_CACHE_DIR)"

##@ Install
install: check init ## Install this package using Jython with caching enabled.
@echo "Installing package…"
jython -m pip install --cache-dir="$(JYTHON_CACHE_DIR)" .

install-clean: check init clean ## Perform clean installation using Jython with caching enabled.
@echo "Running clean install…"
jython -m pip install --cache-dir="$(JYTHON_CACHE_DIR)" .

install-force: check init ## Reinstall all packages using Jython even if they are already up-to-date.
@echo "Reinstalling all packages…"
jython -m pip install --force-reinstall --cache-dir="$(JYTHON_CACHE_DIR)" .

install-nocache: check ## Install this package using Jython with caching disabled.
@echo "Installing packages (no cache)…"
jython -m pip install --no-cache-dir .

install-nodeps: check ## Install this package without dependencies.
@echo "Installing package without dependencies…"
jython -m pip install --no-deps .
Loading

0 comments on commit 23e0aa9

Please sign in to comment.