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

Setup tooling #68

Closed
wants to merge 11 commits into from
Closed

Setup tooling #68

wants to merge 11 commits into from

Conversation

annie444
Copy link
Collaborator

Overview

This PR adds some extra tooling and introduces a change in how tests are conducted. The tooling introduced is:

NOTE: uv is the only tool that needs to be installed manually. Once uv is installed, you can install ruff with uv tool install ruff. Otherwise, pytest and tox will be installed as apart of the project's virtual environment.

To get started with this PR, all you need is uv. After checking out this branch, you can run uv sync --all-groups which will create a virtual environment in the project directory. You can activate this virtual environment just like any other pyenv or virtualenv with source .venv/bin/activate (making sure to grab the right activation script if your default shell is not bash, sh, or zsh).

All the tests that previously existed only within jupyter notebooks have been cloned as standard pytest tests. These reside under the test/ directory. Each test will spin up a companion container with either podman or docker for the duration of the tests, so it's crucial that one of the two binaries is available. Furthermore, the interactions between firefly_client and the web browser have been mocked. You can run these tests with pytest with no extra arguments, as all arguments are defined in the pyproject.toml under [tool.pytest.ini_options].

Additionally, tox has been added for testing across python versions. To run these tests, use the command tox - again with no added arguments. When you invoke tox it will leverage uv to install python versions 3.10-3.14 and then run the pytest tests against each version of python.

All python files that start with test_ will be scanned for tests by pytest and tox. All functions in these files that start with test_ will be executed as tests.
NOTE: The test_adv_table_imgs_upload test in the test/test_demo_advanced_tables_images_upload.py file is currently failing as it relys on a local file that is not included in the repo, so I was never able to test that function.

Lastly, ruff was added and configured with sensible defaults for code quality. To ensure standard code formatting, you can run ruff format, which will format all files (including the jupyter notebooks) following the PEP standards and the configuration stated in the [tool.ruff] sections of the pyproject.toml. To ensure standard linting and to stay up to date with general python code standards, you can also run ruff check to lint all files. This will output all linting errors, warnings, and suggestions. You may also use ruff check --fix to automatically fix the linting rules that have auto-corrections. Note that ruff format nor ruff check --fix will rewrite any logic. These commands will only modify the syntax of the code.

Similarly to conda and pip, one ready to release, uv provides the uv build and uv publish commands for managing the package. A good place to begin exploring uv beyond the documentation is by simply running uv help.

Disclaimer:

I made some minor modifications to the package. These changes were to support python type checking, as the codebase was failing ruff type checks.

Using Ruff:

Ruff can be added to your code editor, with extensions for NeoVim, VS Code, Sublime, and many other IDEs. With the Ruff tooling extensions, you will get live linting results as you code. This is the recommended way to work with Ruff.

Code Consistency Improvements:

Build Process Update:

  • docs/Makefile: Modified the SPHINXBUILD command to use uv run sphinx-build instead of sphinx-build for building documentation.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@annie444
Copy link
Collaborator Author

A common tool that is used for automating these tests and formatting rules is pre-commit which installs a git hook to your local clone and doesn't allow you to commit code without passing all tests and linting rules. While that might sound annoying, it doesn't require any manual calling of the various CLI commands and also has caught many a stupid mistake in my experience. You can read more about it here!

@stargaser
Copy link
Collaborator

I tried the setup and activated my environment, and ran tox.

I'm getting errors like these, even though I have podman installed on my Intel MacBook Pro.

ERROR test/test_demo_region.py::test_region[container0] - subprocess.CalledProcessError: Command '['podman', 'pull', 'docker.io/ipac/...

Any clues why that would be happening?

@annie444
Copy link
Collaborator Author

Closing this PR and deferring to Issues #69 #70 #71 #72 #73

@annie444 annie444 closed this Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants