Template loader not looking at directories defined in DIRS - python-3.x

I'm trying to add a base template for use in different apps in my Django project. I've created a base.html file at "myapp/templates/base.html"
Here is the relevant info in my settings.py:
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
When I try to load the view in my browser, I get a this error:
TemplateDoesNotExist at /home/
base.html
Request Method: GET
Request URL: http://127.0.0.1:8000/home/
Django Version: 3.1.1
Exception Type: TemplateDoesNotExist
Exception Value:
base.html
Exception Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/template/backends/django.py, line 84, in reraise
Python Executable: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
Python Version: 3.8.5
Python Path:
['/Users/jonmi/PycharmProjects/projects/grocery',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
Server time: Sun, 13 Dec 2020 01:43:02 +0000
As I understand it, the template loader should look in each of my installed_apps' template directories since APP_DIRS is set to True, and it should also look in any directory in the DIRS list. However, the template loader is only looking in the app directories (e.g. myapp/home/templates/home/base.html) and not in anything I add to the DIRS list.
I've tried changing whats in the DIRS list, including just trying to type out the path to base.html as a string myself, but it doesn't check anything I add to the list.
I've seen similar questions asked, but they are all for older versions of Django, and the solutions they've provided did not work for me. There are lots of people who have had the TemplateDoesNotExist error, but this is the question I've found most similar to mine: Django 1.8 ignores DIRS, cannot find templates
However, the solutions posted there did not help me, and the question is about a much older version of Django.
How can I get the template loader to look at what's in the DIRS list?
EDIT:
In trying to add some more info to my question, I figured out what was wrong. I had copy and pasted the TEMPLATES settings from another stackoverflow question into my settings.py, but I hadn't overwritten the old TEMPLATES settings, so they were getting switched back to my initial settings since my old settings were further down in my code.
If you're having this problem, the TEMPLATES settings in my question do indeed work properly.
Thanks to whoever read and commented.

Related

Package.json fields: Child directories are not ignored

I'm working on a large TS-based library. When I build the application, this creates a lot of .d.ts files, most of which are of internal use only, and make no sense to export or ship to the end user. Usually I've used a .npmignore file to keep these out, but recently learned that certain tools really prefer that information to be included via the "files" field of the package.json, so here I am trying to convert.
Now, I have a directory structure that looks somewhat like this:
dist/
--bundle.js
--...
--components/
----componentA.d.ts
----componentB.d.ts
----common/
----...
--hooks/
----...
--util/
----...
The idea is that I want all top level files, and all files directly under /components/ but no child directories. In my .npmignore, I'd do this like:
# blacklist all
**
# include whitelist
!dist/*
!dist/components/*
However, when I do the same under "files" in my package.json, all that crap still comes along. The single wildcard is not respected.
Edit:
"files": [
"dist/*",
"dist/components/*",
...
],
Reproducing what you show of your file system, this works for me:
"files": ["dist/*.js", "dist/components/*.ts"]
Omitting the file extensions indeed included all the subdirectory cruft. I tested with npm 7 and npm 6.

cookie cutter: what's the easiest way to specify variables for the prompts

Is there anything that offers replay-type functionality, by pointing at a predefined prompt-answer file?
What works and what I'd like to achieve.
Let's take an example, using a cookiecutter to prep a Python package for pypi
cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git
You've downloaded /Users/jluc/.cookiecutters/cookiecutter-pypackage before. Is it okay to delete and re-download it? [yes]:
full_name [Audrey Roy Greenfeld]: Spartacus 👈 constant for me/my organization
email [audreyr#example.com]: spartacus#example.com 👈 constant for me/my organization
...
project_name [Python Boilerplate]: GladiatorRevolt 👈 this will vary.
project_slug [q]: gladiator-revolt 👈 this too
...
OK, done.
Now, I can easily redo this, for this project, via:
cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git --replay
This is great!
What I want:
Say I create another project, UnleashHell.
I want to prep a file somehow that has my developer-info and project level info for Unleash. And I want to be able to run it multiple times against this template, without having to deal with prompts. This particular pypi template gets regular updates, for example python 2.7 support has been dropped.
The problem:
A --replay will just inject the last run for this cookiecutter template. If it was run against a different pypi project, too bad.
I'm good with my developer-level info, but I need to vary all the project level info.
I tried copying the replay file via:
cp ~/.cookiecutter_replay/cookiecutter-pypackage.json unleash.json
Edit unleash.json to reflect necessary changes.
Then specify it via --config-file flag
cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git --config-file unleash.json
I get an ugly error, it wants YAML, apparently.
cookiecutter.exceptions.InvalidConfiguration: Unable to parse YAML file .../000.packaging/unleash.json. Error: None of the known patterns match for {
"cookiecutter": {
"full_name": "Spartacus",
No problem, json2yaml to the rescue.
That doesn't work either.
cookiecutter.exceptions.InvalidConfiguration: Unable to parse YAML file ./cookie.yaml. Error: Unable to determine type for "
full_name: "Spartacus"
I also tried a < stdin redirect:
cookiecutter.prompts.txt:
yes
Spartacus
...
It doesn't seem to use it and just aborts.
cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git < ./cookiecutter.prompts.txt
You've downloaded ~/.cookiecutters/cookiecutter-pypackage before. Is it okay to delete and re-download it? [yes]
: full_name [Audrey Roy Greenfeld]
: email [audreyr#example.com]
: Aborted
I suspect I am missing something obvious, not sure what. To start with, what is the intent and format expected for the --config file?
Debrief - how I got it working from accepted answer.
Took accepted answer, but adjusted it for ~/.cookiecutterrc usage. It works but the format is not super clear. Especially not on the rc which has to be yaml, though that's not always/often the case with rc files.
This ended up working:
file ~/.cookiecutterrc:
without nesting under default_context... tons of unhelpful yaml parse errors (on a valid yaml doc).
default_context:
#... cut out for privacy
add_pyup_badge: y
command_line_interface: "Click"
create_author_file: "y"
open_source_license: "MIT license"
# the names to use here are:
# full_name:
# email:
# github_username:
# project_name:
# project_slug:
# project_short_description:
# pypi_username:
# version:
# use_pytest:
# use_pypi_deployment_with_travis:
# add_pyup_badge:
# command_line_interface:
# create_author_file:
# open_source_license:
I still could not get a combination of ~/.cookiecutterrc and a project-specific config.yaml to work. Too bad that expected configuration format is so lightly documented.
So I will use the .rc but enter the project name, slug and description each time. Oh well, good enough for now.
You are near.
Try this cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git --no-input --config-file config.yaml
The --no-input parameter will suppress the terminal user input, it is optional of course.
The config.yaml file could look like this:
default_context:
full_name: "Audrey Roy"
email: "audreyr#example.com"
github_username: "audreyr"
cookiecutters_dir: "/home/audreyr/my-custom-cookiecutters-dir/"
replay_dir: "/home/audreyr/my-custom-replay-dir/"
abbreviations:
pp: https://github.com/audreyr/cookiecutter-pypackage.git
gh: https://github.com/{0}.git
bb: https://bitbucket.org/{0}
Reference to this example file: https://cookiecutter.readthedocs.io/en/1.7.0/advanced/user_config.html
You probably just need the default_context block since that is where the user input goes.

How to set correct root path when use Github Actions ci/cd?

I am trying to use ci/cd workflow with github Actions,
I use jest for unit test and set moduleNameMapper like below:
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/src/$1",
"^components/(.*)$": "<rootDir>/src/components/$1"
}
I can run npm test successfully in local, However github actions always get error:
Could not locate module src/components/tool-panel/Container.vue (mapped as /home/runner/work/its-me/its-me/src/components/tool-panel/Container.vue)
Please check:
"moduleNameMapper": {
"/^src\/(.*)$/": "/home/runner/work/its-me/its-me/src/$1"
},
"resolver": undefined
Seems the <rootDir> is replaced as /home/runner/work/its-me/its-me, and there no folder src in this path: /home/runner/work/its-me/its-me.
So How can i set correct root path?
I am not sure if i can ssh to github action server.
This is my github repo: It's me
Any help would be appreciated!!
I think the problem is that you are referencing the file Container.vue with an uppercase C but the actual file is all lowercase. If your local filesystem is case insensitive it may execute fine.
https://github.com/jeoy/its-me/blob/master/test/unit/toolContainer.spec.js#L8
Change the filename here to all lowercase:
import Container from 'src/components/tool-panel/Container.vue';

Sane RPM custom layout for Artifactory?

I am trying to come up with a sane layout for my RPMs that follow this path structure
<repo_name>/<module_name>/<module_name>-0.0.0-<epoch>.<arch>.rpm
For example, this is a test path:
rpm-rhel7-dev/python-opstools/python-opstools-2.7.6-1.noarch.rpm
Anyone have any hints?
Related documentation
https://www.jfrog.com/confluence/display/RTF/Repository+Layouts
Cleared all packages from 'my-repo'
Created layout 'rpm-default'
Artifact Path Pattern:
[orgPath]/[module]-baseRev-[classifier].[ext]
Folder Integration Revision RegExp
.*
File Integration Revisino RegExp
.*
Once I did this and assigned this layout to my empty repo, I pushed to this path (Jenkins):
upload_spec = """{
"files": [
{
"pattern": "$RPM_ROOT/*.rpm",
"target": "$REPO_NAME/my-module/"
}
]
}"""
Where RPM root is your path to RPM/RPMs per documentation:
https://www.jfrog.com/confluence/display/RTF/RPM+Repositories
https://www.jfrog.com/confluence/display/RTF/Working+With+Pipeline+Jobs+in+Jenkins
https://www.jfrog.com/confluence/display/RTF/Using+File+Specs#UsingFileSpecs-UploadSpecSchema
The key here is to make sure you have a module ID after a push:
Module ID: python-opstools:python-opstools:2.8.0:1
After this, you should see versions to delete or manage when right click the module folder / repo root. Don't ask me yet how to fully deconstruct all the pieces fo the path pattern :P, instead, refer to the documentation:
https://www.jfrog.com/confluence/display/RTF/Repository+Layouts

Is there a html reporter to use with jest-cucumber which shows all the Gherkin annotations on report

I have started using jest-cucumber (https://github.com/bencompton/jest-cucumber) for automating my ReactJS app.
I have tried these reporters with the framework: https://github.com/jest-community/awesome-jest#reporters but I'm not able to see Gherkin steps on the report.
All reports show the test case level details.
I tried to use cucumber-html-reporter https://www.npmjs.com/package/cucumber-html-reporter but unable to use it with jest-cucumber.
Can you suggest any good library which can report the Gherkin annotations step by step which will look like https://www.npmjs.com/package/cucumber-html-reporter
Steps to be followed:
1) Install jest-cucumber with version v2.0.12 that supports reporting. During this writeup this version was not available as stable version of npm. You need to specifically give the version number when installing this.
2) Add below paramter in jest config to specify the report storage location. The jest-cucumber outputs a json file.
reporters: [
"default",
[
"./node_modules/jest-cucumber/dist/src/reporter", //This is the default path
{
formatter: "json",
path: "./tests/integration-test-results/test-report.json" //specific path
}
]
]
3) Create a index.js file for cucumber-html-report conf and mention the location of above created json file and output when the html file need to be placed. For more info, refer: https://www.npmjs.com/package/cucumber-html-reporter
4) Create package.json command as shown below for ease of use so that once the BDD test completes, the report is automatically generated and displayed.
"test-bdd": "jest --config=jest-cucumber.config.js && node ./cucumber-report-config.js"
5) Run: npm run test-bdd
I got it working with cucumber-html-reporter and jest-cucumber version 2.0.12. Please check the issue #27 of jest-cucumber: https://github.com/bencompton/jest-cucumber/issues/27.

Resources