Go: proposal: divide go module dependencies into two categories: require and testRequire

Created on 22 Nov 2020  路  3Comments  路  Source: golang/go

dividing deps into two categories:

  • "dependences" at runtime;
  • "devDependences" during development.
    i think it's a clean way of dependency management.

For examples in Python/Node.js:

python: setup.py -> tests_require
eg: https://github.com/psf/requests/blob/3.0/setup.py#L126

node.js: package.json -> devDependencies
eg: https://github.com/expressjs/express/blob/4.18/package.json#L62

expected layout

go.mod:

module github.com/{namespace}/dbdriver-wrapper

go 1.13

// for biz
require (
   ...
)

// for unittest
testRequire (
    github.com/stretchr/testify v1.6.1
    github.com/mattn/go-sqlite3. v2.0.3
)

Proposal

Most helpful comment

To clarify why Go doesn't, it's because, unlike with NPM and similar languages, the go.mod file does _not_ specify a module's dependencies. It specifies what versions of dependencies are needed. The import statements in the Go files are the ones that actually specify dependencies, so test dependencies are automatically sorted by virtue of being imported only from test files.

All 3 comments

Do you propose any behavioural differences between the two or is this just a cosmetic grouping?

Python and Node need to know the difference between the two in order to decide what becomes part of the build artifacts, while Go does not.

To clarify why Go doesn't, it's because, unlike with NPM and similar languages, the go.mod file does _not_ specify a module's dependencies. It specifies what versions of dependencies are needed. The import statements in the Go files are the ones that actually specify dependencies, so test dependencies are automatically sorted by virtue of being imported only from test files.

Was this page helpful?
0 / 5 - 0 ratings