-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make use of pre-commit to run code formatting tools Add code format checks to ci reorganize code to a python package
- Loading branch information
Showing
17 changed files
with
181 additions
and
82 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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
name: Unit Tests | ||
name: Tests | ||
|
||
on: [push, pull_request] | ||
on: push | ||
|
||
jobs: | ||
test: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v3 | ||
- uses: pre-commit/[email protected] | ||
tox-tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
python-version: [3.9] | ||
|
||
steps: | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
|
@@ -30,12 +37,16 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install -e .[dev] | ||
- name: Start ScienceBeam Docker container | ||
run: | | ||
docker run -d --rm -p 8082:8070 elifesciences/sciencebeam-parser | ||
docker run -d --rm -p 8070 elifesciences/sciencebeam-parser | ||
- name: Run tests | ||
run: | | ||
tox | ||
tox | ||
- name: Test packaging | ||
run: | | ||
tox -e .package |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Ignore the virtual environment directory | ||
_version.py | ||
node_modules | ||
venv/ | ||
*coverage* | ||
.idea | ||
|
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,35 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 24.4.2 | ||
hooks: | ||
- id: black | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: "v0.4.9" | ||
hooks: | ||
- id: ruff | ||
args: ["--fix"] | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
files: ".*\\.py" | ||
exclude: "examples|docs/examples" | ||
- id: check-added-large-files | ||
- id: check-toml | ||
- id: end-of-file-fixer | ||
exclude: "examples|docs/examples" | ||
|
||
# - repo: https://github.com/pre-commit/mirrors-prettier | ||
# rev: v4.0.0-alpha.8 | ||
# hooks: | ||
# - id: prettier | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort | ||
name: isort | ||
args: ["--profile", "black"] |
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
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
from . import _version | ||
|
||
__version__ = _version.version |
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,18 @@ | ||
import click | ||
|
||
from osm_cli.logging.logger import logger | ||
|
||
|
||
@click.group() | ||
def osm(): | ||
"""Main command for OSM""" | ||
pass | ||
|
||
|
||
@osm.command() | ||
@click.argument("file_path", type=click.Path(exists=True)) | ||
@click.argument("file_id", type=str) | ||
def pdf_xml(file_path, file_id): | ||
"""This function converts a file from PDF to XML""" | ||
# Function Implementation | ||
logger.info(f"Converted: {file_path} with ID: {file_id} to XML") |
File renamed without changes.
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
from rich.logging import RichHandler | ||
import logging | ||
|
||
from rich.logging import RichHandler | ||
|
||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="%(message)s", | ||
datefmt="[%X]", | ||
handlers=[RichHandler()] | ||
level=logging.INFO, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()] | ||
) | ||
|
||
logger = logging.getLogger("rich") |
File renamed without changes.
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 pydantic.v1 import BaseSettings | ||
|
||
|
||
class AppConfig(BaseSettings): | ||
PORT: int = 8082 | ||
HOST: str = "localhost" | ||
PROTOCAL: str = "http" | ||
|
||
|
||
config = AppConfig() |
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,55 @@ | ||
[project] | ||
name = "osm-cli" | ||
description = "Open Science Metrics (OSM) client for tracking scientific transparency and reproducibility metrics" | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
keywords = [ | ||
"open science", | ||
"altmetrics", | ||
"scientific transparency", | ||
"reproducibility" | ||
] | ||
dynamic = ["version"] | ||
|
||
dependencies = [ | ||
"click>=8.1.7", | ||
"rich>=13.7.1", | ||
] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"tox>=4.15.0", | ||
"pytest>=8.2.1", | ||
"pytest-cov", | ||
"ruff>=0.4.9", | ||
"build", | ||
"twine", | ||
"pre-commit", | ||
"pkginfo>=1.10" | ||
] | ||
|
||
[project.urls] | ||
homepage = "https://website" | ||
source = "https://github.com/nimh-dsst/osm-cli" | ||
issues = "https://github.com/nimh-dsst/osm-cli/issues" | ||
|
||
[build-system] | ||
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools_scm] | ||
write_to = "osm_cli/_version.py" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["osm_cli"] | ||
|
||
[project.scripts] | ||
osm-cli = "osm_cli.cli.main:osm" | ||
|
||
[tool.black] | ||
line-length = 88 | ||
target-version = ["py38", "py39", "py310"] | ||
|
||
[tool.ruff] | ||
line-length = 88 | ||
indent-width = 4 |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,31 +1,22 @@ | ||
import pytest | ||
from click.testing import CliRunner | ||
import os | ||
import logging | ||
|
||
from commands.file_processing import pdf_xml | ||
import pytest | ||
from click.testing import CliRunner | ||
|
||
@pytest.mark.usefixtures("caplog") | ||
class TestFileProcessing: | ||
def setup_method(self): | ||
# Create a temporary PDF file for testing | ||
self.pdf_path = 'test_sample.pdf' | ||
with open(self.pdf_path, 'wb') as f: | ||
f.write(b'%PDF-1.4\n%Test PDF content\n') | ||
from osm_cli.cli.main import pdf_xml | ||
|
||
def teardown_method(self): | ||
# Remove the temporary PDF file and any generated XML file | ||
if os.path.exists(self.pdf_path): | ||
os.remove(self.pdf_path) | ||
xml_output = f"{self.pdf_path.replace('.pdf', '')}_test_file.xml" | ||
if os.path.exists(xml_output): | ||
os.remove(xml_output) | ||
|
||
def test_pdf_xml_command(self, caplog): | ||
caplog.set_level(logging.INFO) | ||
@pytest.fixture | ||
def sample_pdf(tmp_path): | ||
pdf_path = tmp_path / "test_sample.pdf" | ||
pdf_path.write_bytes(b"%PDF-1.4\n%Test PDF content\n") | ||
yield pdf_path | ||
pdf_path.unlink() | ||
|
||
runner = CliRunner() | ||
result = runner.invoke(pdf_xml, [self.pdf_path, 'test_file']) | ||
|
||
assert result.exit_code == 0 | ||
assert f'Converted: {self.pdf_path}' in caplog.text | ||
def test_pdf_converter(caplog, sample_pdf): | ||
caplog.set_level(logging.INFO) | ||
runner = CliRunner() | ||
result = runner.invoke(pdf_xml, [str(sample_pdf), "test_file"]) | ||
assert result.exit_code == 0 | ||
assert f"Converted: {sample_pdf}" in caplog.text |
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 |
---|---|---|
@@ -1,20 +1,23 @@ | ||
[tox] | ||
envlist = py39, py310, py311, py312, lint | ||
envlist = py39, py310, py311, py312, lint, format | ||
|
||
[testenv] | ||
deps = | ||
pytest | ||
pytest-cov | ||
-r requirements.txt | ||
.[dev] | ||
commands = | ||
python -m pytest --cov=commands --cov-report=term-missing --cov-report=html --cov-report=xml | ||
python -m pytest --cov=osm_cli --cov-report=term-missing --cov-report=html --cov-report=xml | ||
|
||
[testenv:lint] | ||
description = Run ruff to lint the code | ||
commands = | ||
ruff check . | ||
|
||
[testenv:format] | ||
description = Run ruff to format the code | ||
description = Check that code is formatted with ruff | ||
commands = | ||
ruff check --fix . | ||
ruff format --check | ||
|
||
[testenv:.package] | ||
description = Generate distribution package | ||
basepython = python3 | ||
commands = python -m build --sdist --wheel --outdir packaged |