Package: manageprojects
manageprojects - Manage Python / Django projectsMix the idea of Ansible with CookieCutter Templates and Django Migrations to manage and update your Python Packages and Django Projects...The main idea it to transfer changes of a CookieCutter template back to the created project.
Manageprojects used git to create a patch of the template changes and applies it to the created project.Besides this,manageprojectsalso includes other generic helper for Python packages:publish_package()- Build and upload a new release to PyPi, but with many pre-checks.format-file- Format/Check a Python source file with Darker & Co., useful as IDE action.Read below theHelpersection.installCurrently just clone the project and just start the cli (that will create a virtualenv and installs every dependencies)e.g.:~$gitclonehttps://github.com/jedie/manageprojects.git
~$cdmanageprojects
~/manageprojects$./cli.py--helpThe output of./cli.py --helplooks like:Usage: ./cli.py [OPTIONS] COMMAND [ARGS]...

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help      Show this message and exit.                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ clone-project   Clone existing project by replay the cookiecutter template in a new directory.   │
│ format-file     Format and check the given python source code file with                          │
│                 darker/autoflake/isort/pyupgrade/autopep8/mypy etc.                              │
│ reverse         Create a cookiecutter template from a managed project.                           │
│ start-project   Start a new "managed" project via a CookieCutter Template. Note: The             │
│                 CookieCutter Template *must* be use git!                                         │
│ update-project  Update a existing project.                                                       │
│ version         Print version and exit                                                           │
│ wiggle          Run wiggle to merge *.rej in given directory.                                    │
│                 https://github.com/neilbrown/wiggle                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯most important commandsstart-projectHelp from./cli.py start-project --helpLooks like:Usage: ./cli.py start-project [OPTIONS] TEMPLATE OUTPUT_DIR

 Start a new "managed" project via a CookieCutter Template. Note: The CookieCutter Template *must*
 be use git!
 e.g.:
 ./cli.py start-project https://github.com/jedie/cookiecutter_templates/ --directory
 piptools-python ~/foobar/

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --directory             TEXT  Cookiecutter Option: Directory within repo that holds              │
│                               cookiecutter.json file for advanced repositories with multi        │
│                               templates in it                                                    │
│ --checkout              TEXT  Cookiecutter Option: branch, tag or commit to checkout after git   │
│                               clone                                                              │
│ --input/--no-input            Cookiecutter Option: Do not prompt for parameters and only use     │
│                               cookiecutter.json file content                                     │
│                               [default: input]                                                   │
│ --replay/--no-replay          Cookiecutter Option: Do not prompt for parameters and only use     │
│                               information entered previously                                     │
│                               [default: no-replay]                                               │
│ --password              TEXT  Cookiecutter Option: Password to use when extracting the           │
│                               repository                                                         │
│ --config-file           FILE  Cookiecutter Option: Optional path to "cookiecutter_config.yaml"   │
│ --help                        Show this message and exit.                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯update-projectHelp from./cli.py update-project --helpLooks like:Usage: ./cli.py update-project [OPTIONS] PROJECT_PATH

 Update a existing project.
 e.g. update by overwrite (and merge changes manually via git):
 ./cli.py update-project ~/foo/bar/

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --overwrite/--no-overwrite          Overwrite all Cookiecutter template files to the last        │
│                                     template state and do not apply the changes via git patches. │
│                                     The developer is supposed to apply the differences manually  │
│                                     via git. Will be aborted if the project git repro is not in  │
│                                     a clean state.                                               │
│                                     [default: overwrite]                                         │
│ --password                    TEXT  Cookiecutter Option: Password to use when extracting the     │
│                                     repository                                                   │
│ --config-file                 FILE  Cookiecutter Option: Optional path to                        │
│                                     "cookiecutter_config.yaml"                                   │
│ --input/--no-input                  Cookiecutter Option: Do not prompt for parameters and only   │
│                                     use cookiecutter.json file content                           │
│                                     [default: no-input]                                          │
│ --cleanup/--no-cleanup              Cleanup created temporary files [default: cleanup]           │
│ --help                              Show this message and exit.                                  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯workflow1. Create a new projectUsestart-projectcommand and a github url as Cookiecutter template, e.g.:~/manageprojects$./cli.pystart-projecthttps://github.com/jedie/cookiecutter_templates/--directorypiptools-python~/my_new_project/
~/manageprojects$cd~/my_new_project/your_cool_package/
~/my_new_project/your_cool_package/$gitinit
~/my_new_project/your_cool_package/$gitadd.
~/my_new_project/your_cool_package/$gitcommit--message"my cool new project"Note:https://github.com/jedie/cookiecutter_templatesis a multi template repository, thepiptools-pythontemplate is here:https://github.com/jedie/cookiecutter_templates/tree/main/piptools-pythonAfter running thestart-projectcommand, look into the created files.
Manage projects stores all needed meta information about the used Cookiecutter template intopyproject.toml, e.g.:~/manageprojects$cat~/my_new_project/your_cool_package/pyproject.toml
...[manageprojects]# https://github.com/jedie/manageprojectsinitial_revision="6e4c875"initial_date=2022-11-10T12:37:20+01:00cookiecutter_template="https://github.com/jedie/cookiecutter_templates/"cookiecutter_directory="piptools-python"[manageprojects.cookiecutter_context.cookiecutter]...2. Update existing projectIf the source Cookiecutter changed, then you can apply these changes to your created project, e.g.:~/manageprojects$./cli.pyupdate-project~/my_new_project/your_cool_package/After this, manageproject will update the own meta information inpyproject.tomlby addapplied_migrationswith the information about the current Cookiecutter version, e.g.:~/manageprojects$cat~/my_new_project/your_cool_package/pyproject.toml
...[manageprojects]# https://github.com/jedie/manageprojectsinitial_revision="6e4c875"initial_date=2022-11-10T12:37:20+01:00cookiecutter_template="https://github.com/jedie/cookiecutter_templates/"cookiecutter_directory="piptools-python"applied_migrations=["dd69dcf",# 2022-11-22T19:48:28+01:00]...How?Everything is based on git ;)manageprojects knows the git hash of the used Cookiecutter Template at creation time and the current git hash.It builds a git patch between these two commits.This patch will be applied to the created project sources.So theoretically the changes in the template are applied to the project.However, this does not work in every case, because git can't match the changes.See below:drawbacksOne problem is that git can't apply all changes.Butgit applyis used with--reject.
It applies the parts of the patch that are applicable,
and leave the rejected hunks in corresponding*.rejfiles.There is a cool tool, calledwiggle:https://github.com/neilbrown/wiggleIt tries to apply rejected patches by perform word-wise diffs.Just runwigglevia manageproject CLI, e.g.:~/manageprojects$./cli.pywiggle~/my_new_project/your_cool_package/Update by overwriteA alternative way to update a project:Just overwrite all files with the current Cookiecutter template outputMerge changes manually viagitSo you doesn't have trouble with not applyable git patches ;)Just add--overwrite, e.g.:~/manageprojects$./cli.pyupdate-project--overwrite~/my_new_project/your_cool_package/HelperBelow are some generic tools helpful for Python packages."reverse" - Reverse a project into a Cookiecutter templateA existing managed project can be converted back to a Cookiecutter template, e.g.:~/manageprojects$./cli.pyreverse~/my_new_project/~/cookiecutter_template/"format-file" - Format and check the given python source code fileYou can useformat-fileas "Action on save" or manual action in your IDE to fix code style ;)Usage: ./cli.py format-file [OPTIONS] FILE_PATH

 Format and check the given python source code file with
 darker/autoflake/isort/pyupgrade/autopep8/mypy etc.
 The optional fallback values will be only used, if we can't get them from the project meta files
 like ".editorconfig" and "pyproject.toml"

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --py-version                     TEXT     Fallback Python version for darker/pyupgrade, if       │
│                                           version is not defined in pyproject.toml               │
│                                           [default: 3.10]                                        │
│ --max-line-length            -l  INTEGER  Fallback max. line length for darker/isort etc., if    │
│                                           not defined in .editorconfig                           │
│                                           [default: 119]                                         │
│ --darker-prefixes                TEXT     Apply prefixes via autopep8 before calling darker.     │
│                                           [default: E301,E302,E303,E305,W391]                    │
│ --remove-all-unused-imports               Remove all unused imports (not just those from the     │
│                                           standard library) via autoflake                        │
│                                           [default: True]                                        │
│ --help                                    Show this message and exit.                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯publishThemanageprojects.utilities.publish.publish_package()is designed for external packages, too.Build and upload (with twine) a project to PyPi with many pre-checks:Has correct version number?Is on main branch and up-to-date with origin?Check if current version already publishedBuild a git tag based on current package versionAdds change messages since last release to git tag messageSome checks result in a hard exit, but some can be manually confirmed from the user to continue publishing.developmentFor developing manageprojects, there is thedev-cli.py.The output of./dev-cli.py --helplooks like:Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help      Show this message and exit.                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ check-code-style            Check code style by calling darker + flake8                          │
│ coverage                    Run tests and show coverage report.                                  │
│ fix-code-style              Fix code style of all manageprojects source code files via darker    │
│ git-hooks                   Setup our "pre-commit" git hooks                                     │
│ install                     Run pip-sync and install 'manageprojects' via pip as editable.       │
│ mypy                        Run Mypy (configured in pyproject.toml)                              │
│ publish                     Build and upload this project to PyPi                                │
│ run-git-hooks               Run the installed "pre-commit" git hooks                             │
│ safety                      Run safety check against current requirements files                  │
│ test                        Run unittests                                                        │
│ tox                         Run tox                                                              │
│ update                      Update "requirements*.txt" dependencies files                        │
│ update-test-snapshot-files  Update all test snapshot files (by remove and recreate all snapshot  │
│                             files)                                                               │
│ version                     Print version and exit                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯development git hooksTo install the git hooks, run:~/manageprojects$./dev-cli.pygit-hooksHistorySee also git tags:https://github.com/jedie/manageprojects/tagsv0.17.12023-12-29 - Still support Python v3.9v0.17.02023-12-21 - Bugfix: Don't loose the "[manageprojects]" content on overwrite-update2023-12-21 - typing: Optional -> None2023-12-21 - Unify BASE_PATH / PACKAGE_ROOT etc.2023-12-21 - Apply manageprojects updates: Skip Python 3.9 support2023-12-21 - Update requirementsv0.16.22023-12-16 - Update pre-commit-config2023-12-16 - Skip test_readme_history() on CI2023-12-16 - Add git hook "update-readme-history"2023-12-16 - Apply cookiecutter updates2023-12-16 - Update requirementsv0.16.12023-12-05 - Fix "format file" and very verbose error outputExpand older history entries ...v0.16.02023-12-02 - Use code style tooling from cli-base-utilities2023-12-01 - Applyhttps://github.com/jedie/cookiecutter_templatesupdates2023-12-01 - Use: cli_base.cli_tools.test_utils.logs.AssertLogsv0.15.42023-11-27 - Use "flake8-bugbear", too.v0.15.32023-11-09 - Bugfix "reverse" if context contains a list2023-11-07 - Update requirementsv0.15.22023-11-01 - Update requirementsv0.15.12023-10-08 - Update text matrix with Python v3.122023-10-08 - fix github CI2023-10-08 - Update for CookieCutter v2.4.0 changes2023-10-08 - Autogenerate history viahttps://github.com/jedie/cli-base-utilities2023-09-24 - apply migrations2023-09-24 - Update requirementsv0.15.02023-08-17 - Deprecate Git2023-08-17 - Deprecate print_version() (moved to cli_base)v0.14.12023-08-17 - apply project template updates and update requirements2023-08-15 - Update requirementsv0.14.02023-08-09 - Usehttps://github.com/jedie/cli-base-utilitiesv0.13.02023-08-05 - publish: Support "dynamic metadata" from setuptools for the version2023-08-05 - Split CLIv0.12.12023-06-11 - Ehance git.push() by addingget_outputto methodv0.12.02023-06-11 - New: git.get_remote_url() and git.get_github_username()v0.11.02023-06-11 - Update requirements and relase as v0.11.02023-06-11 - Enhance Git()2023-05-12 - Use "--remove-all-unused-imports" as default for autoflakev0.10.02023-05-11 - Enhance "format-file" and add "autoflake" to remove unused imports2023-04-10 - Update requirements2023-04-10 - apply manageprojects updates2023-04-08 - Apply project updatesv0.9.102023-04-08 - Add helper to find and get the "pyproject.toml" filev0.9.92023-04-04 - Set --overwrite as default in update-project command2023-04-04 - Cleanup requirements2023-04-04 - project updatesv0.9.82023-04-04 - Add--overwriteoption toreversecommandv0.9.72023-04-03 - Bugfix reverse command: Optimize replacements2023-03-17 - apply code migrationsv0.9.62023-03-12 - Speedup: Install as editable with '--no-deps'2023-03-12 - Fix #68 Handle if there are no git tags while publishing2023-03-11 - Bugfix reverse command and binary filesv0.9.42023-03-09 - Support "poerty" in publish_package(), too.v0.9.32023-03-07 - Fix publish2023-03-07 - Update project2023-03-06 - coverage xml report + CLI2023-03-06 - Update README.md2023-03-06 - Fix CI / coverage run2023-03-06 - Remove "python_version < 3.11" for "tomli"2023-03-06 - merge cookie cutter template updatesv0.9.22023-02-26 - Make the Result available on an error2023-02-26 - update requirements2023-02-26 - invoke_click(): Raise exception if exists2023-02-23 - Add: "E301 - expected 1 blank line" to "format-file"v0.9.12023-02-22 - Bugfix publish a poetry package and get the version string from pyproject.tomlv0.9.02023-02-21 - README2023-02-21 - Refactor publish command and make is useable for external packages, too.2023-02-21 - Enhance verbose_check_output: Display output on errors and exit2023-02-20 - Enhance SubprocessCallMock: Mock subprocess.run(), too.v0.8.32023-02-20 - Bugfix packaging: remove "tox" from normal, non-dev dependenciesv0.8.22023-02-20 - Path(sys.executable).parent -> PY_BIN_PATH2023-02-20 - Add "E305" to darker prefixes2023-02-20 - Add tox config via manageprojects2023-02-19 - Add "W391 blank line at end of file" to darker pre fixes2023-02-19 - Add check_editor_config()2023-02-19 - CLI: Add "version" back as pseudo command.2023-02-19 - Better subprocess_utils APIv0.8.02023-02-19 - Split "test_cli" and add "format-file" into README2023-02-18 - Add reuseable helper: print_version()2023-02-18 - NEW: "format-file"2023-02-18 - add Safety check2023-02-18 - apply manageprojectsv0.7.32023-01-25 - Bugfix "--overwrite" if there are new directories in template2023-01-25 - Bugfix "overwrite" if there are new filesv0.7.12023-01-25 - Add cli help pages into README using helper in bx_py_utilsv0.7.02023-01-15 - Fix #41 Add "--overwrite" to "update-project" commandv0.6.02023-01-14 - bugfix publish command2023-01-14 - NEW: "update-test-snapshot-files" command2023-01-14 - Fix tests2023-01-13 - Replace typer with the origin click2023-01-12 - apply migration2023-01-12 - Enhance CLI argument documentation2023-01-11 - update requirements2023-01-09 - Better code style test + fix via unittests2023-01-09 - Use RedirectOut from bx_py_utils v732023-01-09 - Bugfix "./cli.py install" and wrong path to req. file2023-01-09 - reverse command: Use "git ls-files" instead of pathspecv0.5.02023-01-08 - NEW: Reverse a project into a Cookiecutter templatev0.4.02022-12-30 - Refactor "dependencies" definition2022-12-30 - Bugfix Git(): Pass environment, but set "en_US" als language2022-12-30 - update requirements2022-12-30 - include all packages2022-12-30 - Capture and check log output in tests2022-12-30 - cleanup editorconfig2022-12-30 - enhance test run2022-12-30 - Bugfix wrong "hint"v0.3.32022-12-21 - Update requirements2022-12-21 - Use new pip-compile resolver2022-12-21 - Bugfix if git output will be translated.2022-11-30 - Fix help by adding './cli.py' and add basic CLI tests2022-11-30 - Enhance "start-project" and "update-project" CLI help pages2022-11-30 - Update README.md2022-11-22 - update reqirements2022-11-20 - SELF MANAGE !!!2022-11-20 - fix typo2022-11-20 - rename: "./mp.py" -> "./cli.py"v0.3.22022-11-19 - git tag on publish2022-11-19 - udpate requirements2022-11-19 - init_git(): Add a "fake" origin and push the current branch to it2022-11-19 - Update README.md2022-11-15 - Bugfix packaging: Release as 0.3.12022-11-15 - Move test utilities to normal package2022-11-15 - update requirements2022-11-15 - code cleanup2022-11-10 - remove own templates ->https://github.com/jedie/cookiecutter_templates2022-11-10 - Bugfix start project with own templates2022-11-10 - NEW: Clone a existing project by replay the cookiecutter template in a new directory.2022-11-10 - Display "git apply patch" output2022-11-10 - Bugfix reset "pyproject.toml" by overwriting with old content2022-11-09 - Use the origin unitest CLI2022-11-09 - Catch if git apply failes and add wiggle command to fix .rej files2022-11-09 - fix tests and set git user name/email if not exists2022-11-08 - Fix tests and more logging/output2022-11-07 - Bugfix patch paths2022-11-07 - Bugfix extra_context2022-11-07 - Generate better git diffs2022-11-07 - fix some optional typehints2022-11-07 - Better update project output2022-11-07 - add "cleanup" to CLI2022-11-07 - pass "no_input"2022-11-07 - change tomlkit.Container to a normal dict2022-11-07 - fix typo2022-11-07 - Better log config2022-11-06 - Add "update-project" to CLI2022-11-06 - +DocString for password2022-11-06 - fix double logging output2022-11-06 - Don't store "_output_dir" in pyproject.toml2022-11-04 - Fix version test if colors are enabled2022-11-04 - Bugfix exit tests on failour2022-11-03 - Simplify store the context to toml file2022-11-03 - refactor and fix tests2022-11-03 - Add --help in README2022-11-03 - Cookiecutter will only checkout a specific commit, iftemplateis a repro url!2022-11-03 - Add "%(name)s" to log output2022-11-03 - Support optional--test-pathfor "./mp.py test"2022-11-03 - Rename "./mp.py unittest" to "./mp.py test"2022-11-01 - WIP: Refactor and add more tests2022-11-01 - Add cleanup argument in TemporaryDirectory2022-11-01 - move code2022-11-01 - Add and use log_func_call() helper2022-10-30 - Store/use Cookiecutter context untouched2022-10-30 - Add helper to convert nested dicts to toml2022-10-29 - WIP: enhance tests2022-10-29 - Fix typo and log more info2022-10-29 - Overwrite existing patch files2022-10-29 - fix some typehints2022-10-29 - WIP: update the existing project2022-10-28 - MOve som ecore parts + start "update project"2022-10-28 - Test start project with local template2022-10-27 - fix typing errors and activate "mypy" in tests2022-10-27 - Coverage: '--fail-under=50'2022-10-27 - test_git_apply_patch()2022-10-27 - Test git diff2022-10-27 - Add init_git() for tests2022-10-27 - Add test utils to generate git repositories "on-the-fly"2022-10-27 - Use assert_is_dir, assert_is_file from bx_py_utils2022-10-26 - Add 3.11 to CI2022-10-26 - fix ci coverage2022-10-26 - Store information into pyproject.toml2022-10-26 - setup coverage2022-10-26 - enhance log setup2022-10-25 - +requires-python = ">=3.9,<4.0.0"2022-10-25 - call "twine check" before upload2022-10-25 - +## start hacking2022-10-25 - fix badges2022-10-25 - fix CI2022-10-25 - Add .flak8 because ofhttps://github.com/PyCQA/flake8/issues/2342022-10-25 - use unitests, add cookiecuttter helper add/fix tests and code style2022-10-24 - change cli+tests2022-10-24 - fix mypy call2022-10-24 - WIP2022-10-23 - chnage minimal template a little bit2022-10-23 - add first cookiecutter template2022-10-23 - Allow manageprojects CLI to be executable throughpython -m manageprojects.2022-10-22 - github actions2022-10-22 - dev2022-10-22 - bootstarp2022-10-22 - add requirements2022-10-22 - init Makefile2022-10-22 - Initial commitLinksOwn Cookiecutter Templates:https://github.com/jedie/cookiecutter_templateshttps://github.com/cookiecutter/cookiecutterAvailable Cookiecutters template on GitHub:https://github.com/search?q=cookiecutter&type=RepositoriesPackaging Python Projects:https://packaging.python.org/en/latest/tutorials/packaging-projects/