-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Publish Python Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.7", "3.8", "3.9", "3.10"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- uses: actions/cache@v3 | ||
name: Configure pip caching | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Install dependencies | ||
run: | | ||
pip install -e '.[test]' | ||
- name: Run tests | ||
run: | | ||
pytest | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: [test] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- uses: actions/cache@v3 | ||
name: Configure pip caching | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-publish-pip-${{ hashFiles('**/setup.py') }} | ||
restore-keys: | | ||
${{ runner.os }}-publish-pip- | ||
- name: Install dependencies | ||
run: | | ||
pip install setuptools wheel twine build | ||
- name: Publish | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | ||
run: | | ||
python -m build | ||
twine upload dist/* | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Test | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.7", "3.8", "3.9", "3.10"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- uses: actions/cache@v3 | ||
name: Configure pip caching | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Install dependencies | ||
run: | | ||
pip install -e '.[test]' | ||
- name: Run tests | ||
run: | | ||
pytest | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.venv | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
venv | ||
.eggs | ||
.pytest_cache | ||
*.egg-info | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# quarto-post-init | ||
|
||
[![PyPI](https://img.shields.io/pypi/v/quarto-post-init.svg)](https://pypi.org/project/quarto-post-init/) | ||
[![Changelog](https://img.shields.io/github/v/release/crossjam/quarto-post-init?include_prereleases&label=changelog)](https://github.com/crossjam/quarto-post-init/releases) | ||
[![Tests](https://github.com/crossjam/quarto-post-init/workflows/Test/badge.svg)](https://github.com/crossjam/quarto-post-init/actions?query=workflow%3ATest) | ||
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/crossjam/quarto-post-init/blob/master/LICENSE) | ||
|
||
Initialize a directory as a post for Quarto | ||
|
||
## Installation | ||
|
||
Install this tool using `pip`: | ||
|
||
pip install quarto-post-init | ||
|
||
## Usage | ||
|
||
For help, run: | ||
|
||
quarto-post-init --help | ||
|
||
You can also use: | ||
|
||
python -m quarto_post_init --help | ||
|
||
## Development | ||
|
||
To contribute to this tool, first checkout the code. Then create a new virtual environment: | ||
|
||
cd quarto-post-init | ||
python -m venv venv | ||
source venv/bin/activate | ||
|
||
Now install the dependencies and test dependencies: | ||
|
||
pip install -e '.[test]' | ||
|
||
To run the tests: | ||
|
||
pytest |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .cli import cli | ||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
import click | ||
|
||
from .logconfig import DEFAULT_LOG_FORMAT, logging_config | ||
|
||
|
||
@click.group() | ||
@click.version_option() | ||
@click.option( | ||
"--log-format", | ||
type=click.STRING, | ||
default=DEFAULT_LOG_FORMAT, | ||
help="Python logging format string", | ||
) | ||
@click.option( | ||
"--log-level", default="ERROR", help="Python logging level", show_default=True | ||
) | ||
@click.option( | ||
"--log-file", | ||
help="Python log output file", | ||
type=click.Path(dir_okay=False, writable=True, resolve_path=True), | ||
default=None, | ||
) | ||
def cli(log_format, log_level, log_file): | ||
"Initialize a directory as a post for Quarto" | ||
|
||
logging_config(log_format, log_level, log_file) | ||
|
||
|
||
@cli.command(name="command") | ||
@click.argument("example") | ||
def first_command(example): | ||
"Command description goes here" | ||
|
||
click.echo("Here is some output") | ||
logging.info("Here's some log output") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import logging | ||
import time | ||
|
||
DEFAULT_LOG_FORMAT = "%(created)d.%(msecs)03d|%(asctime)s|%(levelname)s|%(name)s|%(funcName)s|%(message)s" | ||
|
||
|
||
def logging_config(log_format, log_level, log_file): | ||
logging.Formatter.converter = time.gmtime | ||
numeric_level = getattr(logging, log_level.upper(), None) | ||
if not isinstance(numeric_level, int): | ||
raise ValueError(f"Invalid Python log level: {log_level}") | ||
|
||
if log_file: | ||
logging.basicConfig( | ||
level=numeric_level, | ||
filename=log_file, | ||
format=log_format, | ||
datefmt="%Y/%m/%d %I:%M:%S%z %Z %p", | ||
) | ||
else: | ||
logging.basicConfig( | ||
level=numeric_level, | ||
format=log_format, | ||
datefmt="%Y/%m/%d %I:%M:%S%z %Z %p", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from setuptools import setup | ||
import os | ||
|
||
VERSION = "0.1" | ||
|
||
|
||
def get_long_description(): | ||
with open( | ||
os.path.join(os.path.dirname(os.path.abspath(__file__)), "README.md"), | ||
encoding="utf8", | ||
) as fp: | ||
return fp.read() | ||
|
||
|
||
setup( | ||
name="quarto-post-init", | ||
description="Initialize a directory as a post for Quarto", | ||
long_description=get_long_description(), | ||
long_description_content_type="text/markdown", | ||
author="Brian M. Dennis", | ||
url="https://github.com/crossjam/quarto-post-init", | ||
project_urls={ | ||
"Issues": "https://github.com/crossjam/quarto-post-init/issues", | ||
"CI": "https://github.com/crossjam/quarto-post-init/actions", | ||
"Changelog": "https://github.com/crossjam/quarto-post-init/releases", | ||
}, | ||
license="Apache License, Version 2.0", | ||
version=VERSION, | ||
packages=["quarto_post_init"], | ||
entry_points=""" | ||
[console_scripts] | ||
quarto-post-init=quarto_post_init.cli:cli | ||
""", | ||
install_requires=["click"], | ||
extras_require={ | ||
"test": ["pytest"] | ||
}, | ||
python_requires=">=3.7", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from click.testing import CliRunner | ||
from quarto_post_init.cli import cli | ||
|
||
|
||
def test_version(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
result = runner.invoke(cli, ["--version"]) | ||
assert result.exit_code == 0 | ||
assert result.output.startswith("cli, version ") |