Open aaronjnewman opened 1 year ago
Hey, thanks for your interest, and sorry this isn't better documented.
It's expected that your package directory contains an __init__.py
file. (This traditionally defines at least the package version number as __version__
.)
Could you please try creating this and see if it works for you then?
I should document this requirement explicitly.
thanks - I needed to create a subfolder named the same as I named the project when running cruft, then put __init__.py
in there. But it also required me to create pyproject.toml
and conda-lock.yml
files. I tried creating empy files for each of these but it sill fails at:
ERROR: failed to solve: process "/usr/local/bin/_dockerfile_shell.sh : && micromamba config append channels conda-forge && micromamba install --yes --name base --category dev --category main --file /tmp/conda-lock.yml && micromamba clean --all --yes ;" did not complete successfully: exit code: 1
I was actually trying to co-opt this for a different purpose (installing Python packages to run Jupyter notebooks) and it seems like not the best choice as a starting template, so this may simply reflect my naïveté/user error. But if it helps inform the documentation I hope it wasn't too much trouble!
The steps below are the minimum changes required to build after creating a new project with Hatch and the Cruft template. This was tested using VSCode and DevPod. It's possible this is not "proper", but it does work.
I started with https://gitlab.com/bmares/cookiecutter-micromamba-devcontainer#setup.
hatch new "sandbox"
cd sandbox
cruft create https://github.com/maresb/cookiecutter-micromamba-devcontainer
[1/3] package_name (the_name_of_your_python_package): sandbox
[2/3] timezone (Europe/Berlin):
[3/3] packages_dir (.): pythonBelow are required changes, otherwise the build fails.
mv
- anything related to src
is not required if src
is used as the packages_dir as this is what hatch new
defaults to. I prefer python
. (the example uses this as well)cp
- the version is in the __about__.py
, copy that to __init__.py
sed
- change the about to init and comment out the readme line. sed
- same as 1, only required if not using src
mv src python && \
cp python/sandbox/__about__.py python/sandbox/__init__.py && \
sed -i.bak 's/__about__.py/__init__.py/; s/^readme/# &/' pyproject.toml && \
sed -i.bak 's|src/|python/|g' pyproject.toml
micromamba-devcontainer-example-main/conda-environment.yaml
to project rootconda-lock --file conda-environment.yaml --file .devcontainer/dev-conda-environment.yaml
relock-deps
but in its current state it expects a conda-lock.yml file. Must change paths too.Ref the docs for any other setup / copy remaining files from the example.
Thanks so much @dephora! What you write looks correct, thanks so much for codifying everything!
My latest advice would be to use pixi as the frontend (replacement for Hatch) but to keep hatchling as the Python build-backend. It has integrated lockfile management, is super-fast, and is under very active development. For Dockerization there's pixi-docker.
I'm fairly new to using pixi, and the only difficulty I've found is needing to separately declare Conda packages to cover the pip packages I'm using. (Otherwise things default to pip installation.) I'm not sure yet if there's an easy solution for that, but in worst case I could probably spin off a few helper tools from conda-lock.
I haven't yet gotten around to templating a dev environment. I've been meaning to ask the pixi devs some questions first to make sure I'm using everything correctly.
@maresb - No problem! Thank you for creating this to begin with. Funny you mention pixi, I was looking at that recently before finding your devcontainer. I will keep an eye out for your new dev env.
I tried following the instructions for Cruft. I did not make any modifications to the files, just to see if it would build. It didn't. Output is below. It appears to throw errors for the lines with
COPY --chown=mamba
.Any sugestions?