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

Don't build the extension in pre-commit environments #1226

Closed
wants to merge 1 commit into from

Conversation

mwouts
Copy link
Owner

@mwouts mwouts commented Apr 27, 2024

With this PR, the extension is not build when the Python executable looks like a pre-commit environment.

Closes #1210

After this PR, the test tests/external/pre_commit/test_pre_commit_1_sync_with_no_config.py runs in 25 seconds (was 54 seconds previously).

At least this should fix the issue that Jupytext can't be installed in a pre-commit hook env when npm is not present.

If I new how to do that, I would prefer to not even take a dependency on hatch-jupyter-builder and jupyterlab (I think that's where most of the 25 seconds come from).

I see that it is possible to have dynamical values in the project table (e.g. version, or even dependencies, so I have been thinking of writing a hook that would identify pre-commit environments and set e.g. a build_for_pre_commit_env variable, but then
@mahendrapaipuri do you think I could use that variable to skip the extension build?

Copy link

Thank you for making this pull request.

Did you know? You can try it on Binder: Binder:lab or Binder:notebook.

Also, the version of Jupytext developed in this PR can be installed with pip:

pip install git+https://github.com/mwouts/jupytext.git@no_extension_in_pre_commit_envs

(this requires nodejs, see more at Developing Jupytext)

@mwouts mwouts force-pushed the no_extension_in_pre_commit_envs branch from b804afb to 33b9496 Compare April 27, 2024 18:10
@mwouts
Copy link
Owner Author

mwouts commented Apr 27, 2024

Apparently I have been able to require jupyterlab>=4 dynamically, and now the test runs in only 8 seconds.

@mwouts
Copy link
Owner Author

mwouts commented Apr 27, 2024

Apparently I have been able to require jupyterlab>=4 dynamically, and now the test runs in only 8 seconds.

Well apparently that did not work 😢 (the dev install fails on the CI)

@mwouts mwouts force-pushed the no_extension_in_pre_commit_envs branch from 33b9496 to c607e7d Compare April 27, 2024 20:43
Copy link

codecov bot commented Apr 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.73%. Comparing base (642c709) to head (c607e7d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1226   +/-   ##
=======================================
  Coverage   97.73%   97.73%           
=======================================
  Files          29       29           
  Lines        4463     4463           
=======================================
  Hits         4362     4362           
  Misses        101      101           
Flag Coverage Δ
external 75.14% <ø> (+0.11%) ⬆️
functional 88.48% <ø> (ø)
integration 77.28% <ø> (ø)
unit 66.55% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mwouts mwouts added this to the 1.16.2 milestone Apr 28, 2024
"""

def initialize(self, version, _):
if "/.cache/pre-commit/".replace("/", os.path.sep) in sys.executable:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good idea. But I am not quite sure how are you detecting if the current installation is done by pre-commit and not a regular installation.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Well, so far I have not found a better way than checking whether the Python path contains /.cache/pre-commit/ (I still need to check how it looks like on Windows)

@@ -130,14 +130,14 @@ packages = ["src/jupytext", "src/jupytext_config", "jupyterlab/jupyterlab_jupyte
"jupyterlab/jupyter-config" = "etc/jupyter"
"jupyterlab/jupyterlab_jupytext/labextension" = "share/jupyter/labextensions/jupyterlab-jupytext"

[tool.hatch.build.hooks.jupyter-builder]
[tool.hatch.build.hooks.custom]
# Enable running hook by default.
# We disable this hook only by setting env var HATCH_BUILD_HOOKS_ENABLE=false
# So `HATCH_BUILD_HOOKS_ENABLE=false pip install .` will **not** build JupyterLab related
# extension. A simple `pip install .` will **always** build extension
enable-by-default = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not set enable-by-default = false, so that extension will not build by default. In the CI, we will need to add HATCH_BUILD_HOOKS_ENABLE=true to force the building of extension.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Well sure that would solve this issue indeed! That's how we were doing it up to version 1.14.x I believe. Would that be ok with you? I'll be careful to make sure that we don't miss the extension in the conda package too.

Copy link
Contributor

Choose a reason for hiding this comment

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

From my understanding, most of the jupytext "contributors" are interested in developing core jupytext and do not touch its extension. If that is the case, I think it makes more sense to disable extension building by default as it completely avoids node dependency.

So, yes, I think it makes sense for me to set enable-by-default = false and more over, that is what I proposed originally when we moved to hatch build system.

@mwouts
Copy link
Owner Author

mwouts commented May 5, 2024

As discussed above, I have merged #1233 instead - thanks @mahendrapaipuri for your advice!

@mwouts mwouts closed this May 5, 2024
@mwouts mwouts deleted the no_extension_in_pre_commit_envs branch May 5, 2024 21:34
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.

The Jupytext pre-commit hook fails to install when node is not available
2 participants