Skip to content

Commit

Permalink
Merge pull request #3 from mattwang44/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwang44 authored Jan 24, 2022
2 parents 5c19c4b + 5ffbc4f commit ace3f79
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 36 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on:
push:
branches:
- "dev"
- "main"

pull_request:
branches:
- "dev"
- "main"

jobs:
ci:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10"]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Setup Poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: "1.1.12"

- run: python3 -m poetry install

- name: Run mypy
run: python -m poetry run mypy . --install-types --non-interactive

- name: Run isort
run: python -m poetry run isort . --check-only

- name: Run flake8
run: python -m poetry run flake8 .

# - name: Run unit tests
# run: python -m poetry run pytest .
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ ignore:
patterns:
- "type code(s)?" # "type code" or "type codes" will be skipped
rst_tags:
- source # skip :source:`*`
- source # :source:`*` will be skipped
- class
- c:
- func # -> skip :c:func:`*`
- func # :c:func:`*` will be skipped
- data
```
Expand All @@ -91,8 +91,10 @@ The sample output is shown below:
- [ ] More handy parameters/options
- [ ] CI/CD
- [ ] Unit tests
- [ ] Static checks (mypy, isort, etc)
- [ ] Upload to PyPI
- [ ] Config files
- [ ] Handle missing fields.
- [ ] Commands for creating a basic config file.

## Acknowledge

`poglossary` is primarily inspired by those fantastic translator tools collected in [poutils](https://github.com/afpy/poutils) and [translate toolkit](https://github.com/translate/translate).
136 changes: 135 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions poglossary/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .poglossary import app

app(prog_name="poglossary")
22 changes: 12 additions & 10 deletions poglossary/config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from pathlib import Path
import re
from pathlib import Path
from typing import Any, Dict, List, Pattern, Union

from pydantic import BaseModel, Extra
import yaml
from pydantic import BaseModel, Extra

from . import logger


DEFAULT_CONFIG_PATH = "./poglossary.yml"
DEFAULT_SOURCE_PATH = '.'
DEFAULT_SOURCE_EXCLUDES = [
'./.git',
DEFAULT_SOURCE_EXCLUDE_PATTERNS = [
'.git',
]
DEFAULT_IGNORE_RST_TAG_OBJS = [
'ref', 'keyword', 'dfn',
Expand Down Expand Up @@ -45,11 +44,14 @@ def __init__(self, **data) -> None:

def _build_tags(self, tag_objs: List[Union[Dict, str]]) -> List[str]:
if not self.override_default_rst_tags:
tag_objs = DEFAULT_IGNORE_RST_TAG_OBJS + tag_objs
tag_objs.extend(DEFAULT_IGNORE_RST_TAG_OBJS)

ignore_tags = []
ignore_tags: List[str] = []

def _build_tags_recursively(tag_objs, prefix=''):
def _build_tags_recursively(
tag_objs: List[Union[Dict, str]],
prefix: str = '',
) -> None:
for obj in tag_objs:
if isinstance(obj, str):
ignore_tags.append(f":{prefix}{obj}:")
Expand All @@ -76,7 +78,7 @@ def __init__(
config_file: Union[Path, str],
) -> None:
# TODO: need format check for config file
config_file_path = Path(config_file)
config_file_path: Path = Path(config_file)
self.config: Dict[str, Any] = {}
if config_file_path.is_file():
try:
Expand All @@ -95,6 +97,6 @@ def __init__(
)

@property
def ignore_pattern(self):
def ignore_pattern(self) -> Pattern:
# merely a shorthand
return self.ignore_settings.ignore_pattern
22 changes: 12 additions & 10 deletions poglossary/find_sources.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import glob
from pathlib import Path
from typing import List

from pydantic import BaseModel

from .config import DEFAULT_SOURCE_EXCLUDES
from . import logger
from .config import DEFAULT_SOURCE_EXCLUDE_PATTERNS


class SourceFinder(BaseModel):
path: Path
exlcudes: List[Path] = []
excludes: List[Path] = []
po_paths: List[Path] = []

def __init__(self, *args, **kwargs) -> None:
Expand Down Expand Up @@ -37,17 +38,18 @@ def _get_po_paths(self) -> List[Path]:

def _exclude(self, po_paths: List[Path]) -> List[Path]:
"""Exclude paths by the given list of paths"""
self.exlcudes.extend(DEFAULT_SOURCE_EXCLUDES)
for pattern in DEFAULT_SOURCE_EXCLUDE_PATTERNS:
for relative_path in glob.glob(pattern):
self.excludes.append(self.path / relative_path)

excluded_files = []
excluded_dirs = []
for e in self.exlcudes:
for path in self.path.glob(e):
p = path.resolve()
if p.is_file():
excluded_files.append(p)
else:
excluded_dirs.append(p)
for path in self.excludes:
p = path.resolve()
if p.is_file():
excluded_files.append(p)
else:
excluded_dirs.append(p)

paths = []
for path in po_paths:
Expand Down
Loading

0 comments on commit ace3f79

Please sign in to comment.