Skip to content

Add generate pip dependency's from conda to pre-commit #36531

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

Merged
merged 13 commits into from
Sep 26, 2020
Merged

Add generate pip dependency's from conda to pre-commit #36531

merged 13 commits into from
Sep 26, 2020

Conversation

erfannariman
Copy link
Member

@erfannariman erfannariman commented Sep 21, 2020

closes: #36529

First try, not sure yet how to activate local virtual env, error message right now is:

black................................................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
flake8-pyx...........................................(no files to check)Skipped
flake8-pxd...........................................(no files to check)Skipped
isort................................................(no files to check)Skipped
Generate pip dependency from conda.......................................Failed
- hook id: pip_to_conda
- exit code: 1

Traceback (most recent call last):
  File "scripts/generate_pip_deps_from_conda.py", line 20, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

@erfannariman erfannariman changed the title 36529 add generate pip Add generate pip dependency's from conda Sep 21, 2020
@erfannariman erfannariman changed the title Add generate pip dependency's from conda Add generate pip dependency's from conda to pre-commit Sep 21, 2020
@erfannariman erfannariman marked this pull request as draft September 21, 2020 20:18
@WillAyd
Copy link
Member

WillAyd commented Sep 21, 2020

Hmm not sure I think this is worth adding to pre-commit - this is something that rarely gets touched

@WillAyd WillAyd added the Needs Discussion Requires discussion from core team before further action label Sep 21, 2020
@clbarnes
Copy link
Contributor

I think that, if we're relying on pre-commit to manage checks on CI, we should also be checking that development environments (i.e. those specified by environment.yml and requirements.txt) are doing the same checks when e.g. IDEs do linting. Making sure they all describe the same toolchain is important for this and should at least be part of CI. The time added to pre-commit (compared to formatting and linting) would surely be trivial?

@TomAugspurger
Copy link
Contributor

I think this is exactly what should go in pre-commit. Since I don't change the deps often I never remember the check and am annoyed when CI fails :)

@MarcoGorelli
Copy link
Member

I think you'll need additional-dependencies to add yaml as a dependency. Or you can specify system as language, I think, will take a look tomorrow

@erfannariman
Copy link
Member Author

I tried using system, but it gives a weird error as if the file name is passed as argument:

black................................................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
flake8-pyx...........................................(no files to check)Skipped
flake8-pxd...........................................(no files to check)Skipped
isort................................................(no files to check)Skipped
pyupgrade............................................(no files to check)Skipped
Generate pip dependency from conda.......................................Failed
- hook id: pip_to_conda
- exit code: 2

usage: generate_pip_deps_from_conda.py
       [-h]
       [--compare]
       [--azure]
generate_pip_deps_from_conda.py: error: unrecognized arguments: .pre-commit-config.yaml

@jreback jreback added the CI Continuous Integration label Sep 22, 2020
@jreback jreback added this to the 1.2 milestone Sep 22, 2020
@jreback
Copy link
Contributor

jreback commented Sep 22, 2020

yeah this is prob fine. @erfannariman you can change out of draft mode; ping on green.

@erfannariman erfannariman marked this pull request as ready for review September 22, 2020 22:59
@WillAyd WillAyd removed the Needs Discussion Requires discussion from core team before further action label Sep 23, 2020
@jbrockmendel
Copy link
Member

failed with an ImportError of yaml

@erfannariman
Copy link
Member Author

erfannariman commented Sep 23, 2020

failed with an ImportError of yaml

Yes, same error as my initial comment. Not sure how to use local environment. Tried to go through docs of pre-commit and some issues created for the same problem, could not figure out.

https://pre-commit.com/#repository-local-hooks

@erfannariman
Copy link
Member Author

erfannariman commented Sep 23, 2020

Found the solution, this should work, I had to use pass_filenames: false, and use double quote for my args

@MarcoGorelli
Copy link
Member

Nice!

Could you just remove the

args: ["--compare"]

line, so that if you do modify environment.yml, then pre-commit will fix the requirements file for you?

@erfannariman
Copy link
Member Author

Nice!

Could you just remove the

args: ["--compare"]

line, so that if you do modify environment.yml, then pre-commit will fix the requirements file for you?

Yes makes sense, done.

@clbarnes
Copy link
Contributor

Could this be extended to check that pre-commit uses the same tool versions as environment.yml? I know that's not true currently with flake8 but it could save some pain for contributors in the future, as pre-commit uses a different environment to the rest.

@erfannariman
Copy link
Member Author

@MarcoGorelli we can have files: ^environment.yml$ so it will only run if environment.yml has changed. Would that be desirable?

@erfannariman
Copy link
Member Author

Could this be extended to check that pre-commit uses the same tool versions as environment.yml? I know that's not true currently with flake8 but it could save some pain for contributors in the future, as pre-commit uses a different environment to the rest.

Not sure if I understand you correctly, but isn't the usecase for this hook that it checks your local environment?

@MarcoGorelli
Copy link
Member

Could this be extended to check that pre-commit uses the same tool versions as environment.yml? I know that's not true currently with flake8 but it could save some pain for contributors in the future, as pre-commit uses a different environment to the rest.

I think that, once the version of flake8 has been aligned between environment.yml and pre-commit-config.yaml, then this could be added as a separate pre-commit hook (in a separate PR)

@MarcoGorelli
Copy link
Member

@MarcoGorelli we can have files: ^environment.yml$ so it will only run if environment.yml has changed. Would that be desirable?

sounds like a good idea

@erfannariman
Copy link
Member Author

ready for review @MarcoGorelli

@MarcoGorelli
Copy link
Member

ready for review @MarcoGorelli

can you resolve the conflict please? Then I'll take another look

Copy link
Contributor

@clbarnes clbarnes left a comment

Choose a reason for hiding this comment

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

Could also include requirements-dev.txt, in case it was changed accidentally and no longer matches?

@erfannariman
Copy link
Member Author

@MarcoGorelli yes, done

@clbarnes added requirements-dev.txt as well.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice! I just checked this out locally and it works as intended

@jreback jreback merged commit 422030b into pandas-dev:master Sep 26, 2020
@jreback
Copy link
Contributor

jreback commented Sep 26, 2020

thanks @erfannariman

@erfannariman erfannariman deleted the 36529-add-generate-pip branch September 26, 2020 07:33
@jbrockmendel
Copy link
Member

I'm seeing /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named scripts when the hook runs. any chance of changing python to python3?

@MarcoGorelli
Copy link
Member

I'm seeing /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named scripts when the hook runs. any chance of changing python to python3?

I thought python3 was the default if you just put python, can you try upgrading pre-commit (pip install -U pre-commit) and then doing pre-commit clean?

@jbrockmendel
Copy link
Member

Looks like on mac python will point at python3 sometime later this year when 10.16 is released. ill just be patient until then. thanks for taking a look

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Oct 7, 2020

Sorry, my bad, this uses language: system, so it does depend on what your python points to

@jbrockmendel if you change this hook to

-   repo: local
    hooks:
    -   id: pip_to_conda
        name: Generate pip dependency from conda
        description: This hook checks if the conda environment.yml and requirements-dev.txt are equal
        language: python
        entry: python -m scripts.generate_pip_deps_from_conda
        files: ^(environment.yml|requirements-dev.txt)$
        pass_filenames: false
        additional_dependencies: [pyyaml]

then does it work?

(just tried this on a laptop where python points to Python2.7 and it works for me)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add generate_pip_deps_from_conda.py to pre-commit
7 participants