Skip to content

Commit

Permalink
Added publishing to PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
anevis committed Apr 6, 2024
1 parent ae1f444 commit 33e8bff
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 19 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CD Pipeline
run-name: CD 📦🚀

on:
workflow_run:
workflows: ['CI']
types: [completed]
branches:
- 'main'

jobs:
CD:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: Installing Devbox ⚙️
uses: jetpack-io/[email protected]
- name: Install all dependencies 📦
run: devbox run install-dev
- name: 📦 Package
run: devbox run build
- name: 🚀 Publish to PyPI
run: devbox run publish
- run: echo "🍏 This job's status is ${{ job.status }}."
6 changes: 4 additions & 2 deletions .github/workflows/ci-cd.yaml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI/CD Pipeline
run-name: CI/CD 🚀
name: CI Pipeline
run-name: CI 🚀
on: [push]
jobs:
CI:
Expand All @@ -18,4 +18,6 @@ jobs:
run: devbox run install-dev
- name: 🧹 Linting & Formatting
run: devbox run lint && devbox run format
- name: 🧪 Running Tests
run: devbox run test
- run: echo "🍏 This job's status is ${{ job.status }}."
6 changes: 6 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
],
"format": [
"black src/"
],
"build": [
"python setup.py sdist bdist_wheel"
],
"publish": [
"twine upload dist/*"
]
}
}
Expand Down
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ mypy==1.9.0
pep8-naming==0.13.3
safety

# Packaging
setuptools==69.2.0
twine==5.0.0
wheel==0.43.0

# Typing
types-mock==5.1.0.20240311
types-orjson==3.6.2
Expand Down
31 changes: 31 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from setuptools import setup, find_packages
import calendar
import time

gmt = time.gmtime()
ts = calendar.timegm(gmt)

with open("README.md", "r") as fh:
long_description = fh.read()

setup(
name="json-to-markdown",
version=f"0.1.{ts}",
packages=find_packages(where="src"),
package_dir={"": "src"},
url="https://anevis.github.io/json-to-markdown/",
license="MIT",
author="anevis",
install_requires=[
"click==8.1.7",
"jsonschema[format]==4.21.1",
"pyyaml==6.0.1",
],
entry_points={
"console_scripts": [
"json-to-markdown=json_to_markdown.convert:main",
],
},
long_description=long_description,
long_description_content_type="text/markdown",
)
55 changes: 38 additions & 17 deletions src/json_to_markdown/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,57 @@ def _get_yaml_data(yaml_file: str) -> Dict[str, Any]:
return yaml.safe_load(y_file)


def _help() -> None:
click.echo("Convert JSON or YAML to Markdown.")
click.echo(
"Usage: json-to-markdown -o <output_file> [-y <yaml_file> | -j <json_file>]"
)
click.echo(
" -o, --output-file <output_file>: Path to the output file as a string [Mandatory]."
)
click.echo(
" -y, --yaml-file <yaml_file>: Path to the YAML file as a string [Optional]"
)
click.echo(
" -j, --json-file <json_file>: Path to the JSON file as a string [Optional]"
)
click.echo(" -h, --help: Show this message and exit.")
click.echo(
"Note: Either yaml_file or json_file is required along with output_file."
)
click.echo("Example: json-to-markdown -o output.md -y data.yaml")


@click.command()
@click.option("-o", "--output-file", "output_file", type=str)
@click.option("-y", "--yaml-file", "yaml_file", type=str, default=None)
@click.option("-j", "--json-file", "json_file", type=str, default=None)
def main(output_file: str, yaml_file: Optional[str], json_file: Optional[str]) -> None:
@click.option("-h", "--help", "show_help", default=False, is_flag=True)
def main(
output_file: str,
yaml_file: Optional[str],
json_file: Optional[str],
show_help: bool,
) -> None:
if show_help or (yaml_file is None and json_file is None) or output_file is None:
_help()
return

convert(output_file=output_file, yaml_file=yaml_file, json_file=json_file)


def convert(
output_file: str, yaml_file: Optional[str] = None, json_file: Optional[str] = None
) -> None:
if yaml_file is None and json_file is None:
raise RuntimeError("One of yaml_file or json_file is required.")
if yaml_file is None and json_file is None or output_file is None:
_help()
raise RuntimeError(
"One of yaml_file or json_file is required along with output_file"
)

data = _get_json_data(json_file) if json_file else _get_yaml_data(yaml_file)
with io.open(output_file, "w", encoding="utf-8") as md_file:
converter = MDConverter()
converter.set_selected_sections(
sections=[
"assessment-date",
"assessors",
"description",
"diagram",
"external-dependencies",
"roles",
"entry-points",
"threats",
]
)
converter.convert(data=data, output_writer=md_file)
MDConverter().convert(data=data, output_writer=md_file)


if __name__ == "__main__":
Expand Down

0 comments on commit 33e8bff

Please sign in to comment.