Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run TimeTagger by just timetagger #517

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AlexElvers
Copy link

Thank you for this great tool!

Currently, TimeTagger is started by python -m timetagger. I'd like to suggest adding a timetagger console script as an alternative. This command is easier to remember.

By having a console script with the same name as the package, it is possible to install and run TimeTagger using uvx, e.g.: uvx timetagger --version (automatically sets up a temporary venv, installs the package and runs the command) or if you want to try it as long as this change is not released on PyPI: uvx --from=. timetagger --version or uvx --from=git+https://github.com/AlexElvers/timetagger@console-script timetagger

Because the generated console script the imports the specified module (from timetagger.__main__ import main), __name__ is not "__main__" in this case. To support --version, I moved most of the previous __main__.py to _serve.py and added the version info handling and the import of _serve to the new timetagger.__main__:main function.

Please let me know if you generally like this change, if you'd want me to change something or if I missed something. :)

With this change, it is possible to run the server by just running `timetagger`, as an alternative to `python -m timetagger`.

Move timetagger/__main__.py to timetagger/_serve.py and create a new __main__.py for special handling of --version.
setuptools might not be installed in the venv anymore, but we need pkg_resources.
@almarklein
Copy link
Owner

Hi @AlexElvers thanks for this PR!

The timetagger command is already used by the timetagger_cli package, so we can perhaps call the command timetagger_server.

Could you also put a comment in __main__.py to direct ppl to _serve.py? I've been referring users to __main__.py as an example startup script, than can be copied to run timetagger in a custom way.

@AlexElvers
Copy link
Author

Thanks for your response!

I've implemented your suggestions (and merged the changes of the main branch). Besides python -m timetagger, the server can now be started by timetagger_server (or if one want to use uvx when the change is released: uvx --from=timetagger timetagger_server).

Let me know if you have further suggestions. :)

I would suggest to make the simple timetagger_server the preferred way to run the server in the documentation (README.md and docstrings). What do you think?

One thing I noticed: Before my changes, the resources seem to be compiled/collected twice (I don't know why), after my change only once. I think, this is rather an improvement than a problem, right?

Before:

$ python -m timetagger
[INFO 2025-01-08 00:05:27] Collected 14 assets from /home/alex/dev/timetagger/timetagger/common
[INFO 2025-01-08 00:05:27] Compiled pscript from dialogs.py
[INFO 2025-01-08 00:05:27] Compiled pscript from dt.py
[INFO 2025-01-08 00:05:27] Compiled pscript from front.py
[INFO 2025-01-08 00:05:27] Compiled pscript from stores.py
[INFO 2025-01-08 00:05:27] Compiled pscript from tools.py
[INFO 2025-01-08 00:05:27] Compiled pscript from utils.py
[INFO 2025-01-08 00:05:27] Collected 13 assets from /home/alex/dev/timetagger/timetagger/app
[INFO 2025-01-08 00:05:27] Collected 26 assets from /home/alex/dev/timetagger/timetagger/images
[INFO 2025-01-08 00:05:27] Collected 4 assets from /home/alex/dev/timetagger/timetagger/pages
[INFO 2025-01-08 00:05:28] Collected 14 assets from /home/alex/dev/timetagger/timetagger/common
[INFO 2025-01-08 00:05:28] Compiled pscript from dialogs.py
[INFO 2025-01-08 00:05:28] Compiled pscript from dt.py
[INFO 2025-01-08 00:05:28] Compiled pscript from front.py
[INFO 2025-01-08 00:05:28] Compiled pscript from stores.py
[INFO 2025-01-08 00:05:28] Compiled pscript from tools.py
[INFO 2025-01-08 00:05:28] Compiled pscript from utils.py
[INFO 2025-01-08 00:05:28] Collected 13 assets from /home/alex/dev/timetagger/timetagger/app
[INFO 2025-01-08 00:05:28] Collected 26 assets from /home/alex/dev/timetagger/timetagger/images
[INFO 2025-01-08 00:05:28] Collected 4 assets from /home/alex/dev/timetagger/timetagger/pages
[INFO 2025-01-08 00:05:29] Server is starting up

After:

$ python -m timetagger
[INFO 2025-01-08 00:05:01] Collected 14 assets from /home/alex/dev/timetagger/timetagger/common
[INFO 2025-01-08 00:05:01] Compiled pscript from dialogs.py
[INFO 2025-01-08 00:05:01] Compiled pscript from dt.py
[INFO 2025-01-08 00:05:01] Compiled pscript from front.py
[INFO 2025-01-08 00:05:01] Compiled pscript from stores.py
[INFO 2025-01-08 00:05:01] Compiled pscript from tools.py
[INFO 2025-01-08 00:05:01] Compiled pscript from utils.py
[INFO 2025-01-08 00:05:01] Collected 13 assets from /home/alex/dev/timetagger/timetagger/app
[INFO 2025-01-08 00:05:01] Collected 26 assets from /home/alex/dev/timetagger/timetagger/images
[INFO 2025-01-08 00:05:01] Collected 4 assets from /home/alex/dev/timetagger/timetagger/pages
[INFO 2025-01-08 00:05:02] Server is starting up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants