-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat(template): Added hatchling as an option for build-system #144
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ayeankit! Looks good overall. Some comments below. You'll also have to take a look at the failing tests.
@@ -0,0 +1,135 @@ | |||
[build-system] | |||
requires = ["hatchling>=1.17.1", "hatch-vcs>=0.3.0"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, if we are keeping VCS
versioning as the default one, it might make sense to add a version.pyi
file. But as I look at other backends, in particular setuptools
, there is no usage of setuptools_scm
, which means we might not want the VCS
versioning by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require adding something like this -
[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "some/path/here/version.py"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Saransh-cpp I removed the vcs
version as the default one. Is it necessary to add this snippet? (as vcs
is not in use)
[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "some/path/here/version.py"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not now! But we might need to explore the path to provide a user with an option to turn on VCS versioning. cc: @xmnlab.
@xmnlab Can you please review it once ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some design issues -
Each build backend library is kind of a combination of a frontend (CLI tool) and a backend (the actual build-backend), for instance, there is flit
and flit-core
, similarly poetry
and poetry-core
, and the messiest one, setuptools
, that tries to be both a backend and a frontend simultaneously.
So, scicookie
uses the "frontend" names for the build-backends which is completely acceptable, and hence, we should use the name hatch
and not hatchling
throughout the codebase. Remember, hatch
is the CLI frontend, and hatchling
is the backend. We use flit
everywhere to mention the flit
build-backend and not flit-core
, similarly, we should use hatch
everywhere to mention the hatchling
build-backend.
This should also fix your tests as your PR confuses hatch
and hatchling
at a lot of places.
cc: @xmnlab (to fix a convention for naming the backends). Frontend names sound good to me, https://github.com/scientific-python/cookie uses the frontend names too.
Other general tips 🙂
- Please have some meaningful messages in your commits. "Update x" makes it really hard to guess what was updated by just looking at the message.
- Writing "Closes Add hatchling as a build-system option #69" or "Fixes Add hatchling as a build-system option #69" in the PR description will automatically close the issue for which the PR was opened. This does make a maintainer's life easy haha.
- I found a few contradictions in your PR description and the actual files changed.
@@ -0,0 +1,135 @@ | |||
[build-system] | |||
requires = ["hatchling>=1.17.1", "hatch-vcs>=0.3.0"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not now! But we might need to explore the path to provide a user with an option to turn on VCS versioning. cc: @xmnlab.
@Saransh-cpp , totally agree! for now we have just semantic release, but probably we should have an option in a near future to select between semantic-release or vcs aproach. |
tests/smoke/base.sh
Outdated
@@ -49,6 +49,8 @@ elif command -v meson &> /dev/null; then | |||
pip install -e . | |||
elif command -v pdm &> /dev/null; then | |||
pdm install | |||
elif command -v hatch &> /dev/null; then | |||
pip install -e . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be hatch install
? Was that giving any errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I am wrong, I am not a hatch/hatchling user
but it seems that hatch doesn't have a command for install just for building
and it seems that for executing it in local mode we should run tests with something like hatch run pytest .
so using pip install -e here would be a workaround .. but TBH I don't know if that works
another option would be to build it and install it from the packaged created by build
but it probably will not install the dev dependencies (for test and for documentation)
so, not sure yet what could be the best workflow for this to keep it generic ...
otherwise we will need to create an environment variable called for example COMMAND_PREFIX
and add it to all the other commands that will need to have access to the dependencies
and for hachling we will set it to hatch run
for example:
COMMAND_PREFIX="hatch run"
$COMMAND_PREFIX pytest
but the error on CI looks like some syntax error on pyproject.toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, thanks for the clarification!
"Topic :: Scientific/Engineering", | ||
"Typing :: Typed", | ||
] | ||
dynamic = ["version"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably won't fix the TOML error, but you must specify the file from which the version has to be read if you are setting it up dynamically - https://hatch.pypa.io/latest/version/#configuration -
[tool.hatch.version]
path = "path/to/version/file.py"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hatch
requires having either version = "x.x.x"
or __version__ = "x.x.x"
in the version file (in our case, __init__.py
) (without the type signature (: src
). We can update the regex to adapt to this project. If that does not work then we can have a condition in __init__.py
to check for hatch
and change the way version
and __version__
are declared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I have a question here. In the __init__.py
we don't have directly the version value but by the get_version
function. How should this be configured then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Anavelyz
using get_version instead of the direct value maybe is not super necessary with semantic release .. but it would be important with vcs that can also calculate a version from the commit hash. but not sure about hatch
hatch requires having either version = "x.x.x" or version = "x.x.x"
@Saransh-cpp , you mean a literal"x.x.x"
? or just a literal string in this format?
btw, as a general thought, the typing annotation shouldn't be a problem because if we have something like a = "mystring"
without typing annotation it should consider it as str
anyway. not sure why hatch would fail using the version variable with typing annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the typing annotation shouldn't be a problem because if we have something like a = "mystring" without typing annotation it should consider it as str anyway. not sure why hatch would fail using the version variable with typing annotation.
I think the default regex that hatch uses to find the version string does not consider the typing annotation. It just looks for the variable version
or __version__
which is assigned a string without any typing annotation - https://hatch.pypa.io/latest/version/#configuration.
Hi, I have a question here. In the init.py we don't have directly the version value but by the get_version function. How should this be configured then?
Also, given that hatch uses regex to find the version defined in a file, using a function (get_version
) might not work as the function will never be executed.
@Saransh-cpp , you mean a literal "x.x.x" ? or just a literal string in this format?
A string in "x.x.x"
format, sorry for the confusion.
Note how scientific-python/cookie
also defines version just as a string without any type annotation -
Then they link that file in pyproject.toml, similar to the suggestion I made (and I think has been added in this PR) -
@ayeankit regarding the commit messages again, could you add some relevant messages to the commits that you are creating so we know what all you are trying while debugging? This would make reviewing this a bit easier too.
src/scicookie/{{cookiecutter.project_slug}}/build-system/hatch-pyproject.toml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayeankit please take a look at the comments above and below. This PR currently does not implement hatchling
as a backend correctly and the failing CI is right.
{% endif %} | ||
{%- endif -%}{#- end of use_pytest -#} | ||
{%- if cookiecutter.use_hypothesis == "yes" -%} | ||
hypothesis = "^6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hypothesis = "^6.0" | |
hypothesis = "^6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure .. but I guess that hatch doesn't work with ^
so , ^6.0
should be >=6.0,<7.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, I completely missed that. That looks poetry.
src/scicookie/{{cookiecutter.project_slug}}/build-system/hatch-pyproject.toml
Show resolved
Hide resolved
src/scicookie/{{cookiecutter.project_slug}}/build-system/hatch-pyproject.toml
Show resolved
Hide resolved
4eaea36
to
6cb7a4b
Compare
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
…d changed dev-dependence
…-pyproject.toml Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
…-pyproject.toml Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
…-pyproject.toml Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ayeankit! I don't think the package is actually being installed in the CI; making the passing of CI a false positive. See comments below.
@@ -40,7 +40,7 @@ export PATH=$(echo $PATH| sed -E "s/[^:]+\/micromamba\/[^:]+//g") | |||
export PATH=$(echo $PATH| sed -E "s/[^:]+\/anaconda3\/[^:]+//g") | |||
export PATH="${CONDA_PREFIX}:${CONDA_PREFIX}/bin:$PATH" | |||
echo "[II] included env conda to the PATH" | |||
|
|||
COMMAND_PREFIX= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added here by mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it is not necessary, because bash will consider any non declared variable as empty .. but I think it is good (as a "code documentation") to have it declared and assigned to empty at the beginning ... so if anyone wants something similar they will use the same variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification! Did not know that!
elif command -v hatch &> /dev/null; then | ||
COMMAND_PREFIX="hatch run" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should still be pip install --editable .
. We do need to check if the package is being installed correctly. The current passing of CI might be a false positive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Saransh-cpp I tried using pip install --editable .
but it didn't work out. @xmnlab has suggested me to use this method for installing hatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep .. hatch has a very specific workflow ... I am not an expert though ... but it seems that it doesn't work with pip install .. and all the commands that depends on the dependencies need to be executed with hatch run
... maybe there is a way to have a better workflow with hatch ... but as I mentioned I am not an expert .. feel free to suggest a better approach .. to be honest I don't like the current one .. but at least it was a way we found to have it working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds weird 🙂
I install all my hatch-based packages with pip install .
and it works fine for me. We might want to look at this in the future.
$COMMAND_PREFIX ipython kernel install --name "python3" --user | ||
|
||
$COMMAND_PREFIX pre-commit install | ||
|
||
pre-commit install | ||
pre-commit run --all-files --verbose | ||
$COMMAND_PREFIX pre-commit run --all-files --verbose | ||
|
||
make docs-build | ||
$COMMAND_PREFIX make docs-build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were the tests failing when not using "COMMAND_PREFIX"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that everything worked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry .. maybe I miss understood your question .. when not using command prefix (empty variable) for the other backend works fine .. but for hatch .. it requests hatch run
"Topic :: Scientific/Engineering", | ||
"Typing :: Typed", | ||
] | ||
version = "{{ cookiecutter.project_version }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I am not a big fan of static versioning and neither is this repository. It looks like all the Pythonic backends (except poetry, probably because it does not support it by default) in this repository use dynamic versioning, which makes it natural to make Hatch use dynamic versioning too.
The final call would be of the maintainers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In parts I agree about the static vs dynamic versioning
but using semantic-release, although you will end up with the versions static there, but you can use semantic-release-replace to update the versions automatically. and semantic release is a full stack for releasing ... different than the scm approaches ... maybe it would be possible to use semantic release + any scm approach .. but I never tested it to be honest. but also IIRC poetry doesn't have a good alternative for scm).
with all this said, what I meant is: for now it uses semantic release by default ...
so what we would need to have is (not for this PR):
- an option for static or dynamic versioning
- and an option for releasing tool, and can start with just semantic-release
for this PR I think that static versioning is ok, so we can keep consistency with all the other build systems and we can open an issue about that and start some discussions to check what we need for supporting both static and dynamic options.
PS: the idea is to be open to different approach as much as possible .. and we can have different "profiles" that could be more opinionated
[tool.hatch.version] | ||
{# keep this line here #} | ||
{%- if cookiecutter.project_layout == 'flat' -%} | ||
path = "{{ cookiecutter.package_slug }}/__init__.py" | ||
{% elif cookiecutter.project_layout == 'src' -%} | ||
path = "src/{{ cookiecutter.package_slug }}/__init__.py" | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be required if we end up using static versioning for Hatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Saransh-cpp could you add more information here please?
I am not following you, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion. These lines are only required when we use dynamic version in pyproject.toml
-
dynamic = ["version"]
but as this PR now uses static version -
scicookie/src/scicookie/{{cookiecutter.project_slug}}/build-system/hatch-pyproject.toml
Line 37 in 32704a5
version = "{{ cookiecutter.project_version }}" |
the whole [tool.hatch.version]
section is basically redundant.
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Finally, all the test cases pass!! @xmnlab Can you review it and merge it, please? Thank you. |
🎉 This PR is included in version 0.4.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Pull Request description
Fixes #69
How to test these changes
...
Pull Request checklists
This PR is a:
About this PR:
Author's checklist:
Additional information
Reviewer's checklist
Copy and paste this template for your review's note: