The story of releasing a Python text check tool on GitHub x CircleCI for the first time

Preface

--I have a Github account, but I haven't published anything ――I sometimes want a general-purpose text check tool, but I didn't really want it, so let's make it and publish it! ――I heard that the next company uses CircleCI --There is also a free plan, so let's use it! ――I will write down the points that I suffered when doing the above.

I made a tool to format and validate dates in Python

[Err file path]/Users/xxxx/Documents/test.txt
[Err]Date format does't conform to rules: 2016/2/29 (Monday) 23:59
[Err]Date format does't conform to rules: 2016/2/29 (Month) 23:59
[Err]Date format does't conform to rules(NG list): \n2/29 (Monday) 23:59
[Err]2016/2/30 isn't exist: 2016/2/30 (Tue) 23:59

――I wanted to check various texts in the future, so I named it text_ broadly.

Difficulties in creating tools

About Python naming conventions

Do you put the test code?

――I will put the conclusion --The test code is also included in TensorFlow published by Google in the world, so I decided that it is okay to put it in. ――As I will describe later, when you want to test with CircleCI, it seems to be troublesome if it is not in the project, so you have to put it in

What is a good library to write test?

--Select pytest. ――I was worried about unittest, but when I asked an experienced Python person, it was intuitively easy to understand, so I chose pytest. It's a simple tool, so you don't have to get lost at this point, and you can wrap it around long ones.

What does the Python file hierarchy look like in the first place?

――Conclusion I made it like this

tree .
.
├── tests #Test related
│   ├── conftest.py
│   └── test_text_verifier.py
├── textverifier #Main module related
│   ├── config.yaml
│   ├── pattern.yaml
│   └── text_verifier.py
└── verify_text.py #Existence that only executes

--It's a unit test, but I used it as a reference! : Directory structure when writing tests with Python 3 standard unittest

I can't run pytest because I can't load the module ...

--The conclusion is that I created conftest.py (which is executed as a pre-process for the entire test) and described the process to pass the relative path of the module directory. --Reference -Import by directly specifying the directory path -Introduction to pytest --Notes from fighting IT engineers --In the above file hierarchy, I imported the module as follows

from text_verifier import TextVerifier

But such an error

ImportError while importing test module 'xxx'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_text_verifier.py:5: in <module>
    from text_verifier import TextVerifier
E   ModuleNotFoundError: No module named 'text_verifier'

--So, I wrote conftest.py under the test directory as follows.

conftest.py


import sys 
import os

sys.path.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../textverifier/"))

About CircleCI

getting started

--By the way, the final config.yml looks like this

version: 2
jobs:
  build:
    docker:
      - image: circleci/python:latest
    steps:
      - checkout

      - run:
          command: |
            sudo pip install pipenv
            pipenv install
            pipenv run pip install pyyaml
            pipenv run pip install pytest
            pipenv run pytest

I want to display the CircleCI batch because it's a big deal

--This is the readme on GitHub  image.png

Does the test result make an error?

--Create a state where an error occurs once in the local test image.png --push! & Run! (Failed properly!) image.png --The error was the same as the local error, and it became FAILED there. image.png --Batch was also FAILED image.png

Impressions

--As for the tool, I noticed it after making it, but there was also a convenient one called textlint ... I wanted to check the format pattern match for this tool. So it's okay, but I felt that the validity check was good with textlint ――Because I've been an uncle Jenkins for a long time, it was quite meaningful just to know CircleCI's glue! I was used to putting the configuration file (execution shell etc.) on the server side, so it was fresh to put it on the repository side (Is GitHub Actions the same?) ――Since it's still the starting line, I'd like to play with CircleCI in particular ... ――Next, I want to make something that can be published on PyPI.

Recommended Posts

The story of releasing a Python text check tool on GitHub x CircleCI for the first time
I tried Python on Mac for the first time.
I tried python on heroku for the first time
See python for the first time
A memorandum of understanding for the Python package management tool ez_setup
The story of making a standard driver for db with python.
The story of returning to the front line for the first time in 5 years and refactoring Python Django
MongoDB for the first time in Python
The story of blackjack A processing (python)
Randomly play the movie on ChromeCast for a certain period of time
A useful note when using Python for the first time in a while
The story of low learning costs for Python
Image processing? The story of starting Python for
At the time of python update on ubuntu
[Note] The story of setting up the SDK for Python of Azure IoT Hub on Linux
Check the processing time and the number of calls for each process in python (cProfile)
The story of creating a "spirit and time chat room" exclusively for engineers in the company
What kind of environment should people who are learning Python for the first time build?
The story of creating a VIP channel for in-house chatwork
The story of how the Python bottle worked on Sakura Internet
Summary of stumbling blocks in Django for the first time
Kaguru for the first time
Put the process to sleep for a certain period of time (seconds) or more in Python
The story of making a tool that runs on Mac and Windows at the game development site
A Python beginner first tried a quick and easy analysis of weather data for the last 10 years.
What I learned by writing a Python Pull Request for the first time in my life
Let's measure the test coverage of pushed python code on GitHub.
A story that struggled to handle the Python package of PocketSphinx
How to check the memory size of a variable in Python
On Linux, the time stamp of a file is a little past.
How to check the memory size of a dictionary in Python
[Python3] Define a decorator to measure the execution time of a function
A command to easily check the speed of the network on the console
I made a scaffolding tool for the Python web framework Bottle
The story of making a module that skips mail with python
Get the number of readers of a treatise on Mendeley in Python
#The command to check the encoding of a text file (ISO-2022-JP, Shift_JIS, EUC-JP, UTF-8 or UTF-16) on Linux is nkf --guess (forget every time)
The story of Python and the story of NaN
[For self-learning] Go2 for the first time
Start Django for the first time
The story of making a tool to load an image with Python ⇒ save it as another name
The story of writing a program
How to use the Slack API using Python to delete messages that have passed a certain period of time for a specific user on a specific channel
The story of making a university 100 yen breakfast LINE bot with Python
The story of having a hard time introducing OpenCV with M1 MAC
Check the in-memory bytes of a floating point number float in Python
I measured the run queue wait time of a process on Linux
The story of the escape probability of a random walk on an integer grid
Get a datetime instance at any time of the day in Python
I made a program to check the size of a file in Python
Python: I want to measure the processing time of a function neatly
Since I'm free, the front-end engineer tried Python (v3.7.5) for the first time.
Check the behavior of destructor in Python
I tried tensorflow for the first time
The story of making Python an exe
Check the existence of the file with python
Python Master RTA for the time being
Check the path of the Python imported module
The story of manipulating python global variables
Memo for creating a text formatting tool
[python] [meta] Is the type of python a type?