nimble icon indicating copy to clipboard operation
nimble copied to clipboard

Feature: Task-level dependencies

Open mratsim opened this issue 6 years ago • 8 comments

I'd like to use Quickcheck for testing but it seems like currently either it's listed as a full dependency and get pulled on user machine, or it's not listed and it cannot be run as a nimble task.

Can we also allow requires at the task level.

mratsim avatar Apr 24 '18 13:04 mratsim

Another use case: comparing against reference implementations/libraries. In my case a C++ wrapper that I rewrote in pure Nim.

mratsim avatar Apr 24 '18 16:04 mratsim

Perhaps you could run nimble install ... in the task?

dom96 avatar Apr 24 '18 19:04 dom96

I just tried, that unfortunately didn't work :/

  Executing task test_property_debug in /Users/<username>/Programming/Status/stint/stint.nimble
   Warning: Package 'stint' has an incorrect structure. The top level of the package source directory should contain at most one module, named 'stint.nim', but a file named 'io.nim' was found. This will be an error in the future.
      Hint: If this is the primary source file in the package, rename it to 'stint.nim'. If it's a source file required by the main module, or if it is one of several modules exposed by 'stint', then move it into a 'stint/' subdirectory. If it's a test file or otherwise not required to build thethe package 'stint.nim', prevent its installation by adding `skipFiles = @["io.nim"]` to the .nimble file. See https://github.com/nim-lang/nimble#libraries for more info.
Downloading https://github.com/alehander42/nim-quicktest using git
   Warning: Package 'quicktest' has an incorrect structure. The top level of the package source directory should contain at most one module, named 'quicktest.nim', but a file named 'js_lib.nim' was found. This will be an error in the future.
      Hint: If this is the primary source file in the package, rename it to 'quicktest.nim'. If it's a source file required by the main module, or if it is one of several modules exposed by 'quicktest', then move it into a 'quicktest/' subdirectory. If it's a test file or otherwise not required to build the the package 'quicktest.nim', prevent its installation by adding `skipFiles = @["js_lib.nim"]` to the .nimble file. See https://github.com/nim-lang/nimble#libraries for more info.
  Verifying dependencies for [email protected]
      Info: Dependency on random@#head already satisfied
  Verifying dependencies for random@#head
      Info: Dependency on https://github.com/alehander42/breeze.git@>= 0.0.5 already satisfied
  Verifying dependencies for [email protected]
 Installing [email protected]
    Prompt: [email protected] already exists. Overwrite? [y/N]
    Answer: y
   Success: quicktest installed successfully.
  Verifying dependencies for [email protected]
  Compiling tests/property_based.nim (from package stint) using c backend
Hint: used config file '/Users/<username>/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: property_based [Processing]
Hint: stint [Processing]
...
Hint: tables [Processing]
Hint: termios [Processing]
property_based.nim(10, 32) Error: cannot open 'quicktest'
       Tip: 4 messages have been suppressed, use --verbose to show them.
     Error: Execution failed with exit code 256
        ... Command: "/Users/<username>/.nimble/bin/nim" c --noNimblePath "--define:mpint_test" "--out:./build/property_based" "--run" "--nimcache:"nimcache""  "tests/property_based.nim"

mratsim avatar May 03 '18 09:05 mratsim

After discussion on IRC I am tempted to implement this instead of https://github.com/nim-lang/nimble/pull/464.

https://irclogs.nim-lang.org/20-08-2018.html#16:05:30

For the Nimgen use case:

before install:
  requires "nimgen"
  exec "nimgen ngen.cfg"

For the test use case:

task test:
  requires "quickcheck"
  exec "nim c -r tests/tester"

Unlike the global requires, a task-level requires will immediately install the specified dependencies when the task is being executed.

Note: If nimble c -r tests/tester is used instead, the compilation will fail since the .nimble file only specifies quickcheck in the test task. This is why the workaround failed for you @mratsim. Nimble needs to allow the c task to be executed directly instead of via exec to solve this :(.

dom96 avatar Aug 20 '18 17:08 dom96

Okay, so I need to be able to override the NimScript task template for this. As such I will postpone this until another release.

dom96 avatar Aug 27 '18 16:08 dom96

Looking at @dom96 earlier comment, specifying a required package for a custom task can only install the package if it isn't already present. It doesn't actually make it seamless to use the package. User has to resort to exec calls to nim or nimble. Nim might even work if the dep is installed globally but nimble won't as seen above. Fixing that is not trivial given the new architecture where nimble spawns nim e instead of embedding the VM.

How about a testRequires option instead that specifies additional packages required when nimble test is called? This will not help custom tasks but at least make it seamless when you have a tests directory with a bunch of test files that nimble can then automatically call as required.

genotrance avatar Jul 20 '20 04:07 genotrance

So another failure and lost time that could be avoided with task level dependencies so that test packages don't pollute everything:

image

nim-json-serialization is bringing Chronos because it needs to test and work with it, and then it turns Chronos is bringing BearSSL and a testutils a fuzzing framework. All those things pollute builds and could be avoided if task-level dependencies were supported.

mratsim avatar Feb 09 '21 18:02 mratsim

I've create a nimble fork for temporary solution , https://github.com/bung87/slim

bung87 avatar Jun 12 '21 17:06 bung87

Implemented in #1035

ire4ever1190 avatar Nov 19 '22 06:11 ire4ever1190