generated from rochacbruno/python-project-template
-
-
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.
Merge pull request #7 from sdementen/second_working_code
Second working code
- Loading branch information
Showing
43 changed files
with
864 additions
and
94 deletions.
There are no files selected for viewing
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
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,11 @@ | ||
# Sample gnucash books | ||
|
||
This folder holds a set of gnucash books used for testing, examples and debugging. | ||
|
||
|
||
## Default empty books | ||
|
||
The following gnucash books can be used to introspect the SQL schema: | ||
- reference/default_2_6_21_basic.gnucash: empty gnucash books created with gnucash 2.6.21 and no specific options | ||
- reference/default_2_6_21_full_options.gnucash: empty gnucash books created with gnucash 2.6.21 with multiple options enabled (trading accounts, ...) | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 @@ | ||
@py.exe make.py %* |
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,104 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
import typer | ||
|
||
os.environ["PYTHONIOENCODING"] = "utf-8" | ||
|
||
app = typer.Typer() | ||
|
||
HERE = Path(__file__).parent | ||
|
||
|
||
@app.command() | ||
def release(tag: str): | ||
print(f"WARNING: This operation will create version {tag=} and push to github") | ||
typer.confirm("Do you want to continue?", abort=True) | ||
Path("piecash2/VERSION").write_text(tag) | ||
os.system("gitchangelog > HISTORY.md") | ||
os.startfile("HISTORY.md") | ||
typer.confirm("Did you update the changelog?", abort=True) | ||
os.system("git add piecash2/VERSION HISTORY.md") | ||
os.system(f'git commit -m "release: version {tag}') | ||
print(f"creating git tag : {tag}") | ||
os.system(f"git tag {tag}") | ||
os.system("git push -u origin HEAD --tags") | ||
print("Github Actions will detect the new tag and release the new version.") | ||
|
||
|
||
@app.command() | ||
def lint(): | ||
"""lint: ## Run pep8, black, mypy linters.""" | ||
os.system("flake8 piecash2/") | ||
os.system("black -l 140 --check piecash2/") | ||
os.system("black -l 140 --check tests/") | ||
os.system("mypy --ignore-missing-imports piecash2/") | ||
|
||
|
||
@app.command() | ||
def fmt(): | ||
"""fmt: ## Format code using black & isort.""" | ||
os.system("isort piecash2/") | ||
os.system("black -l 140 piecash2/") | ||
os.system("black -l 140 tests/") | ||
|
||
|
||
@app.command() | ||
def docs(): | ||
"""fmt: ## Format code using black & isort.""" | ||
os.system("mkdocs build") | ||
os.startfile(Path(__file__).parent / "site" / "index.html") | ||
|
||
|
||
@app.command() | ||
def clean(): | ||
"""clean: ## Clean up unused files.""" | ||
patterns = [ | ||
"**/*.pyc", | ||
"**/__pycache__", | ||
"**/Thumbs.db", | ||
"**/*~", | ||
".cache", | ||
".pytest_cache", | ||
".mypy_cache", | ||
".tox", | ||
"build", | ||
"dist", | ||
"*.egg-info", | ||
"htmlcov", | ||
"docs/_build", | ||
] | ||
|
||
for fp in patterns: | ||
for f in HERE.glob(fp): | ||
if f.is_file(): | ||
f.unlink() | ||
else: | ||
shutil.rmtree(f) | ||
|
||
|
||
@app.command() | ||
def test(): | ||
"""test: ## Run tests and generate coverage report.""" | ||
os.system("pytest -v --cov-config .coveragerc --cov=piecash2 -l --tb=short --maxfail=1 tests/") | ||
os.system("coverage xml") | ||
os.system("coverage html") | ||
os.startfile(HERE / "htmlcov" / "index.html") | ||
|
||
|
||
@app.command() | ||
def schema(): | ||
"""schema: ## Generate the schema from the sqlite database using sqlacodegen.""" | ||
import piecash2.schema.generation.schema_generation as schema_generation | ||
import piecash2.schema.generated as generated | ||
|
||
schema_generation.path_schemas = Path(generated.__file__).parent | ||
|
||
print(f"Generating schemas in {schema_generation.path_schemas}") | ||
for book in (HERE / "data").glob("*.gnucash"): | ||
schema_generation.generate_schema(book, schema_generation.get_schema_name(book)) | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
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 +1 @@ | ||
0.1.1 | ||
0.1.2 |
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,5 @@ | ||
from piecash2.schema.generation.schema_generation import add_book_module_in_path | ||
|
||
from .core.book import open_book | ||
|
||
__ALL__ = [open_book, add_book_module_in_path] |
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
import sqlite3 | ||
from pathlib import Path | ||
|
||
import sqlalchemy | ||
import sqlalchemy.orm | ||
|
||
from piecash2.schema.generation.schema_generation import import_gnucash | ||
|
||
|
||
def open_book(book, regenerate_schema=False): | ||
if isinstance(book, str): | ||
book = Path(book) | ||
|
||
book_posix = book.as_posix() | ||
|
||
# make a backup of the DB in memory | ||
db_memory_name = f":memgeco_{abs(hash(book_posix))}:" | ||
with sqlite3.connect(book_posix) as source: | ||
sqliteconn = f"file:{db_memory_name}?mode=memory&cache=shared" | ||
dest = sqlite3.connect(sqliteconn, uri=True) | ||
source.backup(dest) | ||
|
||
engine = sqlalchemy.create_engine(f"sqlite:///{db_memory_name}", echo=False, creator=lambda: sqlite3.connect(sqliteconn, uri=True)) | ||
|
||
Session = sqlalchemy.orm.sessionmaker(bind=engine, autoflush=True, autocommit=False) | ||
|
||
# must execute some query otherwise future call to the Session raise error | ||
with Session() as s: | ||
s.execute(sqlalchemy.text("")) | ||
|
||
Session.module = import_gnucash(book, regenerate_schema=regenerate_schema) | ||
|
||
return Session |
Empty file.
Empty file.
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 @@ | ||
# mypy: ignore-errors | ||
# list all glasses with a guid property (that can be linked to in Slot/Recurrence through obj_guid) | ||
gl = globals() | ||
name2kls = {n: gl[n] for n in klswithguid_names} # noqa: F821 |
Oops, something went wrong.