0

In Python, let's say I'm using a library like flake8 to do style guide enforcement for my project and I've also told my fellow coders working on the same project that flake8 guidelines is what we will be using as the style guide. However, I'm not using it for anything directly in my project. I run flake8 in the command line to check if my project follows flake8 guidelines, but don't use it in my project for anything other that. If this is the case, Is flake8 something that belongs in the requirements.txt file? Or can it be omitted and only the dependencies actually used in the project need to go inside the requirements.txt file?

Yang K
  • 407
  • 4
  • 13
  • 1
    One thing to look into is [pipenv](https://docs.pipenv.org/). It solves some of the issues with requirements.txt files and (like many other package managers) allows you to specify a dependency as a "dev dependency," which will only be installed in development. – Bailey Parker Jul 11 '18 at 03:25

2 Answers2

-1

A requirements file should only include required dependencies of your program. Since flake8 is a supporting module to ensure styling consistency it does not fall into this category. I would not include it.

Ron Wellman
  • 387
  • 3
  • 10
  • So the same would go for libraries like `mypy` correct? – Yang K Jul 11 '18 at 03:07
  • I haven't tried out `mypy` so I'll need to read up on its use but If you don't have to import it to get your program to run, putting it into the requirements file seems unnecessary to me. I personally would make note of the various support packages that aid in your development of the project in a README file since they fall within the management of your project rather than being hard dependencies. – Ron Wellman Jul 11 '18 at 12:49
-1

Flake8 is a development dependency. Meaning, that while those packages need not be in a production environment, they should by all means be in a development one.

Following this SO answer, I'd recommend using a multi-environment requirement txt file structure:

`-- your_project_root
|-- requirements
|   |-- common.txt
|   |-- dev.txt
|   `-- prod.txt
`-- requirements.txt

The files' contents would look like this:

common.txt:

# Contains requirements common to all environments
req1~=1.0
req2~=1.0
req3~=1.0
...

dev.txt:

# Specifies only dev-specific requirements
# But imports the common ones too
-r common.txt
flake8~=6.0.0
dev_req~=1.0
...

prod.txt:

# Same for prod...
-r common.txt
prod_req~=1.0
...

Then you can run either

pip install -r requirements/dev.txt

or

pip install -r requirements/prod.txt

Depending on what environment you're on.

Depending on what other build tools and CI/CD you use, you may still need a requirements.txt, in which case you can fill it with the content you need:

requirements.txt:

# Mirrors prod
-r requirements/prod.txt
Joey Baruch
  • 4,180
  • 6
  • 34
  • 48