Skip to content

Commit

Permalink
Major refactor and tests with ~80% coverage and mostly passing
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklinke committed Jul 3, 2024
1 parent 17a721d commit 9a9f4ef
Show file tree
Hide file tree
Showing 60 changed files with 6,365 additions and 1,326 deletions.
1 change: 1 addition & 0 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ poetry-plugin-export==1.8.0
pytest==8.2.1
pytest-cov==5.0.0
pytest-django==4.8.0
pytest-mock==3.14.0
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
/src/*.egg-info/
__pycache__/
.venv/
.idea/

File renamed without changes.
51 changes: 32 additions & 19 deletions compose/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ ARG PYTHON_3_10=3.10.14
ARG PYTHON_3_11=3.11.9
ARG PYTHON_3_12=3.12.3

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV COMPOSE_DOCKER_CLI_BUILD 1
ENV DOCKER_BUILDKIT 1
ENV BUILD_ENV ${BUILD_ENVIRONMENT}
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV COMPOSE_DOCKER_CLI_BUILD=1
ENV DOCKER_BUILDKIT=1
ENV BUILD_ENV=${BUILD_ENVIRONMENT}


# Create user and group
RUN addgroup --system django \
&& adduser --system --ingroup django django

# Make the /app directory and set permissions
RUN mkdir /app && chown django:django /app

WORKDIR ${APP_HOME}

Expand All @@ -33,8 +41,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \

# Install pyenv
RUN git clone https://github.com/pyenv/pyenv.git .pyenv
ENV PYENV_ROOT ${APP_HOME}/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
ENV PYENV_ROOT=${APP_HOME}/.pyenv
ENV PATH=$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

# Install Python version(s)
RUN if [ "$MULTIPLE_PYTHON" = "True" ] ; then \
Expand Down Expand Up @@ -72,36 +80,41 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
RUN pip install poetry

# Copy poetry files
COPY poetry.lock pyproject.toml ${APP_HOME}
COPY --chown=django:django poetry.lock pyproject.toml ${APP_HOME}
COPY --chown=django:django ./src/django_segments/ ${APP_HOME}/django_segments/

# Install dependencies:
RUN poetry config virtualenvs.create false \
RUN --mount=type=cache,target=/home/django/.cache/pypoetry,sharing=locked \
poetry config virtualenvs.create false \
&& poetry install --with dev --no-interaction --no-ansi --no-root

# Copy remaining project files
COPY noxfile.py manage.py ${APP_HOME}
COPY .darglint .editorconfig .flake8 .gitignore .pre-commit-config.yaml .prettierignore .readthedocs.yml bandit.yml ${APP_HOME}
COPY CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md LICENSE README.md ${APP_HOME}
COPY ./docs/ ${APP_HOME}/docs
COPY ./example_project/ ${APP_HOME}/example_project/
COPY ./tests/ ${APP_HOME}/tests/
COPY ./src/ ${APP_HOME}/
COPY ./src/ ${APP_HOME}/src/
COPY --chown=django:django noxfile.py manage.py ${APP_HOME}
COPY --chown=django:django .darglint .editorconfig .flake8 .gitignore .pre-commit-config.yaml .prettierignore .readthedocs.yml bandit.yml ${APP_HOME}
COPY --chown=django:django CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md LICENSE README.md ${APP_HOME}
COPY --chown=django:django ./docs/ ${APP_HOME}/docs/
COPY --chown=django:django ./tests/ ${APP_HOME}/tests/

# Rehash pyenv shims
RUN pyenv rehash

# Project initialization:
COPY ./compose/django/entrypoint /entrypoint
COPY --chown=django:django ./compose/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint

COPY ./compose/django/start /start
COPY --chown=django:django ./compose/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

USER django

RUN touch __init__.py

# Initialize git and add .
RUN git init
RUN git add .

ENV DJANGO_SETTINGS_MODULE=tests.config.settings

ENTRYPOINT ["/entrypoint"]
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Add package path to sys.path
sys.path.insert(0, os.path.join(os.path.abspath("."), "../"))
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.config.settings"

# Initialize Django
django.setup()
10 changes: 5 additions & 5 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Package settings.
{
IntegerRangeField.__name__: int,
BigIntegerRangeField.__name__: int,
DecimalRangeField.__name__: float,
DateRangeField.__name__: datetime.date,
DecimalRangeField.__name__: Decimal,
DateRangeField.__name__: date,
DateTimeRangeField.__name__: datetime,
}
This is used to convert the range field to a Python type when using the :meth:`django_segments.models.base.AbstractSpanMetaclass.get_range_field` method.
This is used to convert the range field to a Python type when using the :meth:`django_segments.models.base.BaseSpanMetaclass.get_range_field` method.
Global Span Configuration Options
---------------------------------
Expand Down Expand Up @@ -110,12 +110,12 @@ models/base.py
.. automodule:: django_segments.models.base
:members:
.. autoclass:: django_segments.models.base.AbstractSpanMetaclass
.. autoclass:: django_segments.models.base.BaseSpanMetaclass
:members:
:no-index:
:special-members: __new__
.. autoclass:: django_segments.models.base.AbstractSegmentMetaclass
.. autoclass:: django_segments.models.base.BaseSegmentMetaclass
:members:
:no-index:
:special-members: __new__
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Usage

Until this section is complete, please see the [tests](https://github.com/OmenApps/django-segments/tree/main/tests) and the [example project](https://github.com/OmenApps/django-segments/tree/main/example_project) for usage examples.
Until this section is complete, please see the [example app in tests](https://github.com/OmenApps/django-segments/tree/main/tests/example) for usage examples.
1 change: 0 additions & 1 deletion example_project/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion example_project/example/__init__.py

This file was deleted.

22 changes: 0 additions & 22 deletions example_project/example/admin.py

This file was deleted.

90 changes: 0 additions & 90 deletions example_project/example/migrations/0001_initial.py

This file was deleted.

42 changes: 0 additions & 42 deletions example_project/example/models.py

This file was deleted.

1 change: 0 additions & 1 deletion example_project/example/tests.py

This file was deleted.

Loading

0 comments on commit 9a9f4ef

Please sign in to comment.