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

Replace setup.py usage with pyproject.toml using hatch #3893

Merged
merged 27 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
00fd10d
Create a pyproject.toml for megalinter's core using hatchling build b…
echoix Aug 11, 2024
70e0399
Add dynamic version file
echoix Aug 11, 2024
f1c238f
Update python project version in build script
echoix Aug 11, 2024
c83f234
Delete setup.py
echoix Aug 11, 2024
e9f772c
Configure ruff extend-exclude when used with hatch fmt default config…
echoix Aug 11, 2024
b950ccb
Configure hatch to use uv by default
echoix Aug 11, 2024
d1d8d2d
Adjust test paths for project to not use invalid paths
echoix Aug 11, 2024
df447e5
Set ruff src for megalinter in pyproject.toml
echoix Aug 11, 2024
35a3bf9
Add dependency importlib-metadata only if python is less than 3.9
echoix Aug 11, 2024
1e3f07c
Update python .gitignore
echoix Aug 11, 2024
db500af
[MegaLinter] Apply linters fixes
echoix Aug 11, 2024
3acdd4b
Set up mkdocs docs build for use with `hatch run docs:build` or `hatc…
echoix Aug 11, 2024
2ae516c
Configure test for `hatch test`
echoix Aug 11, 2024
b54cfc7
Adjust dev makefiles for installs
echoix Aug 11, 2024
3efb166
Update source Dockerfiles for installing megalinter through a pip whe…
echoix Aug 11, 2024
f89112c
Update contributing docs
echoix Aug 11, 2024
6a41a1d
Adjust hatch scripts in pyproject.toml
echoix Aug 11, 2024
103d8a8
Install megalinter from wheel built in another stage
echoix Aug 11, 2024
d5eb125
Build dockerfiles
echoix Aug 18, 2024
a467320
Adjust other Dockerfiles with python package install pattern
echoix Aug 18, 2024
69cf841
Set line coverage instead of branch coverage to match CI test invocation
echoix Aug 18, 2024
cc36cde
Set WORKDIR for Hadolint
echoix Aug 18, 2024
3016378
Add pyproject.toml for pyright in the used test folder
echoix Aug 18, 2024
c5718b1
Build Dockerfiles
echoix Aug 18, 2024
9bb9ea9
Update .cspell.json
echoix Aug 21, 2024
f407632
Update CHANGELOG.md
echoix Aug 21, 2024
cb30963
Merge branch 'main' into pyproject-toml
nvuillam Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .automation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3286,6 +3286,14 @@ def generate_version():
)
print(process.stdout)
print(process.stderr)
# Update python project version:
process = subprocess.run(
["hatch", "version", RELEASE_TAG],
stdout=subprocess.PIPE,
text=True,
shell=True,
check=False,
)
# Update changelog
if UPDATE_CHANGELOG is True:
changelog_file = f"{REPO_HOME}/CHANGELOG.md"
Expand Down
1 change: 1 addition & 0 deletions .automation/test/python_mypy/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[tool.pyright]
17 changes: 8 additions & 9 deletions .config/make/python.mak
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Python default launcher
python_launcher ?= python3.11
python_requirements_file ?= .config/python/dev/requirements.txt
python_requirements_dev_file ?= .config/python/dev/requirements.txt

UV = $(shell command -v uv 2> /dev/null)
Expand All @@ -10,7 +9,7 @@ UV = $(shell command -v uv 2> /dev/null)
python-bootstrap: ## Bootstrap python
$(MAKE) python-venv-init
$(MAKE) python-venv-upgrade
$(MAKE) python-venv-requirements
$(MAKE) python-venv-editable-install

.PHONY: python-bootstrap-dev
python-bootstrap-dev: ## Bootstrap python for dev env
Expand All @@ -33,22 +32,22 @@ else
endif

.PHONY: python-venv-upgrade
python-venv-upgrade: ## Upgrade venv with pip, setuptools and wheel
python-venv-upgrade: ## Upgrade venv with pip
ifeq ($(strip $(UV)),)
source .venv/bin/activate
pip install --upgrade pip setuptools wheel
pip install --upgrade pip
else
$(UV) pip install --upgrade pip setuptools wheel
$(UV) pip install --upgrade pip
endif


.PHONY: python-venv-requirements
python-venv-requirements: ## Install or upgrade from $(python_requirements_file)
.PHONY: python-venv-editable-install
python-venv-editable-install: ## Install or upgrade from local project's pyproject.toml
ifeq ($(strip $(UV)),)
source .venv/bin/activate
pip install --upgrade --requirement $(python_requirements_file)
pip install --upgrade -e .
else
$(UV) pip install --upgrade --requirement $(python_requirements_file)
$(UV) pip install --upgrade -e .
endif

.PHONY: python-venv-requirements-dev
Expand Down
6 changes: 5 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@
"displaymath",
"distutils",
"djlint",
"dmypy",
"dockerfilelint",
"dockerfilelintrc",
"dockerignore",
Expand Down Expand Up @@ -881,6 +882,7 @@
"holdy",
"hprof",
"hsts",
"htmlcov",
"htmlhint",
"htmlhintrc",
"htmlout",
Expand Down Expand Up @@ -1104,6 +1106,7 @@
"norionomura",
"normalsize",
"noserver",
"nosetests",
"nostic",
"nosw",
"notemp",
Expand Down Expand Up @@ -1318,6 +1321,7 @@
"scolladon",
"scriptsize",
"scshape",
"sdist",
"seaneagan",
"secretlint",
"secretlintrc",
Expand Down Expand Up @@ -1540,4 +1544,4 @@
"zaach",
"zricethezav"
]
}
}
12 changes: 5 additions & 7 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,15 @@ In order to be able to run locally a server that serves all the documentation an
Commands to execute (only one time):

```bash
mkdir venv
python -m venv venv/
source venv/bin/activate
pip install --upgrade -r .config/python/dev/requirements.txt
pip install pipx
pipx install hatch
hatch shell
```

Commands to run every time you want to enter the environment and run the server:
Commands to run every time you want to build the docs and run the server:

```bash
source venv/bin/activate
mkdocs serve
hatch run build:serve
```

By default it listens on `http://127.0.0.1:8000/`.
Expand Down
72 changes: 71 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ coverage.xml
!**/salesforce/good/report/*
!**/salesforce/bad/report/*

# mkdocs documentation
site/

.sfdx/
Expand Down Expand Up @@ -126,4 +127,73 @@ server/server-files/
.venv
*megalinter_file_names_cspell.txt

.DS_Store
.DS_Store

################################
# Python:
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image

- Core
- Replace usage of setup.py with a pyproject.toml package install, by @echoix in [#3893](https://github.com/oxsecurity/megalinter/pull/3893)

- Media

Expand Down
24 changes: 19 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ FROM alpine/terragrunt:${TERRAFORM_TERRAGRUNT_VERSION} AS terragrunt
# FROM alpine/terragrunt:${TERRAFORM_TERRAGRUNT_VERSION} AS terragrunt
#FROM__END

##################
# Build wheel for megalinter python package
##################
FROM ghcr.io/astral-sh/uv:0.2.37 AS uv
FROM python:3.12.5-alpine3.20 AS build-ml-core
WORKDIR /
COPY pyproject.toml .
COPY --from=uv /uv /bin/uv
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system -r pyproject.toml
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system .

##################
# Get base image #
##################
Expand Down Expand Up @@ -792,11 +806,11 @@ RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh |
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
&& find . \( -type f \( -iname \*.pyc -o -iname \*.pyo \) -o -type d -iname __pycache__ \) -delete
COPY --from=build-ml-core pyproject.toml README.md ./
COPY --from=build-ml-core megalinter /megalinter/
RUN --mount=type=cache,target=/root/.cache/uv,from=build-ml-core \
--mount=from=uv,source=/uv,target=/bin/uv \
uv pip install --system -e .

#######################################
# Copy scripts and rules to container #
Expand Down
31 changes: 26 additions & 5 deletions Dockerfile-quick
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,26 @@
##################
ARG GITHUB_TOKEN
ARG MEGALINTER_BASE_IMAGE=oxsecurity/megalinter:beta
FROM $MEGALINTER_BASE_IMAGE
FROM $MEGALINTER_BASE_IMAGE as base

##################
# Build wheel for megalinter python package
##################
FROM ghcr.io/astral-sh/uv:0.2.37 AS uv
FROM python:3.12.5-alpine3.20 AS build-ml-core
WORKDIR /
COPY pyproject.toml .
COPY --from=uv /uv /bin/uv
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system -r pyproject.toml
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system .

#######################
# Continue base image #
#######################
FROM base

######################
# Set the entrypoint #
Expand All @@ -21,10 +40,12 @@ ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
RUN python /megalinter/setup.py install \
&& python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/*
COPY --from=build-ml-core pyproject.toml README.md ./
COPY --from=build-ml-core megalinter /megalinter/
RUN --mount=type=cache,target=/root/.cache/uv,from=build-ml-core \
--mount=from=uv,source=/uv,target=/bin/uv \
uv pip install --system -e .

#######################################
# Copy scripts and rules to container #
#######################################
Expand Down
24 changes: 19 additions & 5 deletions flavors/c_cpp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ FROM jdkato/vale:${SPELL_VALE_VERSION} AS vale
FROM lycheeverse/lychee:latest-alpine AS lychee
#FROM__END

##################
# Build wheel for megalinter python package
##################
FROM ghcr.io/astral-sh/uv:0.2.37 AS uv
FROM python:3.12.5-alpine3.20 AS build-ml-core
WORKDIR /
COPY pyproject.toml .
COPY --from=uv /uv /bin/uv
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system -r pyproject.toml
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system .

##################
# Get base image #
##################
Expand Down Expand Up @@ -321,11 +335,11 @@ RUN curl --retry 5 --retry-delay 5 -sSLO https://github.com/pinterest/ktlint/rel
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
&& find . \( -type f \( -iname \*.pyc -o -iname \*.pyo \) -o -type d -iname __pycache__ \) -delete
COPY --from=build-ml-core pyproject.toml README.md ./
COPY --from=build-ml-core megalinter /megalinter/
RUN --mount=type=cache,target=/root/.cache/uv,from=build-ml-core \
--mount=from=uv,source=/uv,target=/bin/uv \
uv pip install --system -e .

#######################################
# Copy scripts and rules to container #
Expand Down
24 changes: 19 additions & 5 deletions flavors/ci_light/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ FROM zricethezav/gitleaks:${REPOSITORY_GITLEAKS_VERSION} AS gitleaks
FROM trufflesecurity/trufflehog:${REPOSITORY_TRUFFLEHOG_VERSION} AS trufflehog
#FROM__END

##################
# Build wheel for megalinter python package
##################
FROM ghcr.io/astral-sh/uv:0.2.37 AS uv
FROM python:3.12.5-alpine3.20 AS build-ml-core
WORKDIR /
COPY pyproject.toml .
COPY --from=uv /uv /bin/uv
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system -r pyproject.toml
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system .

##################
# Get base image #
##################
Expand Down Expand Up @@ -215,11 +229,11 @@ RUN curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh |
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
&& find . \( -type f \( -iname \*.pyc -o -iname \*.pyo \) -o -type d -iname __pycache__ \) -delete
COPY --from=build-ml-core pyproject.toml README.md ./
COPY --from=build-ml-core megalinter /megalinter/
RUN --mount=type=cache,target=/root/.cache/uv,from=build-ml-core \
--mount=from=uv,source=/uv,target=/bin/uv \
uv pip install --system -e .

#######################################
# Copy scripts and rules to container #
Expand Down
Loading