Yii2 deployment for contributing - unit-testing

I am beginner Yii2 contributor. When I contribute in yiisoft/yii2 project, it is quite clear how to deploy the project and run its phpunit-tests. But I have some questions about working with extensions:
First I add an extension with composer require. Then git clone the same extension inside my home directory. After that I replace the first directory with symlink, which pointed to the second one. It is quite convenient due to I can see changes on the site, but I can't use composer anymore.
How to run the extension`s tests? They often depend on Yii2 app class, but
$ vendor/bin/phpunit vendor/yiisoft/yii2-elasticsearch/tests/
PHP Fatal error: Class 'yiiunit\extensions\elasticsearch\TestCase' not found in /var/www/yii2.test/vendor/yiisoft/yii2-elasticsearch/tests/ActiveDataProviderTest.php on line 11
$ vendor/bin/phpunit vendor/yiisoft/yii2-queue/tests/
PHP Fatal error: Class 'tests\TestCase' not found in /var/www/yii2.test/vendor/yiisoft/yii2-queue/tests/JobEventTest.php on line 22
Should I specify a config file? Or should I run these tests independently
of the framework?
So, would you please share with me the best practices about this situation?

You should run these tests outside of the framework. From extension perspective, yiisoft/yii2 is a dependency and should be installed in vendor directory inside of extension directory. So in short, you should go to extension directory and call composer install. After this you should get directory structure similar to this:
extension/
├── src/
│ └── ...
├── vendor/
│ ├── yiisoft/
│ │ ├── yii2/
│ │ └── ...
│ └── ...
├──composer.json
└── ...
Then you can run tests directly from extension directory (probably by vendor/bin/phpunit command).

Related

Best way to auto update Poetry TOML versions

I'm managing a repo which maintains common utilities, this repo has my common utils, jenkins file and all the dependencies are managed by Poetry so I've some TOML files to manage. We keep adding new utils as we go on.
.
├── Jenkinsfile
├── README.md
├── common_utils
│ ├── __init__.py
│ ├── aws.py
│ ├── sftp.py
├── pre-commit.yaml
├── poetry.lock
└── pyproject.toml
When I push my code to git, my Jenkinsfile packages it and publishes it to AWS code artifact. But everything time I push it, I've to manually update the TOML version in my local first before I push it to dev branch and then pull a new branch from dev to update the version again before pushing to master branch to update the version again otherwise I get a conflict on TOML version in code artifact.
I can't modify the Jenkins because even though it solves the conflict issue by updating the version, the version in the source code isn't modified, which means I still need to manually update all the versions manually. I'm not sure if pre-commit will help because I dont want to update the version every time I push to feature branch.
Is there a known way to handle this or is going with a release branch the only option?

Django & coverage - .coveragerc omit not working

I have a Django project with multiple applications. In one application, I have a library already tested using unittest + coverage.
When I run the test of the django project, I would like to omit this folder.
My project architecture is :
project/
├── application1/
│ ├── tests.py
│ ├── views.py
│ ├── ...
│ └── my_lib/ << The lib I want to omit
│ ├── tests.py
│ ├── script.py
│ ├── __init__.py
│ └── ...
├── application2/
│ ├── tests.py
│ ├── views.py
│ └── ...
├── application3/
│ ├── tests.py
│ ├── views.py
│ └── ...
├── .coveragerc
├── runtest.bat
├── manage.py
└── ...
runtest.bat is :
CALL activate ./venv
coverage erase
coverage run manage.py test
coverage html
PAUSE
Based on several tutorials and SO questions, I've tried several .coveragerc files but none of them properly skipped the library. Testing it creates a fail because it tries to load with the incorrect relative path.
.coveragerc is :
[run]
omit =
*/application1/my_lib/*
[report]
exclude_lines =
if __name__ == .__main__.:
show_missing = True
I also tried :
[run]
source = .
omit =
/application1/my_lib/*
[run]
source = project/*
omit =
*/application1/my_lib/*
[run]
source = .
omit =
*/application1/my_lib/*
Do you have any clue what am I doing wrong ?
For information :
Django version is 2.2.5
Coverage version is 4.5.4
Python version is 3.7
Few sources :
Django Coverage
Coverage Documentation
SO question
Thanks in advance
EDIT 1:
Just as a background. my_lib is mainly a file containing a class. This code is just embedded in the application to be used "like" a standard library.
In application1/views.py, I simply have a from . import my_lib.
In application1/my_lib/__init__.py, I have from .script import MyClass
The objective is simply to be able then to use in my view with my_lib.MyClass.do_something()
Now the reason why I would like to exclude this "library" from the coverage is because this was developped out of the application. It has his own unittest in applications1/my_lib/tests/py starting with from script import MyClass.
When I run the coverage in the root of the project, Python cannot find script.py in the root of the project so it triggers the error
File "path_to/project/application1/my_lib/tests.py", line 3
from script import MyClass
ModuleNotFoundError: No module named script.
In the worst case scenario, I could put this library to site-packages of my virtual environment bu I would like to avoid it (there will be probably multiple similar my_lib with at most 1 per application)
EDIT 2:
As a temporary solution, I simply renamed application1/my_lib/tests.py by application1/my_lib/script_tests.py. There is no file starting by test so the coverage does not care about this folder anymore.
The other alternative to run the test at the same time as the project required quite a lot of updates due to relative path used to several files

The only page I see in my Django project is "migrations." I'm new to Django and the command line and am trying to create a "Hello World" page

I'm totally new to Django and the command line.. so please bear with me :)
I started a Django project in virtualenv - but the "tree" doesn't show much at all. According to the tutorial I'm using (https://djangoforbeginners.com/hello-world/), after typing
$ django-admin startproject helloworld_project .
and entering
$ tree
I should have seen:
├── Pipfile
├── Pipfile.lock
├── helloworld_project
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
However, I only got:
C:.
└── helloworld_project
I see these files in the directory when I open the folder with the Windows explorer, though. How do I see the whole tree?
I'm trying to create a "Hello World" page in Django using this tutorial:
https://djangoforbeginners.com/hello-world/ ...
Thank you!!!!
This isn't really a question about Django.
The tutorial is clearly written for Mac users (by the mention of homebrew). You're using Windows (as we can see because of the "C:" entry in your tree). The tree command differs between those platforms; on Unix-like platforms such as Mac, it shows the files in all folders by default, but on Windows, you need to use the /f flag. So:
tree /f

How to deploy a Go web application in Beanstalk with custom project folder structure

I'm new to Go.
I am trying to deploy a simple web project to EB without success.
I would like to deploy a project with the following local structure to Amazon EB:
$GOPATH
├── bin
├── pkg
└── src
├── github.com
│   ├── AstralinkIO
│   │   └── api-server <-- project/repository root
│   │   ├── bin
│   │   ├── cmd <-- main package
│   │   ├── pkg
│   │   ├── static
│   │   └── vendor
But I'm not sure how to do that, when building the command, Amazon is treating api-server as the $GOPATH, and of course import paths are broken.
I read that most of the time it's best to keep all repos under the same workspace, but it makes deployment harder..
I'm using Procfile and Buildfile to customize output path, but I can't find a solution to dependencies.
What is the best way to deploy such project to EB?
Long time has past since I used Beanstalk, so I'm a bit rusty on the details. But basic idea is as follows. AWS Beanstalk support for go is a bit odd by design. It basically extracts your source files into a folder on the server, declares that folder as GOPATH and tries to build your application assuming that your main package is at the root of your GOPATH. Which is not a standard layout for go projects. So your options are:
1) Package your whole GOPATH as "source bundle" for Beanstalk. Then you should be able to write build.sh script to change GOPATH and build it your way. Then call build.sh from your Buildfile.
2) Change your main package to be a regular package (e.g. github.com/AstralinkIO/api-server/cmd). Then create an application.go file at the root of your GOPATH (yes, outside of src, while all actual packages are in src as they should be). Your application.go will become your "package main" and will only contain a main function (which will call your current Main function from github.com/AstralinkIO/api-server/cmd). Should do the trick. Though your mileage might vary.
3) A bit easier option is to use Docker-based Go Platform instead. It still builds your go application on the server with mostly same issues as above, but it's better documented and possibility to test it locally helps a lot with getting configuration and build right. It will also give you some insights into how Beanstalk builds go applications thus helping with options 1 and 2. I used this option myself until I moved to plain EC2 instances. And I still use skills gained as a result of it to build my current app releases using docker.
4) Your best option though (in my humble opinion) is to build your app yourselves and package it as a ready to run binary file. See second bullet point paragraph here
Well, which ever option you choose - good luck!

Ember.js project directory structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Is there any good tutorial or Ember.js document describing directory structure for models / views / controllers, app.js and the way to reference those files in the index.html root file.
File to create the "Ember.Application.create" ?
order of inclusion (models.js, apps.js, controllers.js) ?
This tutorial by Dan Gebhardt was very helpful to me in setting up my project structure and figuring out how to include files.
The ember-skeleton project has a reasonable example of project layout for rake pipeline. They do it something like this (from the README):
ember-skeleton
├── Assetfile - App build file
├── Gemfile - Package dependencies for rakep/rack
├── Gemfile.lock - Here be dragons: don't touch, always include
├── app - App specific code
│ ├── css - App CSS or SCSS (.scss)
│ ├── lib - App code, *modularized during build*
│ ├── modules - Module code, *already modularized*
│ ├── plugins - Plugins (e.g. jquery.jsonrpc.js)
│ │ └── loader.js - JS module loader
│ ├── static - Static files, never touched, copied over during build
│ ├── templates - Handlebars templates, *modularized during build*
│ ├── tests - QUnit application tests
│ └── vendor - Vendor code, *modularized during build*
├── assets - Built out asset files, minified in production
│ ├── app.css - Built out app CSS/SCSS
│ ├── app.js - Built out app JS
│ └── loader.js - Built out JS module loader
├── config.ru - Rack development web server configuration
├── index.html - The app entry point
├── tests - QUnit testing files
│ ├── index.html - The testing entry point
│ ├── qunit - Testing support files
│ └── run-tests.js - The PhantomJS QUnit test runner
└── tmp - Temporary build files used by rakep
I have a layout that I am pretty happy with
app.js - this is the main application file and includes settings and the router
views.js - contains views used within the app, although I usually now split this out to homeView.js navigtaionView.js etc
dataModels.js - this is where I hold all my data model objects for the app
dataSources.js - I use this to load datamodels or arrays of datamodels from any api calls I make
accountController.js - controller class, in the attached sample I also have an emailMessagingController and an smsMessagingController
You can find my sample project here
https://github.com/bwship/neptunejs
and the coffeescript files for ember here
https://github.com/bwship/neptunejs/tree/master/public/coffeescripts
and finally the jad file for the layout and index showing how I add these here
https://github.com/bwship/neptunejs/tree/master/views
I do want to eventually start using the ember data style, but have put out a few solid apps using the dataSources and dataModels files.
There still seems to be no clear convention, but currently many people seem to be using Yeoman and the official Ember generator https://github.com/yeoman/generator-ember
While I appreciate the "open" nature of the Ember tutorials, one of the nice things about Rails is the convention of file placement. When we hire a new developer, we don't need to give an explanation about our directory structure... I hope Ember sets an official standard soon.