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

[PACKAGE-1] Package to PIP #84

Merged
merged 32 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
081adac
chore: port changes from test-1
seyLu Oct 22, 2023
60febe8
feat: project rename
seyLu Oct 22, 2023
83a6cce
chore: clean up deps
seyLu Oct 22, 2023
2c8d56d
feat: build with hatchling, build and upload dist using twine
seyLu Oct 22, 2023
744f4d7
Merge branch 'main' into feat/PACKAGE-1
seyLu Oct 22, 2023
9557d53
feat: move deps to src
seyLu Oct 22, 2023
ec348e3
feat: add entry point
seyLu Oct 22, 2023
98dcb8e
feat: add deps to pyproject.toml and resolve path shenanigans
seyLu Oct 22, 2023
a7cfa53
feat: add deps to pyproject.toml and resolve path shenanigans
seyLu Oct 22, 2023
a45dbfa
chore: change color of project name in version callback
seyLu Oct 22, 2023
4773399
docs: update README
seyLu Oct 22, 2023
29e3c30
docs: add basic usage
seyLu Oct 22, 2023
b1c2e77
docs: add advanced usage
seyLu Oct 22, 2023
973413b
feat: rename PERSONAL_ACCESS_TOKEN to just TOKEN
seyLu Oct 22, 2023
d9d550d
docs: add short -h command on setup and dump
seyLu Oct 22, 2023
748e786
docs: update alt text of icon
seyLu Oct 22, 2023
907325d
chore: revert version to 0.0.1
seyLu Oct 22, 2023
38a93a9
feat: add dynamic versioning
seyLu Oct 22, 2023
e15f858
docs: update basic usage
seyLu Oct 22, 2023
05b7544
chore: move build-system up
seyLu Oct 22, 2023
18ec43d
feat: add bandit to ruff config
seyLu Oct 22, 2023
c47e856
chore: reformat
seyLu Oct 22, 2023
2fc4fdc
chore: reformat
seyLu Oct 22, 2023
3f7f492
feat: add pre-commit prettier
seyLu Oct 23, 2023
ceaeae3
feat: add ruff config flake8-builtins
seyLu Oct 23, 2023
284c8bb
feat: add ruff config flake8-builtins
seyLu Oct 23, 2023
f1e8e40
feat: add more ruff rules and add HTTPError request exception handling
seyLu Oct 23, 2023
335c72a
feat (pre-commit): deprecate black in favor of ruff format
seyLu Feb 14, 2024
75ab1ff
chore: remove unecessary main function
seyLu Feb 14, 2024
142f200
Merge branch 'main' into feat/PACKAGE-1
seyLu Feb 14, 2024
ffdeb0e
Merge branch 'main' into feat/PACKAGE-1
seyLu Mar 29, 2024
2d1d5b2
ci (lint): deprecate black in favor of ruff
seyLu Mar 29, 2024
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GITHUB_PERSONAL_ACCESS_TOKEN=<your_github_personal_access_token>
GITHUB_TOKEN=<your_github_personal_access_token>
GITHUB_REPO_OWNER=<target_github_repository_owner>
GITHUB_REPO_NAME=<target_github_repository_name>
2 changes: 0 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,3 @@ jobs:
mypy .
--install-types
--non-interactive
--check-untyped-defs
--ignore-missing-imports
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
89 changes: 58 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,99 @@
<div align="center">
<img height=100 src="https://github.com/seyLu/setup-issue-label-cli/blob/main/static/icons/labels.png" alt="Setup Github Label CLI Icon">
<h1Github Label CLI</h1>
<img height=100 src="https://github.com/seyLu/ghlabel/blob/main/labels.png" alt="ghlabel icon">
<h1>ghlabel</h1>
<p>CLI tool to help setup Github Labels from a yaml/json config file.</p>
<p>
<a href="https://github.com/seyLu/setup-issue-label-cli/issues/new">Report Bug</a>
<img src="https://github.com/seyLu/ghlabel/actions/workflows/codeql.yaml/badge.svg" alt="Codeql badge">
<img src="https://github.com/seyLu/ghlabel/actions/workflows/lint.yaml/badge.svg" alt="Lint badge">
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/python-3.11+-blue" alt="Python 3.11+ badge"></a>
<a href="https://peps.python.org/pep-0008/"><img src="https://img.shields.io/badge/code%20style-pep8-orange.svg" alt="PEP8 badge"></a>
<a href="https://github.com/seyLu/ghlabel/blob/main/LICENSE"><img src="https://img.shields.io/github/license/seyLu/ghlabel.svg" alt="MIT License"></a>
</p>
<p>
<a href="https://github.com/seyLu/ghlabel/issues/new">Report Bug</a>
·
<a href="https://github.com/seyLu/setup-issue-label-cli/issues/new">Request Feature</a>
<a href="https://github.com/seyLu/ghlabel/issues/new">Request Feature</a>
·
<a href="https://github.com/seyLu/setup-issue-label-cli/discussions">Ask Question</a>
<a href="https://github.com/seyLu/ghlabel/discussions">Ask Question</a>
</p>
</div>

