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

refactor tests and dev env #422

Closed
wants to merge 7 commits into from
Closed

Conversation

kingarrrt
Copy link
Contributor

@kingarrrt kingarrrt commented Nov 28, 2023

This attempts to extend and clean up the test suite and dev environment. Not complete but a good start (I think) and I hope not controversial. I was surprised that you are not dogfooding with an .envrc, and have added that in.

The tests are now self-contained, so unaffected by external state, and equally they won't mess with your $HOME. The bear in the corner remains - gc tests still use the real store, which is painful.

One thing this flags up is your minimum nix requirement. Nix 2.4 was removed from Nixpkgs in July/22. The lowest version you can support in Nixpkgs is 2.10, but this has it's own problems, see the last commit. Maybe time to bump the requirement?

* fix deprecation warnings
* define dependencies once
* expose all supported nix versions in nixpkgs for test
* use ruff for both check and format, dropping black
* factor out duplicated code
* make tests an importable package
* idiomatic pytest usage
* do not touch files outside of the tmp test tree and do not depend on
  external state (except for /nix/store ☹)
* run coverage to root out dead code
drop redundant configuration
* test envs have a local gc root under ./._test_gcroot
* update github workflow to run tests on a matrix of supported nix
  versions and ubuntu/macos
* use jrmurr/direnv-nix-action in github workflow
@bbenne10
Copy link
Contributor

Hah. I was just thinking that I would like to get the tests working more transparently (and figure out why they aren't running on #420?). I'll look this over soon.

@kingarrrt
Copy link
Contributor Author

kingarrrt commented Nov 28, 2023

Er, I've got two more branches, https://github.com/kingarrrt/nix-direnv/tree/cleanup and https://github.com/kingarrrt/nix-direnv/tree/cached. The first is a general cleanup, the second re-implements the cache keyed on the hash of watched files. Unfortunately each builds on the last, including this one, and I can't create pull requests without a bunch of duplicate commits. I thought Github would deal with the situation but no. I'm not quite sure what to do. This was an attempt an making things easier to review...

Re the failures: I hadn't realized Garnix ran flake check. I've got to head out but will come back later and move these tests to be exposed under something that won't get picked by it, since the tests are still impure so cannot work in this context.

Re #420: I ended up doing something similar on the cached branch, sorry to step on your toes.

@bbenne10
Copy link
Contributor

Frankly, I think these branches are too big and leading to PRs that are much too large for easy review. I'd be telling developers at work the same thing
Looking at your cached branch, I see a bunch of potential PRs that sort of build on one another (these are probably out of order):

  • Add .envrc to dogfood ./direnvrc in development
  • Test & Entrypoint refactor
  • Python modernization
  • Use_flake tests
  • Hash watched files (this actually addresses hash all the files #299, I think?)
  • Only create manual reload script if necessary (See note below on this one)
  • Factor out _nix command and modernize nix invocations (This is where you'd drop nix_direnv_realpath)
  • Correct typos in README
  • Improve manual reloading (this one's a doozy and definitely deserves a standalone PR)
  • And so on

I am happy to review MORE pull requests, but the code here is complex enough that I don't want to review one MASSIVE pull request doing all of this as the potential for missteps in reviewing one big PR is much higher than multiple small(er) ones. I might suggest, actually, closing this one and starting with smaller PRs. It isn't completely necessary, but it does simplify PR creation, management, and review.

Re: conditional manual reload script creation: We decided to ALWAYS create the manual reload script. It's simpler to do and there's no real drawback to creating the script itself. You're welcome to open a PR to re-open discussion on this, but I don't see a reason for my opinion to change yet.

@@ -0,0 +1,37 @@
from __future__ import annotations
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this? We don't need to support python 3.7 anymore for our internal test suite.


[tool.coverage.report]
Copy link
Member

Choose a reason for hiding this comment

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

Only our test code is using python, so I don't think we need code coverage for this.

nix
] ++ (with python3.pkgs; [
pytestCheckHook
pytest-cov
Copy link
Member

Choose a reason for hiding this comment

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

So we might not need this?

installPhase = ''
install -m400 -D direnvrc $out/share/nix-direnv/direnvrc
'';

passthru.tests = {
lint = runCommand "lint-${finalAttrs.name}" {
Copy link
Member

Choose a reason for hiding this comment

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

I got rid of lint now in favor of treefmt.

pytestCheckHook
pytest-cov
pytest-randomly
pytest-sugar
Copy link
Member

Choose a reason for hiding this comment

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

Checked the number of dependencies and it seems reasonable.

@Mic92
Copy link
Member

Mic92 commented Nov 29, 2023

There are certainly some good things in this PR but I also would like to take this in a smaller scoped pull requests.

@Mic92
Copy link
Member

Mic92 commented Nov 29, 2023

I wanted to make myself familiar with these new lints, so I applied them myself in #425

That hopefully also reduce the scope of this PR.

@kingarrrt
Copy link
Contributor Author

Understood. I'll split this down and resubmit.

@kingarrrt kingarrrt closed this Nov 29, 2023
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.

3 participants