Skip to content

Conversation

@machshev
Copy link

@machshev machshev commented Sep 30, 2025

This is probably too much in one PR, but if your interesting in going in this direction I could perhaps split this up into more incremental changes.

  • Add nix flake + direnv so that it's easier to develop on NixOS
  • Moved the Python cli code from the scripts dir into a python package structure. This means it could be published as a python package.
  • Ruff format - auto format to fix up some of the main lint issues and git a bit more consistency.

Add a nix flake to make it easier for developers using NixOS or anyone
who like a repeatable Nix based development environment. The `.envrc` is
for those who use direnv, and just loads the flake.

Using this a developer with nix + direnv can enter the directory, run
`direnv allow .` and get a Python virtual env with everything installed
and setup ready to go.

Signed-off-by: David James McCorrie <djmccorrie@gmail.com>
Signed-off-by: David James McCorrie <djmccorrie@gmail.com>
Signed-off-by: David James McCorrie <djmccorrie@gmail.com>
@github-actions
Copy link

You are welcome to add an entry to the CHANGELOG.md as well

@GameTec-live
Copy link
Contributor

Hey, thanks for the PR!
A few things:

  • Can we get a few more details on what got changed as its a pretty big PR
  • Can you fix the autobuilds as it seems like your PR breaks the pyinstaller autobuilds among other things
    and - Am I right in assuming, that these changes still keep the CLI standalone runnable as detailed in the current docs?

@machshev
Copy link
Author

machshev commented Oct 2, 2025

The nix flake + direnv is a standalone change that I can pull out into a separate PR.

The python refactoring should just be:

  • creating a new directory for the python source - which becomes the top level python package name (hence chameleon). So scripts is not a great namespace, it's normally the same or close to the python wheel name. Quite often there would be a src dir and then the package name. But with src already containing C code that's not practical.
  • update the pyproject.toml to
    • tell it where to find the python source as it's not in a standard place now.
    • move the dev dependencies def to the standard location so UV and pip understands them. It's then possible to do pip install -e .[dev] for example.
    • simplify the package name in case you wanted to release to pypi at some point.
    • add a script entry point so the tool is available on PATH when the python package is installed.
  • add __init__.py which is a marker file to tell the interpreter that this directory is a python package.
  • rename the python modules to remove the chameleon namespace in the filename. The namespace is there already now with the name of the parent directory "chameleon" being part of the module path.
  • fix up the imports making them fully qualified module path imports. Preferring the recommended explicit from ... import ... so that only the parts of the module required are imported.

I think that's it in terms of changes. The tests are still in the scripts dir, but would normally be in a tests dir in the same dir as the pyproject.toml. I'm not sure what pyinstaller is for, I'll look it up later.

If this is a direction you want to go i.e. a more standard python package that could be installed with pip install chameleon (if you uploaded a package to pypi). Then I'll try and find some time to tidy this up.

The way to run the cli is more like a standard installed program than a "script". Although it would be easy to put back a wrapper script to fix up the docs... or I could fix up the docs to match?

@GameTec-live
Copy link
Contributor

GameTec-live commented Oct 2, 2025

Thanks!
Ill need to pull and test this PR to see how its currently behaving, but the important part is that one can clone the repo, install deps and just run the CLI without needing to compile or install anything (ok, C parts excluded), etc.

Feel free to pull the Nix changes into a separate PR, as that I think I can just merge as its only introducing a new packaging variant / config file. Dont have to tho if you dont want to.

@felurx
Copy link

felurx commented Oct 12, 2025

I think it would be very nice to have the CLI as a python package. Once that's done, it should be fairly easy to make the CLI installable with pipx. That'd be pretty convenient, you just run pipx install ... and pipx creates the venv, installs dependencies, and makes sure the program is on your PATH.

As far as I can see from the pipx docs, this should be just a few lines in pyproject.toml.
After the python package stuff is done and this is merged, I'd take a look at that and submit a PR if I'm successful :)

@GameTec-live
Copy link
Contributor

@felurx might be worth targeting UV instead, but as its just a python package it should work on both.
https://docs.astral.sh/uv/#tools

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.

3 participants