<br>

### Supported Python version
### Installation and Setup

It is recommended to not install the CLI tool globally.

#### 1. Create a new directory where you want the configuration to live

```bash
python==3.11
mkdir ghlabel

# this is where the labels config will be located
cd ghlabel
```

<br>
#### 2. Create and activate virtual environment

### Setup
```bash
python -m venv .venv

#### 1. Clone the repo
# Linux/Mac
. .venv/bin/activate

```bash
git clone git@github.com:seyLu/setup-github-label-cli.git
# Windows
.venv\Scripts\activate.bat
```

#### 2. Install dependencies

##### Create a new virtual environment
#### 3. Install package

```bash
python -m venv .venv
pip install ghlabel

# check if installed
ghlabel -v
```

##### Activate the virtual environment
#### 4. Create `.env` and supply github credentials

```bash
# Linux/Mac
. .venv/bin/activate
touch .env

# Windows
.venv\Scripts\activate.bat
type nul > .env
```

```bash
GITHUB_PERSONAL_ACCESS_TOKEN=<your_github_personal_access_token>
GITHUB_REPO_OWNER=<target_github_repository_owner>
GITHUB_REPO_NAME=<target_github_repository_name>
```

##### Install dependencies from requirements.txt
<br>

### Basic Usage

#### 1. Generate labels config

```bash
pip install -r requirements.txt
ghlabel dump
```

#### 3. Create `.env` and supply github credentials
#### 2. Setup labels in GitHub

```bash
cp .env.example .env
ghlabel setup
```

##### `.env.example` preview
<br>

For advanced usage, see:
```bash
GITHUB_PERSONAL_ACCESS_TOKEN=<your_github_personal_access_token>
GITHUB_REPO_OWNER=<target_github_repository_owner>
GITHUB_REPO_NAME=<target_github_repository_name>
ghlabel -h
```

<br>
<br>

## :red_circle: `ghlabel`
Expand All @@ -87,7 +114,7 @@ $ ghlabel [OPTIONS] COMMAND [ARGS]...
Show version and exit.
#### `--debug`, `-D`
Enable debug mode and show logs.
#### `--help`
#### `--help`, `-h`
Show this message and exit.

<br>
Expand Down Expand Up @@ -123,7 +150,7 @@ Specify the dir where to find labels.
Label file extension.
#### `--app`, `-a [app|game|web]` [default: app]
App to determine label template.
#### `--help`
#### `--help`, `-h`
Show this message and exit.

<br>
Expand Down Expand Up @@ -160,7 +187,7 @@ Add more labels.
Remove more labels.
#### `--remove-all`, `-R [disable|enable|silent]` [default: disable]
Remove all Github labels.
#### `--help`
#### `--help`, `-h`
Show this message and exit.

<br>
Expand All @@ -186,7 +213,7 @@ ghlabel setup -r "Type: Feature Request, Type: Bug"
```bash
# -a [valid json string]
# will be parsed as list[dict[str, str]]
ghlabel setup -a "[{'name': 'wontfix', 'color': '##ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
ghlabel setup -a "[{'name': 'wontfix', 'color': '#ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
```

<br>
Expand Down
8 changes: 4 additions & 4 deletions ghlabel.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ ghlabel [OPTIONS] COMMAND [ARGS]...
Show version and exit.
#### `--debug`, `-D`
Enable debug mode and show logs.
#### `--help`
#### `--help`, `-h`
Show this message and exit.

<br>
Expand Down Expand Up @@ -54,7 +54,7 @@ Specify the dir where to find labels.
Label file extension.
#### `--app`, `-a [app|game|web]` [default: app]
App to determine label template.
#### `--help`
#### `--help`, `-h`
Show this message and exit.

<br>
Expand Down Expand Up @@ -91,7 +91,7 @@ Add more labels.
Remove more labels.
#### `--remove-all`, `-R [disable|enable|silent]` [default: disable]
Remove all Github labels.
#### `--help`
#### `--help`, `-h`
Show this message and exit.

<br>
Expand All @@ -117,5 +117,5 @@ ghlabel setup -r "Type: Feature Request, Type: Bug"
```bash
# -a [valid json string]
# will be parsed as list[dict[str, str]]
ghlabel setup -a "[{'name': 'wontfix', 'color': '##ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
ghlabel setup -a "[{'name': 'wontfix', 'color': '#ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
```
File renamed without changes
49 changes: 40 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "python-template"
version = "0.0.1"
# Support Python 3.11.
requires-python = "==3.11"
name = "ghlabel"
requires-python = ">=3.11"
license = "MIT"
authors = [
{name = "MJ Sabit (seyLu)", email = "98249191+seyLu@users.noreply.github.com"},
]
description = "CLI tool to help setup Github Labels from a yaml/json config file."
readme = "README.md"
dynamic = ["version"]
keywords = [
"github-tool",
"github-labels",
"cli-tool",
]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"typer[all]==0.9.0",
"requests==2.31.0",
"python-dotenv==1.0.0",
"PyYAML==6.0.1",
]

[project.urls]
Documentation = "https://github.com/seyLu/ghlabel#readme"
"Homepage" = "https://github.com/seyLu/ghlabel"
"Bug Tracker" = "https://github.com/seyLu/ghlabel/issues"

[project.scripts]
ghlabel = "ghlabel.cli:app"


[tool.hatch.version]
path = "src/ghlabel/__about__.py"


[tool.ruff]
select = [
"E", # Pyflakes
"F", # Pycodestyle
"B", # flake8-bugbear
"S", # flake8-bandit
"I001" # isort
]

Expand All @@ -29,14 +63,11 @@ unfixable = ["B"]
"path/to/file.py" = ["E402"]


[tool.isort]
# Automatically apply black to isort.
profile = "black"


[tool.mypy]
strict = "True"
implicit_reexport = "True"
check_untyped_defs = true
ignore_missing_imports = true

# Exclude type checking on files/dirs
exclude = [
Expand Down
33 changes: 11 additions & 22 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
certifi==2023.7.22
cfgv==3.4.0
charset-normalizer==3.3.0
click==8.1.7
colorama==0.4.6
distlib==0.3.7
filelock==3.12.4
identify==2.5.30
idna==3.4
markdown-it-py==3.0.0
mdurl==0.1.2
nodeenv==1.8.0
platformdirs==3.11.0
pre-commit==3.5.0
Pygments==2.16.1
# core
typer[all]==0.9.0
requests==2.31.0
python-dotenv==1.0.0
PyYAML==6.0.1
requests==2.31.0
rich==13.6.0
shellingham==1.5.3
typer==0.9.0
typing_extensions==4.8.0
urllib3==2.0.7
virtualenv==20.24.5

# packaging
hatchling==1.18.0
build==1.0.3
twine==4.0.2

# dev tools
pre-commit==3.5.0
1 change: 1 addition & 0 deletions src/ghlabel/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1"
File renamed without changes.
22 changes: 15 additions & 7 deletions cli.py → src/ghlabel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
__github__ = "github.com/seyLu"

__licence__ = "MIT"
__version__ = "0.0.1"
__maintainer__ = "seyLu"
__status__ = "Prototype"

Expand All @@ -18,10 +17,12 @@
from typing import Annotated, Optional

import typer
from rich import print as rich_print
from rich.progress import Progress, SpinnerColumn, TextColumn

from scripts.dump_label import DumpLabel
from scripts.setup_github_label import GithubConfig, GithubLabel
from .__about__ import __version__
from .utils.dump_label import DumpLabel
from .utils.setup_github_label import GithubConfig, GithubLabel


def parse_remove_labels(labels: str | None) -> list[str] | None:
Expand All @@ -38,7 +39,9 @@ def parse_add_labels(labels: str | None) -> list[dict[str, str]] | None:

def version_callback(show_version: bool) -> None:
if show_version:
print(f"{os.path.basename(__file__)} {__version__}")
rich_print(
f"\n[green]{os.path.basename(os.path.dirname(__file__))}[/green] {__version__}\n"
)
raise typer.Exit()


Expand All @@ -59,15 +62,20 @@ class RemoveAllChoices(str, Enum):
silent = "silent"


app = typer.Typer(add_completion=False)
app = typer.Typer(
add_completion=False,
context_settings={
"help_option_names": ["-h", "--help"],
},
)


@app.command("setup", help="Add/Remove Github labels from config files.") # type: ignore[misc]
def setup_labels(
token: Annotated[
Optional[str],
typer.Argument(
envvar="PERSONAL_ACCESS_TOKEN",
envvar="TOKEN",
show_default=False,
),
] = None,
Expand Down Expand Up @@ -133,7 +141,7 @@ def setup_labels(
) as progress:
progress.add_task(description="[green]Fetching...", total=None)
if token:
GithubConfig.set_PERSONAL_ACCESS_TOKEN(token)
GithubConfig.set_TOKEN(token)
if repo_owner:
GithubConfig.set_REPO_OWNER(repo_owner)
if repo_name:
Expand Down
File renamed without changes.
Empty file added src/ghlabel/utils/__init__.py
Empty file.
Loading