-
Notifications
You must be signed in to change notification settings - Fork 2
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
Draft: Add modern Python tools #4
Open
tiliv
wants to merge
18
commits into
main
Choose a base branch
from
pytest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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 reverts commit 67da5a6.
Bootstrapping renpy didn't pan out on the first go. We can import the renpy code in test files and loose python utilities, but it's not configured and quickly runs into obvious bootstrapping failures with pyx and compiled files. |
"auto" chooses "long" format and it's abusive, honestly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale:
I have been waiting for 10 years for Ren'py to support python 3. We shall show no weakness. We will assume everything is python 3 & renpy 8.
This PR was not interesting before renpy 8, because the system was based on ancient python. Now we're on Python 3.9 and life is pretty again.
Misc:
This version of the template is hardcoding
renpy-8.0.1-sdk
in the pyproject.toml, which I'd like to avoid, if it becomes practical. Compatibility is not especially concerning, so hardcoding is unreasonable except for the mechanics of having no env variables in pyproject.toml. Not sure if an.env
file is fixing this or not. Pytest is very hard to modify the path for. My initial attempt was to useimportlib
to read the sdk named in our.renpy-sdk
hint, and nothing to do withsys.path
seems to have an effect.Poetry
https://python-poetry.org/
Modern python project management with virtualenv support and a dependency lock file.
When the files in the PR are present, use
poetry install
to install optional development support packages needed for pytest and coverage.When working in your project directory from the command line, always be sure to activate a shell for it:
If you enjoy npm, yarn, and similar tools, you can use poetry similar to npx:
If you want custom commands, they have to launch a function in a python module:
Click
https://click.palletsprojects.com/en/8.1.x/quickstart/#screencast-and-examples
Click is a simple framework for declaring a fully automatic command line interface out of a python file. The default
cli.py
file has been added to pyproject.toml as a Poetry script, so that you have an obvious place to make new commands.The default
cli.py
features are not strictly required--the developer can always freely run the tools that the cli invokes--but this provides a unified location for such commands, and self-documents how you can interact with the installed tools. Better yet, if you want to swap out or add tools, all you have to do is editcli.py
. The command names are not special, emphasized by their generic names instead of using the literal tool names.You can run
cli.py
directly, or as a poetry script withpoetry run cli
. Poetry's pyproject.toml is already configured to know that the script "cli" points to cli.py, and the Click help takes over from there, allowing all the normal command line arguments:All of these funnel you to running
cli.py
in exactly the same way, so the arguments are the same for any approach.If you prefer to launch tasks with your editor UI, you can ask it to run with any of these strategies and it'll work just fine.
Note that the default commands are not adding or modifying any arguments to the underlying tool, so you'll get exactly the same behavior as configured in your
pyproject.toml
file, which controls default arguments to those tools.If you want to use the cli to pass additional new arguments, these commands have support for adding a
--
between the command and your override arguments.Pytest
https://docs.pytest.org/en/latest/contents.html
Pytest provides a simple runner called
pytest
. This is also the name of an importable module in python code that enables sending data fixtures, marking tests for multiple runs, and helps with setup/teardown tasks.Tests with pytest are just files and functions or classes that adhere to naming patterns. Files and function should start with
test_*
and classes should begin withTest*
. Changing these is possible in pyproject.tomlTest files can be created anywhere.
Declare
conftest.py
for common fixtures and helpers that should be loaded for all test files in the same folder or deeper.Coverage
https://coverage.readthedocs.io/en/latest/
Coverage offers a runner that will collect stats about which code is executed and which is not. Traditionally this is useful in combination with a testing framework, to get an idea of how much code you've tested. Your "coverage" is the percentage of your code that is tested.
A support plugin for pytest called
pytest-cov
allows coverage to activate automatically whenpytest --cov
is run.You can run
coverage
directly, but you would need an entry point that will run some code. You won't have to do this unless you're really interested in generating off-the-cuff coverage reports in alternate styles (html, etc)Pdoc
https://pdoc.dev/docs/pdoc.html#quickstart
Pdoc is a no-configuration documentation generator from your python files (not renpy files--yet?).
.vscode/settings.json
WIP
test runner for
test_*.rpy
files