Is it possible to divide dev-packages into several directories? - python

In pip file I now have this structure
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
pydantic = ">=1.8.0,<2"
kubernetes = ">=21.7.0,<24"
PyYAML = ">=6.0"
[dev-packages]
psycopg2= ">=2.8.5"
cx-Oracle= "==8.3.0"
flake8 = ">=5.0.4,<6"
flake8-bugbear = "==22.8.22"
pep8-naming = ">=0.13.2,<1"
black = "==22.6.0"
pytest = "==7.2.0"
pytest-cov = "==4.0.0"
sqlparse = ">=0.4.1,<1"
requests = "*"
[requires]
python_version = "3.8"
I want to split the development packages into different directories so that when using pipenv, extra packages are not installed.Exemple:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
pydantic = ">=1.8.0,<2"
kubernetes = ">=21.7.0,<24"
PyYAML = ">=6.0"
[dev-packages]
black = "==22.6.0"
sqlparse = ">=0.4.1,<1"
requests = "*"
[pytest]
pytest = "==7.2.0"
pytest-cov = "==4.0.0"
[flake8]
flake8 = ">=5.0.4,<6"
flake8-bugbear = "==22.8.22"
pep8-naming = ">=0.13.2,<1"
[db-packages]
psycopg2= ">=2.8.5"
cx-Oracle= "==8.3.0"
[requires]
python_version = "3.8"
How can I manage multiple groups of packages using pipenv?
It seems to be possible to create a Makefile, but I think it will be difficult to support.

Related

Could not load required libraries. Please check your installation and make sure you activated any necessary virtual environment

