-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build artefacts in gitignore * Add support for date_fin attribute and is_open_ended method * add test case * start check_expiry * add cli command * archive support * add latest_version_id attribute and related logic * move to datetime * fixes * fix * assert_never requires typing_extensions before python 3.11 * typer needs an explicit Exit exception to return an error code
- Loading branch information
Showing
9 changed files
with
266 additions
and
8 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 |
---|---|---|
|
@@ -12,3 +12,5 @@ __pycache__/ | |
# Unit test / coverage reports | ||
.coverage | ||
|
||
.tox/ | ||
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
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 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,49 @@ | ||
import logging | ||
import warnings | ||
from datetime import datetime, timezone | ||
from pathlib import Path | ||
from typing import TextIO | ||
|
||
from catleg.parse_catala_markdown import parse_catala_file | ||
from catleg.query import get_backend | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
async def check_expiry(f: TextIO, *, file_path: Path | None = None): | ||
# parse articles from file | ||
articles = parse_catala_file(f, file_path=file_path) | ||
|
||
back = get_backend("legifrance") | ||
ref_articles = await back.articles([article.id.upper() for article in articles]) | ||
has_expired_articles = False | ||
now = datetime.now(timezone.utc) | ||
|
||
for article, ref_article in zip(articles, ref_articles): | ||
if ref_article is None: | ||
warnings.warn(f"Could not retrieve article '{article.id}'") | ||
continue | ||
|
||
if article.is_archive: | ||
logger.info("article '%s' is achived, skipping expiry check", article.id) | ||
continue | ||
|
||
logger.info("checking article '%s'", article.id) | ||
|
||
if not ref_article.is_open_ended: | ||
if now > ref_article.end_date: | ||
warnings.warn( | ||
f"Article '{article.id}' has expired " | ||
f"(on {ref_article.end_date.date()}). " | ||
f"It has been replaced by '{ref_article.latest_version_id}'." | ||
) | ||
has_expired_articles = True | ||
else: | ||
warnings.warn( | ||
f"Article '{article.id}' will expire " | ||
f"on {ref_article.end_date.date()}. " | ||
f"It will be replaced by '{ref_article.latest_version_id}'" | ||
) | ||
|
||
return 0 if not has_expired_articles else 1 |
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 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 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
Oops, something went wrong.