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

Add cruft compatibility, read from .cruft.json #756

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

MicaelJarniac
Copy link

@MicaelJarniac MicaelJarniac commented Jun 26, 2023

Closes #755

  • Basic functionality
  • Documentation
  • Tests

@MicaelJarniac
Copy link
Author

MicaelJarniac commented Jun 26, 2023

Currently failing Nox sessions:

  • safety - I believe this is due to the dependencies being outdated, and unrelated to this PR
  • typeguard-3.8
  • typeguard-3.7
  • coverage - I'll be adding tests to cover the new functionality Done!

This is still WIP.
For some reason, `.cookiecutter.json` is still present.
@MicaelJarniac

This comment was marked as resolved.

tests/conftest.py Outdated Show resolved Hide resolved
I forgot to add the vanilla cookiecutter test back.
This seems to work correctly, and separate the tests for vanilla cookiecutter and cruft.
@MicaelJarniac
Copy link
Author

I believe this PR is now ready!

@MicaelJarniac
Copy link
Author

It might be possible to remove some # type: ignores if this PR gets merged:

cookiecutter(template, no_input=True, output_dir=str(flavor_path))
return flavor_path / context["project_slug"]
elif flavor == "cruft":
import cruft # type: ignore[import]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import cruft # type: ignore[import]
import cruft

They merged it, now waiting for the release.

@pytest.fixture(params=["vanilla", "cruft"])
def flavor(request: pytest.FixtureRequest) -> str:
"""Test flavor, either vanilla cookiecutter or cruft."""
out: str = request.param # type: ignore[attr-defined]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out: str = request.param # type: ignore[attr-defined]
out: str = request.param

This # type: ignore can be removed by updating Pytest to >= 7.1 I believe.
I tried updating it with Poetry, but I believe it'd be better to update all dependencies at once.

@MicaelJarniac
Copy link
Author

@cjolowicz could you take a look at this PR?

path = Path(".cookiecutter.json")
text = repository.read_text(path, ref=ref)
data = json.loads(text)
except KeyError:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why KeyError?

Copy link
Owner

@cjolowicz cjolowicz Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that what git.Repository.read_text raises when it doesn't find the file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be!

repository.read_text(path, ref=ref)
Traceback (most recent call last):
  File "/home/micael/projects/retrocookie/src/retrocookie/core.py", line 42, in load_context
    text = repository.read_text(path, ref=ref)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/micael/projects/retrocookie/src/retrocookie/git.py", line 200, in read_text
    blob = functools.reduce(operator.truediv, path.parts, commit.tree)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '.cookiecutter.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/micael/projects/retrocookie/src/retrocookie/git.py", line 200, in read_text
    blob = functools.reduce(operator.truediv, path.parts, commit.tree)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '.cookiecutter.json'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd be better to, for example, modify the read_text method to raise a clearer error, like a FileNotFoundError, instead?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but not in this PR. Sorry for the slow review, have little bandwidth atm

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. And sorry for pinging you. I had forgotten about this PR, then realized it had been over a year with no activity.

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.

Add cruft compatibility, read from .cruft.json
2 participants