I am working on a simple Python project using Poetry using a template, with some dependencies and files.
I have installed the dependencies with: poetry install
And then when I run: poetry run python src/server/app/__main__.py
I get the following:
💣 Could not load required libraries. Please check your installation
and make sure you activated any necessary virtual environment
I am not really quite sure what's the issue since from a quick Google search there is no mention of anyone that has experienced this error.
Here is the pyproject.toml:
[tool.poetry]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development",
"Typing :: Typed",
]
description = "Opinionated template for integrating Starlite with a SPA"
documentation = "https://cofin.github.io/starlite-full-stack-example"
homepage = "https://github.com/cofin/starlite-full-stack-example"
include = ["CHANGELOG.md"]
keywords = ["api", "rest", "http", "asgi", "pydantic", "starlette", "fastapi", "framework", "websocket", "vite", "spa"]
license = "MIT"
maintainers = ["Cody Fincher <cody.fincher#gmail.com>"]
name = "app"
packages = [
{include = "app", from = "src/server"},
]
readme = "README.md"
repository = "https://github.com/cofin/starlite-full-stack-example"
version = "0.1.0"
[tool.poetry.scripts]
app = "app.__main__:main"
[tool.poetry.dependencies]
alembic = "*"
asyncpg = "*"
click = "*"
greenlet = "*"
hiredis = "*"
httpx = "*"
passlib = {version = "*", extras = ["argon2"]}
pydantic = {extras = ["dotenv", "email"], version = "*"}
python = ">=3.10,<4.0"
redis = "*"
rich = "*"
sqlalchemy = {git = "https://github.com/sqlalchemy/sqlalchemy.git", branch = "main", extras = ["asyncio"]}
starlite = {version = "^1.25.0", extras = ["brotli","picologging","structlog"]}
starlite-jwt = "^1.4.0"
uvicorn = {extras = ["standard"], version = "*"}
orjson = "^3.8.3"
[tool.poetry.group.dev.dependencies]
bump2version = "*"
coverage = {extras = ["toml"], version = "*"}
cython = "*"
hypothesis = {extras = ["cli"], version = "*"}
ipykernel = "*"
ipython = "*"
pytest = "*"
pytest-asyncio = "*"
pytest-cov = "*"
pytest-dotenv = "*"
pytest-mock = "*"
tox = "*"
[tool.poetry.group.docs]
optional = true
[tool.poetry.group.docs.dependencies]
mkdocs = "*"
mkdocs-material = "*"
mkdocstrings = "*"
mkdocstrings-python = "*"
[tool.poetry.group.lint]
optional = true
[tool.poetry.group.lint.dependencies]
autoflake = "*"
bandit = "*"
black = "*"
blacken-docs = "*"
flake8 = "*"
flake8-bugbear = "*"
flake8-comprehensions = "*"
flake8-mutable = "*"
flake8-print = "*"
flake8-simplify = "*"
flake8-type-checking = "*"
freezegun = "*"
httpx = "*"
isort = "*"
mypy = "*"
pre-commit = "*"
pylint = "*"
pyupgrade = "*"
slotscheck = "*"
types-click = "*"
types-freezegun = "*"
types-passlib = "*"
types-python-jose = "*"
types-pyyaml = "*"
types-redis = "*"
[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core", "setuptools", "wheel", "cython"]
[tool.black]
exclude = '''
/(
\.git
| \.mypy_cache
| \.tox
| venv
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
include = '\.pyi?$'
line-length = 120
[tool.autoflake]
check = true
[tool.isort]
line_length = 119
multi_line_output = 3
profile = "black"
skip_gitignore = true
src_paths = ["src/server", "test/server"]
[tool.coverage.run]
omit = ["*/tests/server/*"]
[tool.coverage.report]
exclude_lines = [
'pragma: no cover',
'if TYPE_CHECKING:',
'except ImportError as e:',
'\.\.\.',
"if __name__ == '__main__':",
]
[tool.pytest.ini_options]
addopts = "--cov=src -v --doctest-modules --doctest-glob=*.md --ignore=migrations"
asyncio_mode = "auto"
env_files = [".env.example"]
[tool.bandit]
exclude_dirs = ["tests"]
skips = ["B101", "B601"]
tests = ["B201", "B301", "B101"]
What could cause this? What can I try to find out what's causing this error?
Take a look at this. By using this Python module you can easily create templates of Python projects. Not only the file system layout of the project files but also the debugger configs for vscode. I also suffered myself the pain of trying to get Python modules without reference errors
Project description
PyArchetype
This project is used to simplify the skeleton creation of python projects
Installation
pip install pyarchetype
Source Code
https://github.com/redcorjo/pyarchetype.git
Version: 2023010702
You should run this command preferably: poetry run python -m app.

How to define "python_requires" in pyproject.toml using setuptools?

Setuptools allows you to specify the minimum python version as such:
from setuptools import setup
[...]
setup(name="my_package_name",
python_requires='>3.5.2',
[...]
However, how can you do this with the pyproject.toml? The following two things did NOT work:
[project]
...
# ERROR: invalid key
python_requires = ">=3"
# ERROR: no matching distribution found
dependencies = ["python>=3"]
According to PEP 621, the equivalent field in the [project] table is requires-python.
More information about the list of valid configuration fields can be found in: https://packaging.python.org/en/latest/specifications/declaring-project-metadata/.
The equivalent pyproject.toml of your example would be:
[project]
name = "my_package_name"
requires-python = ">3.5.2"
...
You can specify this in setup.cfg. For example:
..
[options]
packages = find_namespace:
install_requires =
matplotlib~=3.5
numpy~=1.22
python_requires = >=3.8
include_package_data = True
package_dir =
=src
zip_safe = False
[options.packages.find]
where = src

How to configure coverage with tox?

I am using tox to run tests on different envs using tox -p(run in parallel), but have a problem with coverage report generation for all tests.
tox.ini:
[tox]
envlist = env1,ev2,report
skipsdist=True
[base]
deps = pytest
[testenv:env1]
deps = custom-package-1
{[base]deps}
commands = pytest --cov-append tests/flows/test_1.py
[testenv:env2]
deps = custom-package-2
{[base]deps}
commands = pytest --cov-append tests/flows/test_2.py
[testenv:report]
deps = coverage[toml]
commands = coverage report
depends = env1,env2
parallel_show_output = true
pyproject.toml coverage section:
[tool.coverage.report]
fail_under = 100
show_missing = true
exclude_lines = [
'pragma: no cover',
'\.\.\.',
'if TYPE_CHECKING:',
"if __name__ == '__main__':",
]
Error:
No source for code: '/Users/my_user/projects/my_proect/flows/__init__.py'.
Can someone tell me what is wrong with provided configuration?
You need to remap the source files see https://coverage.readthedocs.io/en/6.2/config.html?highlight=paths#paths and for example https://github.com/tox-dev/tox/blob/master/tox.ini#L136-L143

Specify per-file-ignores with pyproject.toml and flake8

I am using flake8 (with flakehell but that should not interfere) and keep its configuration in a pyproject.toml file. I want to add a per-file-ignores config but nothing works and there is no documentation on how it is supposed to be formatted in a toml file.
Flake8 docs show only the 'native' config file format:
per-file-ignores =
project/__init__.py:F401
setup.py:E121
other_project/*:W9
There is no description / example for pyproject.toml.
I tried:
per-file-ignores=["file1.py:W0621", "file2.py:W0621"]
and
per-file-ignores={"file1.py" = "W0621", "file2.py" = "W0621"}
both of which silently fail and have no effect (the warning is still raised).
What is the proper syntax for per-file-ignores setting in flake8/flakehell while using pyproject.toml?
flake8 does not have support for pyproject.toml, only .flake8, setup.cfg, and tox.ini
disclaimer: I am the flake8 maintainer
Currently, pyproject-flake8 enables you to write your flake8 settings on pyproject.toml like this.
# pyproject.toml
[tool.flake8]
exclude = ".venv"
max-complexity = 10
max-line-length = 100
extend-ignore = """
W503,
E203,
E701,
"""
per-file-ignores = """
__init__.py: F401
./src/*: E402
"""

How do I sync values in setup.py / install_requires with Pipfile / packages

If you work on a project that uses both setup.py and Pipfile you often find the same values in: Pipfile/[packages] and setup.py/install_requires.
Does anyone know how I can tell Pipfile to use values from setup.py/install_requires for [packages]?
Within your setup.py:
Define a function to read a section:
def locked_requirements(section):
"""Look through the 'Pipfile.lock' to fetch requirements by section."""
with open('Pipfile.lock') as pip_file:
pipfile_json = json.load(pip_file)
if section not in pipfile_json:
print("{0} section missing from Pipfile.lock".format(section))
return []
return [package + detail.get('version', "")
for package, detail in pipfile_json[section].items()]
Within the setup function return the list from the default section:
setup(
# ...snip...
install_requires=locked_requirements('default'),
# ...snip...
)
IMPORTANT NOTE: include Pipfile.lock within the MANIFEST.in like:
include Pipfile.lock

Categories