mypy pre-commit check on a Django project with Pipenv - django

I would like to run mypy static type checks with pre-commit and thus have the below config in .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.0.0'
hooks:
- id: mypy
args: ['--ignore-missing-imports', '--cache-dir', '/dev/null', '--show-error-codes']
However, I get errors like No module named 'mypy_django_plugin', and basically the same for all project dependencies. I am aware additional_dependencies should be used to list dependencies. The thing is, the project has 30+ dependencies and manually listing them here is a bit impractical (same goes for keeping them in sync with Pipfile).
I have also read elsewhere (SO, pre-commit GitHub) that installing dependencies dynamically from a requirements file is not supported.
So is it somehow possible to populate additional_dependencies from a pipfile.lock? Is there a solution for Pipenv similar to the one existing for Poetry (see link below.). Or is there another workaround to make mypy work?
PS:
How to have a single source of truth for poetry and pre-commit package version? deals with the same problem, but the post and solution are Poetry specific.

Related

how to run go-unit-tests pre-commit hook to run with option -p

I was looking into this golang-precommit hooks repository: https://github.com/dnephin/pre-commit-golang
go-unit-tests hook runs the command go test -tags=unit -timeout 30s -short -v but what if I want go hook to run command with
-p=1 option. Is there any way to achieve this?
Here's the content from my .pre-commit-config.yaml file
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: go-fmt
- id: go-unit-tests
there isn't given that hook directly, but that repo isn't really adding too terribly much, you could replicate what you want via a repo: local hook (untested):
- repo: local
hooks:
- id: go-unit-tests
name: go unit tests
entry: go test -p=1 ./...
pass_filenames: false
types: [go]
language: system
disclaimer: I wrote pre-commit
/blatant self-promotion
I invite you to have a look at my golang pre-commit hooks project:
github: TekWizely/pre-commit-golang
The project includes built-in hooks for "go test":
README -> go-test
These hooks were specifically designed to enable you to pass extra arguments to the go tools.
Just use pre-commit's built-in args mechanism:
https://pre-commit.com/#passing-arguments-to-hooks
Additionally, each hook has a version to run against different scopes:
Individually Modified .go Files
All .go Files in Repository
Full Module Containing Modified .go|go.mod Files
All Modules In Repository
Full Package Containing Modified .go Files (deprecated)
All Packages in Repository (deprecated)
note: Available scopes are dependent on what each tool actually supports.
Finally, there's a mechanism to invoke general go tools that do not
(yet) have built-in hooks (its hard to keep up with them all).
Per your original question, here's an example of running go test with -p=1:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: master
hooks:
- id: go-test-mod
args: ['-p=1']
I hope you'll give my project a try. I think you'll find it offers the best available pre-commit hooks for golang.
(feel free to ask any clarifying questions, but please don't ask for too much support here - the issue and discussion trackers on the project page are a better place for such things)
[edit: grammar]

I copy/pasted/modified a dependency in my project. This was not a smart dependency management strategy. How do I step back?

Context:
MainProject depends on a header-only dependency Module.
Both MainProject and Module are:
still under development and subject to modifications
modern CMake projects
independent repositories on Github
controlled by me
Problem:
Few months before, I tried without success to manage this dependency using CMake and versioning. Pressed by deadlines, I ended up opting for the "simplest solution" to copy-paste project Module headers in MainProject. Developing MainProject led to add features and modify interfaces in the Module local copy. Now there are two diverging Module.
How it could have worked
It could have worked if Module was very stable (copy/pasting headers is actually the solution I opted for dependencies that are stable and for which I don't have ownership).
I could have modified/commited/pushed/recopy/repasted the Module repository for every modification I wanted to bring. But of course I did not because ... time and deadlines.
Question
Now I would like to step back from this solution (ie, reflect the modifications on the initial Module project) and chose a better dependency management strategy.
What I can think of
create a new branch update on Module git project, copy-paste the modified version, commit it and use git diff to check the differences with branch master
use one or a combination of these three approaches (but I don't know how to chose)
git submodules
git subtrees
C++20 modules
Your Module project literally is a Git submodule: an independently-updated history, from which your MainProject builds use specific revisions.
Developing MainProject led to add features and modify interfaces in the Module local copy. Now there are two diverging Module
Quickest: from a clean checkout of your current MainProject revision,
git tag slice $(git commit-tree -m slice #:path/to/Module)
git rm -rf path/to/Module
git submodule add u://r/l path/to/Module
git push path/to/Module slice
cd path/to/Module
git read-tree -um slice
git commit -m 'Module content from MainProject'
and now you've got your content and ancestry looking serviceable, and you can add labels and push it wherever it needs to go, e.g. git checkout -b MainProjectModule; git push -u origin MainProjectModule
If you've got a long history of Module changes in your main project that you want to preserve in the Module history proper, it's doable, and even fairly efficient, but you'll need to adapt some history surgery to achieve it, instead of tagging a nonce commit, tag the submodule commit that command produces and merge that rather than just adding its tip content as a new commit.

repo2 is a library for repo1

In the moment, I have two github repositories, i.e. repo1 and repo2. Both are two django projects created by our team. In requirements.pipin ~/work_projects/repo1, I have the line
-e git+ssh://git#gitlab.com/repo2.git#de5622dcf0b9a084f9b0a34cdd1d932026904370#egg=repo2
Hence, repo2 becomes a library used by repo1 in ~/.virtualenvs/venv/src (repo1's virtual environment). In the moment, I need to modify both repositories at the same time. My main focus in the moment is that each time I modify repo2, I need to test out the results on repo1. I want to look at the impact of repo2 on repo1 once modified.
I don't want to push my changes on github and reinstall repo2 on repo1 each time I want to see those changes. How could I make it works easily, workaround?
I have a similar setup and I usually install from file (run from console):
pip install -e ../repo2
And since you said git, and you also said you don't want to push, but nothing about committing, here's a version that can install your library from a tag, branch or commit in a local git repo:
pip install -e git+file:~/work_projects/repo2#develop#egg=repo2

How to run bash commands like "npm install" on complie

I need to run npm install && gulp build inside my static/semantic-ui folder, so it creates the needed css file.
I saw this example with Setup.hs, however on my scaffolded project I don't have it, so my question where is the right place to put the code to run those bash commands.
If you're using the default Yesod scaffolding (generated by stack tool), then it indeed doesn't contain Setup.hs (which is a bit weird, as their own guide - https://github.com/commercialhaskell/stack/blob/master/doc/GUIDE.md - recommends having it as a good practice)
Setup.hs should be located in main project directory (same where stack.yml and yourproject.cabal are located) and content should be roughly the same as in your included example (defaultMainWithHooks is the key part).
Details of hooks usage are specified in https://www.haskell.org/cabal/users-guide/developing-packages.html and in cabal spec: https://hackage.haskell.org/package/Cabal-1.24.0.0/docs/Distribution-Simple.html
BTW, for now stack doesn't support pre-build hooks on its own (for details see: https://github.com/commercialhaskell/stack/issues/503), so you have to stick to ones provided by cabal - that's where Setup.hs comes from.

linking ember-cli master causes merge errors

I have followed the ember-cli instructions for referencing the master branch in development.
It works fine when I use a new ember project.
However when I try linking to an existing ember project i get this kind of error:
Merge error: file "bootstrap/.bower.json" exists in vendor and vendor - pass option { overwrite: true } to mergeTrees in order to have the latter file win
I have tried everything to get rid of this (i.e. clone repository, and initialize things one step at a time.
The occurs once I install stefanpenner/loader.js#1.0.1
Fundamental problem is that vendor directory has changed to bower_components directory.
this leaves the .bowerrc file pointing to "vendor" which seems to cause the problem.
make sure to - delete .bowerrc file or update it so it points to bower-components
This will happen as long as you do everything in the right order
go to directory containing your working copy (master) of ember-cli
npm link
go to your code directory
npm link ember-cli
ember init (make sure to update .bowerrc, and update/merge .gitignore, bower.json, package.json)
you should be good to go
The problem I was having was running bower install BEFORE ember init (per the ember-cli web page)
This was installing stuff in the vendor directory, so you end up with duplicates.